Skip to content

toolmark-monorepo / @toolmark/mcp/client / mcpPairing

Function: mcpPairing() ​

mcpPairing(o?): (tm) => () => void

Defined in: packages/mcp/src/client/index.ts:84

Pairs the page with a local toolmark-mcp (spec §11.3, D31): attach with tm.use(mcpPairing({ code, port, onStatus })). Connects to ws://127.0.0.1:<port>, sends { type: 'pair', code } (or { type: 'resume', token } with the session token kept in sessionStorage under toolmark:mcp:<port>), waits for paired, then serves the registry as a bridge with caller mcp (inline confirmation). Close codes 4400, 4401, 4408 and 4409 stop reconnecting and detach the bridge: calls still running for the CLI are aborted and their inline confirmations withdrawn. On 1001 (the CLI shutting down) the bridge is detached the same way and a fresh one attached: the session token is kept and the page keeps reconnecting and resumes when the CLI is back. Other closes reconnect with backoff and resume, keeping running calls.

Parameters ​

o? ​

McpPairingOptions = {}

The code, port and status callback.

Returns ​

A consumer for tm.use. Without a code and without a stored token it is inert (no socket; the disposer does nothing).

(tm) => () => void

Throws ​

TypeError for a port outside 1–65535 or a non-string code.