mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 02:39:19 -05:00
refactor: update Dockerfile and package.json to add zod dependency; improve code formatting in server.ts
This commit is contained in:
@@ -3,9 +3,9 @@ FROM node:22-alpine
|
|||||||
|
|
||||||
# Install Python and pip
|
# Install Python and pip
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
python3 \
|
python3 \
|
||||||
py3-pip \
|
py3-pip \
|
||||||
&& ln -sf python3 /usr/bin/python
|
&& ln -sf python3 /usr/bin/python
|
||||||
|
|
||||||
# Create symbolic links for python commands
|
# Create symbolic links for python commands
|
||||||
RUN ln -sf /usr/bin/pip3 /usr/bin/pip
|
RUN ln -sf /usr/bin/pip3 /usr/bin/pip
|
||||||
|
|||||||
@@ -21,7 +21,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.8.0",
|
"@modelcontextprotocol/sdk": "^1.8.0",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"express": "^4.18.2"
|
"express": "^4.18.2",
|
||||||
|
"zod": "^3.24.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
|
|||||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -17,6 +17,9 @@ importers:
|
|||||||
express:
|
express:
|
||||||
specifier: ^4.18.2
|
specifier: ^4.18.2
|
||||||
version: 4.21.2
|
version: 4.21.2
|
||||||
|
zod:
|
||||||
|
specifier: ^3.24.2
|
||||||
|
version: 3.24.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@types/express':
|
'@types/express':
|
||||||
specifier: ^4.17.21
|
specifier: ^4.17.21
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|||||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||||
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
||||||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
||||||
import { z, ZodType, ZodRawShape } from 'zod';
|
import * as z from 'zod';
|
||||||
|
import { ZodType, ZodRawShape } from 'zod';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
@@ -31,14 +32,17 @@ function loadSettings(): McpSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize clients and transports from settings
|
// Initialize clients and transports from settings
|
||||||
function initializeClientsFromSettings(): { clients: Client[]; transports: (SSEClientTransport | StdioClientTransport)[] } {
|
function initializeClientsFromSettings(): {
|
||||||
|
clients: Client[];
|
||||||
|
transports: (SSEClientTransport | StdioClientTransport)[];
|
||||||
|
} {
|
||||||
const settings = loadSettings();
|
const settings = loadSettings();
|
||||||
const clients: Client[] = [];
|
const clients: Client[] = [];
|
||||||
const transports: (SSEClientTransport | StdioClientTransport)[] = [];
|
const transports: (SSEClientTransport | StdioClientTransport)[] = [];
|
||||||
|
|
||||||
Object.entries(settings.mcpServers).forEach(([name, config]) => {
|
Object.entries(settings.mcpServers).forEach(([name, config]) => {
|
||||||
let transport;
|
let transport;
|
||||||
|
|
||||||
if (config.url) {
|
if (config.url) {
|
||||||
transport = new SSEClientTransport(new URL(config.url));
|
transport = new SSEClientTransport(new URL(config.url));
|
||||||
} else if (config.command && config.args) {
|
} else if (config.command && config.args) {
|
||||||
@@ -87,7 +91,7 @@ export const registerAllTools = async (server: McpServer) => {
|
|||||||
tool.name,
|
tool.name,
|
||||||
tool.description || '',
|
tool.description || '',
|
||||||
cast(tool.inputSchema.properties),
|
cast(tool.inputSchema.properties),
|
||||||
async (params) => {
|
async (params: Record<string, unknown>) => {
|
||||||
console.log(`Calling tool: ${tool.name} with params: ${JSON.stringify(params)}`);
|
console.log(`Calling tool: ${tool.name} with params: ${JSON.stringify(params)}`);
|
||||||
const result = await client.callTool({
|
const result = await client.callTool({
|
||||||
name: tool.name,
|
name: tool.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user