Module: LLM::MCP::RPC
- Included in:
- LLM::MCP
- Defined in:
- lib/llm/mcp/rpc.rb
Overview
The RPC module provides the JSON-RPC interface used by LLM::MCP. MCP uses JSON-RPC to exchange messages between a client and a server. A client sends a method name and its parameters as a request, and the server replies with either a result or an error.
This module is responsible for composing those requests, applying the defaults needed by built-in MCP methods such as initialize, and reading responses for request methods. Notifications are sent without waiting for a response, and errors are raised as Error.
Instance Method Summary collapse
-
#call(transport, method, params = {}) ⇒ Object?
Sends a method over the transport.
Instance Method Details
#call(transport, method, params = {}) ⇒ Object?
Sends a method over the transport.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/llm/mcp/rpc.rb', line 27 def call(transport, method, params = {}) = {jsonrpc: "2.0", method:, params: default_params(method).merge(params)} if notification?(method) router.write(transport, ) return nil end id, mailbox = router.register begin router.write(transport, .merge(id:)) recv(transport, id, mailbox) ensure router.clear(id) end end |