mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
Simplify MCP server timeout configuration (#7661)
This commit is contained in:
@@ -644,7 +644,9 @@ export async function discoverTools(
|
||||
cliConfig: Config,
|
||||
): Promise<DiscoveredMCPTool[]> {
|
||||
try {
|
||||
const mcpCallableTool = mcpToTool(mcpClient);
|
||||
const mcpCallableTool = mcpToTool(mcpClient, {
|
||||
timeout: mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
||||
});
|
||||
const tool = await mcpCallableTool.tool();
|
||||
|
||||
if (!Array.isArray(tool.functionDeclarations)) {
|
||||
@@ -675,7 +677,6 @@ export async function discoverTools(
|
||||
funcDecl.name!,
|
||||
funcDecl.description ?? '',
|
||||
funcDecl.parametersJsonSchema ?? { type: 'object', properties: {} },
|
||||
mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
||||
mcpServerConfig.trust,
|
||||
undefined,
|
||||
cliConfig,
|
||||
@@ -871,18 +872,6 @@ export async function connectToMcpServer(
|
||||
unlistenDirectories = undefined;
|
||||
};
|
||||
|
||||
// patch Client.callTool to use request timeout as genai McpCallTool.callTool does not do it
|
||||
// TODO: remove this hack once GenAI SDK does callTool with request options
|
||||
if ('callTool' in mcpClient) {
|
||||
const origCallTool = mcpClient.callTool.bind(mcpClient);
|
||||
mcpClient.callTool = function (params, resultSchema, options) {
|
||||
return origCallTool(params, resultSchema, {
|
||||
...options,
|
||||
timeout: mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const transport = await createTransport(
|
||||
mcpServerName,
|
||||
|
||||
@@ -98,20 +98,6 @@ describe('DiscoveredMCPTool', () => {
|
||||
expect(tool.schema.parameters).toBeUndefined();
|
||||
expect(tool.schema.parametersJsonSchema).toEqual(inputSchema);
|
||||
expect(tool.serverToolName).toBe(serverToolName);
|
||||
expect(tool.timeout).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should accept and store a custom timeout', () => {
|
||||
const customTimeout = 5000;
|
||||
const toolWithTimeout = new DiscoveredMCPTool(
|
||||
mockCallableToolInstance,
|
||||
serverName,
|
||||
serverToolName,
|
||||
baseDescription,
|
||||
inputSchema,
|
||||
customTimeout,
|
||||
);
|
||||
expect(toolWithTimeout.timeout).toBe(customTimeout);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -596,7 +582,6 @@ describe('DiscoveredMCPTool', () => {
|
||||
serverToolName,
|
||||
baseDescription,
|
||||
inputSchema,
|
||||
undefined,
|
||||
true,
|
||||
undefined,
|
||||
{ isTrustedFolder: () => true } as any,
|
||||
@@ -761,7 +746,6 @@ describe('DiscoveredMCPTool', () => {
|
||||
serverToolName,
|
||||
baseDescription,
|
||||
inputSchema,
|
||||
undefined,
|
||||
true, // trust = true
|
||||
undefined,
|
||||
mockConfig(true) as any, // isTrustedFolder = true
|
||||
@@ -779,7 +763,6 @@ describe('DiscoveredMCPTool', () => {
|
||||
serverToolName,
|
||||
baseDescription,
|
||||
inputSchema,
|
||||
undefined,
|
||||
true, // trust = true
|
||||
undefined,
|
||||
mockConfig(false) as any, // isTrustedFolder = false
|
||||
@@ -799,7 +782,6 @@ describe('DiscoveredMCPTool', () => {
|
||||
serverToolName,
|
||||
baseDescription,
|
||||
inputSchema,
|
||||
undefined,
|
||||
false, // trust = false
|
||||
undefined,
|
||||
mockConfig(true) as any, // isTrustedFolder = true
|
||||
|
||||
@@ -68,7 +68,6 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
|
||||
readonly serverName: string,
|
||||
readonly serverToolName: string,
|
||||
readonly displayName: string,
|
||||
readonly timeout?: number,
|
||||
readonly trust?: boolean,
|
||||
params: ToolParams = {},
|
||||
private readonly cliConfig?: Config,
|
||||
@@ -182,7 +181,6 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
|
||||
readonly serverToolName: string,
|
||||
description: string,
|
||||
override readonly parameterSchema: unknown,
|
||||
readonly timeout?: number,
|
||||
readonly trust?: boolean,
|
||||
nameOverride?: string,
|
||||
private readonly cliConfig?: Config,
|
||||
@@ -205,7 +203,6 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
|
||||
this.serverToolName,
|
||||
this.description,
|
||||
this.parameterSchema,
|
||||
this.timeout,
|
||||
this.trust,
|
||||
`${this.serverName}__${this.serverToolName}`,
|
||||
this.cliConfig,
|
||||
@@ -220,7 +217,6 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
|
||||
this.serverName,
|
||||
this.serverToolName,
|
||||
this.displayName,
|
||||
this.timeout,
|
||||
this.trust,
|
||||
params,
|
||||
this.cliConfig,
|
||||
|
||||
Reference in New Issue
Block a user