McPorter 实战:一键管理 OpenClaw 的 MCP 服务器

McPorter 实战:一键管理 OpenClaw 的 MCP 服务器

McPorter 实战:一键管理 OpenClaw 的 MCP 服务器

🚀 MCP 服务器配好了一堆,却只能在 Agent 聊天里用?McPorter 让你在终端里直接列出、调用、调试任何 MCP 服务器——还能生成 TypeScript 客户端代码

📑 文章目录

  1. 痛点:MCP 服务器配好了,然后呢?
  2. McPorter 是什么:MCP 的统一 CLI 运行时
  3. McPorter vs 手动配置 vs OpenClaw Skills:三者关系
  4. 安装 McPorter
  5. 核心命令速查:list、call、config、auth
  6. 实战一:列出所有可用的 MCP 服务器和工具
  7. 实战二:从终端直接调用 MCP 工具
  8. 实战三:添加和管理 MCP 服务器配置
  9. 实战四:OAuth 认证与远程 MCP 服务器
  10. 进阶:生成 TypeScript 客户端和独立 CLI
  11. McPorter + OpenClaw:联合使用最佳实践

1. 痛点:MCP 服务器配好了,然后呢?

如果你跟着我之前的文章在 OpenClaw 里配好了几个 MCP 服务器,你可能会碰到这些问题:

配好 MCP 服务器后的常见困扰: 1. 服务器到底有哪些工具? ← 翻文档 or 猜 2. 工具的参数格式是什么? ← 每个 Server 都不一样 3. 想快速测试一个工具调用? ← 只能通过 Agent 聊天触发 4. OAuth 认证过期了怎么办? ← 手动重新走流程 5. 在 CI/CD 里想调 MCP 工具? ← 没有好办法 6. 已经在 Cursor/Claude 配了 MCP,不想重复配置 ← 配置散落各处 7. 想给别人共享一个 MCP 工具的 CLI? ← 没法脱离 Agent 使用 

McPorter 就是为了解决这些问题而生的。


2. McPorter 是什么:MCP 的统一 CLI 运行时

一句话定义

McPorter 是一个 MCP 服务器的 CLI 运行时和 TypeScript SDK,让你可以在终端或代码中直接列出、调用、认证和管理 MCP 服务器——无需通过 AI Agent 中转。

注意:McPorter ≠ 包管理器

很多人第一反应是"McPorter 是 MCP 的 apt-get"——这是错的。McPorter 不负责安装 MCP 服务器包,也不是注册表/商店。它的核心能力是:

能力说明类比
🔍 发现自动检测你已配置的所有 MCP 服务器类似 docker ps
📞 调用从终端直接调用任意 MCP 工具类似 curl
🔑 认证管理 OAuth 流程和 token 缓存类似 aws configure
⚙️ 配置统一管理多来源的 MCP 配置类似 git config
🏭 生成为 MCP 工具生成独立 CLI 或 TypeScript 类型类似 protoc

零配置自动发现

McPorter 最强大的特性之一是零配置发现——它会自动合并以下来源的 MCP 服务器配置:

McPorter 配置合并优先级(高 → 低): 1. 命令行 ad-hoc 参数(--http-url / --stdio) 2. 项目级配置:./config/mcporter.json 3. 用户级配置:~/.mcporter/mcporter.json 4. 自动导入: ├── Cursor: ~/.cursor/mcp.json ├── Claude: ~/.claude.json / .mcp.json ├── Codex: codex 配置文件 ├── Windsurf: windsurf 配置文件 ├── VS Code: vscode 配置文件 └── OpenCode: opencode 配置文件 
💡 这意味着如果你已经在 Cursor 或 Claude Desktop 里配过 MCP 服务器,McPorter 直接就能用——不需要重新配置!

3. McPorter vs 手动配置 vs OpenClaw Skills:三者关系

三者对比

