Class: Whoosh::MCP::Server
- Inherits:
-
Object
- Object
- Whoosh::MCP::Server
- Defined in:
- lib/whoosh/mcp/server.rb
Instance Method Summary collapse
- #handle(request) ⇒ Object
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #list_tools ⇒ Object
- #register_tool(name:, description:, input_schema: {}, handler:) ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
8 9 10 |
# File 'lib/whoosh/mcp/server.rb', line 8 def initialize @tools = {} end |
Instance Method Details
#handle(request) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/whoosh/mcp/server.rb', line 20 def handle(request) id = request["id"] method = request["method"] params = request["params"] || {} case method when "initialize" Protocol.response(id: id, result: { protocolVersion: Protocol::SPEC_VERSION, capabilities: { tools: { listChanged: false } }, serverInfo: { name: "whoosh", version: Whoosh::VERSION } }) when "tools/list" Protocol.response(id: id, result: { tools: list_tools }) when "tools/call" handle_tools_call(id, params) when "ping" Protocol.response(id: id, result: {}) when "notifications/initialized" nil else Protocol.error_response(id: id, code: -32601, message: "Method not found: #{method}") end end |
#list_tools ⇒ Object
16 17 18 |
# File 'lib/whoosh/mcp/server.rb', line 16 def list_tools @tools.values.map { |t| { name: t[:name], description: t[:description], inputSchema: t[:inputSchema] } } end |
#register_tool(name:, description:, input_schema: {}, handler:) ⇒ Object
12 13 14 |
# File 'lib/whoosh/mcp/server.rb', line 12 def register_tool(name:, description:, input_schema: {}, handler:) @tools[name] = { name: name, description: description, inputSchema: input_schema, handler: handler } end |