mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-23 18:29:21 -05:00
refactor: update Dockerfile and entrypoint script to use REQUEST_TIMEOUT; improve variable naming in mcpService
This commit is contained in:
@@ -9,7 +9,11 @@ RUN apt-get update && apt-get install -y curl gnupg \
|
||||
|
||||
RUN npm install -g pnpm
|
||||
|
||||
RUN pip install mcp-server-fetch
|
||||
ARG REQUEST_TIMEOUT=120000
|
||||
ENV REQUEST_TIMEOUT=$REQUEST_TIMEOUT
|
||||
|
||||
RUN uv tool install mcp-server-fetch
|
||||
RUN uv tool update-shell
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
NPM_REGISTRY=${NPM_REGISTRY:-https://registry.npmjs.org/}
|
||||
echo "Setting npm registry to ${NPM_REGISTRY}"
|
||||
npm config set registry "$NPM_REGISTRY"
|
||||
|
||||
echo "Using REQUEST_TIMEOUT: $REQUEST_TIMEOUT"
|
||||
|
||||
exec "$@"
|
||||
|
||||
@@ -7,6 +7,7 @@ dotenv.config();
|
||||
|
||||
const defaultConfig = {
|
||||
port: process.env.PORT || 3000,
|
||||
timeout: process.env.REQUEST_TIMEOUT || 120000,
|
||||
mcpHubName: 'mcphub',
|
||||
mcpHubVersion: '0.0.1',
|
||||
};
|
||||
|
||||
@@ -43,7 +43,7 @@ export const initializeClientsFromSettings = (): ServerInfo[] => {
|
||||
const existingServerInfos = serverInfos;
|
||||
serverInfos = [];
|
||||
|
||||
for (const [name, config] of Object.entries(settings.mcpServers)) {
|
||||
for (const [name, conf] of Object.entries(settings.mcpServers)) {
|
||||
// Check if server is already connected
|
||||
const existingServer = existingServerInfos.find(
|
||||
(s) => s.name === name && s.status === 'connected',
|
||||
@@ -55,14 +55,14 @@ export const initializeClientsFromSettings = (): ServerInfo[] => {
|
||||
}
|
||||
|
||||
let transport;
|
||||
if (config.url) {
|
||||
transport = new SSEClientTransport(new URL(config.url));
|
||||
} else if (config.command && config.args) {
|
||||
const env: Record<string, string> = config.env || {};
|
||||
if (conf.url) {
|
||||
transport = new SSEClientTransport(new URL(conf.url));
|
||||
} else if (conf.command && conf.args) {
|
||||
const env: Record<string, string> = conf.env || {};
|
||||
env['PATH'] = expandEnvVars(process.env.PATH as string) || '';
|
||||
transport = new StdioClientTransport({
|
||||
command: config.command,
|
||||
args: config.args,
|
||||
command: conf.command,
|
||||
args: conf.args,
|
||||
env: env,
|
||||
});
|
||||
} else {
|
||||
@@ -89,7 +89,7 @@ export const initializeClientsFromSettings = (): ServerInfo[] => {
|
||||
},
|
||||
},
|
||||
);
|
||||
client.connect(transport, { timeout: 120000 }).catch((error) => {
|
||||
client.connect(transport, { timeout: Number(config.timeout) }).catch((error) => {
|
||||
console.error(`Failed to connect client for server ${name} by error: ${error}`);
|
||||
const serverInfo = getServerInfoByName(name);
|
||||
if (serverInfo) {
|
||||
@@ -121,7 +121,7 @@ export const registerAllTools = async (server: McpServer, forceInit: boolean): P
|
||||
serverInfo.status = 'connecting';
|
||||
console.log(`Connecting to server: ${serverInfo.name}...`);
|
||||
|
||||
const tools = await serverInfo.client.listTools();
|
||||
const tools = await serverInfo.client.listTools({}, { timeout: Number(config.timeout) });
|
||||
serverInfo.tools = tools.tools.map((tool) => ({
|
||||
name: tool.name,
|
||||
description: tool.description || '',
|
||||
|
||||
Reference in New Issue
Block a user