mcpcodeserver MCP Server

官方

mcpcode服务器不直接调用MCP工具,而是将MCP工具调用转换为TypeScript程序,使大语言模型能够实现更智能、更低延迟的编排。

文档

mcpcodeserver

NPM Version MIT licensed Install MCP Server Install in VS Code (npx)

一个模型上下文协议(MCP)代理服务器,可将工具调用转换为 TypeScript 代码生成。LLM 无需反复进行多次工具调用,而是可以编写 TypeScript 代码自然地调用多个工具,从而减少令牌开销,并利用 LLM 卓越的代码生成能力。

❌ 未使用 mcpcodeserver 时

LLM 进行多次顺序工具调用,消耗令牌且难以处理复杂工作流:

  • ❌ LLM 与工具之间多次往返
  • ❌ 复杂的工具调用序列容易出错
  • ❌ 数据难以在工具之间传递
  • ❌ 错误处理和控制流能力有限

✅ 使用 mcpcodeserver 后

LLM 编写 TypeScript 代码自然地调用多个工具:

  • ✅ 编写代码按顺序调用多个工具
  • ✅ 自然地使用变量、循环和条件语句
  • ✅ 通过 try/catch 实现更好的错误处理
  • ✅ 通过合并操作减少令牌使用量
  • ✅ 利用 LLM 强大的代码生成能力

快速开始

  1. 在您的 MCP 客户端中安装 mcpcodeserver(参见下方安装部分)
  2. 创建一个 mcp.json 配置文件,包含您的子 MCP 服务器
  3. 开始使用 - 您的 LLM 现在可以生成并执行调用工具的 TypeScript 代码
// Instead of multiple tool calls, write code like this:
const files = await filesystem.list_directory({ path: "/tmp" });
const results = await Promise.all(
  files.map(file => filesystem.read_file({ path: file.path }))
);
return results.filter(content => content.includes("important"));

概述

mcpcodeserver 是一个独特的 MCP 服务器,它可以:

  • 作为 MCP 客户端连接到一个或多个子 MCP 服务器
  • 发现所有子服务器的工具
  • 向父 LLM 客户端暴露三个强大的工具:
    1. list_servers - 列出连接到此 MCP 服务器的所有可用子服务器
    2. get_tool_definitions - 返回已发现工具的 TypeScript 类型定义(可选择按服务器过滤)
    3. generate_and_execute_code - 在沙箱中生成并执行调用这些工具的 TypeScript 代码

这种架构允许 LLM 通过编写代码来编排复杂的多工具工作流,而不是进行顺序工具调用,这对于现代语言模型来说通常更高效、更自然。

相关研究与工作

此方法受到近期研究的启发,这些研究表明 LLM 在生成可执行代码时比直接进行工具调用表现更好:

  • CodeAct: Your LLM Agent Acts Better when Generating Code(Apple,ICML 2024)- 证明 LLM 代理在使用可执行 Python 代码作为统一动作空间时,成功率比使用预定义工具调用格式高出 20%。

  • Cloudflare Code Mode - 一个类似的实现,将 MCP 工具转换为 TypeScript API,表明“LLM 更擅长编写代码来调用 MCP,而不是直接调用 MCP。”

这些研究的关键见解是,LLM 在真实世界代码方面接受了大量训练,但对合成工具调用格式的接触有限,这使得代码生成成为复杂代理工作流更自然、更有效的方法。

为什么使用它?

传统工具调用的问题

  • LLM 与工具之间的多次往返消耗令牌
  • LLM 通常难以处理复杂的工具调用序列
  • 每次工具调用都需要理解 JSON schema 并进行格式化
  • 数据难以在不经过 LLM 的情况下在工具之间传递

代码生成解决方案

  • 编写 TypeScript 代码按顺序调用多个工具
  • 自然地使用变量、循环和条件语句
  • 通过 try/catch 实现更好的错误处理
  • 通过合并操作减少令牌使用量
  • 利用 LLM 强大的代码生成能力

