mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 14:04:41 -07: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
|
- **`targetServiceAccount`** (string): The email address of the Google Cloud
|
||||||
Service Account to impersonate. Used with
|
Service Account to impersonate. Used with
|
||||||
`authProviderType: 'service_account_impersonation'`.
|
`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
|
### 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
|
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`).
|
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:
|
description:
|
||||||
'Service account email to impersonate (name@project.iam.gserviceaccount.com).',
|
'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: {
|
TelemetrySettings: {
|
||||||
|
|||||||
@@ -204,8 +204,6 @@ export class MCPServerConfig {
|
|||||||
readonly targetAudience?: string,
|
readonly targetAudience?: string,
|
||||||
/* targetServiceAccount format: <service-account-name>@<project-num>.iam.gserviceaccount.com */
|
/* targetServiceAccount format: <service-account-name>@<project-num>.iam.gserviceaccount.com */
|
||||||
readonly targetServiceAccount?: string,
|
readonly targetServiceAccount?: string,
|
||||||
// Include the MCP server initialization instructions in the system instructions
|
|
||||||
readonly useInstructions?: boolean,
|
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,8 +195,7 @@ describe('McpClientManager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('getMcpInstructions', () => {
|
describe('getMcpInstructions', () => {
|
||||||
it('should only return instructions from servers with useInstructions: true', async () => {
|
it('should not return instructions for servers that do not have instructions', async () => {
|
||||||
// Override McpClient mock for this test to return distinct objects based on config
|
|
||||||
vi.mocked(McpClient).mockImplementation(
|
vi.mocked(McpClient).mockImplementation(
|
||||||
(name, config) =>
|
(name, config) =>
|
||||||
({
|
({
|
||||||
@@ -206,42 +205,34 @@ describe('McpClientManager', () => {
|
|||||||
getServerConfig: vi.fn().mockReturnValue(config),
|
getServerConfig: vi.fn().mockReturnValue(config),
|
||||||
getInstructions: vi
|
getInstructions: vi
|
||||||
.fn()
|
.fn()
|
||||||
.mockReturnValue(`Instructions for ${name}`),
|
.mockReturnValue(
|
||||||
|
name === 'server-with-instructions'
|
||||||
|
? `Instructions for ${name}`
|
||||||
|
: '',
|
||||||
|
),
|
||||||
}) as unknown as McpClient,
|
}) as unknown as McpClient,
|
||||||
);
|
);
|
||||||
|
|
||||||
const manager = new McpClientManager({} as ToolRegistry, mockConfig);
|
const manager = new McpClientManager({} as ToolRegistry, mockConfig);
|
||||||
|
|
||||||
// 1. Configured server with useInstructions: true
|
|
||||||
mockConfig.getMcpServers.mockReturnValue({
|
mockConfig.getMcpServers.mockReturnValue({
|
||||||
'enabled-server': {
|
'server-with-instructions': {},
|
||||||
useInstructions: true,
|
'server-without-instructions': {},
|
||||||
},
|
|
||||||
'disabled-server': {
|
|
||||||
useInstructions: false,
|
|
||||||
},
|
|
||||||
'default-server': {
|
|
||||||
// undefined should be treated as false
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
await manager.startConfiguredMcpServers();
|
await manager.startConfiguredMcpServers();
|
||||||
|
|
||||||
const instructions = manager.getMcpInstructions();
|
const instructions = manager.getMcpInstructions();
|
||||||
|
|
||||||
expect(instructions).toContain(
|
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(
|
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 {
|
getMcpInstructions(): string {
|
||||||
const instructions: string[] = [];
|
const instructions: string[] = [];
|
||||||
for (const [name, client] of this.clients) {
|
for (const [name, client] of this.clients) {
|
||||||
// Only include instructions if explicitly enabled in config
|
const clientInstructions = client.getInstructions();
|
||||||
if (client.getServerConfig().useInstructions) {
|
if (clientInstructions) {
|
||||||
const clientInstructions = client.getInstructions();
|
instructions.push(
|
||||||
if (clientInstructions) {
|
`# Instructions for MCP Server '${name}'\n${clientInstructions}`,
|
||||||
instructions.push(
|
);
|
||||||
`# Instructions for MCP Server '${name}'\n${clientInstructions}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return instructions.join('\n\n');
|
return instructions.join('\n\n');
|
||||||
|
|||||||
@@ -1467,10 +1467,6 @@
|
|||||||
"targetServiceAccount": {
|
"targetServiceAccount": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Service account email to impersonate (name@project.iam.gserviceaccount.com)."
|
"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