@@ -21,6 +21,30 @@ class UpdateTool < MCP::Tool
2121 required : [ "id" ]
2222 )
2323
24+ output_schema (
25+ properties : {
26+ success : {
27+ type : "boolean" ,
28+ description : "Se a operação foi bem-sucedida"
29+ } ,
30+ post : {
31+ type : "object" ,
32+ properties : {
33+ id : { type : "integer" } ,
34+ title : { type : "string" } ,
35+ description : { type : "string" } ,
36+ created_at : { type : "string" , format : "date-time" } ,
37+ updated_at : { type : "string" , format : "date-time" }
38+ }
39+ } ,
40+ message : {
41+ type : "string" ,
42+ description : "Mensagem de retorno"
43+ }
44+ } ,
45+ required : [ "success" , "message" ]
46+ )
47+
2448 def self . call ( id :, title : nil , description : nil , server_context :)
2549 post = Post . find ( id )
2650
@@ -31,30 +55,44 @@ def self.call(id:, title: nil, description: nil, server_context:)
3155 if update_params . empty?
3256 return MCP ::Tool ::Response . new ( [ {
3357 type : "text" ,
34- text : "Nenhum campo fornecido para atualização"
58+ text : { success : false , message : "Nenhum campo fornecido para atualização" } . to_json
3559 } ] )
3660 end
3761
3862 if post . update ( update_params )
63+ result = {
64+ success : true ,
65+ post : {
66+ id : post . id ,
67+ title : post . title ,
68+ description : post . description ,
69+ created_at : post . created_at . iso8601 ,
70+ updated_at : post . updated_at . iso8601
71+ } ,
72+ message : "Post atualizado com sucesso!"
73+ }
74+
75+ output_schema . validate_result ( result )
76+
3977 MCP ::Tool ::Response . new ( [ {
4078 type : "text" ,
41- text : "Post atualizado com sucesso! ID: #{ post . id } , Título: #{ post . title } "
79+ text : result . to_json
4280 } ] )
4381 else
4482 MCP ::Tool ::Response . new ( [ {
4583 type : "text" ,
46- text : "Erro ao atualizar post: #{ post . errors . full_messages . join ( ', ' ) } "
84+ text : { success : false , message : "Erro ao atualizar post: #{ post . errors . full_messages . join ( ', ' ) } " } . to_json
4785 } ] )
4886 end
4987 rescue ActiveRecord ::RecordNotFound
5088 MCP ::Tool ::Response . new ( [ {
5189 type : "text" ,
52- text : "Post com ID #{ id } não encontrado"
90+ text : { success : false , message : "Post com ID #{ id } não encontrado" } . to_json
5391 } ] )
5492 rescue StandardError => e
5593 MCP ::Tool ::Response . new ( [ {
5694 type : "text" ,
57- text : "Erro ao atualizar post: #{ e . message } "
95+ text : { success : false , message : "Erro ao atualizar post: #{ e . message } " } . to_json
5896 } ] )
5997 end
6098 end
0 commit comments