动态工具发现

mcpcodeserver 自动监控子 MCP 服务器的工具变化,并在工具添加、移除或修改时通知父客户端:

  • 自动刷新:每 30 秒检查一次工具变化
  • 实时通知:向父客户端发送 notifications/tools/list_changed
  • 动态更新:工具定义和摘要自动更新
  • 无需手动刷新:父 LLM 接收通知以刷新其工具知识

这确保了父 LLM 始终拥有最新的工具定义,无需手动干预。

服务器过滤

为了减少上下文窗口使用并提高专注度,mcpcodeserver 支持按特定服务器过滤工具定义:

  • 列出可用服务器:使用 list_servers 查看所有连接的子服务器
  • 过滤工具定义:使用 get_tool_definitions 并配合 server_names 参数,仅获取特定服务器的工具
  • 减少冗余:获取聚焦的 TypeScript 定义,避免 LLM 上下文窗口过载
  • 方法命名空间:所有生成的函数都带有服务器名称前缀(例如 pizzashop_create_pizzafilesystem_read_file

使用示例:

// List available servers
const servers = await list_servers({});
// Returns: ["pizzashop", "filesystem", "memory"]

// Get all tool definitions
const allTools = await get_tool_definitions({});

// Get only pizzashop tools
const pizzashopTools = await get_tool_definitions({
  server_names: ["pizzashop"]
});

高级 MCP 功能

当父服务器和子服务器都支持时,mcpcodeserver 支持传递高级 MCP 协议功能:

  • Elicitation:子服务器可以在工具执行期间请求用户输入,该请求会传递给父客户端
  • Roots:列出并聚合所有子服务器的根,提供可用资源的统一视图
  • Sampling:使 LLM 采样请求能够传递给子服务器,以实现高级 AI 功能

这些功能会自动向父客户端公布,并在底层子 MCP 服务器支持时无缝工作。

快速开始

使用 npx 立即尝试(无需安装):

# From GitHub
npx github:zbowling/mcpcodeserver --help

# Or when published to npm
npx mcpcodeserver --help

🛠️ 安装

要求

  • Node.js >= v18.0.0
  • Cursor、Claude Code、VSCode、Windsurf 或其他 MCP 客户端

通过 Smithery 安装

要通过 Smithery 为任何客户端自动安装 mcpcodeserver:

npx -y @smithery/cli@latest install mcpcodeserver --client <client-name> --key <smithery-key>

在 Cursor 中安装

前往:Settings -> Cursor Settings -> MCP -> Add new global MCP server

推荐将以下配置粘贴到您的 Cursor ~/.cursor/mcp.json 文件中。您也可以通过创建项目文件夹中的 .cursor/mcp.json 在特定项目中安装。

Cursor 一键安装

Install MCP Server

Cursor 本地服务器连接

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

Cursor 远程服务器连接(如果您设置了 HTTP 传输)

{
  "mcpServers": {
    "mcpcodeserver": {
      "url": "http://localhost:3000/mcp"
    }
  }
}

在 Claude Code 中安装

运行此命令。更多信息请参阅 Claude Code MCP 文档

Claude Code 本地服务器连接

claude mcp add mcpcodeserver -- npx -y mcpcodeserver --config /path/to/your/mcp.json

Claude Code 远程服务器连接

claude mcp add --transport http mcpcodeserver http://localhost:3000/mcp

在 VSCode 中安装

VSCode 一键安装

Install in VS Code (npx)

VSCode 手动配置

添加到您的 VSCode MCP 设置:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

在 Windsurf 中安装

Windsurf 一键安装

Install in Windsurf

在 AI 编码助手中安装

对于 ContinueClineRooCode,添加到您的配置中:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

在 Amp 中安装

在终端中运行此命令。更多信息请参阅 Amp MCP 文档

amp mcp add mcpcodeserver -- npx -y mcpcodeserver --config /path/to/your/mcp.json

在文本编辑器中安装

对于 AiderCodiumZedNovaSublime Text,添加到您的配置中:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

在 Neovim 中安装

添加到您的 Neovim MCP 配置:

{
  mcpServers = {
    mcpcodeserver = {
      command = "npx",
      args = {"-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"}
    }
  }
}

在 Emacs 中安装

添加到您的 Emacs MCP 配置:

(setq mcp-servers
      '((mcpcodeserver
         :command "npx"
         :args ("-y" "mcpcodeserver" "--config" "/path/to/your/mcp.json"))))