维度手动编辑 openclaw.jsonOpenClaw Skills (ClawHub)McPorter
是什么直接编辑 JSON5 配置Agent 行为增强包MCP CLI 运行时
管理对象MCP Server 配置Skills(可内嵌 MCP)MCP Server 调用与配置
安装 MCP 包✅ 手动配置✅ Skill 内声明自动配置❌ 不负责安装
直接调用工具❌ 只能通过 Agent❌ 只能通过 Agentmcporter call
跨应用发现❌ 仅 OpenClaw❌ 仅 OpenClaw✅ Cursor/Claude/Codex 等
OAuth 管理❌ 手动部分支持mcporter auth
TypeScript API✅ 完整 SDK
CLI 生成mcporter generate-cli

它们的关系

┌─────────────────────────────────────────────────┐ │ 你的工作环境 │ │ │ │ OpenClaw Agent │ │ ├── Skills (来自 ClawHub) │ │ ├── MCP Servers (openclaw.json 配置) │ │ └── 内置工具 │ │ │ │ Cursor / Claude Desktop / VS Code │ │ └── MCP Servers (各自的 mcp.json 配置) │ │ │ │ McPorter ← 统一层 │ │ ├── 自动发现上述所有 MCP 配置 │ │ ├── 提供 CLI 直接调用任何工具 │ │ ├── 管理 OAuth 认证 │ │ └── 生成 TypeScript 客户端 / 独立 CLI │ └─────────────────────────────────────────────────┘ 
💡 简单记法:OpenClaw/Cursor/Claude 各自管自己的 MCP 配置,McPorter 是横跨它们之上的统一调用层。你不用它也能用 MCP,但有了它,调试和开发效率大幅提升。

4. 安装 McPorter

4.1 通过 npm 安装(推荐)

# 全局安装npminstall-g mcporter # 验证安装 mcporter --version# mcporter 0.7.3

4.2 通过 Homebrew 安装(macOS)

brew install pdxfinder/tap/mcporter 

4.3 免安装使用(npx)

# 不安装,直接用 npx mcporter list 

5. 核心命令速查:list、call、config、auth

5.1 🔍 list — 列出服务器和工具

# 列出所有已配置的 MCP 服务器 npx mcporter list # 输出示例:# brave-search - Brave Search MCP (2 tools, 0.3s) [source: ~/.cursor/mcp.json]# postgres - PostgreSQL MCP (3 tools, 0.5s) [source: ./config/mcporter.json]# filesystem - Filesystem MCP (5 tools, 0.2s) [source: ~/.claude.json]# ✔ Listed 3 servers (3 healthy)# 查看某个 Server 的工具签名(TypeScript 风格) npx mcporter list brave-search # brave-search - Brave Search MCP; web and local search# 2 tools · 312ms · stdio## /**# * Search the web using Brave Search# * @param query The search query string# * @param count Number of results to return# */# function brave_web_search(query: string, count?: number);## /**# * Search for local businesses and places# * @param query Local search query# */# function brave_local_search(query: string);# 显示完整 JSON Schema npx mcporter list brave-search --schema

5.2 📞 call — 直接调用 MCP 工具

# 基本调用语法:mcporter call <server.tool> key=value npx mcporter call brave-search.brave_web_search query="OpenClaw MCP best practices"# 函数风格调用 npx mcporter call "brave-search.brave_web_search(query: \"OpenClaw 2026\")"# JSON 参数方式 npx mcporter call brave-search.brave_web_search --args'{"query": "MCP tutorial", "count": 5}'# 调用本地 stdio 服务器(无需预先配置) npx mcporter call --stdio"npx -y @modelcontextprotocol/server-filesystem /tmp" list_directory path=/tmp # 调用远程 HTTP MCP 服务器 npx mcporter call https://mcp.example.com/mcp fetch url=https://example.com # 查看响应的原始日志 npx mcporter call postgres.pg_query query="SELECT 1" --tail-log 

5.3 ⚙️ config — 管理配置

