mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-29 14:34:55 -07:00
Simplify MCP server timeout configuration (#7661)
This commit is contained in:
@@ -644,7 +644,9 @@ export async function discoverTools(
|
|||||||
cliConfig: Config,
|
cliConfig: Config,
|
||||||
): Promise<DiscoveredMCPTool[]> {
|
): Promise<DiscoveredMCPTool[]> {
|
||||||
try {
|
try {
|
||||||
const mcpCallableTool = mcpToTool(mcpClient);
|
const mcpCallableTool = mcpToTool(mcpClient, {
|
||||||
|
timeout: mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
||||||
|
});
|
||||||
const tool = await mcpCallableTool.tool();
|
const tool = await mcpCallableTool.tool();
|
||||||
|
|
||||||
if (!Array.isArray(tool.functionDeclarations)) {
|
if (!Array.isArray(tool.functionDeclarations)) {
|
||||||
@@ -675,7 +677,6 @@ export async function discoverTools(
|
|||||||
funcDecl.name!,
|
funcDecl.name!,
|
||||||
funcDecl.description ?? '',
|
funcDecl.description ?? '',
|
||||||
funcDecl.parametersJsonSchema ?? { type: 'object', properties: {} },
|
funcDecl.parametersJsonSchema ?? { type: 'object', properties: {} },
|
||||||
mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC,
|
|
||||||
mcpServerConfig.trust,
|
mcpServerConfig.trust,
|
||||||
undefined,
|
undefined,
|
||||||
cliConfig,
|
cliConfig,
|
||||||
@@ -871,18 +872,6 @@ export async function connectToMcpServer(
|
|||||||
unlistenDirectories = undefined;
|
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 {
|
try {
|
||||||
const transport = await createTransport(
|
const transport = await createTransport(
|
||||||
mcpServerName,
|
mcpServerName,
|
||||||
|
|||||||
@@ -98,20 +98,6 @@ describe('DiscoveredMCPTool', () => {
|
|||||||
expect(tool.schema.parameters).toBeUndefined();
|
expect(tool.schema.parameters).toBeUndefined();
|
||||||
expect(tool.schema.parametersJsonSchema).toEqual(inputSchema);
|
expect(tool.schema.parametersJsonSchema).toEqual(inputSchema);
|
||||||
expect(tool.serverToolName).toBe(serverToolName);
|
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,
|
serverToolName,
|
||||||
baseDescription,
|
baseDescription,
|
||||||
inputSchema,
|
inputSchema,
|
||||||
undefined,
|
|
||||||
true,
|
true,
|
||||||
undefined,
|
undefined,
|
||||||
{ isTrustedFolder: () => true } as any,
|
{ isTrustedFolder: () => true } as any,
|
||||||
@@ -761,7 +746,6 @@ describe('DiscoveredMCPTool', () => {
|
|||||||
serverToolName,
|
serverToolName,
|
||||||
baseDescription,
|
baseDescription,
|
||||||
inputSchema,
|
inputSchema,
|
||||||
undefined,
|
|
||||||
true, // trust = true
|
true, // trust = true
|
||||||
undefined,
|
undefined,
|
||||||
mockConfig(true) as any, // isTrustedFolder = true
|
mockConfig(true) as any, // isTrustedFolder = true
|
||||||
@@ -779,7 +763,6 @@ describe('DiscoveredMCPTool', () => {
|
|||||||
serverToolName,
|
serverToolName,
|
||||||
baseDescription,
|
baseDescription,
|
||||||
inputSchema,
|
inputSchema,
|
||||||
undefined,
|
|
||||||
true, // trust = true
|
true, // trust = true
|
||||||
undefined,
|
undefined,
|
||||||
mockConfig(false) as any, // isTrustedFolder = false
|
mockConfig(false) as any, // isTrustedFolder = false
|
||||||
@@ -799,7 +782,6 @@ describe('DiscoveredMCPTool', () => {
|
|||||||
serverToolName,
|
serverToolName,
|
||||||
baseDescription,
|
baseDescription,
|
||||||
inputSchema,
|
inputSchema,
|
||||||
undefined,
|
|
||||||
false, // trust = false
|
false, // trust = false
|
||||||
undefined,
|
undefined,
|
||||||
mockConfig(true) as any, // isTrustedFolder = true
|
mockConfig(true) as any, // isTrustedFolder = true
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
|
|||||||
readonly serverName: string,
|
readonly serverName: string,
|
||||||
readonly serverToolName: string,
|
readonly serverToolName: string,
|
||||||
readonly displayName: string,
|
readonly displayName: string,
|
||||||
readonly timeout?: number,
|
|
||||||
readonly trust?: boolean,
|
readonly trust?: boolean,
|
||||||
params: ToolParams = {},
|
params: ToolParams = {},
|
||||||
private readonly cliConfig?: Config,
|
private readonly cliConfig?: Config,
|
||||||
@@ -182,7 +181,6 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
|
|||||||
readonly serverToolName: string,
|
readonly serverToolName: string,
|
||||||
description: string,
|
description: string,
|
||||||
override readonly parameterSchema: unknown,
|
override readonly parameterSchema: unknown,
|
||||||
readonly timeout?: number,
|
|
||||||
readonly trust?: boolean,
|
readonly trust?: boolean,
|
||||||
nameOverride?: string,
|
nameOverride?: string,
|
||||||
private readonly cliConfig?: Config,
|
private readonly cliConfig?: Config,
|
||||||
@@ -205,7 +203,6 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
|
|||||||
this.serverToolName,
|
this.serverToolName,
|
||||||
this.description,
|
this.description,
|
||||||
this.parameterSchema,
|
this.parameterSchema,
|
||||||
this.timeout,
|
|
||||||
this.trust,
|
this.trust,
|
||||||
`${this.serverName}__${this.serverToolName}`,
|
`${this.serverName}__${this.serverToolName}`,
|
||||||
this.cliConfig,
|
this.cliConfig,
|
||||||
@@ -220,7 +217,6 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
|
|||||||
this.serverName,
|
this.serverName,
|
||||||
this.serverToolName,
|
this.serverToolName,
|
||||||
this.displayName,
|
this.displayName,
|
||||||
this.timeout,
|
|
||||||
this.trust,
|
this.trust,
|
||||||
params,
|
params,
|
||||||
this.cliConfig,
|
this.cliConfig,
|
||||||
|
|||||||
Reference in New Issue
Block a user