@@ -30,7 +30,7 @@ class McpProcessor
3030 def initialize ( body :, status :)
3131 @body = body
3232 @status = status
33- super ( " MCP parse error" )
33+ super ( ' MCP parse error' )
3434 end
3535 end
3636
@@ -46,17 +46,17 @@ def root_endpoint
4646
4747 def rpc_endpoint ( raw_body )
4848 req = JSON . parse ( raw_body . to_s )
49- method = req [ " method" ]
50- params = req [ " params" ]
49+ method = req [ ' method' ]
50+ params = req [ ' params' ]
5151
52- if req . key? ( "id" )
53- rpc_response ( id : req [ "id" ] , method : method , params : params )
52+ if req . key? ( 'id' )
53+ rpc_response ( id : req [ 'id' ] , method : method , params : params )
5454 else
5555 notification_response ( method : method , params : params )
5656 end
5757 rescue JSON ::ParserError => e
5858 @logger &.warn ( "MCP JSON parse failed: #{ e . message } " )
59- body = error_response ( id : nil , code : -32700 , message : " Parse error" )
59+ body = error_response ( id : nil , code : -32_700 , message : ' Parse error' )
6060 raise ParseError . new ( body : body , status : 400 )
6161 end
6262
@@ -86,21 +86,21 @@ def notification_response(method:, params:)
8686
8787 def handle ( method :, params :)
8888 case method
89- when " tools/list" then list_tools
90- # when " resources/list" then {}
91- # when " prompts/list" then {}
92- when " tools/call" then call_tool ( params || { } )
93- when " initialize" then initialize_response
94- when " notifications/initialized" then @logger &.debug ( params ) ; { }
95- when " logging/setLevel" then @logger &.debug ( params ) ; { }
89+ when ' tools/list' then list_tools
90+ # when ' resources/list' then {}
91+ # when ' prompts/list' then {}
92+ when ' tools/call' then call_tool ( params || { } )
93+ when ' initialize' then initialize_response
94+ when ' notifications/initialized' then @logger &.debug ( params ) ; { }
95+ when ' logging/setLevel' then @logger &.debug ( params ) ; { }
9696 else
97- rpc_error! ( -32601 , "Unknown method #{ method } " )
97+ rpc_error! ( -32_601 , "Unknown method #{ method } " )
9898 end
9999 end
100100
101101 def handle_notification ( method :, params :)
102102 case method
103- when " notifications/initialized" , " notifications/cancelled"
103+ when ' notifications/initialized' , ' notifications/cancelled'
104104 @logger &.debug ( "MCP notification accepted: #{ method } " )
105105 else
106106 @logger &.debug ( "MCP notification ignored: #{ method } " )
@@ -127,7 +127,7 @@ def initialize_response
127127 private
128128
129129 def json_rpc_response ( id :)
130- body = { jsonrpc : " 2.0" , id : id }
130+ body = { jsonrpc : ' 2.0' , id : id }
131131
132132 begin
133133 result = yield
@@ -136,17 +136,17 @@ def json_rpc_response(id:)
136136 body [ :error ] = { code : e . code , message : e . message }
137137 rescue => e
138138 @logger &.error ( "Unhandled RPC error: #{ e . class } : #{ e . message } \n #{ e . backtrace &.first } " )
139- body [ :error ] = { code : -32603 , message : " Internal error" }
139+ body [ :error ] = { code : -32_603 , message : ' Internal error' }
140140 end
141141
142142 body . delete ( :result ) if body [ :error ]
143143 JSON . dump ( body )
144144 end
145145
146146 def call_tool ( params )
147- name = params [ " name" ]
148- arguments = params [ " arguments" ] || { }
149- tool = registry . fetch ( name ) || rpc_error! ( -32601 , "Unknown tool #{ name } " )
147+ name = params [ ' name' ]
148+ arguments = params [ ' arguments' ] || { }
149+ tool = registry . fetch ( name ) || rpc_error! ( -32_601 , "Unknown tool #{ name } " )
150150 response = tool . call_tool ( arguments )
151151 return response if mcp_tool_response? ( response )
152152
@@ -160,15 +160,15 @@ def registry
160160 def mcp_tool_response? ( response )
161161 return false unless response . is_a? ( Hash )
162162
163- [ :content , :structuredContent , :isError , " content" , " structuredContent" , " isError" ] . any? do |key |
163+ [ :content , :structuredContent , :isError , ' content' , ' structuredContent' , ' isError' ] . any? do |key |
164164 response . key? ( key )
165165 end
166166 end
167167
168168 def wrap_tool_response ( response )
169169 {
170170 content : [
171- { " type" : " text" , " text" : response . is_a? ( String ) ? response : JSON . dump ( response ) }
171+ { ' type' => ' text' , ' text' => response . is_a? ( String ) ? response : JSON . dump ( response ) }
172172 ] ,
173173 isError : false
174174 }
0 commit comments