# 列出当前配置中的所有服务器 npx mcporter config list # 添加一个新的 MCP 服务器配置 npx mcporter config add brave-search --stdio"npx -y @modelcontextprotocol/server-brave-search"\--envBRAVE_API_KEY=BSAxxxxxxxxx # 从 Cursor 导入配置 npx mcporter config import cursor # 从 Claude Desktop 导入 npx mcporter config import claude-code # 删除一个配置 npx mcporter config remove brave-search # 查看某个服务器的配置来源 npx mcporter config get brave-search 

配置文件格式(config/mcporter.json):

// config/mcporter.json — 支持 JSONC(注释 + 尾逗号) { "brave-search": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "BRAVE_API_KEY": "${BRAVE_API_KEY}" // 支持 ${ENV} 占位符 } }, "postgres": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres"], "env": { "POSTGRES_CONNECTION_STRING": "${POSTGRES_CONNECTION_STRING}" } }, "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/workspace"] } } 

5.4 🔑 auth — OAuth 认证

# 对需要 OAuth 的服务器进行认证(如 Linear、Vercel) npx mcporter auth linear # → 自动打开浏览器完成 OAuth 流程# → Token 缓存到 ~/.mcporter/<server>/# 重置认证 npx mcporter auth linear --reset# 对远程 HTTP 服务器认证 npx mcporter auth https://mcp.linear.app/mcp 

5.5 🤖 daemon — 后台服务

# 启动后台 daemon(持续运行 MCP 服务器进程) npx mcporter daemon start # 查看 daemon 状态 npx mcporter daemon status # 重启 / 停止 npx mcporter daemon restart npx mcporter daemon stop 

6. 实战一:列出所有可用的 MCP 服务器和工具

假设你已经在 Cursor 里配了几个 MCP 服务器,又在 OpenClaw 的 openclaw.json 里配了几个。McPorter 能一次性发现它们全部:

npx mcporter list # 输出:# brave-search - Brave Search (2 tools, 312ms) [source: ~/.cursor/mcp.json]# linear - Hosted Linear MCP (23 tools, 1654ms) [source: ~/.cursor/mcp.json]# filesystem - Filesystem MCP (5 tools, 89ms) [source: ./config/mcporter.json]# vercel - Vercel MCP (requires OAuth) [source: ~/.cursor/mcp.json]# ✔ Listed 4 servers (3 healthy, 1 requires auth)

看到 vercel 需要 OAuth?一条命令搞定:

npx mcporter auth vercel # → 浏览器打开,完成 Vercel OAuth# ✅ Token cached to ~/.mcporter/vercel/

再次 list:

npx mcporter list vercel # vercel - Vercel MCP (requires OAuth)# 15 tools · 890ms · HTTP https://mcp.vercel.com/mcp## function search_documentation(topic: string);# function list_projects(limit?: number);# ...

7. 实战二:从终端直接调用 MCP 工具

这是 McPorter 最实用的场景——不需要打开 Agent 聊天,直接在终端测试和调用 MCP 工具

npx mcporter call brave-search.brave_web_search query="McPorter MCP CLI"# 返回搜索结果的 JSON# 拼手动 typo?McPorter 会自动纠正 npx mcporter call brave-search.brave_web_serch query="test"# ⚠ Did you mean brave_web_search? (edit distance: 1)# → 自动重试正确的工具名

7.2 调用 PostgreSQL

npx mcporter call postgres.query query="SELECT count(*) FROM users"

7.3 调用 Ad-hoc 服务器(无需预先配置)

# 直接指定一个 stdio 命令 npx mcporter call --stdio"npx -y @modelcontextprotocol/server-filesystem /tmp"\ list_directory path=/tmp # 直接指定一个 HTTP URL npx mcporter call https://mcp.context7.com/mcp resolve-library-id query=react 

7.4 在脚本和 CI/CD 中使用