在 JetBrains IDE 中安装

对于 IntelliJ IDEAWebStormPyCharmAndroid Studio,添加到您的 MCP 设置中:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

在 AI 工具中安装

对于 CodeiumTabnineGitHub CopilotAmazon CodeWhisperer,添加到您的 MCP 设置中:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

在云 IDE 中安装

对于 ReplitCodeSandboxStackBlitzGitPodGitHub CodespacesGitLab Web IDEBitbucket Cloud,添加到您的 MCP 设置中:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

在其他工具中安装

对于 XcodeFleetSourcegraphJetBrains Gateway,添加到您的 MCP 配置中:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

在远程开发中安装

对于远程开发环境,您也可以使用 HTTP 传输:

{
  "mcpServers": {
    "mcpcodeserver": {
      "url": "http://your-server:3000/mcp"
    }
  }
}

配置文件

创建一个 mcp.json 配置文件来定义您的子 MCP 服务器:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
      "env": { "DEBUG": "false" }
    },
    "memory": {
      "command": "npx", 
      "args": ["-y", "@modelcontextprotocol/server-memory"]
    },
    "brave-search": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-brave-search"],
      "env": { "BRAVE_API_KEY": "your-api-key" }
    }
  }
}

开发环境安装

# Install dependencies (using Bun for faster performance)
bun install

# Or with npm
npm install

# Build the project
bun run build

# Test the built server
bun dist/index.js --help

注意:本项目使用 Bun 以获得更好的性能,但 npm/node 也可以正常工作。

🚨 故障排除

找不到模块错误

如果您遇到 ERR_MODULE_NOT_FOUND,请尝试使用 bunx 而不是 npx

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "bunx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

ESM 解析问题

对于类似 Error: Cannot find module 的错误,请尝试 --experimental-vm-modules 标志:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "--node-options=--experimental-vm-modules", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

TLS/证书问题

使用 --experimental-fetch 标志绕过 TLS 相关问题:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "--node-options=--experimental-fetch", "mcpcodeserver", "--config", "/path/to/your/mcp.json"]
    }
  }
}

一般 MCP 客户端错误

  1. 尝试在包名中添加 @latest
  2. 使用 bunx 作为 npx 的替代方案
  3. 考虑使用 deno 作为另一个替代方案
  4. 确保您使用 Node.js v18 或更高版本以获得原生 fetch 支持

配置问题

  • 确保您的 mcp.json 文件是有效的 JSON
  • 检查所有子服务器命令在您的 PATH 中是否可用
  • 验证子服务器是否可以独立启动
  • 检查配置文件路径的文件权限

使用 MCP Inspector 测试

npx -y @modelcontextprotocol/inspector npx mcpcodeserver --config /path/to/your/mcp.json

💻 开发

CLI 参数

