mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-13 06:40:33 -07:00
Add support for MCP server instructions behind config option (#13432)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -193,4 +193,55 @@ 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
|
||||
vi.mocked(McpClient).mockImplementation(
|
||||
(name, config) =>
|
||||
({
|
||||
connect: vi.fn(),
|
||||
discover: vi.fn(),
|
||||
disconnect: vi.fn(),
|
||||
getServerConfig: vi.fn().mockReturnValue(config),
|
||||
getInstructions: vi
|
||||
.fn()
|
||||
.mockReturnValue(`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
|
||||
},
|
||||
});
|
||||
await manager.startConfiguredMcpServers();
|
||||
|
||||
const instructions = manager.getMcpInstructions();
|
||||
|
||||
expect(instructions).toContain(
|
||||
"# Instructions for MCP Server 'enabled-server'",
|
||||
);
|
||||
expect(instructions).toContain('Instructions for enabled-server');
|
||||
|
||||
expect(instructions).not.toContain(
|
||||
"# Instructions for MCP Server 'disabled-server'",
|
||||
);
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -323,4 +323,20 @@ export class McpClientManager {
|
||||
}
|
||||
return mcpServers;
|
||||
}
|
||||
|
||||
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}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return instructions.join('\n\n');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +218,10 @@ export class McpClient {
|
||||
getServerConfig(): MCPServerConfig {
|
||||
return this.serverConfig;
|
||||
}
|
||||
|
||||
getInstructions(): string | undefined {
|
||||
return this.client?.getInstructions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user