# JSON 输出,方便管道处理 npx mcporter call brave-search.brave_web_search query="test"--output json | jq '.content[0].text'

8. 实战三:添加和管理 MCP 服务器配置

# 1. 添加到 mcporter 配置(不是 openclaw.json) npx mcporter config add brave-search \--stdio"npx -y @modelcontextprotocol/server-brave-search"\--envBRAVE_API_KEY=BSAxxxxxxxxxxxxxxxxxx # 2. 验证 npx mcporter list brave-search 

8.2 添加 PostgreSQL

npx mcporter config add postgres \--stdio"npx -y @modelcontextprotocol/server-postgres"\--envPOSTGRES_CONNECTION_STRING="postgresql://readonly:xxx@localhost:5432/mydb" npx mcporter call postgres.list_tables 

8.3 添加 Filesystem

npx mcporter config add filesystem \--stdio"npx -y @modelcontextprotocol/server-filesystem /home/user/workspace"
🚨 目录限制是安全底线。Filesystem MCP 只能访问你在 args 中指定的目录。绝对不要把 /~ 整个给它

8.4 从现有工具导入配置

# 如果你已经在 Cursor 里配好了 MCP 服务器 npx mcporter config import cursor # ✔ Imported 5 servers from ~/.cursor/mcp.json# 从 Claude Desktop 导入 npx mcporter config import claude-code 

9. 实战四:OAuth 认证与远程 MCP 服务器

越来越多的 MCP 服务器使用 Streamable HTTP + OAuth 模式,不再要求本地安装 npm 包。McPorter 对此有一流支持:

# 认证 Linear(托管 MCP 服务器) npx mcporter auth https://mcp.linear.app/mcp # → 自动检测需要 OAuth# → 在 127.0.0.1 启动临时回调服务器# → 打开浏览器完成授权# → Token 持久化到 ~/.mcporter/linear/# 然后就可以直接调用 npx mcporter call linear.searchIssues team=ENG status=InProgress # Token 过期?重新认证 npx mcporter auth linear --reset

10. 进阶:生成 TypeScript 客户端和独立 CLI

10.1 生成独立 CLI

想把某个 MCP 服务器包装成一个独立的命令行工具?

# 为 Context7 生成独立 CLI npx mcporter generate-cli \--server'{"name":"context7","command":"https://mcp.context7.com/mcp"}'\--output dist/context7.ts \--runtime bun \--compile# 生成的 CLI 可以直接运行chmod +x dist/context7 ./dist/context7 resolve-library-id react # 只包含部分工具 npx mcporter generate-cli --server linear --include-tools searchIssues,createIssue # 试运行(看看会生成什么,但不实际执行) npx mcporter generate-cli --from linear --dry-run 

10.2 生成 TypeScript 类型定义

# 生成 .d.ts 类型文件 npx mcporter emit-ts linear --mode types --out linear.d.ts # 生成可用的客户端代码 npx mcporter emit-ts linear --mode client --out linear-client.ts 

10.3 在 TypeScript 代码中使用

import{ createRuntime, createServerProxy }from"mcporter";const runtime =awaitcreateRuntime({ servers:[{ name:"brave-search", command:{ kind:"stdio", command:"npx", args:["-y","@modelcontextprotocol/server-brave-search"], env:{BRAVE_API_KEY: process.env.BRAVE_API_KEY!}}}]});// 工具调用变成 TypeScript 方法const proxy =createServerProxy(runtime,"brave-search");const result =await proxy.braveWebSearch({ query:"McPorter tutorial"});console.log(result.text());

11. McPorter + OpenClaw:联合使用最佳实践

OpenClaw 配置 MCP 的方式

OpenClaw 使用自己的 ~/.openclaw/openclaw.json(JSON5 格式)来配置 MCP 服务器,写法如下:

