Class: OpenLoam::Mcp::Server
- Inherits:
-
Object
- Object
- OpenLoam::Mcp::Server
- Defined in:
- lib/open_loam/mcp/server.rb
Overview
The stdio transport for the OpenLoam MCP server (L-302): newline-delimited JSON-RPC over stdin/stdout, the MCP-spec stdio binding. Authenticates ONCE from OPEN_LOAM_MCP_TOKEN (a OpenLoam API token — never a tool argument, so it can't land in an agent transcript), then runs every message inside that token's tenant + actor. Nothing but JSON-RPC is written to stdout; logs go to stderr (wired in the rake task) — a stray stdout line corrupts the stream.
Instance Method Summary collapse
-
#initialize(input: $stdin, output: $stdout, token: ENV["OPEN_LOAM_MCP_TOKEN"]) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(input: $stdin, output: $stdout, token: ENV["OPEN_LOAM_MCP_TOKEN"]) ⇒ Server
Returns a new instance of Server.
12 13 14 15 16 |
# File 'lib/open_loam/mcp/server.rb', line 12 def initialize(input: $stdin, output: $stdout, token: ENV["OPEN_LOAM_MCP_TOKEN"]) @input = input @output = output @token = token end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/open_loam/mcp/server.rb', line 18 def run api_token = OpenLoam::ApiToken.authenticate(@token) return fail_auth unless api_token tenant = api_token.tenant actor = api_token.user @input.each_line do |line| line = line.strip next if line.empty? request = parse(line) next write(OpenLoam::Mcp.err(nil, -32700, "parse error")) if request.nil? begin response = OpenLoam.as_tenant(tenant, actor: actor) { OpenLoam::Mcp.handle_jsonrpc(request) } write(response) if response ensure OpenLoam::Current.reset end end end |