(sigil mcp server)

MCP server implementation.

Provides the main server loop, message routing, and MCP protocol handling for the Sigil MCP server.

Exports

mcp-serverprocedure

Construct a mcp-server struct.

mcp-server?procedure

Test if a value is a mcp-server struct.

Get the name field of a mcp-server struct.

Get the version field of a mcp-server struct.

Get the tools field of a mcp-server struct.

Get the resources field of a mcp-server struct.

Get the prompts field of a mcp-server struct.

Get the capabilities field of a mcp-server struct.

Get the instructions field of a mcp-server struct.

Get the initialized field of a mcp-server struct.

Get the legacy-only field of a mcp-server struct.

Set the tools field of a mcp-server struct.

Set the resources field of a mcp-server struct.

Set the prompts field of a mcp-server struct.

Set the initialized field of a mcp-server struct.

Set the initialized field of a mcp-server struct.

tool-defprocedure

Construct a tool-def struct.

tool-def?procedure

Test if a value is a tool-def struct.

tool-def-nameprocedure

Get the name field of a tool-def struct.

Get the description field of a tool-def struct.

Get the input-schema field of a tool-def struct.

Get the handler field of a tool-def struct.

Get the handler field of a tool-def struct.

resource-defprocedure

Construct a resource-def struct.

resource-def?procedure

Test if a value is a resource-def struct.

Get the uri field of a resource-def struct.

Get the name field of a resource-def struct.

Get the description field of a resource-def struct.

Get the mime-type field of a resource-def struct.

Get the handler field of a resource-def struct.

Get the handler field of a resource-def struct.

prompt-defprocedure

Construct a prompt-def struct.

prompt-def?procedure

Test if a value is a prompt-def struct.

Get the name field of a prompt-def struct.

Get the description field of a prompt-def struct.

Get the arguments field of a prompt-def struct.

Get the handler field of a prompt-def struct.

Register a tool with the server.

Register a resource with the server.

Register a prompt with the server.

Send a notification from the server to the client.

Used for server-initiated messages such as channel events. The notification is written as a JSON-RPC message to the current output port.

Examples:

(mcp-server-notify! server "notifications/claude/channel"
  params: '((content . "new message")
            (meta . ((sender . "david")))))

The server's identity, as initialize and _meta.serverInfo both want it.

A function rather than two exported field accessors: transports need the pair together, and this keeps the struct's shape private so a field can be renamed without breaking an importer.

Does a modern-era result for method have to carry cache metadata?

The modern protocol revision a request names in its _meta, or #f when the request is legacy (no _meta version, or a revision that is only reachable through initialize).

A modern client sends its version on EVERY request instead of negotiating it once, so this is how a transport tells which shape of result the client will validate against.

Stamp a successful result with the envelope every modern result owes: resultType, _meta.serverInfo, and ttlMs/cacheScope for the methods that require them. Error responses pass through untouched -- the spec puts none of this on an error.

A modern client REJECTS a listing without the cache fields rather than defaulting them: Claude Code 2.1.282 validates tools/list against a schema where both are required, retries a few times, and then registers no tools at all.

Idempotent: a result that already carries resultType is returned unchanged, so a transport may stamp a response that mcp-server-handle-message has already stamped without emitting duplicate JSON keys.

Answer server/discover: the versions, capabilities and identity a client reads before sending anything else. Required of every server from revision 2026-07-28, and harmless on stdio, so it is answered here rather than in a single transport.

Handle a parsed JSON-RPC message and return a response (or #f for notifications).

A request whose _meta names protocol revision 2026-07-28 gets a result in that revision's shape (see mcp-augment-modern-result), so a custom read loop can write the response as-is.

(No description)