Skip to content

Commit 780fdf7

Browse files
authored
🕒 feat: Add Configurable MCP Server Timeouts (#6199)
1 parent c8f7588 commit 780fdf7

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

librechat.example.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ mcpServers:
113113
everything:
114114
# type: sse # type can optionally be omitted
115115
url: http://localhost:3001/sse
116+
timeout: 60000 # 1 minute timeout for this server, this is the default timeout for MCP servers.
116117
puppeteer:
117118
type: stdio
118119
command: npx
119120
args:
120121
- -y
121122
- "@modelcontextprotocol/server-puppeteer"
123+
timeout: 300000 # 5 minutes timeout for this server
122124
filesystem:
123125
# type: stdio
124126
command: npx

packages/data-provider/src/mcp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { extractEnvVariable } from './utils';
33

44
const BaseOptionsSchema = z.object({
55
iconPath: z.string().optional(),
6+
timeout: z.number().optional(),
67
});
78

89
export const StdioOptionsSchema = BaseOptionsSchema.extend({

packages/mcp/src/connection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ export class MCPConnection extends EventEmitter {
4343
private isInitializing = false;
4444
private reconnectAttempts = 0;
4545
iconPath?: string;
46+
timeout?: number;
4647

4748
constructor(serverName: string, private readonly options: t.MCPOptions, private logger?: Logger) {
4849
super();
4950
this.serverName = serverName;
5051
this.logger = logger;
5152
this.iconPath = options.iconPath;
53+
this.timeout = options.timeout;
5254
this.client = new Client(
5355
{
5456
name: 'librechat-mcp-client',

packages/mcp/src/manager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export class MCPManager {
159159
};
160160
}
161161
} catch (error) {
162-
this.logger.warn(`[MCP][${serverName}] Not connected, skipping tool fetch`);
162+
this.logger.warn(`[MCP][${serverName}] Error fetching tools:`, error);
163163
}
164164
}
165165
}
@@ -183,7 +183,7 @@ export class MCPManager {
183183
});
184184
}
185185
} catch (error) {
186-
this.logger.error(`[MCP][${serverName}] Error fetching tools`, error);
186+
this.logger.error(`[MCP][${serverName}] Error fetching tools:`, error);
187187
}
188188
}
189189
}
@@ -209,6 +209,7 @@ export class MCPManager {
209209
},
210210
},
211211
CallToolResultSchema,
212+
{ timeout: connection.timeout },
212213
);
213214
return formatToolContent(result, provider);
214215
}

0 commit comments

Comments
 (0)