McpProtocolImpl

class McpProtocolImpl(registry: ToolRegistry, serverName: String = "droid-mcp", serverVersion: String = DROID_MCP_VERSION, readOnly: Boolean = false, auditSink: AuditSink? = null, resources: ResourceRegistry = ResourceRegistry(), prompts: PromptRegistry = PromptRegistry(), notifiesListChanged: Boolean = false) : McpProtocol

The default McpProtocol implementation: a JSON-RPC 2.0 handler over a ToolRegistry. Services initialize, tools/list, tools/call, resources/list, resources/templates/list, resources/read, prompts/list, prompts/get, completion/complete and ping. Messages without an id are notifications: they are accepted silently and never answered (the transport replies 202). notifications/cancelled cancels the caller's own in-flight tools/call with that requestId; the cancelled request then gets no response.

initialize negotiates the protocol version: the client's requested version is echoed when it is in SUPPORTED_PROTOCOL_VERSIONS, otherwise the newest supported version is offered.

Errors follow JSON-RPC 2.0: -32700 only for unparseable JSON, -32600 for a structurally invalid request (non-object, batch array, wrong jsonrpc, missing method), -32601 for an unknown method, -32602 for malformed params (keeping the request id), and -32603 for an unexpected internal failure. Error responses always carry id (null when unknown). The handler never throws back to the transport.

Honours readOnly mode (filters tools/list to read-only tools and rejects mutating tools/calls with an isError content payload) and emits a ToolCallAudit to auditSink after every call, every resources/read (tool name resources/read) and every tool a completion reads through (tool name completion/complete) — a failing sink is swallowed so it can never break a call. A resource provider is visible only while its ResourceProvider.requiredTools are, so tool gating and read-only mode apply to the same data served as resources.

Constructors

Link copied to clipboard
constructor(registry: ToolRegistry, serverName: String = "droid-mcp", serverVersion: String = DROID_MCP_VERSION, readOnly: Boolean = false, auditSink: AuditSink? = null, resources: ResourceRegistry = ResourceRegistry(), prompts: PromptRegistry = PromptRegistry(), notifiesListChanged: Boolean = false)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun handleMessage(jsonRequest: String): String

Handle one JSON-RPC request and return the JSON-RPC response string.

open suspend override fun handleMessage(jsonRequest: String, clientLabel: String?): String

Handle a message attributing any tools/call to clientLabel for audit. Defaults to the unattributed form for implementations that don't audit.