mcpcodeserver 接受以下 CLI 标志:

  • --config <path> – MCP 配置文件的路径(默认:./mcp.json
  • --transport <stdio|http> – 使用的传输方式(默认为 stdio)。请注意,HTTP 传输会自动提供 HTTP 和 SSE 端点
  • --port <number> – 使用 http 传输时监听的端口(默认 3000
  • --help – 显示帮助信息

使用 HTTP 传输和端口 8080 的示例:

npx mcpcodeserver --config /path/to/mcp.json --transport http --port 8080

使用 stdio 传输的示例:

npx mcpcodeserver --config /path/to/mcp.json --transport stdio

环境变量

您可以使用环境变量进行配置:

  • MCP_CONFIG_PATH – MCP 配置文件的路径(替代 --config
  • MCP_TRANSPORT – 传输类型(替代 --transport
  • MCP_PORT – HTTP 传输的端口号(替代 --port

使用环境变量的示例:

# .env
MCP_CONFIG_PATH=/path/to/your/mcp.json
MCP_TRANSPORT=stdio

使用环境变量的 MCP 配置示例:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver"],
      "env": {
        "MCP_CONFIG_PATH": "/path/to/your/mcp.json"
      }
    }
  }
}

注意: 当同时提供 CLI 标志和环境变量时,CLI 标志优先。

本地开发配置

对于本地开发,您可以直接运行 TypeScript 源代码:

{
  "mcpServers": {
    "mcpcodeserver": {
      "command": "npx",
      "args": ["tsx", "/path/to/mcpcodeserver/src/index.ts", "--config", "/path/to/your/mcp.json"]
    }
  }
}

运行模式

Stdio 模式(默认)

服务器默认以 stdio 模式运行,非常适合与 Claude Desktop 等 MCP 客户端集成:

# Run in stdio mode
npx mcpcodeserver --config mcp.json

# Or with custom config path
npx mcpcodeserver --config /path/to/your/mcp.json

HTTP 模式

对于调试、测试或与基于 Web 的 MCP 客户端集成,您可以以 HTTP 模式运行服务器:

# Run in HTTP mode on default port 3000
npx mcpcodeserver --http --config mcp.json

# Run on custom port and host
npx mcpcodeserver --http --port 8080 --host 0.0.0.0 --config mcp.json

在 HTTP 模式下运行时,服务器将在以下地址可用:

  • 服务器 URLhttp://localhost:3000/mcp(或您自定义的主机:端口)
  • MCP Inspector:使用 npx @modelcontextprotocol/inspector http://localhost:3000/mcp 进行调试和测试

MCP Inspector 集成

MCP Inspector 是调试和测试 MCP 服务器的强大工具。在 HTTP 模式下运行时,您可以使用它来:

  • 检查可用工具及其 schema
  • 交互式测试工具调用
  • 调试资源访问和提示
  • 监控实时通知
# Start the server in HTTP mode
npx mcpcodeserver --http --config mcp.json

# In another terminal, start the MCP Inspector
npx @modelcontextprotocol/inspector http://localhost:3000/mcp

# Or use the shorthand script (includes all example servers)
npm run inspector

Inspector 将在您的浏览器中打开,并提供一个完整的界面来探索和测试您的 MCP 服务器。

注意npm run inspector 命令使用 mcp-test.json,其中包含来自官方示例的 8 个 MCP 服务器(共 67 个工具),包括基于 TypeScript(npx)和 Python(uvx)的服务器。

配置

创建一个 mcp.json 文件,用于定义要连接哪些子 MCP 服务器。该文件遵循标准的 MCP 客户端配置格式:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
      "env": {
        "DEBUG": "false"
      }
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your-token-here"
      }
    },
    "weather": {
      "url": "http://localhost:3000/mcp",
      "transport": "sse"
    }
  }
}

配置选项

每个服务器条目支持:

对于 stdio 传输:

  • command(必需)- 要执行的命令(例如 "node"、"python"、"npx")
  • args(可选)- 传递给命令的参数数组
  • env(可选)- 子进程的环境变量

对于 HTTP/SSE 传输:

  • url(必需)- HTTP 端点 URL
  • transport - 设置为 "sse" 以使用服务器发送事件

用法

启动服务器

# Use default config (./mcp.json)
mcpcodeserver

# Use custom config location
mcpcodeserver --config /path/to/custom-mcp.json

# Show help
mcpcodeserver --help

作为 MCP 服务器使用

在你的 MCP 客户端(如 Claude Desktop、Claude Code、Cline 等)中配置 mcpcodeserver:

使用 npx(推荐 - 无需安装):

