diff --git a/librechat.example.yaml b/librechat.example.yaml index 7913c50455..12c6ed9635 100644 --- a/librechat.example.yaml +++ b/librechat.example.yaml @@ -113,12 +113,14 @@ mcpServers: everything: # type: sse # type can optionally be omitted url: http://localhost:3001/sse + timeout: 60000 # 1 minute timeout for this server, this is the default timeout for MCP servers. puppeteer: type: stdio command: npx args: - -y - "@modelcontextprotocol/server-puppeteer" + timeout: 300000 # 5 minutes timeout for this server filesystem: # type: stdio command: npx diff --git a/packages/data-provider/src/mcp.ts b/packages/data-provider/src/mcp.ts index 2328a0071e..f0520dbec7 100644 --- a/packages/data-provider/src/mcp.ts +++ b/packages/data-provider/src/mcp.ts @@ -3,6 +3,7 @@ import { extractEnvVariable } from './utils'; const BaseOptionsSchema = z.object({ iconPath: z.string().optional(), + timeout: z.number().optional(), }); export const StdioOptionsSchema = BaseOptionsSchema.extend({ diff --git a/packages/mcp/src/connection.ts b/packages/mcp/src/connection.ts index 68b5c5ed59..64ec305745 100644 --- a/packages/mcp/src/connection.ts +++ b/packages/mcp/src/connection.ts @@ -43,12 +43,14 @@ export class MCPConnection extends EventEmitter { private isInitializing = false; private reconnectAttempts = 0; iconPath?: string; + timeout?: number; constructor(serverName: string, private readonly options: t.MCPOptions, private logger?: Logger) { super(); this.serverName = serverName; this.logger = logger; this.iconPath = options.iconPath; + this.timeout = options.timeout; this.client = new Client( { name: 'librechat-mcp-client', diff --git a/packages/mcp/src/manager.ts b/packages/mcp/src/manager.ts index bf74478b17..3e216b7336 100644 --- a/packages/mcp/src/manager.ts +++ b/packages/mcp/src/manager.ts @@ -159,7 +159,7 @@ export class MCPManager { }; } } catch (error) { - this.logger.warn(`[MCP][${serverName}] Not connected, skipping tool fetch`); + this.logger.warn(`[MCP][${serverName}] Error fetching tools:`, error); } } } @@ -183,7 +183,7 @@ export class MCPManager { }); } } catch (error) { - this.logger.error(`[MCP][${serverName}] Error fetching tools`, error); + this.logger.error(`[MCP][${serverName}] Error fetching tools:`, error); } } } @@ -209,6 +209,7 @@ export class MCPManager { }, }, CallToolResultSchema, + { timeout: connection.timeout }, ); return formatToolContent(result, provider); }