@brightbeamai/chap-coordinator-mcp 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/schemas.ts","../src/tools.ts","../src/envelope.ts"],"sourcesContent":["/**\n * @brightbeamai/chap-coordinator-mcp\n *\n * MCP server adapter for a CHAP Coordinator. Wraps a Coordinator\n * instance and exposes every CHAP method as an MCP tool.\n *\n * Spec target: MCP 2026-07-28 (current), serving MCP 2025-11-25\n * clients as well. CHAP 0.3.\n *\n * Usage (stdio):\n *\n * import { Coordinator } from \"@brightbeamai/chap-coordinator\";\n * import { makeChapMcpServer } from \"@brightbeamai/chap-coordinator-mcp\";\n * import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\n *\n * const coord = new Coordinator({ ... });\n * const server = makeChapMcpServer(coord, { name: \"chap\", version: \"0.3.3\" });\n * await server.connect(new StdioServerTransport());\n *\n * Usage (Streamable HTTP): see reference/mcp-server-ts/server.ts.\n *\n * Architecture notes:\n *\n * - One Coordinator -> one MCP server. Multi-workspace is handled\n * inside the Coordinator (workspaces are addressable by id).\n *\n * - The adapter holds no state. Every tool call translates to a\n * JSON-RPC envelope and dispatches through coord.dispatch().\n *\n * - Tool naming follows \"chap.<method>\" so the prefix avoids\n * collisions with other MCP servers a client might load.\n *\n * - Tool inputs are described by JSON Schemas (not Zod) and are\n * passed through to the Coordinator without re-validating at the\n * MCP layer. The Coordinator's own dispatch validates params and\n * returns spec-correct JSON-RPC error codes, which we surface as\n * MCP tool errors. This keeps the schema definitions single-sourced.\n *\n * - Authentication is intentionally out of scope at this layer.\n * Apply OAuth 2.1 / Streamable HTTP auth at the transport layer\n * per MCP's auth model.\n */\n\nimport { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema,\n ErrorCode,\n type CallToolResult,\n type Tool,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { z } from \"zod\";\nimport type { Coordinator, Envelope } from \"@brightbeamai/chap-coordinator\";\n\nimport { SCHEMAS, TOOL_NAMES, methodForTool, coerceToolArgs } from \"./schemas.js\";\nimport { TOOL_DESCRIPTIONS, TOOL_ANNOTATIONS } from \"./tools.js\";\nimport { classifyEnvelope, ProtocolError, SUPPORTED_PROTOCOL_VERSIONS, type ProtocolEra } from \"./envelope.js\";\n\nexport { SCHEMAS, TOOL_NAMES, schemaFor, methodForTool, coerceToolArgs } from \"./schemas.js\";\nexport { TOOL_DESCRIPTIONS, TOOL_ANNOTATIONS } from \"./tools.js\";\nexport type { ToolAnnotations } from \"./tools.js\";\nexport type { JsonSchema } from \"./schemas.js\";\n\nexport {\n ProtocolError,\n MODERN_PROTOCOL_VERSIONS,\n SUPPORTED_PROTOCOL_VERSIONS,\n UNSUPPORTED_PROTOCOL_VERSION,\n META_PROTOCOL_VERSION,\n META_CLIENT_INFO,\n META_CLIENT_CAPABILITIES,\n classifyEnvelope,\n} from \"./envelope.js\";\nexport type { ProtocolEra } from \"./envelope.js\";\n\n/** `_meta` key carrying server identity (MCP 2026-07-28, SEP-2575). */\nexport const META_SERVER_INFO = \"io.modelcontextprotocol/serverInfo\";\n\n/** Freshness hint for cacheable list results. The CHAP tool surface is\n * fixed at construction, so a long TTL is safe. */\nconst LIST_TTL_MS = 3_600_000;\n\n/**\n * Request schema for `server/discover` (MCP 2026-07-28, SEP-2575).\n *\n * Hand-written because the pinned SDK major predates the 2026 era. The\n * shape is permissive on `params` so a probe carrying `_meta`\n * (protocolVersion, clientInfo, clientCapabilities) validates, and a\n * bare probe with no params validates too.\n */\nexport const ServerDiscoverRequestSchema = z.object({\n method: z.literal(\"server/discover\"),\n params: z.optional(z.object({ _meta: z.optional(z.record(z.string(), z.unknown())) }).loose()),\n});\n\nexport interface ChapMcpOptions {\n /** Server name advertised to MCP clients. Default: \"chap\". */\n name?: string;\n /** Server version. Default: \"0.3.3\". */\n version?: string;\n /** Override the list of CHAP methods to expose. Default: all 39. */\n toolFilter?: (toolName: string) => boolean;\n /** Optional id generator for the envelopes emitted by tool calls. */\n envelopeIdFactory?: () => string | number;\n}\n\n/**\n * Wrap a CHAP Coordinator as an MCP server. The returned ``Server``\n * has ``tools/list`` and ``tools/call`` handlers registered for every\n * CHAP method; pass it to a transport (stdio, Streamable HTTP) to\n * start serving.\n */\nexport function makeChapMcpServer(coord: Coordinator, options: ChapMcpOptions = {}): Server {\n const serverInfo = {\n name: options.name ?? \"chap\",\n version: options.version ?? \"0.3.3\",\n };\n\n const server = new Server(\n serverInfo,\n {\n capabilities: {\n tools: {},\n },\n },\n );\n\n let counter = 0;\n const nextId = options.envelopeIdFactory ?? (() => `mcp-${++counter}`);\n const filter = options.toolFilter ?? (() => true);\n\n const enabledTools: Tool[] = TOOL_NAMES\n .filter((name) => filter(name) && methodForTool(name) !== null)\n .map((name) => {\n const ann = TOOL_ANNOTATIONS[name];\n return {\n name,\n // The title was the tool name, which told a reader nothing they could\n // not already see. The annotation carries a readable one.\n title: ann?.title ?? name,\n description: TOOL_DESCRIPTIONS[name] ?? `CHAP method ${methodForTool(name)}.`,\n inputSchema: SCHEMAS[name] as Tool[\"inputSchema\"],\n // Behavioural hints. Without these a client has only the prose to go\n // on when deciding whether a call is safe to make or to retry.\n ...(ann ? { annotations: ann } : {}),\n };\n });\n\n server.setRequestHandler(ListToolsRequestSchema, async (request) => {\n // Rejects a malformed or unsupported envelope before any work is done.\n const era = classifyEnvelope(request.params);\n if (era === \"legacy\") return { tools: enabledTools };\n\n // 2026-07-28 requires every result to be typed, and makes list results\n // cacheable. These fields are 2026 vocabulary, so they are emitted only\n // to a caller that asked in 2026 terms; a handshake-era session gets the\n // result shape its own revision defines.\n return {\n tools: enabledTools,\n resultType: \"complete\",\n ttlMs: LIST_TTL_MS,\n cacheScope: \"public\",\n _meta: { [META_SERVER_INFO]: serverInfo },\n };\n });\n\n // server/discover (MCP 2026-07-28, SEP-2575). Servers MUST implement it;\n // clients MAY call it for up-front version selection, and on stdio a\n // client that supports both eras SHOULD probe with it first. Answering\n // the probe is what keeps this server usable by 2026-era clients: a\n // server that stays silent is only reachable through timeout-based\n // fallback to the legacy initialize handshake.\n //\n // Registered against a hand-written schema because the pinned SDK\n // (1.x) predates the 2026 era and does not export one yet. When the\n // SDK ships its own ServerDiscover types this can be swapped for them\n // without changing the wire behaviour.\n server.setRequestHandler(ServerDiscoverRequestSchema, async (request) => {\n // `server/discover` is 2026 vocabulary. A request that carries no\n // per-request envelope belongs to the handshake era, where the method\n // does not exist; answering it anyway would tell a dual-era client that\n // a legacy connection can speak 2026. Mirrors the Python SDK, which\n // returns MethodNotFound in the same situation.\n if (classifyEnvelope(request.params) === \"legacy\") {\n // `data` carries the method name, matching what the Python SDK emits,\n // so a client sees the same error either side.\n throw new ProtocolError(ErrorCode.MethodNotFound, \"Method not found\", \"server/discover\");\n }\n return {\n resultType: \"complete\",\n supportedVersions: SUPPORTED_PROTOCOL_VERSIONS,\n capabilities: { tools: {} },\n instructions:\n \"CHAP Coordinator exposed as MCP tools. Every accepted call that \" +\n \"changes state is recorded on the CHAP audit log, as is a member's \" +\n \"refused attempt at a governed action. Governed methods enforce \" +\n \"membership and review rules server-side.\",\n ttlMs: LIST_TTL_MS,\n cacheScope: \"public\",\n _meta: { [META_SERVER_INFO]: serverInfo },\n };\n });\n\n server.setRequestHandler(CallToolRequestSchema, async (request): Promise<CallToolResult> => {\n const era = classifyEnvelope(request.params);\n // `resultType` is 2026 vocabulary: emitted to a modern caller, withheld\n // from a handshake-era one whose revision does not define the field.\n const terminal = <T extends object>(result: T): T =>\n (era === \"modern\" ? { resultType: \"complete\", ...result } : result) as T;\n\n const toolName = request.params.name;\n const rawArgs = (request.params.arguments ?? {}) as Record<string, unknown>;\n const method = methodForTool(toolName);\n\n if (!method) {\n return terminal({\n isError: true,\n content: [{ type: \"text\", text: `Unknown CHAP tool: ${toolName}` }],\n });\n }\n\n // Normalise stringified-JSON arguments (a common MCP-client\n // behaviour) before they reach the protocol core. See coerceToolArgs.\n const args = coerceToolArgs(toolName, rawArgs);\n\n const envelope: Envelope = {\n jsonrpc: \"2.0\",\n id: nextId(),\n method,\n params: args,\n };\n\n let response: Envelope;\n try {\n response = coord.dispatch(envelope);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n return terminal({\n isError: true,\n content: [{ type: \"text\", text: `CHAP dispatch threw: ${msg}` }],\n });\n }\n\n if (response.error) {\n return terminal({\n isError: true,\n content: [{\n type: \"text\",\n text: JSON.stringify({\n chap_error: response.error.code,\n message: response.error.message,\n ...(response.error.data !== undefined ? { data: response.error.data } : {}),\n }, null, 2),\n }],\n });\n }\n\n return terminal({\n content: [{\n type: \"text\",\n text: JSON.stringify(response.result, null, 2),\n }],\n });\n });\n\n return server;\n}\n\n/**\n * Lower-level helper: translate a tool call to a CHAP envelope and\n * back. Useful for tests and for embedding the adapter inside a\n * larger MCP server that registers its own additional tools.\n */\nexport function dispatchToolCall(\n coord: Coordinator,\n toolName: string,\n args: Record<string, unknown>,\n envelopeId: string | number = \"mcp-call\",\n): Envelope {\n const method = methodForTool(toolName);\n if (!method) {\n return {\n jsonrpc: \"2.0\",\n id: envelopeId,\n error: { code: -32601, message: `Unknown CHAP tool: ${toolName}` },\n };\n }\n return coord.dispatch({\n jsonrpc: \"2.0\",\n id: envelopeId,\n method,\n params: coerceToolArgs(toolName, args ?? {}),\n });\n}\n","/**\n * @brightbeamai/chap-coordinator-mcp/schemas\n *\n * JSON Schema definitions for each CHAP method, used as the\n * inputSchema for the corresponding MCP tool. Each schema describes\n * the params object that the CHAP envelope would carry; the tool\n * handler wraps the params in a JSON-RPC 2.0 envelope before dispatch.\n *\n * A description here is what an MCP client reads before deciding\n * whether and how to call the tool, so each one states what the\n * coordinator does with the parameter, and names the error code where\n * a constraint is enforced. A parameter that is recorded but not acted\n * on says so; describing an intention the code does not implement is\n * worse than saying nothing.\n *\n * Aligned with CHAP 0.3 (see profiles/*.md) and MCP 2025-11-25.\n */\n\nexport interface JsonSchema {\n type?: string;\n description?: string;\n properties?: Record<string, JsonSchema>;\n required?: string[];\n enum?: string[];\n items?: JsonSchema;\n additionalProperties?: boolean | JsonSchema;\n oneOf?: JsonSchema[];\n default?: unknown;\n /** JSON Schema `pattern`, used where a string has a fixed wire shape. */\n pattern?: string;\n}\n\n// Common reusable fragments.\nconst PARTICIPANT_URI: JsonSchema = {\n type: \"string\",\n description: \"Participant URI, e.g. 'human:alice@example.org' or 'agent:bot@local'.\",\n};\n\nconst WORKSPACE_ID: JsonSchema = {\n type: \"string\",\n description: \"Workspace identifier, e.g. 'wsp_techcorp_support'.\",\n};\n\nconst TASK_ID: JsonSchema = {\n type: \"string\",\n description: \"Task identifier returned by chap.task.create.\",\n};\n\n/**\n * SPECIFICATION.md S7: a number in a CHAP envelope must be an integer.\n * Fractional values travel as decimal strings, so that canonicalisation and\n * therefore the audit hash are identical across implementations. A JSON number\n * with a fractional part is refused at ingress with -32602, so any parameter\n * that is conceptually fractional is declared here as a string.\n */\nconst decimalStringNote = (example: string) =>\n `Written as a decimal string, e.g. \"${example}\". CHAP canonicalisation accepts integers only, so a JSON number with a fractional part is refused with -32602.`;\n\nconst ROUTING_HINTS: JsonSchema = {\n type: \"object\",\n description: \"Signals recorded on the task and read by the routing/1.0 methods: task.route, review.depth and escalate.auto. Recording a hint has no effect on its own; it is consulted only when one of those methods is called.\",\n properties: {\n criticality: {\n type: \"string\",\n enum: [\"low\", \"medium\", \"high\", \"critical\"],\n description: \"How costly a wrong answer would be. The default review-depth policy reads it: 'critical' gives a full review, and 'high' with confidence below 0.7 does the same. The default assignee policy does not read it.\",\n },\n deadline: { type: \"string\", description: \"When the work is needed by, as an ISO 8601 timestamp. Recorded on the task; the coordinator does not act on it.\" },\n risk_tier: { type: \"string\", description: \"Operator-defined risk band, e.g. 'regulated' or 'internal'. No built-in policy reads it; it is available to an operator-supplied routing policy.\" },\n max_cost_usd: { type: \"string\", description: `Budget ceiling for this task in US dollars. ${decimalStringNote(\"12.50\")} No built-in policy reads it.` },\n },\n additionalProperties: true,\n};\n\n/** Free-text justification attached to a decision and kept in the audit log. */\nconst COMMENT: JsonSchema = {\n type: \"string\",\n description: \"The reviewer's note on this decision. Recorded in the audit entry for the decision.\",\n};\n\n/** Workspace-defined labels carried on a decision. */\nconst TAGS: JsonSchema = {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Workspace-defined labels for this decision, e.g. ['tone', 'unsupported-claim']. Recorded in the audit entry. chap.audit.read does not filter on tags, so grouping by tag is done by the reader.\",\n};\n\n/** Binds a decision to the exact artefact the reviewer saw. */\nconst ARTEFACT_DIGEST: JsonSchema = {\n type: \"string\",\n pattern: \"^sha256:[0-9a-f]{64}$\",\n description: \"Optional. SHA-256 over the JCS canonicalisation of the artefact under review, in the form `sha256:<hex>`. When present it binds the decision to the exact content reviewed, and a mismatch is refused with -32074.\",\n};\n\n/** Applies to `output` and `artefact`, which are opaque JSON payloads. */\nconst STRUCTURED_PAYLOAD_NOTE =\n \"Pass a JSON object or array. A JSON-encoded string is parsed back to the structured value before dispatch, so patches in chap.decide.override apply against a real object.\";\n\n// ============================================================\n// Core\n// ============================================================\n\nexport const SCHEMAS: Record<string, JsonSchema> = {\n \"chap.workspace.create\": {\n type: \"object\",\n properties: {\n workspace: { ...WORKSPACE_ID, description: \"Workspace id to create. If omitted, one is generated.\" },\n profiles: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Profile identifiers to enable, e.g. ['core/1.0', 'review/1.0']. Recorded on the workspace. Two profiles change behaviour by being present: modes/1.0, under which a trial-mode task requires review, and audit-scitt/1.0, which turns on the hash-linked chain.\",\n },\n mode: {\n type: \"string\",\n enum: [\"shadow\", \"trial\", \"production\"],\n default: \"trial\",\n description: \"Default mode for tasks created here. Under modes/1.0 a trial-mode task has review_required set to true whatever the caller passes. 'shadow' and 'production' are recorded on the task and carry no further behaviour in this implementation.\",\n },\n mode_ceiling: {\n type: \"string\",\n enum: [\"shadow\", \"trial\", \"production\"],\n default: \"production\",\n description: \"Highest mode a task in this workspace may request. A task.create above the ceiling is refused with -32040. The ceiling can be changed afterwards with chap.control.set_mode_ceiling.\",\n },\n },\n additionalProperties: false,\n },\n\n \"chap.workspace.describe\": {\n type: \"object\",\n properties: { workspace: WORKSPACE_ID },\n required: [\"workspace\"],\n },\n\n \"chap.workspace.set_profiles\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n profiles: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"The complete profile set to enable, replacing the current one. Adding audit-scitt/1.0 to a workspace that already has entries leaves those entries unchained and outside chain verification.\",\n },\n },\n required: [\"workspace\", \"profiles\"],\n },\n\n \"chap.participant.join\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: PARTICIPANT_URI,\n type: {\n type: \"string\",\n enum: [\"human\", \"agent\", \"service\", \"group\", \"workspace\"],\n description: \"The kind of participant. Only members of type 'human' are eligible for the review that chap.task.complete opens on a task marked review_required, and a completion with no eligible human is refused with -32011.\",\n },\n role: { type: \"string\", description: \"Operator-defined role, e.g. 'reviewer' or 'drafter'. One value is read by the coordinator: 'admin' permits revoking another member's key.\" },\n display_name: { type: \"string\", description: \"Human-readable name for interfaces. Not used in authorisation.\" },\n },\n required: [\"workspace\", \"from\", \"type\"],\n },\n\n \"chap.participant.leave\": {\n type: \"object\",\n properties: { workspace: WORKSPACE_ID, from: PARTICIPANT_URI },\n required: [\"workspace\", \"from\"],\n },\n\n \"chap.task.create\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: { ...PARTICIPANT_URI, description: \"The delegator. Must be a workspace member.\" },\n kind: { type: \"string\", description: \"Task kind, e.g. 'draft_response' or 'review'. Free text; the coordinator records it without interpreting it.\" },\n assignee: { ...PARTICIPANT_URI, description: \"Who the task is assigned to. Must be a workspace member, and must not be paused: assigning to a paused member is refused with -32063.\" },\n input: { type: \"object\", description: \"Task-specific input payload.\", additionalProperties: true },\n routing_hints: ROUTING_HINTS,\n mode: {\n type: \"string\",\n enum: [\"shadow\", \"trial\", \"production\"],\n description: \"Mode for this task, defaulting to the workspace mode. A mode above the workspace ceiling is refused with -32040.\",\n },\n review_required: {\n type: \"boolean\",\n description: \"When true, chap.task.complete opens a review instead of completing: the output becomes the artefact under review, and the task reaches 'completed' only on a reviewer decision. chap.task.update cannot complete such a task. Under modes/1.0 a trial-mode task has this set to true whatever is passed here.\",\n },\n deadline: { type: \"string\", description: \"When the task is due, as an ISO 8601 timestamp. Recorded on the task; the coordinator does not act on it.\" },\n idempotency_key: {\n type: \"string\",\n description: \"Caller-chosen key for safe retries. A second create carrying a key already seen in this workspace returns the original task and records nothing further. The workspace retains the 10,000 most recent keys.\",\n },\n },\n required: [\"workspace\", \"from\", \"kind\", \"assignee\", \"input\"],\n },\n\n \"chap.task.update\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: PARTICIPANT_URI,\n task_id: TASK_ID,\n state: {\n type: \"string\",\n enum: [\"in_progress\", \"declined\", \"cancelled\", \"completed\"],\n description: \"The state to move the task to. Only the transitions in SPECIFICATION.md 8.1 are legal from the task's current state; others are refused with -32602. A review opens with chap.review.request, or with chap.task.complete on a task that requires one, so 'review_requested' is not a target here. A task marked review_required cannot be moved to 'completed' here: submit the output with chap.task.complete, which opens the review.\",\n },\n progress_note: { type: \"string\", description: \"Short note on what changed, kept in the task's history.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"state\"],\n },\n\n \"chap.task.complete\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: PARTICIPANT_URI,\n task_id: TASK_ID,\n output: { description: `The task's output artefact. ${STRUCTURED_PAYLOAD_NOTE}` },\n confidence: { type: \"string\", description: `Self-reported confidence in the output, between 0 and 1. ${decimalStringNote(\"0.86\")}` },\n routing_hints: ROUTING_HINTS,\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.audit.read\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n range: {\n type: \"object\",\n description: \"Sequence window to return. Omit for the whole log.\",\n properties: {\n from_seq: { type: \"integer\", description: \"Start sequence number, inclusive.\" },\n to_seq: { type: \"integer\", description: \"End sequence number, exclusive.\" },\n },\n },\n filter: {\n type: \"object\",\n description: \"Narrows the entries returned. Conditions combine with AND, and are applied within the sequence window rather than before it.\",\n properties: {\n method: { type: \"string\", description: \"Return only entries for this CHAP method, e.g. 'decide.override'. Matched in full, without the 'chap.' tool-name prefix.\" },\n from: { type: \"string\", description: \"Return only entries whose actor is this participant URI.\" },\n task_id: { type: \"string\", description: \"Return only entries about this task.\" },\n outcome: {\n type: \"string\",\n enum: [\"accepted\", \"refused\"],\n description: \"Return only accepted calls, or only the refused attempts the coordinator recorded. Omit for both.\",\n },\n },\n },\n },\n required: [\"workspace\"],\n },\n\n // ============================================================\n // review/1.0\n // ============================================================\n\n \"chap.review.request\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: PARTICIPANT_URI,\n task_id: TASK_ID,\n to: {\n oneOf: [PARTICIPANT_URI, { type: \"array\", items: PARTICIPANT_URI }],\n description: \"One or more reviewers, as a single URI string or an array of URI strings. Only a workspace member can go on to decide, so a review addressed elsewhere cannot be closed by its recipient.\",\n },\n rule: {\n type: \"string\",\n enum: [\"any_one_approves\", \"all_approve\", \"quorum:2\", \"quorum:3\"],\n default: \"any_one_approves\",\n description: \"How many of the addressed reviewers must approve before the task completes. quorum:N is accepted for any N of 1 or more. The rule is fixed once the review is open: a later request naming a different one is refused with -32014. Omitting it on a later request leaves the rule alone, which is how reviewers are added to an open review.\",\n },\n artefact: { description: `The draft being submitted for review. ${STRUCTURED_PAYLOAD_NOTE} Re-requesting with the same artefact widens the reviewer set; a different artefact on an open review is refused with -32014.` },\n deadline: { type: \"string\", description: \"When the review is needed by, as an ISO 8601 timestamp. Recorded on the review; the coordinator does not act on it.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"to\", \"artefact\"],\n },\n\n \"chap.decide.approve\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n approved_artefact_digest: ARTEFACT_DIGEST,\n comment: COMMENT,\n tags: TAGS,\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.decide.reject\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n approved_artefact_digest: ARTEFACT_DIGEST,\n comment: COMMENT,\n tags: TAGS,\n request_revision: { type: \"boolean\", description: \"When true the task returns to 'in_progress' rather than 'declined', so the assignee can revise and resubmit.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.decide.override\": {\n type: \"object\",\n properties: {\n approved_artefact_digest: ARTEFACT_DIGEST,\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n diff: {\n type: \"array\",\n description: \"RFC 6902 JSON Patch operations applied to the artefact under review. The patched artefact becomes the task output; a patch that does not apply is refused with -32012.\",\n items: {\n type: \"object\",\n properties: {\n op: { type: \"string\", enum: [\"add\", \"replace\", \"remove\", \"copy\", \"move\", \"test\"], description: \"The patch operation to apply.\" },\n path: { type: \"string\", description: \"JSON Pointer into the artefact, e.g. '/body' or '/items/0/severity'.\" },\n value: { description: \"The new value, for add, replace and test.\" },\n from: { type: \"string\", description: \"Source JSON Pointer, for copy and move.\" },\n },\n required: [\"op\", \"path\"],\n },\n },\n rationale: { type: \"string\", description: \"Why the correction was made. Required on every override and recorded in the audit entry, since the diff shows what changed but not why.\" },\n tags: TAGS,\n policy_refs: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Identifiers of the policies or guidelines this correction applies, e.g. ['policy:no-delivery-promises']. Recorded in the audit entry.\",\n },\n logical_id: {\n type: \"string\",\n description: \"Caller-chosen identifier for the item being decided, stable across revisions and overrides of the same underlying content. Recorded in the audit entry.\",\n },\n intent_preserved: {\n type: \"boolean\",\n description: \"True when the edit refines the decision the draft was making, false when it substitutes a different one. Recorded in the audit entry.\",\n },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"diff\", \"rationale\"],\n },\n\n \"chap.abstain.declare\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n reason: { type: \"string\", description: \"Why this reviewer is standing aside. Recorded in the audit entry.\" },\n category: {\n type: \"string\",\n enum: [\"conflict_of_interest\", \"insufficient_context\", \"out_of_scope\", \"other\"],\n description: \"The kind of abstention. Recorded in the audit entry.\",\n },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"reason\"],\n },\n\n \"chap.escalate.raise\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n original_task_id: { ...TASK_ID, description: \"The task being escalated. It moves to 'escalated' and is linked to the successor. A completed, cancelled or superseded task cannot be escalated.\" },\n new_task: {\n type: \"object\",\n description: \"The successor task to open for the escalation target.\",\n properties: {\n kind: { type: \"string\", description: \"Task kind for the successor. Defaults to the original's kind.\" },\n assignee: { ...PARTICIPANT_URI, description: \"Who the escalation goes to. Must be a workspace member who is not paused: a paused assignee is refused with -32063.\" },\n input: { type: \"object\", additionalProperties: true, description: \"Input payload for the successor. It defaults to an empty object rather than the original's input, so anything the new assignee needs has to be restated here.\" },\n mode: { type: \"string\", enum: [\"shadow\", \"trial\", \"production\"], description: \"Mode for the successor, defaulting to the original's. A mode above the workspace's current ceiling is refused with -32040, so after the ceiling is lowered a task is escalated by naming a mode within it.\" },\n },\n required: [\"assignee\"],\n },\n },\n required: [\"workspace\", \"from\", \"original_task_id\", \"new_task\"],\n },\n\n // ============================================================\n // whisper/1.0\n // ============================================================\n\n \"chap.whisper.ask\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n to: { type: \"array\", items: PARTICIPANT_URI, description: \"Who is being asked.\" },\n question: { type: \"string\", description: \"The question being put. A whisper is answered on its own, without the recipient opening the task.\" },\n options: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Stable identifier that an answer refers to.\" },\n label: { type: \"string\", description: \"What the option says to the person answering.\" },\n },\n required: [\"id\"],\n },\n description: \"Multiple-choice options. When present, an answer must name one of these ids in answer_option; any other id is refused with -32022.\",\n },\n deadline_ms: { type: \"integer\", description: \"How long the whisper stays open, in milliseconds from now. Once it passes, the whisper lapses and default_if_lapsed is applied.\" },\n default_if_lapsed: { description: \"The value applied if the deadline passes with no answer. Required, so that a lapsed whisper still has a defined outcome.\" },\n urgency: {\n type: \"string\",\n enum: [\"low\", \"medium\", \"high\"],\n default: \"low\",\n description: \"How urgent the question is. Recorded and passed on to the client; it does not change the deadline or the lapse behaviour.\",\n },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"to\", \"question\", \"deadline_ms\", \"default_if_lapsed\"],\n },\n\n \"chap.whisper.answer\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n whisper_id: { type: \"string\", description: \"Identifier returned by chap.whisper.ask. A whisper that has already been answered is refused with -32020, and one past its deadline with -32021.\" },\n answer_option: { type: \"string\", description: \"The id of the chosen option. Required when the whisper carried options.\" },\n answer: { type: \"string\", description: \"Free-text answer, for a whisper with no options.\" },\n comment: { type: \"string\", description: \"Anything else the answerer wants recorded alongside the answer.\" },\n },\n required: [\"workspace\", \"from\", \"whisper_id\"],\n },\n\n // ============================================================\n // deliberation/1.0\n // ============================================================\n\n \"chap.deliberate.open\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n to: { type: \"array\", items: PARTICIPANT_URI, description: \"The participants entitled to vote. A vote from anyone else is refused with -32030.\" },\n task_id: TASK_ID,\n rule: {\n type: \"string\",\n description: \"How the outcome is decided when the deliberation closes: any_one_approves, all_approve, quorum:N, weighted_vote:T or weighted_vote_with_veto:T. An unrecognised rule is refused at open with -32033.\",\n },\n question: { type: \"string\", description: \"What the group is deciding. State it so that a yea or a nay is unambiguous.\" },\n weights: { type: \"object\", additionalProperties: { type: \"integer\" }, description: \"Voter to weight map, read by the weighted rules. A voter with no entry counts as 1. Weights must be integers: a JSON number with a fractional part is refused with -32602.\" },\n veto: { type: \"object\", additionalProperties: { type: \"boolean\" }, description: \"Voter to can-veto map. A veto is honoured only under weighted_vote_with_veto, and only from a voter listed true here.\" },\n deadline: { type: \"string\", description: \"When voting is intended to close, as an ISO 8601 timestamp. Recorded on the deliberation; closing is done by chap.deliberate.close and the coordinator does not close on the deadline.\" },\n },\n required: [\"workspace\", \"from\", \"to\", \"rule\"],\n },\n\n \"chap.deliberate.comment\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n deliberation_id: { type: \"string\", description: \"Identifier returned by chap.deliberate.open. A closed deliberation is refused with -32032.\" },\n comment: { type: \"string\", description: \"The contribution to record. Comments are kept with the deliberation and in the audit log, so the reasoning survives the vote.\" },\n },\n required: [\"workspace\", \"from\", \"deliberation_id\", \"comment\"],\n },\n\n \"chap.deliberate.vote\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n deliberation_id: { type: \"string\", description: \"Identifier returned by chap.deliberate.open. A closed deliberation is refused with -32032, and a second vote from the same voter with -32031.\" },\n vote: { type: \"string\", enum: [\"yea\", \"nay\", \"abstain\"], description: \"This voter's position. An abstention is recorded but counts as neither a yea nor a nay, so under all_approve or quorum:N it withholds the approval those rules need.\" },\n weight: { type: \"integer\", description: \"Recorded with the vote. The tally uses the weights map given at chap.deliberate.open, not this value.\" },\n comment: { type: \"string\", description: \"Why the vote went this way. Recorded with it.\" },\n veto_invoked: { type: \"boolean\", description: \"Blocks the outcome regardless of the tally. Honoured only under weighted_vote_with_veto, and only when the voter is listed true in the veto map given at open.\" },\n },\n required: [\"workspace\", \"from\", \"deliberation_id\", \"vote\"],\n },\n\n \"chap.deliberate.close\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n deliberation_id: { type: \"string\", description: \"Identifier returned by chap.deliberate.open. Closing computes the outcome from the votes cast; closing an already closed deliberation returns the outcome unchanged.\" },\n },\n required: [\"workspace\", \"from\", \"deliberation_id\"],\n },\n\n // ============================================================\n // handoff/1.0\n // ============================================================\n\n \"chap.handoff.propose\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n to: { type: \"string\", description: \"Recipient, as a participant URI or a group URI such as 'group:support-team'. A recipient who is not a workspace member is refused with -32052.\" },\n tasks: {\n type: \"array\",\n description: \"The work being handed over, one entry per task. Every task must currently be assigned to the proposer; otherwise the proposal is refused with -32050.\",\n items: {\n type: \"object\",\n properties: {\n task_id: TASK_ID,\n title: { type: \"string\", description: \"Short label for the task.\" },\n status_summary: { type: \"string\", description: \"Where the work has reached, and what has already been tried.\" },\n next_action: { type: \"string\", description: \"What the recipient should do first.\" },\n blockers: { type: \"array\", items: { type: \"string\" }, description: \"What is preventing progress, if anything.\" },\n },\n required: [\"task_id\"],\n },\n },\n summary: { type: \"string\", description: \"Covering note for the handover as a whole, above the per-task detail.\" },\n context_links: { type: \"array\", items: { type: \"string\" }, description: \"URLs to threads, tickets or documents the recipient will need.\" },\n },\n required: [\"workspace\", \"from\", \"to\", \"tasks\"],\n },\n\n \"chap.handoff.accept\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n handoff_id: { type: \"string\", description: \"Identifier returned by chap.handoff.propose. A handoff already accepted or declined is refused with -32051.\" },\n accepted_task_ids: { type: \"array\", items: TASK_ID, description: \"Which of the proposed tasks are being accepted. If omitted, all of them are.\" },\n comment: { type: \"string\", description: \"Anything the recipient wants recorded when taking the work on.\" },\n },\n required: [\"workspace\", \"from\", \"handoff_id\"],\n },\n\n \"chap.handoff.decline\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n handoff_id: { type: \"string\", description: \"Identifier returned by chap.handoff.propose. A handoff already accepted or declined is refused with -32051.\" },\n reason: { type: \"string\", description: \"Why the handover is refused. Recorded so the proposer can route it elsewhere.\" },\n suggested_target: { ...PARTICIPANT_URI, description: \"Who should take it instead, if the decliner knows.\" },\n },\n required: [\"workspace\", \"from\", \"handoff_id\"],\n },\n\n // ============================================================\n // control/1.0\n // ============================================================\n\n \"chap.control.pause\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n scope: {\n type: \"string\",\n enum: [\"task\", \"participant\", \"workspace\"],\n default: \"task\",\n description: \"What the pause applies to. 'task' moves one task to 'paused'; a task that is completed, declined, cancelled or superseded is refused with -32061. 'participant' stops new tasks being assigned to that member and leaves their existing work running. 'workspace' refuses every method except workspace.create, workspace.describe, control.resume, audit.read, participant.join and participant.leave.\",\n },\n task_id: TASK_ID,\n participant_uri: { ...PARTICIPANT_URI, description: \"Whose work to pause, when scope is 'participant'. Must be a workspace member.\" },\n in_flight_policy: {\n type: \"string\",\n enum: [\"allow_to_complete\", \"interrupt\"],\n description: \"Recorded with the request, and echoed back when scope is 'participant'. The coordinator does not act on it: under either value, work already under way is left alone.\",\n },\n reason: { type: \"string\", description: \"Why the pause was applied. Recorded in the audit entry.\" },\n },\n required: [\"workspace\", \"from\"],\n },\n\n \"chap.control.resume\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n scope: {\n type: \"string\",\n enum: [\"task\", \"participant\", \"workspace\"],\n default: \"task\",\n description: \"What the resume applies to. 'task' returns a paused task to the state it held at the pause; a task that is not paused is refused with -32061. 'participant' allows that member to be assigned tasks again. 'workspace' returns the workspace to active.\",\n },\n task_id: TASK_ID,\n participant_uri: { ...PARTICIPANT_URI, description: \"Whose work to resume, when scope is 'participant'. Must be a workspace member.\" },\n },\n required: [\"workspace\", \"from\"],\n },\n\n \"chap.control.cancel\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: { ...TASK_ID, description: \"The task to cancel. A task that is completed, declined, cancelled or superseded is refused with -32061.\" },\n reason: { type: \"string\", description: \"Why the task was cancelled. Recorded in the audit entry.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.control.snapshot\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n label: { type: \"string\", description: \"Name for this snapshot, recorded on the artefact. chap.control.rollback identifies a snapshot by its artefact id, not by label.\" },\n include: { type: \"array\", items: { type: \"string\" }, description: \"Which aspects of the workspace to capture. Recognised values are 'members', 'open_tasks', 'mode_ceiling', 'policy' and 'audit'. Defaults to members, open_tasks and mode_ceiling.\" },\n },\n required: [\"workspace\", \"from\"],\n },\n\n \"chap.control.rollback\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n to_snapshot_artefact_id: { type: \"string\", description: \"Artefact id returned by chap.control.snapshot. An id with no matching snapshot is refused with -32062.\" },\n what_to_restore: { type: \"array\", items: { type: \"string\" }, description: \"Which captured aspects to apply. Only 'mode_ceiling' and 'members' are restored; the others are held in the snapshot and not reapplied. Restoring members resets role and scopes on members still present, and does not re-add members who have left. Defaults to the snapshot's include list.\" },\n reason: { type: \"string\", description: \"Why the rollback was performed. The rollback is itself an audit entry; earlier entries are not rewritten.\" },\n },\n required: [\"workspace\", \"from\", \"to_snapshot_artefact_id\"],\n },\n\n \"chap.control.supersede\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: { ...TASK_ID, description: \"The task being replaced. It moves to 'superseded' and is linked to the successor rather than deleted.\" },\n successor_task: {\n type: \"object\",\n description: \"The replacement task.\",\n properties: {\n kind: { type: \"string\", description: \"Task kind for the successor. Required.\" },\n assignee: { ...PARTICIPANT_URI, description: \"Who takes the replacement on. Defaults to the superseded task's assignee, and must be a workspace member who is not paused.\" },\n input: { type: \"object\", additionalProperties: true, description: \"Input payload for the successor. Defaults to an empty object.\" },\n mode: { type: \"string\", enum: [\"shadow\", \"trial\", \"production\"], description: \"Mode for the successor, defaulting to the superseded task's. A mode above the workspace's current ceiling is refused with -32040.\" },\n review_required: { type: \"boolean\", description: \"Whether completing the successor needs a reviewer decision. A successor of a task that requires review requires it whatever is passed here, and under modes/1.0 so does a trial-mode successor.\" },\n },\n required: [\"kind\"],\n },\n reason: { type: \"string\", description: \"Why the original is being replaced. Recorded in the audit entry.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"successor_task\"],\n },\n\n \"chap.control.set_mode_ceiling\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n new_ceiling: {\n type: \"string\",\n enum: [\"shadow\", \"trial\", \"production\"],\n description: \"The highest mode tasks in this workspace may request from now on. Existing tasks keep the mode they were created with. Where the coordinator is configured to enforce step-up authentication this method is one of the privileged ones and a call without step-up is refused with -32402.\",\n },\n reason: { type: \"string\", description: \"Why the ceiling is being changed. Recorded in the audit entry.\" },\n },\n required: [\"workspace\", \"from\", \"new_ceiling\"],\n },\n\n // ============================================================\n // routing/1.0\n // ============================================================\n\n \"chap.task.route\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: TASK_ID,\n candidates: { type: \"array\", items: PARTICIPANT_URI, description: \"Candidate assignees. An empty list is refused with -32513. The default policy takes the first candidate that is a workspace member and is not paused, and refuses the call with -32510 when there is none. An operator-supplied routing policy may select on any basis; a choice that is not a member is refused with -32510, and one who is paused with -32063.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"candidates\"],\n },\n\n \"chap.review.depth\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: TASK_ID,\n artefact_routing_hints: {\n type: \"object\",\n description: \"Per-artefact signals such as confidence, model_id and cost_consumed_usd, merged over the task's routing_hints for this call. The default policy reads criticality and confidence. If the merged set is empty the call is refused with -32514. Fractional values are written as decimal strings, e.g. \\\"confidence\\\": \\\"0.86\\\".\",\n additionalProperties: true,\n },\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.escalate.auto\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: TASK_ID,\n default_escalation_target: { ...PARTICIPANT_URI, description: \"Who to escalate to when the policy decides to escalate and names no target of its own. It must be a workspace member or a group URI; if the policy escalates with no usable target the call is refused with -32516.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n // ============================================================\n // security-signed/1.0\n // ============================================================\n\n \"chap.participant.rotate_key\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n old_kid: { type: \"string\", description: \"Key id being retired. It is given a valid_until timestamp and stays in the member's key history, so signatures made before the rotation still verify. A key id that is unknown is refused with -32071, and one already revoked with -32072.\" },\n new_jwk: { type: \"object\", additionalProperties: true, description: \"The replacement public key as a JWK. It must carry a 'kid'. Whether the request itself has to be signed with the old key is decided at dispatch, and only where the coordinator is configured to require signatures.\" },\n },\n required: [\"workspace\", \"from\", \"old_kid\", \"new_jwk\"],\n },\n\n \"chap.participant.revoke_key\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n target_uri: { ...PARTICIPANT_URI, description: \"Whose key is being revoked. Revoking another member's key requires the caller to hold the role 'admin'; otherwise the call is refused with -32011.\" },\n kid: { type: \"string\", description: \"Key id to revoke. It is marked revoked with a timestamp and a reason, and signatures presented with it are refused from then on. A key id that is unknown is refused with -32071.\" },\n reason: { type: \"string\", description: \"Why the key was revoked, e.g. 'laptop lost'. Recorded on the key and in the audit entry.\" },\n },\n required: [\"workspace\", \"from\", \"target_uri\", \"kid\"],\n },\n\n // ============================================================\n // audit-scitt/1.0\n // ============================================================\n\n \"chap.audit.submit_to_scitt\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n range: {\n type: \"object\",\n description: \"Sequence window to anchor. Omit to submit the whole chain.\",\n properties: {\n from_seq: { type: \"integer\", description: \"Start sequence number, inclusive.\" },\n to_seq: { type: \"integer\", description: \"End sequence number, exclusive.\" },\n },\n },\n issuer: { type: \"string\", description: \"Issuer identifier placed on each SCITT signed statement, naming who vouches for the chain. Defaults to 'service:coordinator'. Where no submitter is configured the statements are returned unsigned for the deployment to submit out of band.\" },\n },\n required: [\"workspace\"],\n },\n\n \"chap.audit.verify_receipt\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n receipt: { type: \"object\", additionalProperties: true, description: \"The SCITT receipt to check, as returned by the transparency service. Verification is delegated to a hook supplied by the deployment, and fails closed with -32082 where no hook is configured.\" },\n },\n required: [\"workspace\", \"receipt\"],\n },\n\n \"chap.audit.verify_chain\": {\n type: \"object\",\n properties: { workspace: WORKSPACE_ID, from: PARTICIPANT_URI },\n required: [\"workspace\"],\n },\n};\n\n/** Methods that map to MCP tools. Currently: all 39 CHAP methods. */\nexport const TOOL_NAMES = Object.keys(SCHEMAS);\n\n/** Get the JSON Schema for a tool, or null if not a known CHAP method. */\nexport function schemaFor(toolName: string): JsonSchema | null {\n return SCHEMAS[toolName] ?? null;\n}\n\n/** Map an MCP tool name back to its CHAP method name. */\nexport function methodForTool(toolName: string): string | null {\n if (!toolName.startsWith(\"chap.\")) return null;\n return toolName.slice(\"chap.\".length);\n}\n\n// ============================================================\n// Stringified-JSON coercion\n// ============================================================\n//\n// LLM MCP clients (Claude Desktop, Cursor, and others) frequently\n// serialise structured tool arguments as JSON-encoded *strings* rather\n// than as native JSON objects/arrays. For example, an `artefact` that\n// should arrive as { \"draft\": \"...\" } arrives as the string\n// \"{\\\"draft\\\": \\\"...\\\"}\", and a `to` that should be [\"human:me@local\"]\n// arrives as \"[\\\"human:me@local\\\"]\".\n//\n// The CHAP protocol core is deliberately strict: it stores artefacts\n// and applies JSON Patches against whatever it receives. A stringified\n// object therefore (a) pollutes the audit log with the wrong type and\n// (b) makes object-path patches in decide.override impossible, because\n// there is no object to traverse.\n//\n// We fix this at the adapter boundary, leaving the protocol core\n// untouched. Before an argument is wrapped in a CHAP envelope, any\n// string value whose schema admits a non-string type is JSON-parsed\n// when (and only when) it parses cleanly to a type the schema allows.\n// Plain strings that the schema accepts as strings (participant URIs,\n// task ids, rationales) are never touched, so a bare \"human:me@local\"\n// passed to a string|array `to` field is preserved as-is.\n\n/** True if the schema admits `object` as a value type. */\nfunction admitsType(schema: JsonSchema | undefined, t: \"object\" | \"array\"): boolean {\n if (!schema) return false;\n if (schema.type === t) return true;\n if (schema.oneOf) return schema.oneOf.some((s) => admitsType(s, t));\n // A field declared with neither `type` nor `oneOf` (e.g. `output`,\n // `artefact`) is an opaque payload: it admits any JSON value, so we\n // allow coercion to both object and array for it.\n if (schema.type === undefined && !schema.oneOf && !schema.enum) return true;\n return false;\n}\n\n/**\n * Coerce a single argument value against its parameter schema. Returns\n * the parsed value when the string is stringified JSON the schema\n * accepts; otherwise returns the value unchanged.\n */\nfunction coerceValue(value: unknown, schema: JsonSchema | undefined): unknown {\n if (typeof value !== \"string\") return value;\n const trimmed = value.trim();\n if (trimmed.length === 0) return value;\n const looksLikeObject = trimmed.startsWith(\"{\");\n const looksLikeArray = trimmed.startsWith(\"[\");\n if (!looksLikeObject && !looksLikeArray) return value;\n\n const wantObject = looksLikeObject && admitsType(schema, \"object\");\n const wantArray = looksLikeArray && admitsType(schema, \"array\");\n if (!wantObject && !wantArray) return value;\n\n try {\n const parsed = JSON.parse(value);\n // Only accept the parse if its type is one the schema admits. This\n // guards against, say, a string that happens to start with \"[\" but\n // is meant to be a literal string in a string-only field.\n if (Array.isArray(parsed) && admitsType(schema, \"array\")) return parsed;\n if (parsed !== null && typeof parsed === \"object\" && !Array.isArray(parsed)\n && admitsType(schema, \"object\")) return parsed;\n return value;\n } catch {\n // Not valid JSON: leave it for the coordinator to validate/reject.\n return value;\n }\n}\n\n/**\n * Normalise the arguments object for a tool call, coercing any\n * stringified-JSON values whose parameter schema admits a structured\n * type. Unknown keys (not in the schema) are passed through untouched.\n *\n * This is a pure function: it returns a new object and does not mutate\n * its input. Coordinator dispatch sees correctly-typed params, so the\n * audit log records the right shapes and decide.override patches apply\n * against real objects.\n */\nexport function coerceToolArgs(\n toolName: string,\n args: Record<string, unknown>,\n): Record<string, unknown> {\n const schema = schemaFor(toolName);\n const props = schema?.properties;\n if (!props) return args;\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(args)) {\n out[key] = coerceValue(value, props[key]);\n }\n return out;\n}\n","/**\n * @brightbeamai/chap-coordinator-mcp/tools\n *\n * Tool-level descriptions and behavioural annotations for each CHAP\n * method exposed over MCP. A client shows these in its UI and reads\n * them when choosing a tool.\n *\n * A description says what the method does, how it differs from its\n * nearest sibling, and the consequence a caller most needs to know\n * before calling. It does not restate the parameter schema: every\n * parameter is already described in schemas.ts, and repeating that\n * here costs length and adds no meaning.\n *\n * The annotations carry what prose states poorly.\n *\n * `readOnlyHint` is not a judgement. It is exactly the coordinator's\n * own READ_ONLY_METHODS set, the list that decides whether an envelope\n * is recorded on the audit chain, and a test holds the two together.\n * Anything absent from that set appends an entry, which is a change of\n * state whatever else it does.\n *\n * `idempotentHint` was derived by calling each method twice with\n * identical arguments and comparing workspace state, and is claimed\n * only where the second call both succeeds and leaves that state\n * untouched. Where a repeat is refused rather than absorbed, the hint\n * is absent: an agent must not read an error as a safe retry. It is\n * also absent from `task.create`, which is idempotent only when the\n * caller supplies `idempotency_key` and creates a second task when\n * they do not.\n *\n * `destructiveHint` marks the methods that overwrite or remove state\n * that was there before, or settle it somewhere it cannot come back\n * from. Most of CHAP is additive and carries `false`.\n */\n\nexport const TOOL_DESCRIPTIONS: Record<string, string> = {\n // Core\n \"chap.workspace.create\":\n \"Create a workspace: the container for the participants, tasks and audit log of one piece of \" +\n \"collaborative work. Returns the workspace id, which every later call carries.\",\n\n \"chap.workspace.describe\":\n \"Report the current state of a workspace: its members, enabled profiles, audit length, and task and \" +\n \"override counts.\",\n\n \"chap.workspace.set_profiles\":\n \"Replace the whole set of profiles enabled on a workspace. The list is not merged: any profile absent \" +\n \"from it is dropped, so send the complete set you want. Enabling audit-scitt/1.0 on a workspace that \" +\n \"already has entries starts the chain from that point and leaves the earlier entries permanently outside \" +\n \"it, which chap.audit.verify_chain then reports as not_evaluated. Prefer setting profiles at \" +\n \"chap.workspace.create, where no entries exist yet to strand.\",\n\n \"chap.participant.join\":\n \"Add a participant to a workspace. The type given, human, agent, service, group or workspace, decides \" +\n \"whether they are eligible to review work that requires it.\",\n\n \"chap.participant.leave\":\n \"Remove a participant from a workspace. Entries they have already written stay in the audit log and their \" +\n \"past signatures still verify, so leaving is not a way to withdraw a decision. They can no longer be \" +\n \"assigned tasks or act as a reviewer, and returning means a fresh chap.participant.join.\",\n\n \"chap.task.create\":\n \"Create a task: a unit of work assigned to one participant. Set review_required to make completion depend \" +\n \"on a reviewer decision rather than on the assignee. Returns a task_id that the rest of the lifecycle \" +\n \"takes. Supplying idempotency_key is what makes a retry safe: a repeat carrying a key already seen \" +\n \"returns the original task, while a repeat without one creates a second task. Assigning to a paused \" +\n \"member is refused.\",\n\n \"chap.task.update\":\n \"Move a task to a new state. Only the transitions in the specification's lifecycle table are accepted, \" +\n \"and a task that requires review cannot be completed here.\",\n\n \"chap.task.complete\":\n \"Submit a task's output. A task that requires review does not complete: the output is held as the \" +\n \"artefact under review, the task moves to review_requested, and a reviewer decision completes it. Any \" +\n \"other task completes immediately.\",\n\n \"chap.audit.read\":\n \"Read entries from a workspace's audit log, optionally within a sequence range and filtered by method, \" +\n \"sender, task or outcome. This is the query surface for everything the workspace has recorded, decisions \" +\n \"and overrides included. An accepted call is under 'envelope'. A refused attempt the coordinator recorded, \" +\n \"such as a decision by someone the review was not addressed to, is under 'request' with an 'outcome' \" +\n \"giving the error code, and it did not take effect. Reads only: it records nothing, so it never appears in \" +\n \"its own output. Entries come back as recorded, without aggregation, so grouping them, by tag for \" +\n \"instance, is the reader's job.\",\n\n // review/1.0\n \"chap.review.request\":\n \"Open a review on a task and address it to one or more reviewers. They then call chap.decide.approve, \" +\n \"chap.decide.reject, chap.decide.override or chap.abstain.declare. Repeating the request with the same \" +\n \"artefact adds reviewers to the open review.\",\n\n \"chap.decide.approve\":\n \"Approve the artefact under review as it stands. Only a reviewer the review was addressed to may decide, \" +\n \"and anyone else is refused with -32011. The task completes once the review's rule is satisfied, so under \" +\n \"all_approve or quorum:N an approval may leave the review open awaiting others. Use chap.decide.override \" +\n \"instead to accept a corrected version.\",\n\n \"chap.decide.reject\":\n \"Reject the artefact under review. The task is declined, or returns to in_progress when request_revision \" +\n \"is set, which is the choice between ending the work and sending it back. Only a reviewer the review was \" +\n \"addressed to may decide. Use chap.decide.override instead to correct the artefact and accept it rather \" +\n \"than refuse it.\",\n\n \"chap.decide.override\":\n \"Correct the artefact under review with an RFC 6902 JSON Patch and accept the result. The patch, the \" +\n \"rationale and any tags are recorded together, so the audit log holds what was changed and why, rather \" +\n \"than only that the work was not accepted as written.\",\n\n \"chap.abstain.declare\":\n \"Stand aside from a review this participant cannot decide, for example on a conflict of interest or for \" +\n \"want of context. Use it in place of chap.decide.reject, which judges the work; abstaining judges nothing \" +\n \"and leaves the artefact intact. It requires an open review addressed to the caller and answers -32010 \" +\n \"otherwise. The task moves to abstained, which is not terminal: chap.escalate.raise or a fresh \" +\n \"chap.review.request can still carry it forward.\",\n\n \"chap.escalate.raise\":\n \"Hand a task upwards, where the current holder can act but should not decide alone. The original moves to \" +\n \"escalated and is linked to a new task for whoever takes it on. Use chap.handoff.propose to pass work \" +\n \"sideways without that link, and chap.control.supersede to replace a task outright. The successor starts \" +\n \"with an empty input unless one is supplied, so restate whatever the new assignee needs. A completed, \" +\n \"cancelled or superseded task cannot be escalated. The successor takes the mode new_task.mode names, or \" +\n \"else the original's, and requires review when the original did, or when it is a trial task under \" +\n \"modes/1.0. A paused assignee is refused with -32063, and a mode above the workspace's current ceiling \" +\n \"with -32040; after the ceiling is lowered, name a mode within it.\",\n\n // whisper/1.0\n \"chap.whisper.ask\":\n \"Put one question to one or more participants, with a deadline and a default. If the deadline passes \" +\n \"unanswered the default applies, so a task is never blocked waiting on a reply.\",\n\n \"chap.whisper.answer\":\n \"Answer an open whisper. Where the question carried options, the answer must name one of their ids and \" +\n \"any other value is refused with -32022. A whisper already answered is refused with -32020 and one past \" +\n \"its deadline with -32021, in which case the default supplied at chap.whisper.ask has already been \" +\n \"applied.\",\n\n // deliberation/1.0\n \"chap.deliberate.open\":\n \"Open a group decision among several participants under a stated voting rule: any_one_approves, \" +\n \"all_approve, quorum:N, weighted_vote:T or weighted_vote_with_veto:T. Use it where several people must \" +\n \"weigh in on one question; chap.review.request is the tool for judging one participant's output. Returns \" +\n \"a deliberation_id that the comment, vote and close tools all take. The participant list, rule, weights \" +\n \"and veto map are fixed at open, so the terms are settled before anyone votes. No outcome exists until \" +\n \"chap.deliberate.close computes one.\",\n\n \"chap.deliberate.comment\":\n \"Record a comment on an open deliberation, so the reasoning behind a vote survives alongside the tally. \" +\n \"Comments carry no weight in the outcome and may be added by any participant at any point before \" +\n \"chap.deliberate.close.\",\n\n \"chap.deliberate.vote\":\n \"Cast a yea, nay or abstain in an open deliberation. Each participant votes once and a second attempt \" +\n \"answers -32031, so a vote cannot be revised. An abstention is recorded but counts as neither side, which \" +\n \"under all_approve or quorum:N withholds the approval those rules need. The tally is computed later, by \" +\n \"chap.deliberate.close.\",\n\n \"chap.deliberate.close\":\n \"Close a deliberation and compute its outcome from the votes cast under its rule. Closing is final: \" +\n \"further comments and votes are refused with -32032. Calling it again on a closed deliberation returns \" +\n \"the same outcome and changes nothing, so a retry is safe. Votes never cast are simply absent from the \" +\n \"tally rather than counted as abstentions.\",\n\n // handoff/1.0\n \"chap.handoff.propose\":\n \"Propose handing one or more tasks to another participant or a group, with the context needed to pick \" +\n \"them up. Every task must currently be assigned to the proposer.\",\n\n \"chap.handoff.accept\":\n \"Accept a proposed handoff. The accepted tasks are reassigned to the accepting participant, which is the \" +\n \"point at which responsibility actually moves. Omitting accepted_task_ids accepts all of them. Accepting \" +\n \"resolves the proposal for good: a later accept or decline on the same handoff answers -32051. A paused \" +\n \"participant cannot accept and is refused with -32063.\",\n\n \"chap.handoff.decline\":\n \"Decline a proposed handoff. The tasks stay with the proposer and nothing is reassigned, which is the \" +\n \"difference from chap.handoff.accept. Declining resolves the proposal for good: a later accept or decline \" +\n \"on the same handoff answers -32051, and trying again means a fresh proposal. The reason is recorded so \" +\n \"the proposer can route the work elsewhere.\",\n\n // control/1.0\n \"chap.control.pause\":\n \"Pause work. Scoped to a task it moves that task to paused; to a participant it stops new tasks being \" +\n \"assigned to them; to the workspace it refuses every method except describing, reading the audit log, \" +\n \"joining, leaving and resuming.\",\n\n \"chap.control.resume\":\n \"Resume work paused at the same scope: a task returns to the state it held at the pause, a participant \" +\n \"can be assigned tasks again, a workspace returns to active.\",\n\n \"chap.control.cancel\":\n \"Cancel a task. Cancelled is terminal, and a task that has already settled cannot be cancelled.\",\n\n \"chap.control.snapshot\":\n \"Capture the workspace state as an artefact before a change you may want to undo. Returns a snapshot \" +\n \"artefact id, which is the only thing chap.control.rollback accepts as a target; the label is for a human \" +\n \"reading the log and cannot be used to select it. Taking a snapshot changes nothing. Note that a rollback \" +\n \"restores only the mode ceiling and member roles, so a snapshot is a narrow safety net rather than a \" +\n \"general undo.\",\n\n \"chap.control.rollback\":\n \"Restore workspace state from a snapshot. The mode ceiling and member roles are restored; the rollback is \" +\n \"appended to the audit log rather than rewriting it.\",\n\n \"chap.control.supersede\":\n \"Replace a task with a successor in one call. The original moves to superseded and stays linked to its \" +\n \"replacement. The successor requires review when the original did, whatever its own review_required \" +\n \"says, and a paused assignee is refused with -32063.\",\n\n \"chap.control.set_mode_ceiling\":\n \"Set the highest operating mode tasks in this workspace may request. A task above the ceiling is refused.\",\n\n // routing/1.0\n \"chap.task.route\":\n \"Choose an assignee for a task from a list of candidates and reassign the task to the one selected. Use \" +\n \"it where the choice itself belongs on the record: it writes a route_decision artefact naming the policy, \" +\n \"the candidate chosen and the alternatives passed over, none of which is captured by setting assignee \" +\n \"directly on chap.task.create. The default policy takes the first candidate that is a workspace member \" +\n \"and is not paused. An operator-supplied policy may choose on any basis, and the call is refused with \" +\n \"-32510 when its choice is not a member, or with -32063 when its choice is paused.\",\n\n \"chap.review.depth\":\n \"Decide how much review a task warrants, skip, spot_check or full, from its routing hints. Records a \" +\n \"route_decision artefact giving the rule that produced the answer.\",\n\n \"chap.escalate.auto\":\n \"Evaluate a task's routing hints against the escalation policy and report whether it should be escalated, \" +\n \"and to whom. It decides only: a route_decision artefact is recorded but the task does not move, so act \" +\n \"on the answer with chap.escalate.raise. The default policy escalates on criticality critical, or high \" +\n \"with confidence below 0.6.\",\n\n // security-signed/1.0\n \"chap.participant.rotate_key\":\n \"Retire a participant's signing key and register its replacement. The old key stays in the key history \" +\n \"with a valid_until timestamp, so envelopes it signed still verify.\",\n\n \"chap.participant.revoke_key\":\n \"Revoke a signing key, for example after a device is lost. Signatures presented with it are refused from \" +\n \"then on. Revoking another participant's key requires the admin role.\",\n\n // audit-scitt/1.0\n \"chap.audit.submit_to_scitt\":\n \"Build COSE_Sign1-shaped statements for a range of audit entries and submit them to the configured SCITT \" +\n \"transparency service. Where none is configured the statements are returned for submission out of band.\",\n\n \"chap.audit.verify_receipt\":\n \"Check a receipt returned by an external SCITT transparency service, confirming that service logged the \" +\n \"statement. This is the external half of verification; chap.audit.verify_chain checks the local prev-hash \" +\n \"chain instead, and the two answer different questions. Verification is delegated to a hook the \" +\n \"deployment supplies and fails closed with -32082 when none is configured, so a missing verifier can \" +\n \"never read as a pass. Reads only: nothing is recorded.\",\n\n \"chap.audit.verify_chain\":\n \"Replay a workspace's prev-hash chain. Only status verified with ok true means the log was checked and is \" +\n \"intact. Status not_evaluated with ok false means part of the log was never checked, so its integrity is \" +\n \"unknown and must not be reported as verified; entries_unchecked says how much. An error means the chain \" +\n \"is broken or absent.\",\n};\n\n/** MCP tool annotations (2025-03-26 onwards). Every field is a hint. */\nexport interface ToolAnnotations {\n /** Human-readable title, shown by a client instead of the raw tool name. */\n title: string;\n /** Does not modify state. Mirrors the coordinator's own read-only set. */\n readOnlyHint: boolean;\n /** May overwrite or remove existing state, or settle it irreversibly. */\n destructiveHint: boolean;\n /** A repeat with identical arguments succeeds and changes nothing further. */\n idempotentHint: boolean;\n /** Reaches a system outside this coordinator. */\n openWorldHint: boolean;\n}\n\n/**\n * Read-only, and so never recorded on the chain. This is the coordinator's own\n * READ_ONLY_METHODS set, the list that decides whether an envelope is\n * recorded. It is repeated here rather than imported so the adapter does not\n * depend on a coordinator export at runtime, and annotations.test.ts reads\n * that source and fails if the two ever diverge.\n */\nconst READ_ONLY = new Set([\n \"chap.workspace.describe\", \"chap.audit.read\", \"chap.audit.verify_chain\", \"chap.audit.verify_receipt\",\n // Submitting reads the chain and sends it onward. It changes nothing here,\n // which is what readOnlyHint claims; openWorldHint carries the fact that it\n // reaches a service outside this coordinator.\n \"chap.audit.submit_to_scitt\",\n]);\n\n/** Overwrites, removes, or settles state irreversibly. */\nconst DESTRUCTIVE = new Set([\n \"chap.workspace.set_profiles\", // replaces the profile set; can strand entries outside the chain\n \"chap.participant.leave\", // removes a member\n \"chap.participant.revoke_key\", // invalidates a key from then on\n \"chap.control.cancel\", // cancelled is terminal\n \"chap.control.supersede\", // superseded is terminal\n \"chap.control.rollback\", // overwrites the mode ceiling and member roles\n]);\n\n/** Verified by calling twice with identical arguments and diffing workspace state. */\nconst IDEMPOTENT = new Set([\n \"chap.workspace.describe\", \"chap.audit.read\", \"chap.audit.verify_chain\", \"chap.audit.verify_receipt\",\n \"chap.participant.join\", // a re-join is additive and adds no duplicate member\n \"chap.participant.leave\", // leaving twice leaves the same absence\n \"chap.control.pause\", // pausing an already paused target changes nothing\n \"chap.control.set_mode_ceiling\", // setting the ceiling it already has changes nothing\n \"chap.deliberate.close\", // returns the same outcome, recomputing nothing\n]);\n\n/** Reaches a transparency service outside this coordinator. */\nconst OPEN_WORLD = new Set([\n \"chap.audit.submit_to_scitt\", \"chap.audit.verify_receipt\",\n]);\n\n/**\n * Human-readable titles. A client that shows a title instead of the tool\n * name should still show something a person can read at a glance.\n */\nconst TITLES: Record<string, string> = {\n \"chap.workspace.create\": \"Create workspace\",\n \"chap.workspace.describe\": \"Describe workspace\",\n \"chap.workspace.set_profiles\": \"Replace workspace profiles\",\n \"chap.participant.join\": \"Add participant\",\n \"chap.participant.leave\": \"Remove participant\",\n \"chap.task.create\": \"Create task\",\n \"chap.task.update\": \"Change task state\",\n \"chap.task.complete\": \"Submit task output\",\n \"chap.audit.read\": \"Read audit log\",\n \"chap.review.request\": \"Request review\",\n \"chap.decide.approve\": \"Approve\",\n \"chap.decide.reject\": \"Reject\",\n \"chap.decide.override\": \"Override with a correction\",\n \"chap.abstain.declare\": \"Abstain from review\",\n \"chap.escalate.raise\": \"Escalate task\",\n \"chap.whisper.ask\": \"Ask a whisper\",\n \"chap.whisper.answer\": \"Answer a whisper\",\n \"chap.deliberate.open\": \"Open deliberation\",\n \"chap.deliberate.comment\": \"Comment on deliberation\",\n \"chap.deliberate.vote\": \"Vote in deliberation\",\n \"chap.deliberate.close\": \"Close deliberation\",\n \"chap.handoff.propose\": \"Propose handoff\",\n \"chap.handoff.accept\": \"Accept handoff\",\n \"chap.handoff.decline\": \"Decline handoff\",\n \"chap.control.pause\": \"Pause work\",\n \"chap.control.resume\": \"Resume work\",\n \"chap.control.cancel\": \"Cancel task\",\n \"chap.control.snapshot\": \"Snapshot workspace\",\n \"chap.control.rollback\": \"Roll back to snapshot\",\n \"chap.control.supersede\": \"Supersede task\",\n \"chap.control.set_mode_ceiling\": \"Set mode ceiling\",\n \"chap.task.route\": \"Route task to an assignee\",\n \"chap.review.depth\": \"Decide review depth\",\n \"chap.escalate.auto\": \"Evaluate auto-escalation\",\n \"chap.participant.rotate_key\": \"Rotate signing key\",\n \"chap.participant.revoke_key\": \"Revoke signing key\",\n \"chap.audit.submit_to_scitt\": \"Anchor audit log in SCITT\",\n \"chap.audit.verify_receipt\": \"Verify SCITT receipt\",\n \"chap.audit.verify_chain\": \"Verify audit chain\",\n};\n\n/** Annotations for every tool, derived from the sets above. */\nexport const TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = Object.fromEntries(\n Object.keys(TOOL_DESCRIPTIONS).map((name) => [name, {\n title: TITLES[name] ?? name,\n readOnlyHint: READ_ONLY.has(name),\n // Meaningful only when readOnlyHint is false, per the specification.\n destructiveHint: DESTRUCTIVE.has(name),\n idempotentHint: IDEMPOTENT.has(name),\n openWorldHint: OPEN_WORLD.has(name),\n }]),\n);\n","/**\n * Per-request protocol envelope (MCP 2026-07-28).\n *\n * The 2026 revision is stateless: instead of negotiating once through an\n * `initialize` handshake, every request declares its protocol version and\n * client capabilities in `_meta`, and the server accepts or rejects each\n * request on its own. This module implements that classification so the\n * TypeScript adapter behaves the same way the Python `mcp` 2.x SDK does,\n * which enforces the same rules natively.\n *\n * Two version sets, deliberately different:\n *\n * - `MODERN_PROTOCOL_VERSIONS` is what may be declared per request. Only\n * revisions that use per-request metadata qualify, so `2025-11-25` is\n * not a legal per-request declaration: it is negotiated by handshake.\n * This is the set named in an `UnsupportedProtocolVersionError`, so a\n * client retrying from that list always retries with something usable.\n *\n * - `SUPPORTED_PROTOCOL_VERSIONS` is what `server/discover` advertises. It\n * spans both eras because CHAP serves both: a modern client uses\n * `2026-07-28` per request, a handshake-era client negotiates\n * `2025-11-25` through `initialize`.\n */\n\nimport { ErrorCode } from \"@modelcontextprotocol/sdk/types.js\";\n\n/**\n * A JSON-RPC error carrying a spec-exact `message`.\n *\n * The SDK's own `McpError` rewrites the message to `MCP error <code>: <text>`\n * and the protocol layer puts that rewritten string on the wire, which would\n * make CHAP answer `MCP error -32022: Unsupported protocol version` where the\n * specification, and the Python implementation, both say `Unsupported\n * protocol version`. The protocol layer reads `code`, `message` and `data`\n * off whatever is thrown, so a plain `Error` carrying those fields\n * serialises exactly as written.\n */\nexport class ProtocolError extends Error {\n readonly code: number;\n readonly data?: unknown;\n\n constructor(code: number, message: string, data?: unknown) {\n super(message);\n this.name = \"ProtocolError\";\n this.code = code;\n if (data !== undefined) this.data = data;\n }\n}\n\n/** `_meta` key carrying the protocol version of a single request. */\nexport const META_PROTOCOL_VERSION = \"io.modelcontextprotocol/protocolVersion\";\n/** `_meta` key carrying client identity. Optional per the specification. */\nexport const META_CLIENT_INFO = \"io.modelcontextprotocol/clientInfo\";\n/** `_meta` key carrying client capabilities. Required on a modern request. */\nexport const META_CLIENT_CAPABILITIES = \"io.modelcontextprotocol/clientCapabilities\";\n\n/**\n * `UnsupportedProtocolVersionError`. The specification reserves -32020 to\n * -32099 for its own codes; -32022 is the one it assigns to a version the\n * server does not implement.\n */\nexport const UNSUPPORTED_PROTOCOL_VERSION = -32022;\n\n/** Revisions that may be declared in a per-request `_meta` envelope. */\nexport const MODERN_PROTOCOL_VERSIONS = [\"2026-07-28\"] as const;\n\n/**\n * Revisions advertised by `server/discover`, newest first. The tool surface\n * is identical across both: CHAP exposes plain tools with JSON Schema\n * inputs, which the 2026-07-28 stateless core carries unchanged.\n */\nexport const SUPPORTED_PROTOCOL_VERSIONS = [\"2026-07-28\", \"2025-11-25\"] as const;\n\n/**\n * Which era a single request belongs to. `modern` means it carried a valid\n * per-request envelope; `legacy` means it carried no protocol version at\n * all and therefore belongs to a handshake-negotiated session.\n */\nexport type ProtocolEra = \"modern\" | \"legacy\";\n\n/**\n * Classify one request by its `_meta` envelope, rejecting a malformed or\n * unsupported one.\n *\n * The rejection ladder matches the Python SDK's, rung for rung, so the two\n * implementations answer an identical probe identically:\n *\n * 1. no `_meta`, or no protocol version in it, is a handshake-era request\n * 2. a declared version with no `clientCapabilities` is malformed: -32602\n * 3. a non-string version is malformed: -32602\n * 4. a version outside `MODERN_PROTOCOL_VERSIONS`: -32022\n *\n * @throws ProtocolError on a malformed or unsupported envelope.\n */\nexport function classifyEnvelope(params: unknown): ProtocolEra {\n const meta = readMeta(params);\n if (meta === null) return \"legacy\";\n\n if (!(META_PROTOCOL_VERSION in meta)) return \"legacy\";\n const declared = meta[META_PROTOCOL_VERSION];\n if (declared === undefined || declared === null) return \"legacy\";\n\n // A declared version makes this a modern request, so the rest of the\n // required envelope must be present. The specification marks\n // clientCapabilities required and clientInfo optional, and requires a\n // missing required field to be rejected as invalid params.\n if (!(META_CLIENT_CAPABILITIES in meta)) {\n throw new ProtocolError(\n ErrorCode.InvalidParams,\n `params._meta is missing the required envelope key(s): ${META_CLIENT_CAPABILITIES}`,\n );\n }\n\n if (typeof declared !== \"string\") {\n throw new ProtocolError(\n ErrorCode.InvalidParams,\n \"the protocol-version envelope value must be a string\",\n );\n }\n\n if (!(MODERN_PROTOCOL_VERSIONS as readonly string[]).includes(declared)) {\n throw new ProtocolError(UNSUPPORTED_PROTOCOL_VERSION, \"Unsupported protocol version\", {\n supported: [...MODERN_PROTOCOL_VERSIONS],\n requested: declared,\n });\n }\n\n return \"modern\";\n}\n\n/** Read `params._meta` as a plain object, or null when it is absent. */\nfunction readMeta(params: unknown): Record<string, unknown> | null {\n if (typeof params !== \"object\" || params === null) return null;\n const meta = (params as Record<string, unknown>)._meta;\n if (typeof meta !== \"object\" || meta === null || Array.isArray(meta)) return null;\n return meta as Record<string, unknown>;\n}\n"],"mappings":";AA2CA,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA,aAAAA;AAAA,OAGK;AACP,SAAS,SAAS;;;AClBlB,IAAM,kBAA8B;AAAA,EAClC,MAAM;AAAA,EACN,aAAa;AACf;AAEA,IAAM,eAA2B;AAAA,EAC/B,MAAM;AAAA,EACN,aAAa;AACf;AAEA,IAAM,UAAsB;AAAA,EAC1B,MAAM;AAAA,EACN,aAAa;AACf;AASA,IAAM,oBAAoB,CAAC,YACzB,sCAAsC,OAAO;AAE/C,IAAM,gBAA4B;AAAA,EAChC,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
+ {"version":3,"sources":["../src/index.ts","../src/schemas.ts","../src/tools.ts","../src/envelope.ts"],"sourcesContent":["/**\n * @brightbeamai/chap-coordinator-mcp\n *\n * MCP server adapter for a CHAP Coordinator. Wraps a Coordinator\n * instance and exposes every CHAP method as an MCP tool.\n *\n * Spec target: MCP 2026-07-28 (current), serving MCP 2025-11-25\n * clients as well. CHAP 0.3.\n *\n * Usage (stdio):\n *\n * import { Coordinator } from \"@brightbeamai/chap-coordinator\";\n * import { makeChapMcpServer } from \"@brightbeamai/chap-coordinator-mcp\";\n * import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\n *\n * const coord = new Coordinator({ ... });\n * const server = makeChapMcpServer(coord, { name: \"chap\", version: \"0.3.4\" });\n * await server.connect(new StdioServerTransport());\n *\n * Usage (Streamable HTTP): see reference/mcp-server-ts/server.ts.\n *\n * Architecture notes:\n *\n * - One Coordinator -> one MCP server. Multi-workspace is handled\n * inside the Coordinator (workspaces are addressable by id).\n *\n * - The adapter holds no state. Every tool call translates to a\n * JSON-RPC envelope and dispatches through coord.dispatch().\n *\n * - Tool naming follows \"chap.<method>\" so the prefix avoids\n * collisions with other MCP servers a client might load.\n *\n * - Tool inputs are described by JSON Schemas (not Zod) and are\n * passed through to the Coordinator without re-validating at the\n * MCP layer. The Coordinator's own dispatch validates params and\n * returns spec-correct JSON-RPC error codes, which we surface as\n * MCP tool errors. This keeps the schema definitions single-sourced.\n *\n * - Authentication is intentionally out of scope at this layer.\n * Apply OAuth 2.1 / Streamable HTTP auth at the transport layer\n * per MCP's auth model.\n */\n\nimport { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema,\n ErrorCode,\n type CallToolResult,\n type Tool,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { z } from \"zod\";\nimport type { Coordinator, Envelope } from \"@brightbeamai/chap-coordinator\";\n\nimport { SCHEMAS, TOOL_NAMES, methodForTool, coerceToolArgs } from \"./schemas.js\";\nimport { TOOL_DESCRIPTIONS, TOOL_ANNOTATIONS } from \"./tools.js\";\nimport { classifyEnvelope, ProtocolError, SUPPORTED_PROTOCOL_VERSIONS, type ProtocolEra } from \"./envelope.js\";\n\nexport { SCHEMAS, TOOL_NAMES, schemaFor, methodForTool, coerceToolArgs } from \"./schemas.js\";\nexport { TOOL_DESCRIPTIONS, TOOL_ANNOTATIONS } from \"./tools.js\";\nexport type { ToolAnnotations } from \"./tools.js\";\nexport type { JsonSchema } from \"./schemas.js\";\n\nexport {\n ProtocolError,\n MODERN_PROTOCOL_VERSIONS,\n SUPPORTED_PROTOCOL_VERSIONS,\n UNSUPPORTED_PROTOCOL_VERSION,\n META_PROTOCOL_VERSION,\n META_CLIENT_INFO,\n META_CLIENT_CAPABILITIES,\n classifyEnvelope,\n} from \"./envelope.js\";\nexport type { ProtocolEra } from \"./envelope.js\";\n\n/** `_meta` key carrying server identity (MCP 2026-07-28, SEP-2575). */\nexport const META_SERVER_INFO = \"io.modelcontextprotocol/serverInfo\";\n\n/** Freshness hint for cacheable list results. The CHAP tool surface is\n * fixed at construction, so a long TTL is safe. */\nconst LIST_TTL_MS = 3_600_000;\n\n/**\n * Request schema for `server/discover` (MCP 2026-07-28, SEP-2575).\n *\n * Hand-written because the pinned SDK major predates the 2026 era. The\n * shape is permissive on `params` so a probe carrying `_meta`\n * (protocolVersion, clientInfo, clientCapabilities) validates, and a\n * bare probe with no params validates too.\n */\nexport const ServerDiscoverRequestSchema = z.object({\n method: z.literal(\"server/discover\"),\n // `.passthrough()` keeps unknown keys under zod 3 and zod 4 alike, and the\n // package accepts both majors. The zod 4 name for the same thing does not\n // exist in zod 3, where it stopped the package at import.\n params: z.optional(z.object({ _meta: z.optional(z.record(z.string(), z.unknown())) }).passthrough()),\n});\n\nexport interface ChapMcpOptions {\n /** Server name advertised to MCP clients. Default: \"chap\". */\n name?: string;\n /** Server version. Default: \"0.3.4\". */\n version?: string;\n /**\n * Restrict the CHAP methods this server offers. Default: all 39. A tool the\n * filter excludes is left out of the list and refused when called.\n */\n toolFilter?: (toolName: string) => boolean;\n /**\n * Make every call as this participant. `from` is filled in on each call,\n * and a call that names another `from` is refused. Use it where the server\n * is one participant's connection, such as an agent's, so the connection\n * cannot act in anyone else's name. Default: each call names its own `from`.\n */\n participant?: string;\n /** Optional id generator for the envelopes emitted by tool calls. */\n envelopeIdFactory?: () => string | number;\n}\n\n/**\n * Wrap a CHAP Coordinator as an MCP server. The returned ``Server``\n * has ``tools/list`` and ``tools/call`` handlers registered for every\n * CHAP method; pass it to a transport (stdio, Streamable HTTP) to\n * start serving.\n */\nexport function makeChapMcpServer(coord: Coordinator, options: ChapMcpOptions = {}): Server {\n const serverInfo = {\n name: options.name ?? \"chap\",\n version: options.version ?? \"0.3.4\",\n };\n\n const server = new Server(\n serverInfo,\n {\n capabilities: {\n tools: {},\n },\n },\n );\n\n let counter = 0;\n const nextId = options.envelopeIdFactory ?? (() => `mcp-${++counter}`);\n const filter = options.toolFilter ?? (() => true);\n\n const enabledTools: Tool[] = TOOL_NAMES\n .filter((name) => filter(name) && methodForTool(name) !== null)\n .map((name) => {\n const ann = TOOL_ANNOTATIONS[name];\n return {\n name,\n // The title was the tool name, which told a reader nothing they could\n // not already see. The annotation carries a readable one.\n title: ann?.title ?? name,\n description: TOOL_DESCRIPTIONS[name] ?? `CHAP method ${methodForTool(name)}.`,\n inputSchema: SCHEMAS[name] as Tool[\"inputSchema\"],\n // Behavioural hints. Without these a client has only the prose to go\n // on when deciding whether a call is safe to make or to retry.\n ...(ann ? { annotations: ann } : {}),\n };\n });\n\n server.setRequestHandler(ListToolsRequestSchema, async (request) => {\n // Rejects a malformed or unsupported envelope before any work is done.\n const era = classifyEnvelope(request.params);\n if (era === \"legacy\") return { tools: enabledTools };\n\n // 2026-07-28 requires every result to be typed, and makes list results\n // cacheable. These fields are 2026 vocabulary, so they are emitted only\n // to a caller that asked in 2026 terms; a handshake-era session gets the\n // result shape its own revision defines.\n return {\n tools: enabledTools,\n resultType: \"complete\",\n ttlMs: LIST_TTL_MS,\n cacheScope: \"public\",\n _meta: { [META_SERVER_INFO]: serverInfo },\n };\n });\n\n // server/discover (MCP 2026-07-28, SEP-2575). Servers MUST implement it;\n // clients MAY call it for up-front version selection, and on stdio a\n // client that supports both eras SHOULD probe with it first. Answering\n // the probe is what keeps this server usable by 2026-era clients: a\n // server that stays silent is only reachable through timeout-based\n // fallback to the legacy initialize handshake.\n //\n // Registered against a hand-written schema because the pinned SDK\n // (1.x) predates the 2026 era and does not export one yet. When the\n // SDK ships its own ServerDiscover types this can be swapped for them\n // without changing the wire behaviour.\n server.setRequestHandler(ServerDiscoverRequestSchema, async (request) => {\n // `server/discover` is 2026 vocabulary. A request that carries no\n // per-request envelope belongs to the handshake era, where the method\n // does not exist; answering it anyway would tell a dual-era client that\n // a legacy connection can speak 2026. Mirrors the Python SDK, which\n // returns MethodNotFound in the same situation.\n if (classifyEnvelope(request.params) === \"legacy\") {\n // `data` carries the method name, matching what the Python SDK emits,\n // so a client sees the same error either side.\n throw new ProtocolError(ErrorCode.MethodNotFound, \"Method not found\", \"server/discover\");\n }\n return {\n resultType: \"complete\",\n supportedVersions: SUPPORTED_PROTOCOL_VERSIONS,\n capabilities: { tools: {} },\n instructions:\n \"CHAP Coordinator exposed as MCP tools. Every accepted call that \" +\n \"changes state is recorded on the CHAP audit log, as is a member's \" +\n \"refused attempt at a governed action. Governed methods enforce \" +\n \"membership and review rules server-side.\",\n ttlMs: LIST_TTL_MS,\n cacheScope: \"public\",\n _meta: { [META_SERVER_INFO]: serverInfo },\n };\n });\n\n server.setRequestHandler(CallToolRequestSchema, async (request): Promise<CallToolResult> => {\n const era = classifyEnvelope(request.params);\n // `resultType` is 2026 vocabulary: emitted to a modern caller, withheld\n // from a handshake-era one whose revision does not define the field.\n const terminal = <T extends object>(result: T): T =>\n (era === \"modern\" ? { resultType: \"complete\", ...result } : result) as T;\n\n const toolName = request.params.name;\n const rawArgs = (request.params.arguments ?? {}) as Record<string, unknown>;\n const method = methodForTool(toolName);\n\n if (!method) {\n return terminal({\n isError: true,\n content: [{ type: \"text\", text: `Unknown CHAP tool: ${toolName}` }],\n });\n }\n // The filter decides what this server offers, so a tool it excludes is\n // refused here as well as left out of the list. Hidden alone, it still ran\n // for any client that called it by name.\n if (!filter(toolName)) {\n return terminal({\n isError: true,\n content: [{ type: \"text\", text: `CHAP tool not offered by this server: ${toolName}` }],\n });\n }\n\n // Normalise stringified-JSON arguments (a common MCP-client\n // behaviour) before they reach the protocol core. See coerceToolArgs.\n const args = { ...coerceToolArgs(toolName, rawArgs) };\n if (options.participant !== undefined) {\n if (args.from !== undefined && args.from !== options.participant) {\n return terminal({\n isError: true,\n content: [{\n type: \"text\",\n text: `This server acts as ${options.participant}; a call cannot name another from (${JSON.stringify(args.from)}).`,\n }],\n });\n }\n args.from = options.participant;\n }\n\n const envelope: Envelope = {\n jsonrpc: \"2.0\",\n id: nextId(),\n method,\n params: args,\n };\n\n let response: Envelope;\n try {\n response = coord.dispatch(envelope);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n return terminal({\n isError: true,\n content: [{ type: \"text\", text: `CHAP dispatch threw: ${msg}` }],\n });\n }\n\n if (response.error) {\n return terminal({\n isError: true,\n content: [{\n type: \"text\",\n text: JSON.stringify({\n chap_error: response.error.code,\n message: response.error.message,\n ...(response.error.data !== undefined ? { data: response.error.data } : {}),\n }, null, 2),\n }],\n });\n }\n\n return terminal({\n content: [{\n type: \"text\",\n text: JSON.stringify(response.result, null, 2),\n }],\n });\n });\n\n return server;\n}\n\n/**\n * Lower-level helper: translate a tool call to a CHAP envelope and\n * back. Useful for tests and for embedding the adapter inside a\n * larger MCP server that registers its own additional tools.\n */\nexport function dispatchToolCall(\n coord: Coordinator,\n toolName: string,\n args: Record<string, unknown>,\n envelopeId: string | number = \"mcp-call\",\n): Envelope {\n const method = methodForTool(toolName);\n if (!method) {\n return {\n jsonrpc: \"2.0\",\n id: envelopeId,\n error: { code: -32601, message: `Unknown CHAP tool: ${toolName}` },\n };\n }\n return coord.dispatch({\n jsonrpc: \"2.0\",\n id: envelopeId,\n method,\n params: coerceToolArgs(toolName, args ?? {}),\n });\n}\n","/**\n * @brightbeamai/chap-coordinator-mcp/schemas\n *\n * JSON Schema definitions for each CHAP method, used as the\n * inputSchema for the corresponding MCP tool. Each schema describes\n * the params object that the CHAP envelope would carry; the tool\n * handler wraps the params in a JSON-RPC 2.0 envelope before dispatch.\n *\n * A description here is what an MCP client reads before deciding\n * whether and how to call the tool, so each one states what the\n * coordinator does with the parameter, and names the error code where\n * a constraint is enforced. A parameter that is recorded but not acted\n * on says so; describing an intention the code does not implement is\n * worse than saying nothing.\n *\n * Aligned with CHAP 0.3 (see profiles/*.md) and MCP 2025-11-25.\n */\n\nexport interface JsonSchema {\n type?: string;\n description?: string;\n properties?: Record<string, JsonSchema>;\n required?: string[];\n enum?: string[];\n items?: JsonSchema;\n additionalProperties?: boolean | JsonSchema;\n oneOf?: JsonSchema[];\n default?: unknown;\n /** JSON Schema `pattern`, used where a string has a fixed wire shape. */\n pattern?: string;\n}\n\n// Common reusable fragments.\nconst PARTICIPANT_URI: JsonSchema = {\n type: \"string\",\n description: \"Participant URI, e.g. 'human:alice@example.org' or 'agent:bot@local'.\",\n};\n\nconst WORKSPACE_ID: JsonSchema = {\n type: \"string\",\n description: \"Workspace identifier, e.g. 'wsp_techcorp_support'.\",\n};\n\nconst TASK_ID: JsonSchema = {\n type: \"string\",\n description: \"Task identifier returned by chap.task.create.\",\n};\n\n/**\n * SPECIFICATION.md S7: a number in a CHAP envelope must be an integer.\n * Fractional values travel as decimal strings, so that canonicalisation and\n * therefore the audit hash are identical across implementations. A JSON number\n * with a fractional part is refused at ingress with -32602, so any parameter\n * that is conceptually fractional is declared here as a string.\n */\nconst decimalStringNote = (example: string) =>\n `Written as a decimal string, e.g. \"${example}\". CHAP canonicalisation accepts integers only, so a JSON number with a fractional part is refused with -32602.`;\n\nconst ROUTING_HINTS: JsonSchema = {\n type: \"object\",\n description: \"Signals recorded on the task and read by the routing/1.0 methods: task.route, review.depth and escalate.auto. Recording a hint has no effect on its own; it is consulted only when one of those methods is called.\",\n properties: {\n criticality: {\n type: \"string\",\n enum: [\"low\", \"medium\", \"high\", \"critical\"],\n description: \"How costly a wrong answer would be. The default review-depth policy reads it: 'critical' gives a full review, and 'high' with confidence below 0.7 does the same. The default assignee policy does not read it.\",\n },\n deadline: { type: \"string\", description: \"When the work is needed by, as an ISO 8601 timestamp. Recorded on the task; the coordinator does not act on it.\" },\n risk_tier: { type: \"string\", description: \"Operator-defined risk band, e.g. 'regulated' or 'internal'. No built-in policy reads it; it is available to an operator-supplied routing policy.\" },\n max_cost_usd: { type: \"string\", description: `Budget ceiling for this task in US dollars. ${decimalStringNote(\"12.50\")} No built-in policy reads it.` },\n },\n additionalProperties: true,\n};\n\n/** Free-text justification attached to a decision and kept in the audit log. */\nconst COMMENT: JsonSchema = {\n type: \"string\",\n description: \"The reviewer's note on this decision. Recorded in the audit entry for the decision.\",\n};\n\n/** Workspace-defined labels carried on a decision. */\nconst TAGS: JsonSchema = {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Workspace-defined labels for this decision, e.g. ['tone', 'unsupported-claim']. Recorded in the audit entry. chap.audit.read does not filter on tags, so grouping by tag is done by the reader.\",\n};\n\n/** Binds a decision to the exact artefact the reviewer saw. */\nconst ARTEFACT_DIGEST: JsonSchema = {\n type: \"string\",\n pattern: \"^sha256:[0-9a-f]{64}$\",\n description: \"Optional. SHA-256 over the JCS canonicalisation of the artefact under review, in the form `sha256:<hex>`. When present it binds the decision to the exact content reviewed, and a mismatch is refused with -32074.\",\n};\n\n/** Applies to `output` and `artefact`, which are opaque JSON payloads. */\nconst STRUCTURED_PAYLOAD_NOTE =\n \"Pass a JSON object or array. A JSON-encoded string is parsed back to the structured value before dispatch, so patches in chap.decide.override apply against a real object.\";\n\n// ============================================================\n// Core\n// ============================================================\n\nexport const SCHEMAS: Record<string, JsonSchema> = {\n \"chap.workspace.create\": {\n type: \"object\",\n properties: {\n workspace: { ...WORKSPACE_ID, description: \"Workspace id to create. If omitted, one is generated.\" },\n profiles: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Profile identifiers to enable, e.g. ['core/1.0', 'review/1.0']. Recorded on the workspace. Two profiles change behaviour by being present: modes/1.0, under which a trial-mode task requires review, and audit-scitt/1.0, which turns on the hash-linked chain.\",\n },\n mode: {\n type: \"string\",\n enum: [\"shadow\", \"trial\", \"production\"],\n default: \"trial\",\n description: \"Default mode for tasks created here. Under modes/1.0 a trial-mode task has review_required set to true whatever the caller passes. 'shadow' and 'production' are recorded on the task and carry no further behaviour in this implementation.\",\n },\n mode_ceiling: {\n type: \"string\",\n enum: [\"shadow\", \"trial\", \"production\"],\n default: \"production\",\n description: \"Highest mode a task in this workspace may request. A task.create above the ceiling is refused with -32040. The ceiling can be changed afterwards with chap.control.set_mode_ceiling.\",\n },\n },\n additionalProperties: false,\n },\n\n \"chap.workspace.describe\": {\n type: \"object\",\n properties: { workspace: WORKSPACE_ID },\n required: [\"workspace\"],\n },\n\n \"chap.workspace.set_profiles\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n profiles: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"The complete profile set to enable, replacing the current one. Adding audit-scitt/1.0 to a workspace that already has entries leaves those entries unchained and outside chain verification.\",\n },\n },\n required: [\"workspace\", \"profiles\"],\n },\n\n \"chap.participant.join\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: PARTICIPANT_URI,\n type: {\n type: \"string\",\n enum: [\"human\", \"agent\", \"service\", \"group\", \"workspace\"],\n description: \"The kind of participant. Only members of type 'human' are eligible for the review that chap.task.complete opens on a task marked review_required, and a completion with no eligible human is refused with -32011.\",\n },\n role: { type: \"string\", description: \"Operator-defined role, e.g. 'reviewer' or 'drafter'. One value is read by the coordinator: 'admin' permits revoking another member's key.\" },\n display_name: { type: \"string\", description: \"Human-readable name for interfaces. Not used in authorisation.\" },\n },\n required: [\"workspace\", \"from\", \"type\"],\n },\n\n \"chap.participant.leave\": {\n type: \"object\",\n properties: { workspace: WORKSPACE_ID, from: PARTICIPANT_URI },\n required: [\"workspace\", \"from\"],\n },\n\n \"chap.task.create\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: { ...PARTICIPANT_URI, description: \"The delegator. Must be a workspace member.\" },\n kind: { type: \"string\", description: \"Task kind, e.g. 'draft_response' or 'review'. Free text; the coordinator records it without interpreting it.\" },\n assignee: { ...PARTICIPANT_URI, description: \"Who the task is assigned to. Must be a workspace member, and must not be paused: assigning to a paused member is refused with -32063.\" },\n input: { type: \"object\", description: \"Task-specific input payload.\", additionalProperties: true },\n routing_hints: ROUTING_HINTS,\n mode: {\n type: \"string\",\n enum: [\"shadow\", \"trial\", \"production\"],\n description: \"Mode for this task, defaulting to the workspace mode. A mode above the workspace ceiling is refused with -32040.\",\n },\n review_required: {\n type: \"boolean\",\n description: \"When true, chap.task.complete opens a review instead of completing: the output becomes the artefact under review, and the task reaches 'completed' only on a reviewer decision. chap.task.update cannot complete such a task. Under modes/1.0 a trial-mode task has this set to true whatever is passed here.\",\n },\n deadline: { type: \"string\", description: \"When the task is due, as an ISO 8601 timestamp. Recorded on the task; the coordinator does not act on it.\" },\n idempotency_key: {\n type: \"string\",\n description: \"Caller-chosen key for safe retries. A second create carrying a key already seen in this workspace returns the original task and records nothing further. The workspace retains the 10,000 most recent keys.\",\n },\n },\n required: [\"workspace\", \"from\", \"kind\", \"assignee\", \"input\"],\n },\n\n \"chap.task.update\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: PARTICIPANT_URI,\n task_id: TASK_ID,\n state: {\n type: \"string\",\n enum: [\"in_progress\", \"declined\", \"cancelled\", \"completed\"],\n description: \"The state to move the task to. Only the transitions in SPECIFICATION.md 8.1 are legal from the task's current state; others are refused with -32602. A review opens with chap.review.request, or with chap.task.complete on a task that requires one, so 'review_requested' is not a target here. A task marked review_required cannot be moved to 'completed' here: submit the output with chap.task.complete, which opens the review.\",\n },\n progress_note: { type: \"string\", description: \"Short note on what changed, kept in the task's history.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"state\"],\n },\n\n \"chap.task.complete\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: PARTICIPANT_URI,\n task_id: TASK_ID,\n output: { description: `The task's output artefact. ${STRUCTURED_PAYLOAD_NOTE}` },\n confidence: { type: \"string\", description: `Self-reported confidence in the output, between 0 and 1. ${decimalStringNote(\"0.86\")}` },\n routing_hints: ROUTING_HINTS,\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.audit.read\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n range: {\n type: \"object\",\n description: \"Sequence window to return. Omit for the whole log.\",\n properties: {\n from_seq: { type: \"integer\", description: \"Start sequence number, inclusive.\" },\n to_seq: { type: \"integer\", description: \"End sequence number, exclusive.\" },\n },\n },\n filter: {\n type: \"object\",\n description: \"Narrows the entries returned. Conditions combine with AND, and are applied within the sequence window rather than before it.\",\n properties: {\n method: { type: \"string\", description: \"Return only entries for this CHAP method, e.g. 'decide.override'. Matched in full, without the 'chap.' tool-name prefix.\" },\n from: { type: \"string\", description: \"Return only entries whose actor is this participant URI.\" },\n task_id: { type: \"string\", description: \"Return only entries about this task.\" },\n outcome: {\n type: \"string\",\n enum: [\"accepted\", \"refused\"],\n description: \"Return only accepted calls, or only the refused attempts the coordinator recorded. Omit for both.\",\n },\n },\n },\n },\n required: [\"workspace\"],\n },\n\n // ============================================================\n // review/1.0\n // ============================================================\n\n \"chap.review.request\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID,\n from: PARTICIPANT_URI,\n task_id: TASK_ID,\n to: {\n oneOf: [PARTICIPANT_URI, { type: \"array\", items: PARTICIPANT_URI }],\n description: \"One or more reviewers, as a single URI string or an array of URI strings. Only a workspace member can go on to decide, so a review addressed elsewhere cannot be closed by its recipient.\",\n },\n rule: {\n type: \"string\",\n enum: [\"any_one_approves\", \"all_approve\", \"quorum:2\", \"quorum:3\"],\n default: \"any_one_approves\",\n description: \"How many of the addressed reviewers must approve before the task completes. quorum:N is accepted for any N of 1 or more. The rule is fixed once the review is open: a later request naming a different one is refused with -32014. Omitting it on a later request leaves the rule alone, which is how reviewers are added to an open review.\",\n },\n artefact: { description: `The draft being submitted for review. ${STRUCTURED_PAYLOAD_NOTE} Re-requesting with the same artefact widens the reviewer set; a different artefact on an open review is refused with -32014.` },\n deadline: { type: \"string\", description: \"When the review is needed by, as an ISO 8601 timestamp. Recorded on the review; the coordinator does not act on it.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"to\", \"artefact\"],\n },\n\n \"chap.decide.approve\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n approved_artefact_digest: ARTEFACT_DIGEST,\n comment: COMMENT,\n tags: TAGS,\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.decide.reject\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n approved_artefact_digest: ARTEFACT_DIGEST,\n comment: COMMENT,\n tags: TAGS,\n request_revision: { type: \"boolean\", description: \"When true the task returns to 'in_progress' rather than 'declined', so the assignee can revise and resubmit.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.decide.override\": {\n type: \"object\",\n properties: {\n approved_artefact_digest: ARTEFACT_DIGEST,\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n diff: {\n type: \"array\",\n description: \"RFC 6902 JSON Patch operations applied to the artefact under review. The patched artefact becomes the task output; a patch that does not apply is refused with -32012.\",\n items: {\n type: \"object\",\n properties: {\n op: { type: \"string\", enum: [\"add\", \"replace\", \"remove\", \"copy\", \"move\", \"test\"], description: \"The patch operation to apply.\" },\n path: { type: \"string\", description: \"JSON Pointer into the artefact, e.g. '/body' or '/items/0/severity'.\" },\n value: { description: \"The new value, for add, replace and test.\" },\n from: { type: \"string\", description: \"Source JSON Pointer, for copy and move.\" },\n },\n required: [\"op\", \"path\"],\n },\n },\n rationale: { type: \"string\", description: \"Why the correction was made. Required on every override and recorded in the audit entry, since the diff shows what changed but not why.\" },\n tags: TAGS,\n policy_refs: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Identifiers of the policies or guidelines this correction applies, e.g. ['policy:no-delivery-promises']. Recorded in the audit entry.\",\n },\n logical_id: {\n type: \"string\",\n description: \"Caller-chosen identifier for the item being decided, stable across revisions and overrides of the same underlying content. Recorded in the audit entry.\",\n },\n intent_preserved: {\n type: \"boolean\",\n description: \"True when the edit refines the decision the draft was making, false when it substitutes a different one. Recorded in the audit entry.\",\n },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"diff\", \"rationale\"],\n },\n\n \"chap.abstain.declare\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n reason: { type: \"string\", description: \"Why this reviewer is standing aside. Recorded in the audit entry.\" },\n category: {\n type: \"string\",\n enum: [\"conflict_of_interest\", \"insufficient_context\", \"out_of_scope\", \"other\"],\n description: \"The kind of abstention. Recorded in the audit entry.\",\n },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"reason\"],\n },\n\n \"chap.escalate.raise\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n original_task_id: { ...TASK_ID, description: \"The task being escalated. It moves to 'escalated' and is linked to the successor. A completed, cancelled or superseded task cannot be escalated.\" },\n new_task: {\n type: \"object\",\n description: \"The successor task to open for the escalation target.\",\n properties: {\n kind: { type: \"string\", description: \"Task kind for the successor. Defaults to the original's kind.\" },\n assignee: { ...PARTICIPANT_URI, description: \"Who the escalation goes to. Must be a workspace member who is not paused: a paused assignee is refused with -32063.\" },\n input: { type: \"object\", additionalProperties: true, description: \"Input payload for the successor. It defaults to an empty object rather than the original's input, so anything the new assignee needs has to be restated here.\" },\n mode: { type: \"string\", enum: [\"shadow\", \"trial\", \"production\"], description: \"Mode for the successor, defaulting to the original's. A mode above the workspace's current ceiling is refused with -32040, so after the ceiling is lowered a task is escalated by naming a mode within it.\" },\n },\n required: [\"assignee\"],\n },\n },\n required: [\"workspace\", \"from\", \"original_task_id\", \"new_task\"],\n },\n\n // ============================================================\n // whisper/1.0\n // ============================================================\n\n \"chap.whisper.ask\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI, task_id: TASK_ID,\n to: { type: \"array\", items: PARTICIPANT_URI, description: \"Who is being asked.\" },\n question: { type: \"string\", description: \"The question being put. A whisper is answered on its own, without the recipient opening the task.\" },\n options: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Stable identifier that an answer refers to.\" },\n label: { type: \"string\", description: \"What the option says to the person answering.\" },\n },\n required: [\"id\"],\n },\n description: \"Multiple-choice options. When present, an answer must name one of these ids in answer_option; any other id is refused with -32022.\",\n },\n deadline_ms: { type: \"integer\", description: \"How long the whisper stays open, in milliseconds from now. Once it passes, the whisper lapses and default_if_lapsed is applied.\" },\n default_if_lapsed: { description: \"The value applied if the deadline passes with no answer. Required, so that a lapsed whisper still has a defined outcome.\" },\n urgency: {\n type: \"string\",\n enum: [\"low\", \"medium\", \"high\"],\n default: \"low\",\n description: \"How urgent the question is. Recorded and passed on to the client; it does not change the deadline or the lapse behaviour.\",\n },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"to\", \"question\", \"deadline_ms\", \"default_if_lapsed\"],\n },\n\n \"chap.whisper.answer\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n whisper_id: { type: \"string\", description: \"Identifier returned by chap.whisper.ask. A whisper that has already been answered is refused with -32020, and one past its deadline with -32021.\" },\n answer_option: { type: \"string\", description: \"The id of the chosen option. Required when the whisper carried options.\" },\n answer: { type: \"string\", description: \"Free-text answer, for a whisper with no options.\" },\n comment: { type: \"string\", description: \"Anything else the answerer wants recorded alongside the answer.\" },\n },\n required: [\"workspace\", \"from\", \"whisper_id\"],\n },\n\n // ============================================================\n // deliberation/1.0\n // ============================================================\n\n \"chap.deliberate.open\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n to: { type: \"array\", items: PARTICIPANT_URI, description: \"The participants entitled to vote. A vote from anyone else is refused with -32030.\" },\n task_id: TASK_ID,\n rule: {\n type: \"string\",\n description: \"How the outcome is decided when the deliberation closes: any_one_approves, all_approve, quorum:N, weighted_vote:T or weighted_vote_with_veto:T. An unrecognised rule is refused at open with -32033.\",\n },\n question: { type: \"string\", description: \"What the group is deciding. State it so that a yea or a nay is unambiguous.\" },\n weights: { type: \"object\", additionalProperties: { type: \"integer\" }, description: \"Voter to weight map, read by the weighted rules. A voter with no entry counts as 1. Weights must be integers: a JSON number with a fractional part is refused with -32602.\" },\n veto: { type: \"object\", additionalProperties: { type: \"boolean\" }, description: \"Voter to can-veto map. A veto is honoured only under weighted_vote_with_veto, and only from a voter listed true here.\" },\n deadline: { type: \"string\", description: \"When voting is intended to close, as an ISO 8601 timestamp. Recorded on the deliberation; closing is done by chap.deliberate.close and the coordinator does not close on the deadline.\" },\n },\n required: [\"workspace\", \"from\", \"to\", \"rule\"],\n },\n\n \"chap.deliberate.comment\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n deliberation_id: { type: \"string\", description: \"Identifier returned by chap.deliberate.open. A closed deliberation is refused with -32032.\" },\n comment: { type: \"string\", description: \"The contribution to record. Comments are kept with the deliberation and in the audit log, so the reasoning survives the vote.\" },\n },\n required: [\"workspace\", \"from\", \"deliberation_id\", \"comment\"],\n },\n\n \"chap.deliberate.vote\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n deliberation_id: { type: \"string\", description: \"Identifier returned by chap.deliberate.open. A closed deliberation is refused with -32032, and a second vote from the same voter with -32031.\" },\n vote: { type: \"string\", enum: [\"yea\", \"nay\", \"abstain\"], description: \"This voter's position. An abstention is recorded but counts as neither a yea nor a nay, so under all_approve or quorum:N it withholds the approval those rules need.\" },\n weight: { type: \"integer\", description: \"Recorded with the vote. The tally uses the weights map given at chap.deliberate.open, not this value.\" },\n comment: { type: \"string\", description: \"Why the vote went this way. Recorded with it.\" },\n veto_invoked: { type: \"boolean\", description: \"Blocks the outcome regardless of the tally. Honoured only under weighted_vote_with_veto, and only when the voter is listed true in the veto map given at open.\" },\n },\n required: [\"workspace\", \"from\", \"deliberation_id\", \"vote\"],\n },\n\n \"chap.deliberate.close\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n deliberation_id: { type: \"string\", description: \"Identifier returned by chap.deliberate.open. Closing computes the outcome from the votes cast; closing an already closed deliberation returns the outcome unchanged.\" },\n },\n required: [\"workspace\", \"from\", \"deliberation_id\"],\n },\n\n // ============================================================\n // handoff/1.0\n // ============================================================\n\n \"chap.handoff.propose\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n to: { type: \"string\", description: \"Recipient, as a participant URI or a group URI such as 'group:support-team'. A recipient who is not a workspace member is refused with -32052.\" },\n tasks: {\n type: \"array\",\n description: \"The work being handed over, one entry per task. Every task must currently be assigned to the proposer; otherwise the proposal is refused with -32050.\",\n items: {\n type: \"object\",\n properties: {\n task_id: TASK_ID,\n title: { type: \"string\", description: \"Short label for the task.\" },\n status_summary: { type: \"string\", description: \"Where the work has reached, and what has already been tried.\" },\n next_action: { type: \"string\", description: \"What the recipient should do first.\" },\n blockers: { type: \"array\", items: { type: \"string\" }, description: \"What is preventing progress, if anything.\" },\n },\n required: [\"task_id\"],\n },\n },\n summary: { type: \"string\", description: \"Covering note for the handover as a whole, above the per-task detail.\" },\n context_links: { type: \"array\", items: { type: \"string\" }, description: \"URLs to threads, tickets or documents the recipient will need.\" },\n },\n required: [\"workspace\", \"from\", \"to\", \"tasks\"],\n },\n\n \"chap.handoff.accept\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n handoff_id: { type: \"string\", description: \"Identifier returned by chap.handoff.propose. A handoff already accepted or declined is refused with -32051.\" },\n accepted_task_ids: { type: \"array\", items: TASK_ID, description: \"Which of the proposed tasks are being accepted. If omitted, all of them are.\" },\n comment: { type: \"string\", description: \"Anything the recipient wants recorded when taking the work on.\" },\n },\n required: [\"workspace\", \"from\", \"handoff_id\"],\n },\n\n \"chap.handoff.decline\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n handoff_id: { type: \"string\", description: \"Identifier returned by chap.handoff.propose. A handoff already accepted or declined is refused with -32051.\" },\n reason: { type: \"string\", description: \"Why the handover is refused. Recorded so the proposer can route it elsewhere.\" },\n suggested_target: { ...PARTICIPANT_URI, description: \"Who should take it instead, if the decliner knows.\" },\n },\n required: [\"workspace\", \"from\", \"handoff_id\"],\n },\n\n // ============================================================\n // control/1.0\n // ============================================================\n\n \"chap.control.pause\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n scope: {\n type: \"string\",\n enum: [\"task\", \"participant\", \"workspace\"],\n default: \"task\",\n description: \"What the pause applies to. 'task' moves one task to 'paused'; a task that is completed, declined, cancelled or superseded is refused with -32061. 'participant' stops new tasks being assigned to that member and leaves their existing work running. 'workspace' refuses every method except workspace.create, workspace.describe, control.resume, audit.read, participant.join and participant.leave.\",\n },\n task_id: TASK_ID,\n participant_uri: { ...PARTICIPANT_URI, description: \"Whose work to pause, when scope is 'participant'. Must be a workspace member.\" },\n in_flight_policy: {\n type: \"string\",\n enum: [\"allow_to_complete\", \"interrupt\"],\n description: \"Recorded with the request, and echoed back when scope is 'participant'. The coordinator does not act on it: under either value, work already under way is left alone.\",\n },\n reason: { type: \"string\", description: \"Why the pause was applied. Recorded in the audit entry.\" },\n },\n required: [\"workspace\", \"from\"],\n },\n\n \"chap.control.resume\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n scope: {\n type: \"string\",\n enum: [\"task\", \"participant\", \"workspace\"],\n default: \"task\",\n description: \"What the resume applies to. 'task' returns a paused task to the state it held at the pause; a task that is not paused is refused with -32061. 'participant' allows that member to be assigned tasks again. 'workspace' returns the workspace to active.\",\n },\n task_id: TASK_ID,\n participant_uri: { ...PARTICIPANT_URI, description: \"Whose work to resume, when scope is 'participant'. Must be a workspace member.\" },\n },\n required: [\"workspace\", \"from\"],\n },\n\n \"chap.control.cancel\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: { ...TASK_ID, description: \"The task to cancel. A task that is completed, declined, cancelled or superseded is refused with -32061.\" },\n reason: { type: \"string\", description: \"Why the task was cancelled. Recorded in the audit entry.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.control.snapshot\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n label: { type: \"string\", description: \"Name for this snapshot, recorded on the artefact. chap.control.rollback identifies a snapshot by its artefact id, not by label.\" },\n include: { type: \"array\", items: { type: \"string\" }, description: \"Which aspects of the workspace to capture. Recognised values are 'members', 'open_tasks', 'mode_ceiling', 'policy' and 'audit'. Defaults to members, open_tasks and mode_ceiling.\" },\n },\n required: [\"workspace\", \"from\"],\n },\n\n \"chap.control.rollback\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n to_snapshot_artefact_id: { type: \"string\", description: \"Artefact id returned by chap.control.snapshot. An id with no matching snapshot is refused with -32062.\" },\n what_to_restore: { type: \"array\", items: { type: \"string\" }, description: \"Which captured aspects to apply. Only 'mode_ceiling' and 'members' are restored; the others are held in the snapshot and not reapplied. Restoring members resets role and scopes on members still present, and does not re-add members who have left. Defaults to the snapshot's include list.\" },\n reason: { type: \"string\", description: \"Why the rollback was performed. The rollback is itself an audit entry; earlier entries are not rewritten.\" },\n },\n required: [\"workspace\", \"from\", \"to_snapshot_artefact_id\"],\n },\n\n \"chap.control.supersede\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: { ...TASK_ID, description: \"The task being replaced. It moves to 'superseded' and is linked to the successor rather than deleted.\" },\n successor_task: {\n type: \"object\",\n description: \"The replacement task.\",\n properties: {\n kind: { type: \"string\", description: \"Task kind for the successor. Required.\" },\n assignee: { ...PARTICIPANT_URI, description: \"Who takes the replacement on. Defaults to the superseded task's assignee, and must be a workspace member who is not paused.\" },\n input: { type: \"object\", additionalProperties: true, description: \"Input payload for the successor. Defaults to an empty object.\" },\n mode: { type: \"string\", enum: [\"shadow\", \"trial\", \"production\"], description: \"Mode for the successor, defaulting to the superseded task's. A mode above the workspace's current ceiling is refused with -32040.\" },\n review_required: { type: \"boolean\", description: \"Whether completing the successor needs a reviewer decision. A successor of a task that requires review requires it whatever is passed here, and under modes/1.0 so does a trial-mode successor.\" },\n },\n required: [\"kind\"],\n },\n reason: { type: \"string\", description: \"Why the original is being replaced. Recorded in the audit entry.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"successor_task\"],\n },\n\n \"chap.control.set_mode_ceiling\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n new_ceiling: {\n type: \"string\",\n enum: [\"shadow\", \"trial\", \"production\"],\n description: \"The highest mode tasks in this workspace may request from now on. Existing tasks keep the mode they were created with. Where the coordinator is configured to enforce step-up authentication this method is one of the privileged ones and a call without step-up is refused with -32402.\",\n },\n reason: { type: \"string\", description: \"Why the ceiling is being changed. Recorded in the audit entry.\" },\n },\n required: [\"workspace\", \"from\", \"new_ceiling\"],\n },\n\n // ============================================================\n // routing/1.0\n // ============================================================\n\n \"chap.task.route\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: TASK_ID,\n candidates: { type: \"array\", items: PARTICIPANT_URI, description: \"Candidate assignees. An empty list is refused with -32513. The default policy takes the first candidate that is a workspace member and is not paused, and refuses the call with -32510 when there is none. An operator-supplied routing policy may select on any basis; a choice that is not a member is refused with -32510, and one who is paused with -32063.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\", \"candidates\"],\n },\n\n \"chap.review.depth\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: TASK_ID,\n artefact_routing_hints: {\n type: \"object\",\n description: \"Per-artefact signals such as confidence, model_id and cost_consumed_usd, merged over the task's routing_hints for this call. The default policy reads criticality and confidence. If the merged set is empty the call is refused with -32514. Fractional values are written as decimal strings, e.g. \\\"confidence\\\": \\\"0.86\\\".\",\n additionalProperties: true,\n },\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n \"chap.escalate.auto\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n task_id: TASK_ID,\n default_escalation_target: { ...PARTICIPANT_URI, description: \"Who to escalate to when the policy decides to escalate and names no target of its own. It must be a workspace member or a group URI; if the policy escalates with no usable target the call is refused with -32516.\" },\n },\n required: [\"workspace\", \"from\", \"task_id\"],\n },\n\n // ============================================================\n // security-signed/1.0\n // ============================================================\n\n \"chap.participant.rotate_key\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n old_kid: { type: \"string\", description: \"Key id being retired. It is given a valid_until timestamp and stays in the member's key history, so signatures made before the rotation still verify. A key id that is unknown is refused with -32071, and one already revoked with -32072.\" },\n new_jwk: { type: \"object\", additionalProperties: true, description: \"The replacement public key as a JWK. It must carry a 'kid'. Whether the request itself has to be signed with the old key is decided at dispatch, and only where the coordinator is configured to require signatures.\" },\n },\n required: [\"workspace\", \"from\", \"old_kid\", \"new_jwk\"],\n },\n\n \"chap.participant.revoke_key\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n target_uri: { ...PARTICIPANT_URI, description: \"Whose key is being revoked. Revoking another member's key requires the caller to hold the role 'admin'; otherwise the call is refused with -32011.\" },\n kid: { type: \"string\", description: \"Key id to revoke. It is marked revoked with a timestamp and a reason, and signatures presented with it are refused from then on. A key id that is unknown is refused with -32071.\" },\n reason: { type: \"string\", description: \"Why the key was revoked, e.g. 'laptop lost'. Recorded on the key and in the audit entry.\" },\n },\n required: [\"workspace\", \"from\", \"target_uri\", \"kid\"],\n },\n\n // ============================================================\n // audit-scitt/1.0\n // ============================================================\n\n \"chap.audit.submit_to_scitt\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n range: {\n type: \"object\",\n description: \"Sequence window to anchor. Omit to submit the whole chain.\",\n properties: {\n from_seq: { type: \"integer\", description: \"Start sequence number, inclusive.\" },\n to_seq: { type: \"integer\", description: \"End sequence number, exclusive.\" },\n },\n },\n issuer: { type: \"string\", description: \"Issuer identifier placed on each SCITT signed statement, naming who vouches for the chain. Defaults to 'service:coordinator'. Where no submitter is configured the statements are returned unsigned for the deployment to submit out of band.\" },\n },\n required: [\"workspace\"],\n },\n\n \"chap.audit.verify_receipt\": {\n type: \"object\",\n properties: {\n workspace: WORKSPACE_ID, from: PARTICIPANT_URI,\n receipt: { type: \"object\", additionalProperties: true, description: \"The SCITT receipt to check, as returned by the transparency service. Verification is delegated to a hook supplied by the deployment, and fails closed with -32082 where no hook is configured.\" },\n },\n required: [\"workspace\", \"receipt\"],\n },\n\n \"chap.audit.verify_chain\": {\n type: \"object\",\n properties: { workspace: WORKSPACE_ID, from: PARTICIPANT_URI },\n required: [\"workspace\"],\n },\n};\n\n/** Methods that map to MCP tools. Currently: all 39 CHAP methods. */\nexport const TOOL_NAMES = Object.keys(SCHEMAS);\n\n/** Get the JSON Schema for a tool, or null if not a known CHAP method. */\nexport function schemaFor(toolName: string): JsonSchema | null {\n return SCHEMAS[toolName] ?? null;\n}\n\n/** Map an MCP tool name back to its CHAP method name. */\nexport function methodForTool(toolName: string): string | null {\n if (!toolName.startsWith(\"chap.\")) return null;\n return toolName.slice(\"chap.\".length);\n}\n\n// ============================================================\n// Stringified-JSON coercion\n// ============================================================\n//\n// LLM MCP clients (Claude Desktop, Cursor, and others) frequently\n// serialise structured tool arguments as JSON-encoded *strings* rather\n// than as native JSON objects/arrays. For example, an `artefact` that\n// should arrive as { \"draft\": \"...\" } arrives as the string\n// \"{\\\"draft\\\": \\\"...\\\"}\", and a `to` that should be [\"human:me@local\"]\n// arrives as \"[\\\"human:me@local\\\"]\".\n//\n// The CHAP protocol core is deliberately strict: it stores artefacts\n// and applies JSON Patches against whatever it receives. A stringified\n// object therefore (a) pollutes the audit log with the wrong type and\n// (b) makes object-path patches in decide.override impossible, because\n// there is no object to traverse.\n//\n// We fix this at the adapter boundary, leaving the protocol core\n// untouched. Before an argument is wrapped in a CHAP envelope, any\n// string value whose schema admits a non-string type is JSON-parsed\n// when (and only when) it parses cleanly to a type the schema allows.\n// Plain strings that the schema accepts as strings (participant URIs,\n// task ids, rationales) are never touched, so a bare \"human:me@local\"\n// passed to a string|array `to` field is preserved as-is.\n\n/** True if the schema admits `object` as a value type. */\nfunction admitsType(schema: JsonSchema | undefined, t: \"object\" | \"array\"): boolean {\n if (!schema) return false;\n if (schema.type === t) return true;\n if (schema.oneOf) return schema.oneOf.some((s) => admitsType(s, t));\n // A field declared with neither `type` nor `oneOf` (e.g. `output`,\n // `artefact`) is an opaque payload: it admits any JSON value, so we\n // allow coercion to both object and array for it.\n if (schema.type === undefined && !schema.oneOf && !schema.enum) return true;\n return false;\n}\n\n/**\n * Coerce a single argument value against its parameter schema. Returns\n * the parsed value when the string is stringified JSON the schema\n * accepts; otherwise returns the value unchanged.\n */\nfunction coerceValue(value: unknown, schema: JsonSchema | undefined): unknown {\n if (typeof value !== \"string\") return value;\n const trimmed = value.trim();\n if (trimmed.length === 0) return value;\n const looksLikeObject = trimmed.startsWith(\"{\");\n const looksLikeArray = trimmed.startsWith(\"[\");\n if (!looksLikeObject && !looksLikeArray) return value;\n\n const wantObject = looksLikeObject && admitsType(schema, \"object\");\n const wantArray = looksLikeArray && admitsType(schema, \"array\");\n if (!wantObject && !wantArray) return value;\n\n try {\n const parsed = JSON.parse(value);\n // Only accept the parse if its type is one the schema admits. This\n // guards against, say, a string that happens to start with \"[\" but\n // is meant to be a literal string in a string-only field.\n if (Array.isArray(parsed) && admitsType(schema, \"array\")) return parsed;\n if (parsed !== null && typeof parsed === \"object\" && !Array.isArray(parsed)\n && admitsType(schema, \"object\")) return parsed;\n return value;\n } catch {\n // Not valid JSON: leave it for the coordinator to validate/reject.\n return value;\n }\n}\n\n/**\n * Normalise the arguments object for a tool call, coercing any\n * stringified-JSON values whose parameter schema admits a structured\n * type. Unknown keys (not in the schema) are passed through untouched.\n *\n * This is a pure function: it returns a new object and does not mutate\n * its input. Coordinator dispatch sees correctly-typed params, so the\n * audit log records the right shapes and decide.override patches apply\n * against real objects.\n */\nexport function coerceToolArgs(\n toolName: string,\n args: Record<string, unknown>,\n): Record<string, unknown> {\n const schema = schemaFor(toolName);\n const props = schema?.properties;\n if (!props) return args;\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(args)) {\n out[key] = coerceValue(value, props[key]);\n }\n return out;\n}\n","/**\n * @brightbeamai/chap-coordinator-mcp/tools\n *\n * Tool-level descriptions and behavioural annotations for each CHAP\n * method exposed over MCP. A client shows these in its UI and reads\n * them when choosing a tool.\n *\n * A description says what the method does, how it differs from its\n * nearest sibling, and the consequence a caller most needs to know\n * before calling. It does not restate the parameter schema: every\n * parameter is already described in schemas.ts, and repeating that\n * here costs length and adds no meaning.\n *\n * The annotations carry what prose states poorly.\n *\n * `readOnlyHint` is not a judgement. It is exactly the coordinator's\n * own READ_ONLY_METHODS set, the list that decides whether an envelope\n * is recorded on the audit chain, and a test holds the two together.\n * Anything absent from that set appends an entry, which is a change of\n * state whatever else it does.\n *\n * `idempotentHint` was derived by calling each method twice with\n * identical arguments and comparing workspace state, and is claimed\n * only where the second call both succeeds and leaves that state\n * untouched. Where a repeat is refused rather than absorbed, the hint\n * is absent: an agent must not read an error as a safe retry. It is\n * also absent from `task.create`, which is idempotent only when the\n * caller supplies `idempotency_key` and creates a second task when\n * they do not.\n *\n * `destructiveHint` marks the methods that overwrite or remove state\n * that was there before, or settle it somewhere it cannot come back\n * from. Most of CHAP is additive and carries `false`.\n */\n\nexport const TOOL_DESCRIPTIONS: Record<string, string> = {\n // Core\n \"chap.workspace.create\":\n \"Create a workspace: the container for the participants, tasks and audit log of one piece of \" +\n \"collaborative work. Returns the workspace id, which every later call carries.\",\n\n \"chap.workspace.describe\":\n \"Report the current state of a workspace: its members, enabled profiles, audit length, and task and \" +\n \"override counts.\",\n\n \"chap.workspace.set_profiles\":\n \"Replace the whole set of profiles enabled on a workspace. The list is not merged: any profile absent \" +\n \"from it is dropped, so send the complete set you want. Enabling audit-scitt/1.0 on a workspace that \" +\n \"already has entries starts the chain from that point and leaves the earlier entries permanently outside \" +\n \"it, which chap.audit.verify_chain then reports as not_evaluated. Prefer setting profiles at \" +\n \"chap.workspace.create, where no entries exist yet to strand.\",\n\n \"chap.participant.join\":\n \"Add a participant to a workspace. The type given, human, agent, service, group or workspace, decides \" +\n \"whether they are eligible to review work that requires it.\",\n\n \"chap.participant.leave\":\n \"Remove a participant from a workspace. Entries they have already written stay in the audit log and their \" +\n \"past signatures still verify, so leaving is not a way to withdraw a decision. They can no longer be \" +\n \"assigned tasks or act as a reviewer, and returning means a fresh chap.participant.join.\",\n\n \"chap.task.create\":\n \"Create a task: a unit of work assigned to one participant. Set review_required to make completion depend \" +\n \"on a reviewer decision rather than on the assignee. Returns a task_id that the rest of the lifecycle \" +\n \"takes. Supplying idempotency_key is what makes a retry safe: a repeat carrying a key already seen \" +\n \"returns the original task, while a repeat without one creates a second task. Assigning to a paused \" +\n \"member is refused.\",\n\n \"chap.task.update\":\n \"Move a task to a new state. Only the transitions in the specification's lifecycle table are accepted, \" +\n \"and a task that requires review cannot be completed here.\",\n\n \"chap.task.complete\":\n \"Submit a task's output. A task that requires review does not complete: the output is held as the \" +\n \"artefact under review, the task moves to review_requested, and a reviewer decision completes it. Any \" +\n \"other task completes immediately.\",\n\n \"chap.audit.read\":\n \"Read entries from a workspace's audit log, optionally within a sequence range and filtered by method, \" +\n \"sender, task or outcome. This is the query surface for everything the workspace has recorded, decisions \" +\n \"and overrides included. An accepted call is under 'envelope'. A refused attempt the coordinator recorded, \" +\n \"such as a decision by someone the review was not addressed to, is under 'request' with an 'outcome' \" +\n \"giving the error code, and it did not take effect. Reads only: it records nothing, so it never appears in \" +\n \"its own output. Entries come back as recorded, without aggregation, so grouping them, by tag for \" +\n \"instance, is the reader's job.\",\n\n // review/1.0\n \"chap.review.request\":\n \"Open a review on a task and address it to one or more reviewers. They then call chap.decide.approve, \" +\n \"chap.decide.reject, chap.decide.override or chap.abstain.declare. Repeating the request with the same \" +\n \"artefact adds reviewers to the open review.\",\n\n \"chap.decide.approve\":\n \"Approve the artefact under review as it stands. Only a reviewer the review was addressed to may decide, \" +\n \"and anyone else is refused with -32011. The task completes once the review's rule is satisfied, so under \" +\n \"all_approve or quorum:N an approval may leave the review open awaiting others. Use chap.decide.override \" +\n \"instead to accept a corrected version.\",\n\n \"chap.decide.reject\":\n \"Reject the artefact under review. The task is declined, or returns to in_progress when request_revision \" +\n \"is set, which is the choice between ending the work and sending it back. Only a reviewer the review was \" +\n \"addressed to may decide. Use chap.decide.override instead to correct the artefact and accept it rather \" +\n \"than refuse it.\",\n\n \"chap.decide.override\":\n \"Correct the artefact under review with an RFC 6902 JSON Patch and accept the result. The patch, the \" +\n \"rationale and any tags are recorded together, so the audit log holds what was changed and why, rather \" +\n \"than only that the work was not accepted as written.\",\n\n \"chap.abstain.declare\":\n \"Stand aside from a review this participant cannot decide, for example on a conflict of interest or for \" +\n \"want of context. Use it in place of chap.decide.reject, which judges the work; abstaining judges nothing \" +\n \"and leaves the artefact intact. It requires an open review addressed to the caller and answers -32010 \" +\n \"otherwise. The task moves to abstained, which is not terminal: chap.escalate.raise or a fresh \" +\n \"chap.review.request can still carry it forward.\",\n\n \"chap.escalate.raise\":\n \"Hand a task upwards, where the current holder can act but should not decide alone. The original moves to \" +\n \"escalated and is linked to a new task for whoever takes it on. Use chap.handoff.propose to pass work \" +\n \"sideways without that link, and chap.control.supersede to replace a task outright. The successor starts \" +\n \"with an empty input unless one is supplied, so restate whatever the new assignee needs. A completed, \" +\n \"cancelled or superseded task cannot be escalated. The successor takes the mode new_task.mode names, or \" +\n \"else the original's, and requires review when the original did, or when it is a trial task under \" +\n \"modes/1.0. A paused assignee is refused with -32063, and a mode above the workspace's current ceiling \" +\n \"with -32040; after the ceiling is lowered, name a mode within it.\",\n\n // whisper/1.0\n \"chap.whisper.ask\":\n \"Put one question to one or more participants, with a deadline and a default. If the deadline passes \" +\n \"unanswered the default applies, so a task is never blocked waiting on a reply.\",\n\n \"chap.whisper.answer\":\n \"Answer an open whisper. Where the question carried options, the answer must name one of their ids and \" +\n \"any other value is refused with -32022. A whisper already answered is refused with -32020 and one past \" +\n \"its deadline with -32021, in which case the default supplied at chap.whisper.ask has already been \" +\n \"applied.\",\n\n // deliberation/1.0\n \"chap.deliberate.open\":\n \"Open a group decision among several participants under a stated voting rule: any_one_approves, \" +\n \"all_approve, quorum:N, weighted_vote:T or weighted_vote_with_veto:T. Use it where several people must \" +\n \"weigh in on one question; chap.review.request is the tool for judging one participant's output. Returns \" +\n \"a deliberation_id that the comment, vote and close tools all take. The participant list, rule, weights \" +\n \"and veto map are fixed at open, so the terms are settled before anyone votes. No outcome exists until \" +\n \"chap.deliberate.close computes one.\",\n\n \"chap.deliberate.comment\":\n \"Record a comment on an open deliberation, so the reasoning behind a vote survives alongside the tally. \" +\n \"Comments carry no weight in the outcome and may be added by any participant at any point before \" +\n \"chap.deliberate.close.\",\n\n \"chap.deliberate.vote\":\n \"Cast a yea, nay or abstain in an open deliberation. Each participant votes once and a second attempt \" +\n \"answers -32031, so a vote cannot be revised. An abstention is recorded but counts as neither side, which \" +\n \"under all_approve or quorum:N withholds the approval those rules need. The tally is computed later, by \" +\n \"chap.deliberate.close.\",\n\n \"chap.deliberate.close\":\n \"Close a deliberation and compute its outcome from the votes cast under its rule. Closing is final: \" +\n \"further comments and votes are refused with -32032. Calling it again on a closed deliberation returns \" +\n \"the same outcome and changes nothing, so a retry is safe. Votes never cast are simply absent from the \" +\n \"tally rather than counted as abstentions.\",\n\n // handoff/1.0\n \"chap.handoff.propose\":\n \"Propose handing one or more tasks to another participant or a group, with the context needed to pick \" +\n \"them up. Every task must currently be assigned to the proposer.\",\n\n \"chap.handoff.accept\":\n \"Accept a proposed handoff. The accepted tasks are reassigned to the accepting participant, which is the \" +\n \"point at which responsibility actually moves. Omitting accepted_task_ids accepts all of them. Accepting \" +\n \"resolves the proposal for good: a later accept or decline on the same handoff answers -32051. A paused \" +\n \"participant cannot accept and is refused with -32063.\",\n\n \"chap.handoff.decline\":\n \"Decline a proposed handoff. The tasks stay with the proposer and nothing is reassigned, which is the \" +\n \"difference from chap.handoff.accept. Declining resolves the proposal for good: a later accept or decline \" +\n \"on the same handoff answers -32051, and trying again means a fresh proposal. The reason is recorded so \" +\n \"the proposer can route the work elsewhere.\",\n\n // control/1.0\n \"chap.control.pause\":\n \"Pause work. Scoped to a task it moves that task to paused; to a participant it stops new tasks being \" +\n \"assigned to them; to the workspace it refuses every method except describing, reading the audit log, \" +\n \"joining, leaving and resuming.\",\n\n \"chap.control.resume\":\n \"Resume work paused at the same scope: a task returns to the state it held at the pause, a participant \" +\n \"can be assigned tasks again, a workspace returns to active.\",\n\n \"chap.control.cancel\":\n \"Cancel a task. Cancelled is terminal, and a task that has already settled cannot be cancelled.\",\n\n \"chap.control.snapshot\":\n \"Capture the workspace state as an artefact before a change you may want to undo. Returns a snapshot \" +\n \"artefact id, which is the only thing chap.control.rollback accepts as a target; the label is for a human \" +\n \"reading the log and cannot be used to select it. Taking a snapshot changes nothing. Note that a rollback \" +\n \"restores only the mode ceiling and member roles, so a snapshot is a narrow safety net rather than a \" +\n \"general undo.\",\n\n \"chap.control.rollback\":\n \"Restore workspace state from a snapshot. The mode ceiling and member roles are restored; the rollback is \" +\n \"appended to the audit log rather than rewriting it.\",\n\n \"chap.control.supersede\":\n \"Replace a task with a successor in one call. The original moves to superseded and stays linked to its \" +\n \"replacement. The successor requires review when the original did, whatever its own review_required \" +\n \"says, and a paused assignee is refused with -32063.\",\n\n \"chap.control.set_mode_ceiling\":\n \"Set the highest operating mode tasks in this workspace may request. A task above the ceiling is refused.\",\n\n // routing/1.0\n \"chap.task.route\":\n \"Choose an assignee for a task from a list of candidates and reassign the task to the one selected. Use \" +\n \"it where the choice itself belongs on the record: it writes a route_decision artefact naming the policy, \" +\n \"the candidate chosen and the alternatives passed over, none of which is captured by setting assignee \" +\n \"directly on chap.task.create. The default policy takes the first candidate that is a workspace member \" +\n \"and is not paused. An operator-supplied policy may choose on any basis, and the call is refused with \" +\n \"-32510 when its choice is not a member, or with -32063 when its choice is paused.\",\n\n \"chap.review.depth\":\n \"Decide how much review a task warrants, skip, spot_check or full, from its routing hints. Records a \" +\n \"route_decision artefact giving the rule that produced the answer.\",\n\n \"chap.escalate.auto\":\n \"Evaluate a task's routing hints against the escalation policy and report whether it should be escalated, \" +\n \"and to whom. It decides only: a route_decision artefact is recorded but the task does not move, so act \" +\n \"on the answer with chap.escalate.raise. The default policy escalates on criticality critical, or high \" +\n \"with confidence below 0.6.\",\n\n // security-signed/1.0\n \"chap.participant.rotate_key\":\n \"Retire a participant's signing key and register its replacement. The old key stays in the key history \" +\n \"with a valid_until timestamp, so envelopes it signed still verify.\",\n\n \"chap.participant.revoke_key\":\n \"Revoke a signing key, for example after a device is lost. Signatures presented with it are refused from \" +\n \"then on. Revoking another participant's key requires the admin role.\",\n\n // audit-scitt/1.0\n \"chap.audit.submit_to_scitt\":\n \"Build COSE_Sign1-shaped statements for a range of audit entries and submit them to the configured SCITT \" +\n \"transparency service. Where none is configured the statements are returned for submission out of band.\",\n\n \"chap.audit.verify_receipt\":\n \"Check a receipt returned by an external SCITT transparency service, confirming that service logged the \" +\n \"statement. This is the external half of verification; chap.audit.verify_chain checks the local prev-hash \" +\n \"chain instead, and the two answer different questions. Verification is delegated to a hook the \" +\n \"deployment supplies and fails closed with -32082 when none is configured, so a missing verifier can \" +\n \"never read as a pass. Reads only: nothing is recorded.\",\n\n \"chap.audit.verify_chain\":\n \"Replay a workspace's prev-hash chain. Only status verified with ok true means the log was checked and is \" +\n \"intact. Status not_evaluated with ok false means part of the log was never checked, so its integrity is \" +\n \"unknown and must not be reported as verified; entries_unchecked says how much. An error means the chain \" +\n \"is broken or absent.\",\n};\n\n/** MCP tool annotations (2025-03-26 onwards). Every field is a hint. */\nexport interface ToolAnnotations {\n /** Human-readable title, shown by a client instead of the raw tool name. */\n title: string;\n /** Does not modify state. Mirrors the coordinator's own read-only set. */\n readOnlyHint: boolean;\n /** May overwrite or remove existing state, or settle it irreversibly. */\n destructiveHint: boolean;\n /** A repeat with identical arguments succeeds and changes nothing further. */\n idempotentHint: boolean;\n /** Reaches a system outside this coordinator. */\n openWorldHint: boolean;\n}\n\n/**\n * Read-only, and so never recorded on the chain. This is the coordinator's own\n * READ_ONLY_METHODS set, the list that decides whether an envelope is\n * recorded. It is repeated here rather than imported so the adapter does not\n * depend on a coordinator export at runtime, and annotations.test.ts reads\n * that source and fails if the two ever diverge.\n */\nconst READ_ONLY = new Set([\n \"chap.workspace.describe\", \"chap.audit.read\", \"chap.audit.verify_chain\", \"chap.audit.verify_receipt\",\n // Submitting reads the chain and sends it onward. It changes nothing here,\n // which is what readOnlyHint claims; openWorldHint carries the fact that it\n // reaches a service outside this coordinator.\n \"chap.audit.submit_to_scitt\",\n]);\n\n/** Overwrites, removes, or settles state irreversibly. */\nconst DESTRUCTIVE = new Set([\n \"chap.workspace.set_profiles\", // replaces the profile set; can strand entries outside the chain\n \"chap.participant.leave\", // removes a member\n \"chap.participant.revoke_key\", // invalidates a key from then on\n \"chap.control.cancel\", // cancelled is terminal\n \"chap.control.supersede\", // superseded is terminal\n \"chap.control.rollback\", // overwrites the mode ceiling and member roles\n]);\n\n/** Verified by calling twice with identical arguments and diffing workspace state. */\nconst IDEMPOTENT = new Set([\n \"chap.workspace.describe\", \"chap.audit.read\", \"chap.audit.verify_chain\", \"chap.audit.verify_receipt\",\n \"chap.participant.join\", // a re-join is additive and adds no duplicate member\n \"chap.participant.leave\", // leaving twice leaves the same absence\n \"chap.control.pause\", // pausing an already paused target changes nothing\n \"chap.control.set_mode_ceiling\", // setting the ceiling it already has changes nothing\n \"chap.deliberate.close\", // returns the same outcome, recomputing nothing\n]);\n\n/** Reaches a transparency service outside this coordinator. */\nconst OPEN_WORLD = new Set([\n \"chap.audit.submit_to_scitt\", \"chap.audit.verify_receipt\",\n]);\n\n/**\n * Human-readable titles. A client that shows a title instead of the tool\n * name should still show something a person can read at a glance.\n */\nconst TITLES: Record<string, string> = {\n \"chap.workspace.create\": \"Create workspace\",\n \"chap.workspace.describe\": \"Describe workspace\",\n \"chap.workspace.set_profiles\": \"Replace workspace profiles\",\n \"chap.participant.join\": \"Add participant\",\n \"chap.participant.leave\": \"Remove participant\",\n \"chap.task.create\": \"Create task\",\n \"chap.task.update\": \"Change task state\",\n \"chap.task.complete\": \"Submit task output\",\n \"chap.audit.read\": \"Read audit log\",\n \"chap.review.request\": \"Request review\",\n \"chap.decide.approve\": \"Approve\",\n \"chap.decide.reject\": \"Reject\",\n \"chap.decide.override\": \"Override with a correction\",\n \"chap.abstain.declare\": \"Abstain from review\",\n \"chap.escalate.raise\": \"Escalate task\",\n \"chap.whisper.ask\": \"Ask a whisper\",\n \"chap.whisper.answer\": \"Answer a whisper\",\n \"chap.deliberate.open\": \"Open deliberation\",\n \"chap.deliberate.comment\": \"Comment on deliberation\",\n \"chap.deliberate.vote\": \"Vote in deliberation\",\n \"chap.deliberate.close\": \"Close deliberation\",\n \"chap.handoff.propose\": \"Propose handoff\",\n \"chap.handoff.accept\": \"Accept handoff\",\n \"chap.handoff.decline\": \"Decline handoff\",\n \"chap.control.pause\": \"Pause work\",\n \"chap.control.resume\": \"Resume work\",\n \"chap.control.cancel\": \"Cancel task\",\n \"chap.control.snapshot\": \"Snapshot workspace\",\n \"chap.control.rollback\": \"Roll back to snapshot\",\n \"chap.control.supersede\": \"Supersede task\",\n \"chap.control.set_mode_ceiling\": \"Set mode ceiling\",\n \"chap.task.route\": \"Route task to an assignee\",\n \"chap.review.depth\": \"Decide review depth\",\n \"chap.escalate.auto\": \"Evaluate auto-escalation\",\n \"chap.participant.rotate_key\": \"Rotate signing key\",\n \"chap.participant.revoke_key\": \"Revoke signing key\",\n \"chap.audit.submit_to_scitt\": \"Anchor audit log in SCITT\",\n \"chap.audit.verify_receipt\": \"Verify SCITT receipt\",\n \"chap.audit.verify_chain\": \"Verify audit chain\",\n};\n\n/** Annotations for every tool, derived from the sets above. */\nexport const TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = Object.fromEntries(\n Object.keys(TOOL_DESCRIPTIONS).map((name) => [name, {\n title: TITLES[name] ?? name,\n readOnlyHint: READ_ONLY.has(name),\n // Meaningful only when readOnlyHint is false, per the specification.\n destructiveHint: DESTRUCTIVE.has(name),\n idempotentHint: IDEMPOTENT.has(name),\n openWorldHint: OPEN_WORLD.has(name),\n }]),\n);\n","/**\n * Per-request protocol envelope (MCP 2026-07-28).\n *\n * The 2026 revision is stateless: instead of negotiating once through an\n * `initialize` handshake, every request declares its protocol version and\n * client capabilities in `_meta`, and the server accepts or rejects each\n * request on its own. This module implements that classification so the\n * TypeScript adapter behaves the same way the Python `mcp` 2.x SDK does,\n * which enforces the same rules natively.\n *\n * Two version sets, deliberately different:\n *\n * - `MODERN_PROTOCOL_VERSIONS` is what may be declared per request. Only\n * revisions that use per-request metadata qualify, so `2025-11-25` is\n * not a legal per-request declaration: it is negotiated by handshake.\n * This is the set named in an `UnsupportedProtocolVersionError`, so a\n * client retrying from that list always retries with something usable.\n *\n * - `SUPPORTED_PROTOCOL_VERSIONS` is what `server/discover` advertises. It\n * spans both eras because CHAP serves both: a modern client uses\n * `2026-07-28` per request, a handshake-era client negotiates\n * `2025-11-25` through `initialize`.\n */\n\nimport { ErrorCode } from \"@modelcontextprotocol/sdk/types.js\";\n\n/**\n * A JSON-RPC error carrying a spec-exact `message`.\n *\n * The SDK's own `McpError` rewrites the message to `MCP error <code>: <text>`\n * and the protocol layer puts that rewritten string on the wire, which would\n * make CHAP answer `MCP error -32022: Unsupported protocol version` where the\n * specification, and the Python implementation, both say `Unsupported\n * protocol version`. The protocol layer reads `code`, `message` and `data`\n * off whatever is thrown, so a plain `Error` carrying those fields\n * serialises exactly as written.\n */\nexport class ProtocolError extends Error {\n readonly code: number;\n readonly data?: unknown;\n\n constructor(code: number, message: string, data?: unknown) {\n super(message);\n this.name = \"ProtocolError\";\n this.code = code;\n if (data !== undefined) this.data = data;\n }\n}\n\n/** `_meta` key carrying the protocol version of a single request. */\nexport const META_PROTOCOL_VERSION = \"io.modelcontextprotocol/protocolVersion\";\n/** `_meta` key carrying client identity. Optional per the specification. */\nexport const META_CLIENT_INFO = \"io.modelcontextprotocol/clientInfo\";\n/** `_meta` key carrying client capabilities. Required on a modern request. */\nexport const META_CLIENT_CAPABILITIES = \"io.modelcontextprotocol/clientCapabilities\";\n\n/**\n * `UnsupportedProtocolVersionError`. The specification reserves -32020 to\n * -32099 for its own codes; -32022 is the one it assigns to a version the\n * server does not implement.\n */\nexport const UNSUPPORTED_PROTOCOL_VERSION = -32022;\n\n/** Revisions that may be declared in a per-request `_meta` envelope. */\nexport const MODERN_PROTOCOL_VERSIONS = [\"2026-07-28\"] as const;\n\n/**\n * Revisions advertised by `server/discover`, newest first. The tool surface\n * is identical across both: CHAP exposes plain tools with JSON Schema\n * inputs, which the 2026-07-28 stateless core carries unchanged.\n */\nexport const SUPPORTED_PROTOCOL_VERSIONS = [\"2026-07-28\", \"2025-11-25\"] as const;\n\n/**\n * Which era a single request belongs to. `modern` means it carried a valid\n * per-request envelope; `legacy` means it carried no protocol version at\n * all and therefore belongs to a handshake-negotiated session.\n */\nexport type ProtocolEra = \"modern\" | \"legacy\";\n\n/**\n * Classify one request by its `_meta` envelope, rejecting a malformed or\n * unsupported one.\n *\n * The rejection ladder matches the Python SDK's, rung for rung, so the two\n * implementations answer an identical probe identically:\n *\n * 1. no `_meta`, or no protocol version in it, is a handshake-era request\n * 2. a declared version with no `clientCapabilities` is malformed: -32602\n * 3. a non-string version is malformed: -32602\n * 4. a version outside `MODERN_PROTOCOL_VERSIONS`: -32022\n *\n * @throws ProtocolError on a malformed or unsupported envelope.\n */\nexport function classifyEnvelope(params: unknown): ProtocolEra {\n const meta = readMeta(params);\n if (meta === null) return \"legacy\";\n\n if (!(META_PROTOCOL_VERSION in meta)) return \"legacy\";\n const declared = meta[META_PROTOCOL_VERSION];\n if (declared === undefined || declared === null) return \"legacy\";\n\n // A declared version makes this a modern request, so the rest of the\n // required envelope must be present. The specification marks\n // clientCapabilities required and clientInfo optional, and requires a\n // missing required field to be rejected as invalid params.\n if (!(META_CLIENT_CAPABILITIES in meta)) {\n throw new ProtocolError(\n ErrorCode.InvalidParams,\n `params._meta is missing the required envelope key(s): ${META_CLIENT_CAPABILITIES}`,\n );\n }\n\n if (typeof declared !== \"string\") {\n throw new ProtocolError(\n ErrorCode.InvalidParams,\n \"the protocol-version envelope value must be a string\",\n );\n }\n\n if (!(MODERN_PROTOCOL_VERSIONS as readonly string[]).includes(declared)) {\n throw new ProtocolError(UNSUPPORTED_PROTOCOL_VERSION, \"Unsupported protocol version\", {\n supported: [...MODERN_PROTOCOL_VERSIONS],\n requested: declared,\n });\n }\n\n return \"modern\";\n}\n\n/** Read `params._meta` as a plain object, or null when it is absent. */\nfunction readMeta(params: unknown): Record<string, unknown> | null {\n if (typeof params !== \"object\" || params === null) return null;\n const meta = (params as Record<string, unknown>)._meta;\n if (typeof meta !== \"object\" || meta === null || Array.isArray(meta)) return null;\n return meta as Record<string, unknown>;\n}\n"],"mappings":";AA2CA,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA,aAAAA;AAAA,OAGK;AACP,SAAS,SAAS;;;AClBlB,IAAM,kBAA8B;AAAA,EAClC,MAAM;AAAA,EACN,aAAa;AACf;AAEA,IAAM,eAA2B;AAAA,EAC/B,MAAM;AAAA,EACN,aAAa;AACf;AAEA,IAAM,UAAsB;AAAA,EAC1B,MAAM;AAAA,EACN,aAAa;AACf;AASA,IAAM,oBAAoB,CAAC,YACzB,sCAAsC,OAAO;AAE/C,IAAM,gBAA4B;AAAA,EAChC,MAAM;AAAA,EACN,aAAa;AAAA,EACb,YAAY;AAAA,IACV,aAAa;AAAA,MACX,MAAM;AAAA,MACN,MAAM,CAAC,OAAO,UAAU,QAAQ,UAAU;AAAA,MAC1C,aAAa;AAAA,IACf;AAAA,IACA,UAAa,EAAE,MAAM,UAAU,aAAa,kHAAkH;AAAA,IAC9J,WAAa,EAAE,MAAM,UAAU,aAAa,mJAAmJ;AAAA,IAC/L,cAAc,EAAE,MAAM,UAAU,aAAa,+CAA+C,kBAAkB,OAAO,CAAC,gCAAgC;AAAA,EACxJ;AAAA,EACA,sBAAsB;AACxB;AAGA,IAAM,UAAsB;AAAA,EAC1B,MAAM;AAAA,EACN,aAAa;AACf;AAGA,IAAM,OAAmB;AAAA,EACvB,MAAM;AAAA,EACN,OAAO,EAAE,MAAM,SAAS;AAAA,EACxB,aAAa;AACf;AAGA,IAAM,kBAA8B;AAAA,EAClC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AACf;AAGA,IAAM,0BACJ;AAMK,IAAM,UAAsC;AAAA,EACjD,yBAAyB;AAAA,IACvB,MAAM;AAAA,IACN,YAAY;AAAA,MACV,WAAW,EAAE,GAAG,cAAc,aAAa,wDAAwD;AAAA,MACnG,UAAU;AAAA,QACR,MAAM;AAAA,QAC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AG,CAAC;AAAA,MACjE,CAAC;AAAA,IACH;AAEA,QAAI,SAAS,OAAO;AAClB,aAAO,SAAS;AAAA,QACd,SAAS;AAAA,QACT,SAAS,CAAC;AAAA,UACR,MAAM;AAAA,UACN,MAAM,KAAK,UAAU;AAAA,YACnB,YAAY,SAAS,MAAM;AAAA,YAC3B,SAAY,SAAS,MAAM;AAAA,YAC3B,GAAI,SAAS,MAAM,SAAS,SAAY,EAAE,MAAM,SAAS,MAAM,KAAK,IAAI,CAAC;AAAA,UAC3E,GAAG,MAAM,CAAC;AAAA,QACZ,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAEA,WAAO,SAAS;AAAA,MACd,SAAS,CAAC;AAAA,QACR,MAAM;AAAA,QACN,MAAM,KAAK,UAAU,SAAS,QAAQ,MAAM,CAAC;AAAA,MAC/C,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;AAOO,SAAS,iBACd,OACA,UACA,MACA,aAA8B,YACpB;AACV,QAAM,SAAS,cAAc,QAAQ;AACrC,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,MACL,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,OAAO,EAAE,MAAM,QAAQ,SAAS,sBAAsB,QAAQ,GAAG;AAAA,IACnE;AAAA,EACF;AACA,SAAO,MAAM,SAAS;AAAA,IACpB,SAAS;AAAA,IACT,IAAI;AAAA,IACJ;AAAA,IACA,QAAQ,eAAe,UAAU,QAAQ,CAAC,CAAC;AAAA,EAC7C,CAAC;AACH;","names":["ErrorCode","ErrorCode"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightbeamai/chap-coordinator-mcp",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "MCP server adapter for the CHAP Coordinator. Exposes every CHAP method as an MCP tool.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Brightbeam AI <oss@brightbeam.com>",
@@ -65,7 +65,7 @@
65
65
  "prepublishOnly": "npm run typecheck && npm run test && npm run build"
66
66
  },
67
67
  "dependencies": {
68
- "@brightbeamai/chap-coordinator": "^0.3.3",
68
+ "@brightbeamai/chap-coordinator": "^0.3.4",
69
69
  "@modelcontextprotocol/sdk": "^1.32.1",
70
70
  "zod": "^3.25 || ^4.0"
71
71
  },