refactor: update Dockerfile and package.json to add zod dependency; improve code formatting in server.ts

This commit is contained in:
samanhappy
2025-03-31 19:42:45 +08:00
parent a61bda6ea9
commit 81d54766f6
4 changed files with 16 additions and 8 deletions

View File

@@ -3,9 +3,9 @@ FROM node:22-alpine
# Install Python and pip
RUN apk add --no-cache \
python3 \
py3-pip \
&& ln -sf python3 /usr/bin/python
python3 \
py3-pip \
&& ln -sf python3 /usr/bin/python
# Create symbolic links for python commands
RUN ln -sf /usr/bin/pip3 /usr/bin/pip

View File

@@ -21,7 +21,8 @@
"dependencies": {
"@modelcontextprotocol/sdk": "^1.8.0",
"dotenv": "^16.3.1",
"express": "^4.18.2"
"express": "^4.18.2",
"zod": "^3.24.2"
},
"devDependencies": {
"@types/express": "^4.17.21",

3
pnpm-lock.yaml generated
View File

@@ -17,6 +17,9 @@ importers:
express:
specifier: ^4.18.2
version: 4.21.2
zod:
specifier: ^3.24.2
version: 3.24.2
devDependencies:
'@types/express':
specifier: ^4.17.21

View File

@@ -3,7 +3,8 @@ import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.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 path from 'path';
@@ -31,14 +32,17 @@ function loadSettings(): McpSettings {
}
// Initialize clients and transports from settings
function initializeClientsFromSettings(): { clients: Client[]; transports: (SSEClientTransport | StdioClientTransport)[] } {
function initializeClientsFromSettings(): {
clients: Client[];
transports: (SSEClientTransport | StdioClientTransport)[];
} {
const settings = loadSettings();
const clients: Client[] = [];
const transports: (SSEClientTransport | StdioClientTransport)[] = [];
Object.entries(settings.mcpServers).forEach(([name, config]) => {
let transport;
if (config.url) {
transport = new SSEClientTransport(new URL(config.url));
} else if (config.command && config.args) {
@@ -87,7 +91,7 @@ export const registerAllTools = async (server: McpServer) => {
tool.name,
tool.description || '',
cast(tool.inputSchema.properties),
async (params) => {
async (params: Record<string, unknown>) => {
console.log(`Calling tool: ${tool.name} with params: ${JSON.stringify(params)}`);
const result = await client.callTool({
name: tool.name,