From df6b41289d90322c1f8717c5e59625e38090dba4 Mon Sep 17 00:00:00 2001 From: Oliver Slapinski Date: Sun, 23 Aug 2026 23:51:16 -0400 Subject: [PATCH] Node: expose MCP server instruction policy Signed-off-by: Oliver Slapinski --- nodejs/src/client.ts | 6 +++++ nodejs/src/types.ts | 11 +++++++++ nodejs/test/client.test.ts | 50 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/nodejs/src/client.ts b/nodejs/src/client.ts index 1be2cbb94..5c109d1b3 100644 --- a/nodejs/src/client.ts +++ b/nodejs/src/client.ts @@ -1604,6 +1604,9 @@ export class CopilotClient { ? { enableGitHubTelemetryForwarding: true } : {}), mcpServers: toWireMcpServers(config.mcpServers), + ...(config.allowAllMcpServerInstructions !== undefined + ? { allowAllMcpServerInstructions: config.allowAllMcpServerInstructions } + : {}), mcpOAuthTokenStorage: config.mcpOAuthTokenStorage, envValueMode: "direct", customAgents: toWireCustomAgents(config.customAgents), @@ -1864,6 +1867,9 @@ export class CopilotClient { ? { enableGitHubTelemetryForwarding: true } : {}), mcpServers: toWireMcpServers(config.mcpServers), + ...(config.allowAllMcpServerInstructions !== undefined + ? { allowAllMcpServerInstructions: config.allowAllMcpServerInstructions } + : {}), mcpOAuthTokenStorage: config.mcpOAuthTokenStorage, envValueMode: "direct", customAgents: toWireCustomAgents(config.customAgents), diff --git a/nodejs/src/types.ts b/nodejs/src/types.ts index 678cd5863..e943e3acf 100644 --- a/nodejs/src/types.ts +++ b/nodejs/src/types.ts @@ -2623,6 +2623,17 @@ export interface SessionConfigBase { */ mcpServers?: Record; + /** + * Include instructions from every MCP server in the system prompt instead + * of only allowlisted servers. + * + * Enabling this broadens the session's instruction trust boundary. Only + * enable it when every configured MCP server is trusted. + * + * @default false + */ + allowAllMcpServerInstructions?: boolean; + /** * Custom agent configurations for the session. */ diff --git a/nodejs/test/client.test.ts b/nodejs/test/client.test.ts index e2d630ba0..97ec08905 100644 --- a/nodejs/test/client.test.ts +++ b/nodejs/test/client.test.ts @@ -3888,6 +3888,56 @@ describe("CopilotClient", () => { }); }); +describe("allowAllMcpServerInstructions serialization", () => { + async function startCaptureClient() { + const client = new CopilotClient({ + connection: RuntimeConnection.forUri("localhost:1234"), + }); + const sendRequest = vi.fn(async (method: string, params: any) => { + if (method === "session.create") return { sessionId: params.sessionId }; + if (method === "session.resume") return { sessionId: params.sessionId }; + throw new Error(`Unexpected method: ${method}`); + }); + vi.spyOn(client as any, "connectToServer").mockImplementation(async () => { + (client as any).connection = { sendRequest, dispose: vi.fn() }; + }); + vi.spyOn(client as any, "verifyProtocolVersion").mockResolvedValue(undefined); + await client.start(); + onTestFinished(() => client.forceStop()); + return { client, sendRequest }; + } + + it.each([true, false])("forwards %s on create and resume", async (value) => { + const { client, sendRequest } = await startCaptureClient(); + + const session = await client.createSession({ + onPermissionRequest: approveAll, + allowAllMcpServerInstructions: value, + }); + await client.resumeSession(session.sessionId, { + onPermissionRequest: approveAll, + allowAllMcpServerInstructions: value, + }); + + const createCall = sendRequest.mock.calls.find(([method]) => method === "session.create"); + const resumeCall = sendRequest.mock.calls.find(([method]) => method === "session.resume"); + expect(createCall![1].allowAllMcpServerInstructions).toBe(value); + expect(resumeCall![1].allowAllMcpServerInstructions).toBe(value); + }); + + it("omits the option on create and resume by default", async () => { + const { client, sendRequest } = await startCaptureClient(); + + const session = await client.createSession({ onPermissionRequest: approveAll }); + await client.resumeSession(session.sessionId, { onPermissionRequest: approveAll }); + + const createCall = sendRequest.mock.calls.find(([method]) => method === "session.create"); + const resumeCall = sendRequest.mock.calls.find(([method]) => method === "session.resume"); + expect(createCall![1]).not.toHaveProperty("allowAllMcpServerInstructions"); + expect(resumeCall![1]).not.toHaveProperty("allowAllMcpServerInstructions"); + }); +}); + describe("managedSettings serialization", () => { async function captureCreateParams(config: Record): Promise { const client = new CopilotClient();