{
  "mcpServers": {
    "codeserver": {
      "command": "npx",
      "args": ["-y", "mcpcodeserver", "--config", "/path/to/mcp.json"]
    }
  }
}

从 GitHub 安装(立即可用):

{
  "mcpServers": {
    "codeserver": {
      "command": "npx",
      "args": ["-y", "github:zbowling/mcpcodeserver", "--config", "/path/to/mcp.json"]
    }
  }
}

使用其他包管理器:

// yarn
{ "command": "yarn", "args": ["dlx", "mcpcodeserver", "--config", "/path/to/mcp.json"] }

// pnpm
{ "command": "pnpm", "args": ["dlx", "mcpcodeserver", "--config", "/path/to/mcp.json"] }

// bun
{ "command": "bunx", "args": ["mcpcodeserver", "--config", "/path/to/mcp.json"] }

更多配置示例和 MCP 客户端特定设置,请参阅 examples/

工具 1:get_tool_definitions

此工具返回所有从子服务器发现的工具的 TypeScript 类型定义。

输入:

  • include_examples(可选布尔值)- 是否包含使用示例

示例:

// Call the tool (in your MCP client)
get_tool_definitions({ include_examples: true })

输出: 返回包含接口和函数声明的 TypeScript 代码:

/**
 * Auto-generated TypeScript definitions for MCP tools
 */

interface ToolResult {
  content: Array<{
    type: string;
    text?: string;
    // ...
  }>;
  isError?: boolean;
}

/**
 * Read contents of a file
 * Server: filesystem
 * Tool: read_file
 */
interface ReadFileParams {
  path: string;
}

declare function filesystem_read_file(params: ReadFileParams): Promise<ToolResult>;

// ... more tool definitions

工具 2:generate_and_execute_code

此工具在沙箱中执行 TypeScript 代码,并可访问所有已发现的工具函数。

输入:

  • code(必需字符串)- 要执行的 TypeScript/JavaScript 代码
  • timeout(可选数字)- 最大执行时间(毫秒)(默认:30000,最大:300000)

示例:

// Call the tool with TypeScript code
generate_and_execute_code({
  code: `
    // Read multiple files and combine them
    const file1 = await filesystem_read_file({ path: "/tmp/file1.txt" });
    const file2 = await filesystem_read_file({ path: "/tmp/file2.txt" });

    const text1 = file1.content[0].text;
    const text2 = file2.content[0].text;

    console.log("File 1 length:", text1.length);
    console.log("File 2 length:", text2.length);

    return {
      combined: text1 + text2,
      totalLength: text1.length + text2.length
    };
  `
})

输出:

=== Console Output ===
File 1 length: 42
File 2 length: 38

=== Result ===
{
  "combined": "...",
  "totalLength": 80
}

沙箱环境

TypeScript 执行沙箱提供:

可用:

  • 所有已发现的工具函数(作为异步函数)
  • 控制台方法:console.log()console.error()console.warn()console.info()
  • 基本 JavaScript 全局对象:MathJSONDateArrayObjectStringNumberBoolean
  • Promise 和 async/await 支持
  • 使用 try/catch 进行错误处理
  • 定时器:setTimeoutsetIntervalclearTimeoutclearInterval

不可用:

  • Node.js 模块(fs、http、child_process 等)
  • 文件系统访问(除非通过 MCP 工具)
  • 网络访问(除非通过 MCP 工具)
  • 进程信息

安全说明: 这不是一个完全安全的沙箱。VM 上下文提供了隔离,但并非无懈可击。仅执行受信任的代码。

错误处理

沙箱中的错误会被捕获并返回堆栈跟踪:

generate_and_execute_code({
  code: `
    try {
      const result = await filesystem_read_file({ path: "/nonexistent" });
      return result;
    } catch (error) {
      console.error("Failed to read file:", error.message);
      throw error; // Re-throw to surface to parent
    }
  `
})

使用 Claude Code 进行测试

想用 Claude Code 试用 mcpcodeserver?使用一键设置命令:

