Class: OKF::MCP::Server::Definition

Inherits:
MCP::Server
  • Object
show all
Defined in:
lib/okf/mcp/server.rb

Overview

The SDK takes resources: as a fixed array at construction, and that is the wrong lifetime for this one: the registry re-reads itself whenever the file moves underneath it (Registry#entries), so a boot snapshot drifts out of step with the served set. A bundle registered afterwards was never advertised, and a removed one stayed advertised until a read of the very URI we published came back "unknown bundle" — and with no listChanged declared, a host had no way to be told either.

resources/list is the only place the cost is owed, so it is the only place that recomputes: one stat per bundle, no bundle read, the same price Resources.list always paid. The public resources= setter is what does the mutation, so the SDK's URI index is rebuilt with it.

Instance Method Summary collapse

Constructor Details

#initialize(registry:, context:, **options) ⇒ Definition

Returns a new instance of Definition.



127
128
129
130
131
# File 'lib/okf/mcp/server.rb', line 127

def initialize(registry:, context:, **options)
  @registry = registry
  @context = context
  super(**options)
end

Instance Method Details

#handle(request, session: nil) ⇒ Object

One request is one unit of work. Both public entry points are wrapped and handle_request deliberately is not: the JSON-RPC layer treats the handler block as a lookupmethod = method_finder.call(name) then method.call(params) — so handle_request has already returned by the time the tool body runs, and a wrapper there encloses nothing.

Two things are owed per request rather than per tool:

The fingerprint memo, because a tool asks the engine for the catalog and then reads the unparseable count off the same folder, and each ask re-walked the tree — a glob plus a stat per markdown file, inside the residency lock. Freshness is a question between requests; asking it three times within one buys nothing and costs three walks.

The residency prune, because the served set is that cache's only honest bound and the registry re-read made the set movable. Anything the registry no longer names is dropped here, so a repointed entry stops retaining the bundle its slug used to mean.



151
152
153
# File 'lib/okf/mcp/server.rb', line 151

def handle(request, session: nil)
  in_request { super }
end

#handle_json(request, session: nil) ⇒ Object



155
156
157
# File 'lib/okf/mcp/server.rb', line 155

def handle_json(request, session: nil)
  in_request { super }
end