mcpcodeserver MCP Server

官方

與直接呼叫MCP工具不同,mcpcode server將MCP工具呼叫轉換為TypeScript程式,使LLM能夠實現更智慧、更低延遲的編排。

文件

mcpcodeserver

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

一個模型上下文協定(MCP)代理伺服器,能將工具呼叫轉換為 TypeScript 程式碼生成。LLM 不必反覆進行多次工具呼叫,而是可以編寫 TypeScript 程式碼自然地呼叫多個工具,從而減少 token 開銷,並善用 LLM 優異的程式碼生成能力。

❌ 不使用 mcpcodeserver 的情況

LLM 需要進行多次連續的工具呼叫,消耗大量 token,且難以處理複雜的工作流程:

  • ❌ LLM 與工具之間需要多次往返
  • ❌ 複雜的工具呼叫序列容易出錯
  • ❌ 資料不易在工具之間傳遞
  • ❌ 錯誤處理與控制流程的能力有限

✅ 使用 mcpcodeserver 的情況

LLM 可以編寫 TypeScript 程式碼自然地呼叫多個工具:

  • ✅ 編寫程式碼來依序呼叫多個工具
  • ✅ 自然地使用變數、迴圈和條件判斷
  • ✅ 透過 try/catch 實現更好的錯誤處理
  • ✅ 合併操作以減少 token 使用量
  • ✅ 善用 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 與工具之間多次往返消耗大量 token
  • LLM 經常難以處理複雜的工具呼叫序列
  • 每次工具呼叫都需要理解 JSON schema 並進行格式化
  • 資料無法輕易在工具之間傳遞,必須透過 LLM 中轉

程式碼生成解決方案

  • 編寫 TypeScript 程式碼來依序呼叫多個工具
  • 自然地使用變數、迴圈和條件判斷
  • 透過 try/catch 實現更好的錯誤處理
  • 合併操作以減少 token 使用量
  • 善用 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 協定功能:

  • 引導詢問:子伺服器可以在工具執行期間請求使用者輸入,並傳遞給上層客戶端
  • 根目錄:列出並彙總所有子伺服器的根目錄,提供可用資源的統一視圖
  • 取樣:允許將 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 模式

為了除錯、測試或與基於網頁的 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"] }

請參閱 examples/ 以取得更多設定範例和 MCP 用戶端專屬的設定方式。

工具 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 進行測試

想試試 mcpcodeserver 搭配 Claude Code 嗎?使用一鍵設定指令:

./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 servers repository 的官方上游 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

資源