emcee 是一个工具,它为具有 OpenAPI 规范的任何 Web 应用程序提供了一个 Model Context Protocol (MCP) 服务器。 你可以使用 emcee 将 Claude Desktop 和 其他应用程序 连接到外部工具和服务, 类似于 ChatGPT 插件。
如果你在 macOS 上并且安装了 Homebrew,你可以快速启动。
# 安装 emcee
brew install mattt/tap/emcee
确保你已经安装了 Claude Desktop。
要配置 Claude Desktop 以与 emcee 一起使用:
配置文件应位于 Application Support 目录中。 你也可以直接使用以下命令在 VSCode 中打开它:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
添加以下配置以添加 weather.gov MCP 服务器:
{
"mcpServers": {
"weather": {
"command": "emcee",
"args": ["https://api.weather.gov/openapi.json"]
}
}
}
保存文件后,退出并重新打开 Claude。 你应该现在在聊天框右下角看到 <kbd>🔨57</kbd>。 点击它可以看到通过 MCP 提供给 Claude 的所有工具列表。
开始一个新的聊天并询问有关你所在位置的天气情况。
俄勒冈州波特兰的天气如何?
Claude 将参考通过 MCP 提供给它的工具,并请求使用其中一个工具来回答你的问题。 你可以查看这个请求并批准或拒绝它。
<img src="https://gips2.baidu.com/it/u=529607643,2345559357&fm=3081&app=3081&f=PNG?w=920&h=420" alt="允许来自天气 MCP 的工具对话框" width="460">如果你允许,Claude 将与 MCP 通信并使用结果来告知其响应。
MCP 提供了一种标准化的方式将 AI 模型连接到工具和数据源。 虽然还处于早期阶段,但已经有多种 可用服务器 可用于连接浏览器、开发工具和其他系统。
我们认为 emcee 是一种方便的方式来连接没有现有 MCP 服务器实现的服务——尤其是你自己构建的服务。 你有一个带有 OpenAPI 规范的 Web 应用吗? 你可能会惊讶于无需仪表板或客户端库可以走多远。
使用 安装脚本 下载并安装适用于你平台的 预构建版本 的 emcee(Linux x86-64/i386/arm64 和 macOS Intel/Apple Silicon)。
# fish
sh (curl -fsSL https://get.emcee.sh | psub)
# bash, zsh
sh <(curl -fsSL https://get.emcee.sh)
使用 Homebrew 安装 emcee。
brew install mattt/tap/emcee
提供了预构建的 Docker 镜像。
docker run -it ghcr.io/mattt/emcee
需要 go 1.24 或更高版本。
git clone https://github.com/mattt/emcee.git
cd emcee
go build -o emcee cmd/emcee/main.go
构建完成后,你可以直接运行 (./emcee) 或将其移动到你的 PATH 中,如 /usr/local/bin。
用法:
emcee [spec-path-or-url] [flags]
标志:
--basic-auth string 基本认证值(可以是 user:pass 或 base64 编码,将会被前缀 'Basic ')
--bearer-auth string Bearer 令牌值(将会被前缀 'Bearer ')
-h, --help emcee 的帮助信息
--raw-auth string Authorization 头的原始值
--retries int 对失败请求的最大重试次数(默认 3)
-r, --rps int 每秒最大请求数(0 表示无限制)
-s, --silent 禁用所有日志
--timeout duration HTTP 请求超时时间(默认 1m0s)
-v, --verbose 启用调试级别日志到 stderr
--version emcee 的版本信息
emcee 实现了 标准输入/输出 (stdio) 运输方式,用于 MCP,它使用 JSON-RPC 2.0 作为其线缆格式。
当你从命令行运行 emcee 时,它会启动一个监听标准输入、输出到标准输出并记录到标准错误的程序。
对于需要认证的 API,emcee 支持几种认证方法:
| 认证类型 | 示例用法 | 结果头 |
|---|---|---|
| Bearer 令牌 | --bearer-auth="abc123" | Authorization: Bearer abc123 |
| 基本认证 | --basic-auth="user:pass" | Authorization: Basic dXNlcjpwYXNz |
| 原始值 | --raw-auth="Custom xyz789" | Authorization: Custom xyz789 |
这些认证值可以直接提供,或者作为 1Password 密钥引用。
当使用 1Password 引用时:
op://vault/item/field
(例如 --bearer-auth="op://Shared/X/credential")PATH 中访问 1Password CLI (op)# 安装 op
brew install 1password-cli
# 登录 1Password CLI
op signin
{
"mcpServers": {
"twitter": {
"command": "emcee",
"args": [
"--bearer-auth=op://shared/x/credential",
"https://api.twitter.com/2/openapi.json"
]
}
}
}
<img src="https://gips0.baidu.com/it/u=3243782921,1759439020&fm=3081&app=3081&f=PNG?w=1024&h=874" alt="1Password 访问请求" width="512">
[!重要]
emcee 不会在下载 OpenAPI 规范时使用认证凭据,这些规范由作为命令参数提供的 URL 提供。 如果你的 OpenAPI 规范需要认证才能访问,请首先使用你喜欢的 HTTP 客户端将其下载到本地文件,然后向 emcee 提供本地文件路径。
你可以在传递给 emcee 之前使用标准 Unix 工具转换 OpenAPI 规范。这可用于:
例如,你可以使用 jq 来仅包括 weather.gov 中的 point 工具。
cat path/to/openapi.json | \
jq 'if .paths then .paths |= with_entries(select(.key == "/points/{point}")) else . end' | \
emcee
你可以通过发送 JSON-RPC 请求直接与提供的 MCP 服务器交互。
[!注意] emcee 仅提供 MCP 工具能力。 其他功能,如资源、提示和采样尚未支持。
{ "jsonrpc": "2.0", "method": "tools/list", "params": {}, "id": 1 }
</details>
<details open>
<summary>响应</summary>
{
"jsonrpc": "2.0",
"result": {
"tools": [
// ...
{
"name": "tafs",
"description": "返回指定机场站的终端航站预报。",
"inputSchema": {
"type": "object",
"properties": {
"stationId": {
"description": "观测站 ID",
"type": "string"
}
},
"required": ["stationId"]
}
}
// ...
]
},
"id": 1
}
</details>
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": { "name": "taf", "arguments": { "stationId": "KPDX" } },
"id": 1
}
</details>
<details open>
<summary>响应</summary>
{
"jsonrpc":"2.0",
"content": [
{
"type": "text",
"text": /* 以 GeoJSON 格式的天气预报 */,
"annotations": {
"audience": ["assistant"]
}
}
]
"id": 1
}
</details>
MCP Inspector 是一个测试和调试 MCP 服务器的工具。 如果 Claude 和/或 emcee 没有按预期工作,检查器可以帮助你理解发生了什么。
npx @modelcontextprotocol/inspector emcee https://api.weather.gov/openapi.json
# 🔍 MCP Inspector 正在 http://localhost:5173 运行 🚀
open http://localhost:5173
此项目在 MIT 许可证下提供。 更多信息请参见 LICENSE 文件。