// ~/.openclaw/openclaw.json { // OpenClaw 自动监控此文件并热加载,大部分改动不需要重启 Gateway "mcpServers": { "brave-search": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "BRAVE_API_KEY": "${BRAVE_API_KEY}" } }, "postgres": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres"], "env": { "POSTGRES_CONNECTION_STRING": "${POSTGRES_CONNECTION_STRING}" } }, "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/workspace"] } } } 

McPorter 在 OpenClaw 工作流中的角色

┌──────────────────────────────────────────────────────────┐ │ 你的日常工作流 │ │ │ │ 📱 通过聊天使用 MCP 工具 → OpenClaw Agent │ │ "帮我查一下数据库里有多少用户" │ │ Agent 自动调用 postgres MCP 的 query 工具 │ │ │ │ 💻 从终端调试/测试 MCP 工具 → McPorter │ │ npx mcporter call postgres.query query="SELECT 1" │ │ 快速验证工具是否正常,无需等 Agent │ │ │ │ 🔧 开发自动化脚本 → McPorter TypeScript SDK │ │ import { callOnce } from "mcporter"; │ │ 在 CI/CD 或脚本中直接调用 MCP 工具 │ │ │ │ 🔑 管理 OAuth 认证 → mcporter auth │ │ npx mcporter auth linear │ │ 统一处理所有 MCP 服务器的 OAuth 流程 │ └──────────────────────────────────────────────────────────┘ 

实用组合技

# 1. 先用 McPorter 在终端快速测试一个新的 MCP 服务器 npx mcporter call --stdio"npx -y @modelcontextprotocol/server-brave-search"\ brave_web_search query="test"# ✅ 确认工作正常# 2. 满意后,手动添加到 OpenClaw 配置# 编辑 ~/.openclaw/openclaw.json,添加 mcpServers 配置# OpenClaw Gateway 会自动热加载# 3. 同时添加到 McPorter 配置(方便以后终端调试) npx mcporter config add brave-search \--stdio"npx -y @modelcontextprotocol/server-brave-search"\--envBRAVE_API_KEY=$BRAVE_API_KEY

McPorter 常用命令速查卡

# === 发现 === mcporter list # 列出所有已配置的 MCP 服务器 mcporter list <server># 查看某个服务器的工具签名 mcporter list <server>--schema# 显示完整 JSON Schema mcporter list <server> --all-parameters # 显示所有参数(含可选)# === 调用 === mcporter call <server.tool>key=value # 调用工具(键值对语法) mcporter call "<server.tool>(k: v)"# 调用工具(函数语法) mcporter call <server.tool>--args'{}'# 调用工具(JSON 参数) mcporter call --stdio"<command>"<tool>key=value # Ad-hoc stdio mcporter call <url.tool>key=value # Ad-hoc HTTP mcporter call <server.tool>--output json # JSON 格式输出 mcporter call <server.tool> --tail-log # 显示调用日志# === 配置 === mcporter config list # 列出配置 mcporter config get <server># 查看某个服务器配置 mcporter config add<name>--stdio"cmd"--envK=V # 添加 mcporter config remove <name># 删除 mcporter config import cursor # 从 Cursor 导入 mcporter config import claude-code # 从 Claude 导入# === 认证 === mcporter auth <server># OAuth 认证 mcporter auth <url># 对远程 URL 认证 mcporter auth <server>--reset# 重置认证# === Daemon === mcporter daemon start # 启动后台服务 mcporter daemon status # 查看状态 mcporter daemon stop # 停止 mcporter daemon restart # 重启# === 代码生成 === mcporter generate-cli --server<name># 生成独立 CLI mcporter generate-cli --command<url># 从 URL 生成 mcporter emit-ts <server>--mode types # 生成 TypeScript 类型 mcporter emit-ts <server>--mode client # 生成 TypeScript 客户端 mcporter inspect-cli <path># 检查已生成的 CLI

📚 参考资料

如果觉得有帮助,欢迎 点赞 👍 收藏 ⭐ 关注 🔔,有问题评论区见!

本文为原创内容,转载请注明出处。

Read more

