Skip to content

Commit cd008bc

Browse files
committed
refactor structure
1 parent 0fd3ac7 commit cd008bc

19 files changed

+332
-317
lines changed

.vscode/mcp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"servers": {
3-
"mcp-posts-server": {
3+
"rails-app-mcp": {
44
"type": "http",
55
"url": "http://localhost:3000/mcp"
66
}

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ bin/rails test
6969
│ Expondo endpoint: /mcp │
7070
│------------------------------------------│
7171
│ Tools: │
72-
│ - create_post_tool
73-
│ - delete_post_tool
74-
│ - list_posts_tool
75-
│ - show_post_tool
76-
│ - update_post_tool
72+
│ - post-create-tool
73+
│ - post-delete-tool
74+
│ - post-index-tool
75+
│ - post-show-tool
76+
│ - post-update-tool
7777
│------------------------------------------│
7878
│ Usa models e lógica do Rails: │
7979
│ Post.create, Post.all, etc. │

app/controllers/mcp_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def handle
2626
version: "1.0.0",
2727
instructions: INSTRUCTIONS,
2828
tools: [
29-
ListPostsTool,
30-
ShowPostTool,
31-
CreatePostTool,
32-
UpdatePostTool,
33-
DeletePostTool
29+
Posts::IndexTool,
30+
Posts::ShowTool,
31+
Posts::CreateTool,
32+
Posts::UpdateTool,
33+
Posts::DeleteTool
3434
],
3535
)
3636

app/mcp_tools/create_post_tool.rb

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/mcp_tools/delete_post_tool.rb

Lines changed: 0 additions & 40 deletions
This file was deleted.

app/mcp_tools/list_posts_tool.rb

Lines changed: 0 additions & 64 deletions
This file was deleted.

app/mcp_tools/show_post_tool.rb

Lines changed: 0 additions & 40 deletions
This file was deleted.

app/mcp_tools/update_post_tool.rb

Lines changed: 0 additions & 58 deletions
This file was deleted.

app/tools/posts/create_tool.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module Posts
2+
class CreateTool < MCP::Tool
3+
tool_name "post-create-tool"
4+
description "Cria uma nova postagem no blog"
5+
6+
input_schema(
7+
properties: {
8+
title: {
9+
type: "string",
10+
description: "Título da postagem (obrigatório)"
11+
},
12+
description: {
13+
type: "string",
14+
description: "Descrição/conteúdo da postagem (obrigatório)"
15+
}
16+
},
17+
required: [ "title", "description" ]
18+
)
19+
20+
def self.call(title:, description:, server_context:)
21+
post = Post.new(title: title, description: description)
22+
23+
if post.save
24+
MCP::Tool::Response.new([ {
25+
type: "text",
26+
text: "Post criado com sucesso! ID: #{post.id}, Título: #{post.title}"
27+
} ])
28+
else
29+
MCP::Tool::Response.new([ {
30+
type: "text",
31+
text: "Erro ao criar post: #{post.errors.full_messages.join(', ')}"
32+
} ])
33+
end
34+
rescue StandardError => e
35+
MCP::Tool::Response.new([ {
36+
type: "text",
37+
text: "Erro ao criar post: #{e.message}"
38+
} ])
39+
end
40+
end
41+
end

app/tools/posts/delete_tool.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module Posts
2+
class DeleteTool < MCP::Tool
3+
tool_name "post-delete-tool"
4+
description "Deleta uma postagem do blog"
5+
6+
input_schema(
7+
properties: {
8+
id: {
9+
type: "integer",
10+
description: "ID da postagem a ser deletada"
11+
}
12+
},
13+
required: [ "id" ]
14+
)
15+
16+
def self.call(id:, server_context:)
17+
post = Post.find(id)
18+
title = post.title
19+
20+
if post.destroy
21+
MCP::Tool::Response.new([ {
22+
type: "text",
23+
text: "Post '#{title}' (ID: #{id}) deletado com sucesso!"
24+
} ])
25+
else
26+
MCP::Tool::Response.new([ {
27+
type: "text",
28+
text: "Erro ao deletar post: #{post.errors.full_messages.join(', ')}"
29+
} ])
30+
end
31+
rescue ActiveRecord::RecordNotFound
32+
MCP::Tool::Response.new([ {
33+
type: "text",
34+
text: "Post com ID #{id} não encontrado"
35+
} ])
36+
rescue StandardError => e
37+
MCP::Tool::Response.new([ {
38+
type: "text",
39+
text: "Erro ao deletar post: #{e.message}"
40+
} ])
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)