# 本地 MCP 服务器

`@tomba-io/tomba-mcp-server` 是一个在您的机器上运行的 MCP 服务器，它使用您的密钥和 Secret 调用 Tomba API。它提供与远程服务器相同的 28 个工具。[远程 MCP 服务器](/llm/remote-mcp/introduction)无需安装，并且还支持 OAuth；[本地服务器的差异](/llm/remote-mcp/tools#local-server-differences)列出了本地服务器与远程服务器在行为上的不同之处。

## 要求

- Node.js 18.20 或更高版本。更早的版本会在启动时报错 `SyntaxError: Unexpected token 'with'` 并停止运行。
- Tomba API 密钥和 Secret。请参阅[获取密钥和 Secret](/authentication#get-your-key-and-secret)。

## 运行服务器

通常由您的 MCP 客户端为您启动服务器，如[配置客户端](#configure-a-client)所示。要检查该包能否正常安装和运行，请打印其版本：

```bash
npx -y @tomba-io/tomba-mcp-server --version
```

服务器从 2 个环境变量中读取您的凭据；如果缺少其中任意一个，它会以 `Error: TOMBA_API_KEY and TOMBA_SECRET_KEY environment variables are required` 退出：

| 变量           | 值                |
| ------------------ | -------------------- |
| `TOMBA_API_KEY`    | 您的 API 密钥，`ta_…` |
| `TOMBA_SECRET_KEY` | 您的 Secret，`ts_…`  |

它接受以下选项：

| 选项              | 默认值 | 说明                                                                                                               |
| ------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
| `--transport`, `-t` | `stdio` | `stdio` 表示与启动它的客户端通信，`http` 表示提供 Streamable HTTP 服务。请参阅 [HTTP 传输方式](#http-transport)。 |
| `--port`, `-p`      | `3000`  | HTTP 传输方式使用的端口                                                                                               |
| `--version`, `-v`   |         | 打印版本并退出                                                                                                |
| `--help`, `-h`      |         | 打印选项并退出                                                                                                |

## 配置客户端

在每个示例中，将 `ta_xxxx` 和 `ts_xxxx` 替换为您的密钥和 Secret。不要将包含 Secret 的配置文件纳入版本控制。

### Claude Desktop

在 Claude Desktop 中，打开 **Settings → Developer** 并选择 **Edit Config**。该文件在 macOS 上位于 `~/Library/Application Support/Claude/claude_desktop_config.json`，在 Windows 上位于 `%APPDATA%\Claude\claude_desktop_config.json`。添加服务器，然后退出并重新启动 Claude Desktop：

```json
{
    "mcpServers": {
        "tomba": {
            "command": "npx",
            "args": ["-y", "@tomba-io/tomba-mcp-server"],
            "env": {
                "TOMBA_API_KEY": "ta_xxxx",
                "TOMBA_SECRET_KEY": "ts_xxxx"
            }
        }
    }
}
```

同样的 `mcpServers` 条目也适用于 Cursor、Windsurf、Gemini CLI 和 Cline 的配置文件；[连接客户端](/llm/remote-mcp/clients)说明了每个客户端存放配置文件的位置。

### Claude Code

```bash
claude mcp add --scope user tomba \
  -e TOMBA_API_KEY="$TOMBA_API_KEY" \
  -e TOMBA_SECRET_KEY="$TOMBA_SECRET_KEY" \
  -- npx -y @tomba-io/tomba-mcp-server
```

### VS Code

将服务器添加到 `.vscode/mcp.json`，或添加到 **MCP: Open User Configuration** 打开的文件中。VS Code 会在首次使用时要求输入密钥和 Secret，并安全地存储它们：

```json
{
    "inputs": [
        {
            "type": "promptString",
            "id": "tomba-key",
            "description": "Tomba API key",
            "password": true
        },
        {
            "type": "promptString",
            "id": "tomba-secret",
            "description": "Tomba secret",
            "password": true
        }
    ],
    "servers": {
        "tomba": {
            "type": "stdio",
            "command": "npx",
            "args": ["-y", "@tomba-io/tomba-mcp-server"],
            "env": {
                "TOMBA_API_KEY": "${input:tomba-key}",
                "TOMBA_SECRET_KEY": "${input:tomba-secret}"
            }
        }
    }
}
```

### Zed

运行 **zed: open settings file**，然后在 `context_servers` 下添加服务器：

```json
{
    "context_servers": {
        "tomba": {
            "command": "npx",
            "args": ["-y", "@tomba-io/tomba-mcp-server"],
            "env": {
                "TOMBA_API_KEY": "ta_xxxx",
                "TOMBA_SECRET_KEY": "ts_xxxx"
            }
        }
    }
}
```

## 验证连接

1. 客户端列出 28 个 Tomba 工具。
2. 让助手运行 `list_flags` 工具。只要返回报告列表（即使为空），就说明您的凭据有效。

服务器通过 stdio 启动时，会将 `Tomba MCP server running on stdio` 写入其错误输出。Claude Desktop 会将该输出保存在 `mcp-server-tomba.log` 中，该文件在 macOS 上位于 `~/Library/Logs/Claude`，在 Windows 上位于 `%APPDATA%\Claude\logs`。

## HTTP 传输方式

使用 `--transport http` 时，服务器会监听指定端口，在 `/mcp` 提供 Streamable HTTP 服务，并在 `/health` 提供健康检查：

```bash
TOMBA_API_KEY="ta_xxxx" TOMBA_SECRET_KEY="ts_xxxx" \
  npx -y @tomba-io/tomba-mcp-server --transport http --port 3000
```

客户端连接到 `http://localhost:3000/mcp`。每个进程只处理 1 个 MCP 会话：在您重启服务器之前，第二个客户端或重新连接的客户端都会收到 HTTP `500`。

<Callout type="danger">
    在 HTTP 模式下，服务器不对客户端进行认证，会监听所有网络接口，并接受来自任何网页来源的请求。任何能访问该端口的人都可以使用您的 Tomba 积分。请仅在该端口对其他机器关闭的环境中运行它，或者改用 stdio。
</Callout>

## 故障排除

| 现象                                                                        | 建议操作                                                                                                                                                             |
| ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 启动时出现 `SyntaxError: Unexpected token 'with'`                              | 将 Node.js 升级到 18.20 或更高版本。客户端运行的是其自身 `PATH` 中找到的 `node`，这可能与您终端中的不同。                                          |
| `Error: TOMBA_API_KEY and TOMBA_SECRET_KEY environment variables are required` | 在客户端配置的 `env` 块中同时设置这 2 个变量。                                                                                                     |
| 工具已列出，但每次调用都返回认证错误           | 服务器仅在工具调用 API 时检查凭据。请检查密钥和 Secret，以及密钥是否已过期：请参阅[密钥过期](/authentication#key-expiry)。 |
| 调用因速率限制错误而失败                                           | 本地服务器不会重试失败的请求。请稍候再调用；请参阅[处理 429 响应](/rate-limits#handle-429-responses)。                                  |