llama-cpp-python架构深度解析:从底层C API到高级Python接口的技术演进

llama-cpp-python架构深度解析:从底层C API到高级Python接口的技术演进 【免费下载链接】llama-cpp-pythonPython bindings for llama.cpp 项目地址: https://gitcode.com/gh_mirrors/ll/llama-cpp-python 在现代AI应用开发中,本地大语言模型的部署与优化已成为技术团队面临的核心挑战。llama-cpp-python作为连接C++高性能推理引擎与Python生态的关键桥梁,其技术架构设计体现了对性能、易用性和扩展性的深度思考。 底层架构:C API的直接映射与优化 llama-cpp-python的核心价值在于其对llama.cpp C API的完整封装。通过ctypes接口,开发者可以直接访问底层C函数,同时享受Python语言的开发效率。这种设计模式既保留了原生C++的性能优势,又提供了Python生态的丰富资源。 该项目的技术栈建立在三个关键层次上: 原生C层:通过vendor/llama.cpp子模块直接集成最新的推理引擎,确保始终使用最优化的底层实现

By Ne0inhk

Python-okx库终极指南:加密货币量化交易API完整教程

Python-okx库终极指南:加密货币量化交易API完整教程 【免费下载链接】python-okx 项目地址: https://gitcode.com/GitHub_Trending/py/python-okx 你是否在为加密货币交易API的复杂集成而烦恼?是否需要一个既能处理现货交易又能管理衍生品合约的Python工具?python-okx库作为OKX交易所v5 API的Python封装,为量化交易新手和开发者提供了完整的解决方案,让你的交易策略开发效率提升3倍。 为什么你的交易策略需要python-okx库? 在加密货币交易中,API集成往往是最大的技术障碍。传统方案需要手动处理签名验证、错误重试、连接管理等繁琐细节,而python-okx库将这些复杂性全部封装,让你专注于策略逻辑。 痛点问题python-okx解决方案效率提升API签名复杂易错自动处理所有签名逻辑减少80%编码时间连接不稳定内置WebSocket重连机制99.9%连接成功率多账户管理困难统一子账户管理接口一键批量操作实时数据处理复杂异步WebSocket推送毫秒级响应 3步快速上手:从零

By Ne0inhk
python中的数据结构与算法(上)

python中的数据结构与算法(上)

相关概述 数据结构:存储和组织数据的方式方法 算法:解决问题的思路\方式 数据结构与算法的关系:算法是解决实际业务问题的思路,数据结构是算法的载体,高效的程序需要在数据结构的基础上设计和选择算法 终极意义:大大提高程序的性能和执行效率 程序 = 数据结构 + 算法 人工智能 = 算法 + 算力 + 数据  数据结构 数据结构是存储和组织数据的方式方法,合适的数据结构往往能带来比较大的性能提升 数据结构的分类:         线性结构(一个前驱父节点,一个后继子节点 --例如:栈\队列 )         线性结构的分类:                 顺序表:存储空间是连续的,存储方式分为一体式存储和分离式存储                         一体式存储:数据区和信息区在一起  arr = [1,2,3]                         分离式存储:数据区和信息区分开存储 arr = ['a',1,False,'asdf'

By Ne0inhk
【Python】第一弹---解锁编程新世界:深入理解计算机基础与Python入门指南

【Python】第一弹---解锁编程新世界:深入理解计算机基础与Python入门指南

✨个人主页: 熬夜学编程的小林 💗系列专栏: 【C语言详解】 【数据结构详解】【C++详解】【Linux系统编程】【MySQL】【Python】 目录 1、计算机基础概念 1.1、什么是计算机 1.2、什么是编程 1.3、编程语言有哪些 2、Python 背景知识 2.1、Python 是咋来的 2.2、Python 都能干啥 2.3、Python 的优缺点  2.4、Python 的前景(钱景)咋样 3、搭建 Python 环境  3.1、安装

By Ne0inhk