Class: Rasti::AI::MCP::Server
- Inherits:
-
Object
- Object
- Rasti::AI::MCP::Server
- Extended by:
- ClassConfig
- Defined in:
- lib/rasti/ai/mcp/server.rb
Constant Summary collapse
- ToolSpecification =
Rasti::Model[:tool, :serialization]
- PROTOCOL_VERSION =
'2024-11-05'.freeze
- JSON_RPC_VERSION =
'2.0'.freeze
Class Method Summary collapse
- .call_tool(name, arguments = {}) ⇒ Object
- .clear_tools ⇒ Object
- .register_tool(tool) ⇒ Object
- .tools_serializations ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(app) ⇒ Server
Returns a new instance of Server.
46 47 48 |
# File 'lib/rasti/ai/mcp/server.rb', line 46 def initialize(app) @app = app end |
Class Method Details
.call_tool(name, arguments = {}) ⇒ Object
33 34 35 36 |
# File 'lib/rasti/ai/mcp/server.rb', line 33 def call_tool(name, arguments={}) raise "Tool #{name} not found" unless tools.key? name tools[name].tool.call arguments end |
.clear_tools ⇒ Object
25 26 27 |
# File 'lib/rasti/ai/mcp/server.rb', line 25 def clear_tools tools.clear end |
.register_tool(tool) ⇒ Object
19 20 21 22 23 |
# File 'lib/rasti/ai/mcp/server.rb', line 19 def register_tool(tool) serialization = ToolSerializer.serialize tool.class raise "Tool #{serialization[:name]} already exist" if tools.key? serialization[:name] tools[serialization[:name]] = ToolSpecification.new tool: tool, serialization: serialization end |
.tools_serializations ⇒ Object
29 30 31 |
# File 'lib/rasti/ai/mcp/server.rb', line 29 def tools_serializations tools.values.map(&:serialization) end |
Instance Method Details
#call(env) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/rasti/ai/mcp/server.rb', line 50 def call(env) request = Rack::Request.new env if request.post? && request.path == self.class.relative_path handle_mcp_request request else app.call env end end |