mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-02-01 22:48:03 +00:00
Always use MCP server instructions (#14297)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -204,8 +204,6 @@ export class MCPServerConfig {
|
||||
readonly targetAudience?: string,
|
||||
/* targetServiceAccount format: <service-account-name>@<project-num>.iam.gserviceaccount.com */
|
||||
readonly targetServiceAccount?: string,
|
||||
// Include the MCP server initialization instructions in the system instructions
|
||||
readonly useInstructions?: boolean,
|
||||
) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user