diff --git a/docs/AGENT_API.md b/docs/AGENT_API.md index 9b3e69a..2b744b7 100644 --- a/docs/AGENT_API.md +++ b/docs/AGENT_API.md @@ -268,7 +268,7 @@ protectedResourceMetadataUrl, allowedOrigins, authenticate, limit })` returns the same `{ handle(request) }` router interface. `mcpUrl` must exactly equal `resource`. It uses the HTTP adapter's trusted authentication/admission ports, URL/Host/Origin rules, protected-resource challenge, strict UTF-8 reader, and -response protections. Metadata is host-owned and is never served by this +response protections. OAuth metadata is host-owned and is never served by this package. Configure the same resource on the dispatcher and both transports. The adapter uses pinned MCP SDK `1.32.2` and Zod `4.6.7`. Each admitted POST @@ -279,6 +279,18 @@ are advertised, using the five names above with useful strict input JSON schemas. Client metadata and capability objects are bounded and validated before reaching the SDK; they grant no server authority. +The unpublished `0.1.6` source candidate accepts opaque JSON extension fields +inside `params._meta` on initialize, ping, tools/list, tools/call, and the +initialized/cancelled notifications. If present, `progressToken` retains its +existing shape validation: a string of at most 128 characters or a safe integer, +without a registered-value allowlist. All extension values share the complete +request's byte, depth, node, array and object-key ceilings described below. +Other envelope fields and tool arguments remain closed. Metadata does not grant +identity, scopes, resource access, evidence, review or publication authority; +those facts still come from separately authenticated host context. The adapter +does not persist these extensions in KB records, include them in application +results, or use them to fetch URLs or construct application commands. + Responses use JSON rather than an SSE stream. Authenticated GET and DELETE receive 405; an accepted initialized notification receives 202. The pinned SDK negotiates the protocol version. Tool calls use the shared dispatcher; diff --git a/docs/RELEASING.md b/docs/RELEASING.md index a851c84..65ba100 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -85,6 +85,23 @@ their own current-head gates; historical results do not validate changed composition. Production hosts require verified trusted versions of both components and their separately retained acceptance. +## Unpublished 0.1.6 candidate + +All four source packages are synchronized at `0.1.6` for the MCP extension +metadata compatibility patch. The adapter accepts bounded opaque `params._meta` +values used by native clients. An optional `progressToken` must be a string of +at most 128 characters or a safe integer, without a registered-value allowlist. +Strict tool arguments, current authorization and existing complete-message +limits remain unchanged. It adds no tool, scope, durable record, credential or +migration. The generic SDK error-response mapping is unchanged. + +The current qualified release remains `0.1.5`; this candidate needs its own +current-head gates, review, signed-tag preparation, trusted publication and +strict complete-set registry verification. Existing `0.1.5` receipts and +tarballs remain unchanged. Hosts and Support Desk consumers must deliberately +align their exact Knowledge Base graph before adoption; producer qualification +does not close native-client or real-host acceptance. + ## Repository and development artifact gates Use Node 22.6.0+ or 24 with `pnpm@10.34.5`. Published package engines remain diff --git a/package.json b/package.json index 444b8a0..1114abc 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,11 @@ "@cloudflare/workers-types": "5.20260730.1", "@modelcontextprotocol/sdk": "1.32.2", "@pegma/authorization-core": "0.4.0", - "@pegma/knowledge-base-application": "0.1.5", + "@pegma/knowledge-base-application": "0.1.6", "@pegma/knowledge-base-application-previous": "npm:@pegma/knowledge-base-application@0.1.1", - "@pegma/knowledge-base-contracts": "0.1.5", - "@pegma/knowledge-base-core": "0.1.5", - "@pegma/knowledge-base-mcp": "0.1.5", + "@pegma/knowledge-base-contracts": "0.1.6", + "@pegma/knowledge-base-core": "0.1.6", + "@pegma/knowledge-base-mcp": "0.1.6", "@pegma/spine": "0.1.2", "@pegma/storage-azure-tables": "0.4.0", "@pegma/storage-cloudflare-d1": "0.4.6", diff --git a/packages/application/package.json b/packages/application/package.json index fbd4bb5..aa97c33 100644 --- a/packages/application/package.json +++ b/packages/application/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/knowledge-base-application", - "version": "0.1.5", + "version": "0.1.6", "description": "Authorized knowledge authoring, evidence, review, and publication over Pegma storage.", "license": "MIT", "type": "module", @@ -31,8 +31,8 @@ "dependencies": { "@pegma/audit": "0.2.0", "@pegma/authorization-core": "0.4.0", - "@pegma/knowledge-base-contracts": "0.1.5", - "@pegma/knowledge-base-core": "0.1.5", + "@pegma/knowledge-base-contracts": "0.1.6", + "@pegma/knowledge-base-core": "0.1.6", "@pegma/spine": "0.1.2", "@pegma/storage-core": "0.4.0" }, diff --git a/packages/contracts/package.json b/packages/contracts/package.json index e802c2f..7193108 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/knowledge-base-contracts", - "version": "0.1.5", + "version": "0.1.6", "description": "Provider-neutral knowledge collections, revisions, validation, and approval contracts.", "license": "MIT", "type": "module", diff --git a/packages/core/package.json b/packages/core/package.json index e45f6c4..bcd7e6b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/knowledge-base-core", - "version": "0.1.5", + "version": "0.1.6", "description": "Pure knowledge article, validation, and publication transitions.", "license": "MIT", "type": "module", @@ -29,7 +29,7 @@ "directory": "packages/core" }, "dependencies": { - "@pegma/knowledge-base-contracts": "0.1.5" + "@pegma/knowledge-base-contracts": "0.1.6" }, "scripts": { "build": "tsc -p tsconfig.json", diff --git a/packages/mcp/README.md b/packages/mcp/README.md index 52678ad..8f0165d 100644 --- a/packages/mcp/README.md +++ b/packages/mcp/README.md @@ -13,6 +13,16 @@ client acceptance remain separate. These source README corrections apply to a future release. Published `0.1.5` tarballs, including their bundled README bytes, remain unchanged. +The synchronized `0.1.6` source candidate is unpublished. It accepts bounded +opaque MCP `params._meta` extensions, including native-client correlation and +standard trace fields, while retaining the existing `progressToken` shape +validation: a string of at most 128 characters or a safe integer. Metadata +does not establish identity, permissions or evidence and is not stored or +returned as an application result. Complete-message byte, depth, node and key +ceilings, strict tool arguments and fresh host authentication remain unchanged. +The official-SDK regression and packed protocol proof exercise fictional +extension values; actual requested-client and host acceptance remain separate. + The contracts, core, and application packages remain independent of MCP, HTTP, provider SDKs, and login flows. Hosts choose this adapter when exposing agent access. The adapter pins `@modelcontextprotocol/sdk` at `1.32.2` and `zod` at diff --git a/packages/mcp/package.json b/packages/mcp/package.json index 24aa545..969f6d9 100644 --- a/packages/mcp/package.json +++ b/packages/mcp/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/knowledge-base-mcp", - "version": "0.1.5", + "version": "0.1.6", "description": "Optional MCP transport for authorized Pegma knowledge authoring and validation.", "license": "MIT", "type": "module", @@ -32,9 +32,9 @@ "@cfworker/json-schema": "4.1.6", "@modelcontextprotocol/sdk": "1.32.2", "@pegma/authorization-core": "0.4.0", - "@pegma/knowledge-base-application": "0.1.5", - "@pegma/knowledge-base-contracts": "0.1.5", - "@pegma/knowledge-base-core": "0.1.5", + "@pegma/knowledge-base-application": "0.1.6", + "@pegma/knowledge-base-contracts": "0.1.6", + "@pegma/knowledge-base-core": "0.1.6", "zod": "4.6.7" }, "scripts": { diff --git a/packages/mcp/src/mcp.ts b/packages/mcp/src/mcp.ts index c54b338..3929663 100644 --- a/packages/mcp/src/mcp.ts +++ b/packages/mcp/src/mcp.ts @@ -52,7 +52,11 @@ const requestId = z.union([ z.number().int().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER), ]); const empty = z.object({}).strict(); -const metadata = z.object({ progressToken: requestId.optional() }).strict(); +// MCP reserves _meta for opaque client extensions, not authority. The complete +// message already passed the shared JSON byte/depth/node/key ceilings. +const metadata = z + .object({ progressToken: requestId.optional() }) + .catchall(z.unknown()); const basicParams = z.object({ _meta: metadata.optional() }).strict(); const featureMap = z.record( z.string().max(128), @@ -349,7 +353,7 @@ export function createKnowledgeAgentMcp( maxRequestBodySize: dispatcher.limits.maxRequestBytes, }); const server = new Server( - { name: "@pegma/knowledge-base-mcp", version: "0.1.5" }, + { name: "@pegma/knowledge-base-mcp", version: "0.1.6" }, { capabilities: { tools: {} }, // Workers prohibit the runtime code generation used by SDK-default AJV. diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7030a2c..7544489 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,19 +24,19 @@ importers: specifier: 0.4.0 version: 0.4.0 '@pegma/knowledge-base-application': - specifier: 0.1.5 + specifier: 0.1.6 version: link:packages/application '@pegma/knowledge-base-application-previous': specifier: npm:@pegma/knowledge-base-application@0.1.1 version: '@pegma/knowledge-base-application@0.1.1' '@pegma/knowledge-base-contracts': - specifier: 0.1.5 + specifier: 0.1.6 version: link:packages/contracts '@pegma/knowledge-base-core': - specifier: 0.1.5 + specifier: 0.1.6 version: link:packages/core '@pegma/knowledge-base-mcp': - specifier: 0.1.5 + specifier: 0.1.6 version: link:packages/mcp '@pegma/spine': specifier: 0.1.2 @@ -81,10 +81,10 @@ importers: specifier: 0.4.0 version: 0.4.0 '@pegma/knowledge-base-contracts': - specifier: 0.1.5 + specifier: 0.1.6 version: link:../contracts '@pegma/knowledge-base-core': - specifier: 0.1.5 + specifier: 0.1.6 version: link:../core '@pegma/spine': specifier: 0.1.2 @@ -102,7 +102,7 @@ importers: packages/core: dependencies: '@pegma/knowledge-base-contracts': - specifier: 0.1.5 + specifier: 0.1.6 version: link:../contracts packages/mcp: @@ -117,13 +117,13 @@ importers: specifier: 0.4.0 version: 0.4.0 '@pegma/knowledge-base-application': - specifier: 0.1.5 + specifier: 0.1.6 version: link:../application '@pegma/knowledge-base-contracts': - specifier: 0.1.5 + specifier: 0.1.6 version: link:../contracts '@pegma/knowledge-base-core': - specifier: 0.1.5 + specifier: 0.1.6 version: link:../core zod: specifier: 4.6.7 diff --git a/scripts/agent-protocol-fixture.mjs b/scripts/agent-protocol-fixture.mjs index 30a25be..3c408f4 100644 --- a/scripts/agent-protocol-fixture.mjs +++ b/scripts/agent-protocol-fixture.mjs @@ -834,7 +834,22 @@ async function httpCall(host, token, operation, input) { async function mcpCall(client, operation, input) { const result = await client.callTool( - { name: knowledgeAgentToolNames[operation], arguments: input }, + { + name: knowledgeAgentToolNames[operation], + arguments: input, + // Ordinary opaque metadata, supplied by the official SDK client. These + // fictional correlation values confer no identity, scopes or authority. + _meta: { + callId: "fictional-packed-call", + threadId: "fictional-packed-thread", + sessionId: "fictional-packed-session", + itemId: "fictional-packed-item", + windowId: "fictional-packed-window", + traceparent: "00-11111111111111111111111111111111-2222222222222222-01", + tracestate: "fictional=packed", + "com.example/extension": { values: [null, false, 7] }, + }, + }, undefined, { timeout: 5_000 }, ); @@ -1199,6 +1214,7 @@ async function runProof() { liveHostsProven: false, targetClientAppsProven: 0, sdkDiscovery: true, + opaqueRequestMetadata: true, s256Pkce: true, browserSession: true, csrfAndOrigin: true, @@ -1458,6 +1474,7 @@ async function runReportProof() { tools: tools.tools.length, scopes: host.configuration.scopes.length, reportQueued: true, + opaqueRequestMetadata: true, bodyFreePolling: true, humanConfirmed: true, originalReceiptCommitted: true, diff --git a/tests/agent-security.test.ts b/tests/agent-security.test.ts index 317661a..521b6bf 100644 --- a/tests/agent-security.test.ts +++ b/tests/agent-security.test.ts @@ -38,6 +38,20 @@ const read = { input: { articleId: "article/export" }, }; +const nativeRequestMetadata = { + callId: "fictional-call", + threadId: "fictional-thread", + sessionId: "fictional-session", + itemId: "fictional-item", + windowId: "fictional-window", + traceparent: "00-11111111111111111111111111111111-2222222222222222-01", + tracestate: "fictional=opaque", + "x-codex-turn-metadata": { + turn_id: "fictional-turn", + workspaces: [{ id: "fictional-workspace" }], + }, +}; + function request( body: BodyInit | null = JSON.stringify(read), init: RequestInit = {}, @@ -381,6 +395,398 @@ describe("KB agent least-authority security", () => { }); describe("KB agent hostile request and transport boundary", () => { + it.each([ + ["native identity and trace fields", nativeRequestMetadata], + [ + "unknown extension JSON", + { + progressToken: 7, + "com.example/client": { + enabled: false, + values: [null, 1, "fictional"], + }, + }, + ], + ])( + "accepts bounded MCP extension metadata from the official SDK: %s", + async (_name, metadata) => { + const f = agentFixture(createMemoryStore()); + await f.setupCollection(); + const client = await f.sdk(); + const input = { + collectionId: "collection/workshop", + kind: "explanation" as const, + }; + const expected = await f.call("MCP", "getValidationRequirements", input); + const before = await allKnowledgeRows(f.store); + const result = await client.callTool({ + name: knowledgeAgentToolNames.getValidationRequirements, + arguments: input, + _meta: metadata, + }); + expect(result.isError).toBe(false); + const content = result.content; + if ( + !Array.isArray(content) || + content.length !== 1 || + content[0]?.type !== "text" + ) + throw new Error("Expected one complete official SDK text result"); + expect(JSON.parse(content[0].text)).toEqual(expected); + const sent = await f.requests.at(-1)!.json(); + expect(sent).toMatchObject({ + method: "tools/call", + params: { _meta: metadata, arguments: input }, + }); + expect(await allKnowledgeRows(f.store)).toEqual(before); + expect(JSON.stringify(result)).not.toContain("fictional-thread"); + }, + ); + + it.each([ + null, + [], + true, + 1, + "not-an-object", + { progressToken: null }, + { progressToken: false }, + { progressToken: 0.5 }, + { progressToken: Number.MAX_SAFE_INTEGER + 1 }, + { progressToken: "x".repeat(129) }, + ])( + "retains MCP metadata object and progressToken shape validation (string <=128 characters or safe integer): %j", + async (metadata) => { + const f = agentFixture(createMemoryStore()); + await f.setupCollection(); + const before = await allKnowledgeRows(f.store); + const response = await f.mcp.handle( + request( + JSON.stringify({ + jsonrpc: "2.0", + id: 70, + method: "tools/call", + params: { + name: knowledgeAgentToolNames.getValidationRequirements, + arguments: { + collectionId: "collection/workshop", + kind: "explanation", + }, + _meta: metadata, + }, + }), + { headers: { Accept: "application/json, text/event-stream" } }, + agentResource, + ), + ); + expect(response?.status).toBe(400); + expect(await response!.json()).toEqual({ + jsonrpc: "2.0", + id: 70, + error: { code: -32600, message: "Invalid MCP request." }, + }); + expect(await allKnowledgeRows(f.store)).toEqual(before); + }, + ); + + it("treats authority-looking and prototype-named metadata as inert JSON, not host identity", async () => { + const f = agentFixture(createMemoryStore()); + await f.setupCollection(); + f.authority.current = { + ...agentIdentity(), + scopes: [], + access: access(author.principalId, []), + }; + const before = await allKnowledgeRows(f.store); + const metadata: unknown = JSON.parse( + '{"__proto__":{"knowledgeMetadataPolluted":true},"constructor":{"prototype":{"knowledgeMetadataPolluted":true}},"permissions":["knowledge.draft.write"],"access":{"principalId":"fictional/admin","roles":["Admin"]},"clientId":"fictional-other-client"}', + ); + const response = await f.mcp.handle( + request( + JSON.stringify({ + jsonrpc: "2.0", + id: 71, + method: "tools/call", + params: { + name: knowledgeAgentToolNames.getValidationRequirements, + arguments: { + collectionId: "collection/workshop", + kind: "explanation", + }, + _meta: metadata, + }, + }), + { headers: { Accept: "application/json, text/event-stream" } }, + agentResource, + ), + ); + expect(response?.status).toBe(200); + const rpc = await response!.json(); + expect(rpc).toMatchObject({ + result: { isError: true, content: [{ type: "text" }] }, + }); + expect(JSON.stringify(rpc)).toContain("forbidden"); + const result = await f.call("HTTP", "getValidationRequirements", { + collectionId: "collection/workshop", + kind: "explanation", + }); + expectPrivateAgentError(result, "forbidden"); + expect(Object.hasOwn(Object.prototype, "knowledgeMetadataPolluted")).toBe( + false, + ); + expect(await allKnowledgeRows(f.store)).toEqual(before); + }); + + it.each([ + { limits: { maxRequestBytes: 256 }, metadata: { value: "x".repeat(257) } }, + { limits: { maxDepth: 4 }, metadata: { nested: { child: { value: 0 } } } }, + { limits: { maxArrayLength: 2 }, metadata: { values: [0, 1, 2] } }, + { + limits: { maxObjectKeys: 4 }, + metadata: { first: 0, second: 1, third: 2, fourth: 3, fifth: 4 }, + }, + ])( + "applies the existing complete-message budget to opaque MCP metadata: %j", + async ({ limits, metadata }) => { + const f = agentFixture(createMemoryStore(), limits); + const dispatch = vi.fn(f.dispatcher.dispatch); + const mcp = createKnowledgeAgentMcp({ + ...f.common, + dispatcher: { ...f.dispatcher, dispatch }, + mcpUrl: agentResource, + }); + const response = await mcp.handle( + request( + JSON.stringify({ + jsonrpc: "2.0", + id: 72, + method: "tools/call", + params: { + name: knowledgeAgentToolNames.getValidationRequirements, + arguments: { + collectionId: "collection/workshop", + kind: "explanation", + }, + _meta: metadata, + }, + }), + { headers: { Accept: "application/json, text/event-stream" } }, + agentResource, + ), + ); + await error(response, 413, "capacity"); + expect(dispatch).not.toHaveBeenCalled(); + }, + ); + + it("admits the same MCP request with absent or small metadata before rejecting metadata node growth", async () => { + const f = agentFixture(createMemoryStore(), { maxNodes: 64 }); + await f.setupCollection(); + const dispatch = vi.fn(f.dispatcher.dispatch); + const mcp = createKnowledgeAgentMcp({ + ...f.common, + dispatcher: { ...f.dispatcher, dispatch }, + mcpUrl: agentResource, + }); + const send = (metadata?: unknown) => + mcp.handle( + request( + JSON.stringify({ + jsonrpc: "2.0", + id: 72, + method: "tools/call", + params: { + name: knowledgeAgentToolNames.getValidationRequirements, + arguments: { + collectionId: "collection/workshop", + kind: "explanation", + }, + ...(metadata === undefined ? {} : { _meta: metadata }), + }, + }), + { headers: { Accept: "application/json, text/event-stream" } }, + agentResource, + ), + ); + for (const metadata of [undefined, { first: [null], second: [null] }]) { + const response = await send(metadata); + expect(response?.status).toBe(200); + expect(await response!.json()).toMatchObject({ + result: { isError: false }, + }); + } + expect(dispatch).toHaveBeenCalledTimes(2); + dispatch.mockClear(); + // Each array independently fits the existing array ceiling. Their aggregate + // graph work exceeds this reduced node budget only when metadata is counted. + await error( + await send({ first: Array(32).fill(null), second: Array(32).fill(null) }), + 413, + "capacity", + ); + expect(dispatch).not.toHaveBeenCalled(); + }); + + it.each([ + { + method: "initialize", + id: 75, + params: { + protocolVersion: "2025-11-25", + capabilities: {}, + clientInfo: { name: "fictional-metadata-client", version: "1" }, + }, + status: 200, + }, + { method: "ping", id: 76, params: {}, status: 200 }, + { method: "tools/list", id: 77, params: {}, status: 200 }, + { method: "notifications/initialized", params: {}, status: 202 }, + { + method: "notifications/cancelled", + params: { requestId: 78, reason: "Fictional cancellation." }, + status: 202, + }, + ])( + "accepts bounded shared-schema metadata on $method without invoking the dispatcher", + async ({ method, id, params, status }) => { + const f = agentFixture(createMemoryStore()); + const dispatch = vi.fn(f.dispatcher.dispatch); + const mcp = createKnowledgeAgentMcp({ + ...f.common, + dispatcher: { ...f.dispatcher, dispatch }, + mcpUrl: agentResource, + }); + const send = (metadata: unknown) => + mcp.handle( + request( + JSON.stringify({ + jsonrpc: "2.0", + ...(id === undefined ? {} : { id }), + method, + params: { ...params, _meta: metadata }, + }), + { headers: { Accept: "application/json, text/event-stream" } }, + agentResource, + ), + ); + const response = await send(nativeRequestMetadata); + expect(response?.status).toBe(status); + if (status === 202) expect(await response!.text()).toBe(""); + else { + const value: unknown = await response!.json(); + expect(value).toHaveProperty("result"); + expect(value).not.toHaveProperty("error"); + if (method === "initialize") + expect(value).toMatchObject({ + result: { capabilities: { tools: {} } }, + }); + if (method === "tools/list") + expect(value).toMatchObject({ + result: { + tools: Object.values(knowledgeAgentToolNames).map((name) => + expect.objectContaining({ name }), + ), + }, + }); + } + expect((await send({ progressToken: false }))?.status).toBe(400); + expect(f.authenticate).toHaveBeenCalledTimes(2); + expect(f.limit).toHaveBeenCalledTimes(2); + expect(dispatch).not.toHaveBeenCalled(); + }, + ); + + it.each(["NaN", "Infinity", "undefined"])( + "rejects the whole request as invalid JSON when a metadata-position token is %s", + async (value) => { + const f = agentFixture(createMemoryStore()); + // This pins whole-body JSON parsing before the metadata schema; it is not + // a metadata-specific validation oracle. + const source = + '{"jsonrpc":"2.0","id":73,"method":"tools/call","params":{"name":"knowledge_v1_get_validation_requirements","arguments":{"collectionId":"collection/workshop","kind":"explanation"},"_meta":{"value":' + + value + + "}}}"; + await error( + await f.mcp.handle( + request( + source, + { headers: { Accept: "application/json, text/event-stream" } }, + agentResource, + ), + ), + 400, + "invalid_request", + ); + }, + ); + + it("keeps extension acceptance inside metadata and leaves envelope and tool arguments closed", async () => { + const f = agentFixture(createMemoryStore()); + await f.setupCollection(); + const packet = { + jsonrpc: "2.0", + id: 74, + method: "tools/call", + params: { + name: knowledgeAgentToolNames.getValidationRequirements, + arguments: { collectionId: "collection/workshop", kind: "explanation" }, + _meta: nativeRequestMetadata, + }, + }; + for (const body of [ + { ...packet, _meta: nativeRequestMetadata }, + { ...packet, params: { ...packet.params, authority: "forged" } }, + ]) { + const response = await f.mcp.handle( + request( + JSON.stringify(body), + { headers: { Accept: "application/json, text/event-stream" } }, + agentResource, + ), + ); + expect(response?.status).toBe(400); + expect(await response!.json()).toMatchObject({ error: { code: -32600 } }); + } + const client = await f.sdk(); + const result = await client.callTool({ + name: packet.params.name, + arguments: { ...packet.params.arguments, authority: "forged" }, + _meta: nativeRequestMetadata, + }); + expect(result.isError).toBe(true); + expect(JSON.stringify(result)).toContain("invalid_request"); + }); + + it("does not retain or echo opaque metadata when an actual SDK draft command commits", async () => { + const f = agentFixture(createMemoryStore()); + await f.setupCollection(); + const client = await f.sdk(); + const result = await client.callTool({ + name: knowledgeAgentToolNames.createDraft, + arguments: { + ...f.command("metadata-draft", 0), + articleId: "article/metadata", + collectionId: "collection/workshop", + draft: draft(), + }, + _meta: { + ...nativeRequestMetadata, + "com.example/private": "METADATA_ONLY_FICTIONAL_CANARY", + }, + }); + expect(result.isError).toBe(false); + expect( + (await f.app.getDraft(author, { articleId: "article/metadata" })).revision + .number, + ).toBe(1); + expect(JSON.stringify(await allKnowledgeRows(f.store))).not.toContain( + "METADATA_ONLY_FICTIONAL_CANARY", + ); + expect(JSON.stringify(result)).not.toContain( + "METADATA_ONLY_FICTIONAL_CANARY", + ); + }); + it("authenticates and admits valid MCP notifications without dispatching domain commands", async () => { const f = agentFixture(createMemoryStore()); await f.setupCollection();