From 844d3a4dfa207fbfe3c083ecb12f0c090ddfa524 Mon Sep 17 00:00:00 2001 From: christine betts Date: Mon, 1 Dec 2025 11:17:54 -0600 Subject: [PATCH] Always use MCP server instructions (#14297) --- docs/tools/mcp-server.md | 8 +++-- packages/cli/src/config/settingsSchema.ts | 5 --- packages/core/src/config/config.ts | 2 -- .../core/src/tools/mcp-client-manager.test.ts | 35 +++++++------------ packages/core/src/tools/mcp-client-manager.ts | 13 +++---- schemas/settings.schema.json | 4 --- 6 files changed, 24 insertions(+), 43 deletions(-) diff --git a/docs/tools/mcp-server.md b/docs/tools/mcp-server.md index 633d433700..9a58f79547 100644 --- a/docs/tools/mcp-server.md +++ b/docs/tools/mcp-server.md @@ -156,8 +156,6 @@ Each server configuration supports the following properties: - **`targetServiceAccount`** (string): The email address of the Google Cloud Service Account to impersonate. Used with `authProviderType: 'service_account_impersonation'`. -- **`useInstructions`** (boolean): If true will include the MCP server's - initialization instructions in the system instructions. ### OAuth Support for Remote MCP Servers @@ -1011,3 +1009,9 @@ gemini mcp remove my-server This will find and delete the "my-server" entry from the `mcpServers` object in the appropriate `settings.json` file based on the scope (`-s, --scope`). + +## Instructions + +Gemini CLI supports +[MCP server instructions](https://modelcontextprotocol.io/specification/2025-06-18/schema#initializeresult), +which will be appended to the system instructions. diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index d098b8cd88..d4ea853727 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -1526,11 +1526,6 @@ export const SETTINGS_SCHEMA_DEFINITIONS: Record< description: 'Service account email to impersonate (name@project.iam.gserviceaccount.com).', }, - useInstructions: { - type: 'boolean', - description: - 'If true, instructions from this server will be included in the system prompt.', - }, }, }, TelemetrySettings: { diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 5e25ae1ae1..40696a4c25 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -204,8 +204,6 @@ export class MCPServerConfig { readonly targetAudience?: string, /* targetServiceAccount format: @.iam.gserviceaccount.com */ readonly targetServiceAccount?: string, - // Include the MCP server initialization instructions in the system instructions - readonly useInstructions?: boolean, ) {} } diff --git a/packages/core/src/tools/mcp-client-manager.test.ts b/packages/core/src/tools/mcp-client-manager.test.ts index 01039edc56..5bb3db7bc5 100644 --- a/packages/core/src/tools/mcp-client-manager.test.ts +++ b/packages/core/src/tools/mcp-client-manager.test.ts @@ -195,8 +195,7 @@ describe('McpClientManager', () => { }); describe('getMcpInstructions', () => { - it('should only return instructions from servers with useInstructions: true', async () => { - // Override McpClient mock for this test to return distinct objects based on config + it('should not return instructions for servers that do not have instructions', async () => { vi.mocked(McpClient).mockImplementation( (name, config) => ({ @@ -206,42 +205,34 @@ describe('McpClientManager', () => { getServerConfig: vi.fn().mockReturnValue(config), getInstructions: vi .fn() - .mockReturnValue(`Instructions for ${name}`), + .mockReturnValue( + name === 'server-with-instructions' + ? `Instructions for ${name}` + : '', + ), }) as unknown as McpClient, ); const manager = new McpClientManager({} as ToolRegistry, mockConfig); - // 1. Configured server with useInstructions: true mockConfig.getMcpServers.mockReturnValue({ - 'enabled-server': { - useInstructions: true, - }, - 'disabled-server': { - useInstructions: false, - }, - 'default-server': { - // undefined should be treated as false - }, + 'server-with-instructions': {}, + 'server-without-instructions': {}, }); await manager.startConfiguredMcpServers(); const instructions = manager.getMcpInstructions(); expect(instructions).toContain( - "# Instructions for MCP Server 'enabled-server'", + "# Instructions for MCP Server 'server-with-instructions'", + ); + expect(instructions).toContain( + 'Instructions for server-with-instructions', ); - expect(instructions).toContain('Instructions for enabled-server'); expect(instructions).not.toContain( - "# Instructions for MCP Server 'disabled-server'", + "# Instructions for MCP Server 'server-without-instructions'", ); - expect(instructions).not.toContain('Instructions for disabled-server'); - - expect(instructions).not.toContain( - "# Instructions for MCP Server 'default-server'", - ); - expect(instructions).not.toContain('Instructions for default-server'); }); }); }); diff --git a/packages/core/src/tools/mcp-client-manager.ts b/packages/core/src/tools/mcp-client-manager.ts index 1d7ca2f5d6..a21c4e160e 100644 --- a/packages/core/src/tools/mcp-client-manager.ts +++ b/packages/core/src/tools/mcp-client-manager.ts @@ -327,14 +327,11 @@ export class McpClientManager { getMcpInstructions(): string { const instructions: string[] = []; for (const [name, client] of this.clients) { - // Only include instructions if explicitly enabled in config - if (client.getServerConfig().useInstructions) { - const clientInstructions = client.getInstructions(); - if (clientInstructions) { - instructions.push( - `# Instructions for MCP Server '${name}'\n${clientInstructions}`, - ); - } + const clientInstructions = client.getInstructions(); + if (clientInstructions) { + instructions.push( + `# Instructions for MCP Server '${name}'\n${clientInstructions}`, + ); } } return instructions.join('\n\n'); diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index c57ba6fed9..0d5c317912 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1467,10 +1467,6 @@ "targetServiceAccount": { "type": "string", "description": "Service account email to impersonate (name@project.iam.gserviceaccount.com)." - }, - "useInstructions": { - "type": "boolean", - "description": "If true, instructions from this server will be included in the system prompt." } } },