./setup-claude-code-test.sh

这将构建项目、安装测试依赖项,并准确显示需要添加到 Claude Code 配置中的内容。详细说明请参阅 TESTING_WITH_CLAUDE.md

开发

# Install dependencies
bun install

# Build the project
bun run build

# Watch mode for development
bun run dev

# Run the server
bun start

# Run tests
bun test                # All tests
bun run test:unit       # Unit tests only
bun run test:integration # Integration tests (requires Python)

# Code quality
bun run lint            # Check linting
bun run format          # Format code
bun run typecheck       # Type checking

项目结构

详细的项目结构和组件文档请参阅 AGENTS.md

使用场景

多文件操作

无需通过 LLM 进行多次工具调用,直接编写代码:

const files = ["/tmp/a.txt", "/tmp/b.txt", "/tmp/c.txt"];
const contents = await Promise.all(
  files.map(path => filesystem_read_file({ path }))
);
return contents.map(r => r.content[0].text);

数据转换

在工具调用之间处理数据,无需 LLM 干预:

const data = await api_fetch({ url: "https://api.example.com/data" });
const json = JSON.parse(data.content[0].text);
const filtered = json.items.filter(item => item.active);
return filtered.length;

条件逻辑

根据工具结果做出决策:

const exists = await filesystem_read_file({ path: "/tmp/config.json" });
if (exists.isError) {
  console.log("Config doesn't exist, using defaults");
  return { source: "defaults" };
} else {
  return { source: "file", config: JSON.parse(exists.content[0].text) };
}

错误恢复

优雅地处理错误,而不会中止整个工作流:

const results = [];
for (const path of ["/tmp/a.txt", "/tmp/b.txt", "/tmp/c.txt"]) {
  try {
    const content = await filesystem_read_file({ path });
    results.push({ path, success: true, data: content });
  } catch (error) {
    results.push({ path, success: false, error: error.message });
  }
}
return results;

上游 MCP 服务器集成

mcpcodeserver 可以与来自 Model Context Protocol 服务器仓库 的官方上游 MCP 服务器集成。这允许你将真实的、生产就绪的 MCP 服务器与自定义工具一起使用。

支持的上游服务器

  • filesystem:文件系统操作(读取、写入、列出目录)
  • memory:内存键值存储
  • sqlite:SQLite 数据库操作
  • github:GitHub API 集成
  • brave-search:网页搜索功能
  • fetch:HTTP 请求功能

配置示例

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
    },
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"]
    },
    "sqlite": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-sqlite", "--db-path", "/tmp/test.db"]
    }
  }
}

测试上游集成

项目包含针对上游服务器集成的全面测试:

# Run upstream servers integration tests
bun tests/integration/run-upstream-tests.ts

# Or manually test with upstream config
npx mcpcodeserver --config tests/integration/upstream-test-config.json

跨服务器工作流

借助上游服务器,你可以创建强大的跨服务器工作流:

// Store database query results in memory and write to file
const queryResult = await sqlite_execute_sql({
  sql: "SELECT COUNT(*) as count FROM users"
});
const count = queryResult.content[0].text;

await memory_create({
  key: "user-count",
  value: count
});

await filesystem_write_file({
  path: "/tmp/user-count.txt",
  content: `Total users: ${count}`
});

限制

  • 执行超时:最长 5 分钟(可配置,默认 30 秒)
  • 内存:受 Node.js VM 上下文限制
  • 执行之间无持久状态
  • 无法 require/import 外部模块
  • 不是安全沙箱 - 不要运行不受信任的代码

贡献

欢迎贡献!本项目使用以下技术构建:

  • TypeScript 5.7+
  • Node.js 18+
  • MCP TypeScript SDK 1.20+
  • Zod 用于验证

详细的贡献指南请参阅 CONTRIBUTING.md

支持

如果你觉得这个项目有帮助,可以考虑请我喝杯咖啡!

Buy Me A Coffee

许可证

MIT

资源