nanobot MCP 集成

上级索引:00-概览与索引 | 上一篇:02-记忆系统-Dream | 下一篇:04-多Agent协作

📖 什么是 MCP

MCP(Model Context Protocol) 是 Anthropic 提出的开放标准协议,让 LLM 能够统一调用外部工具和数据源。类比 USB 接口——一旦设备支持 USB,任何 USB 外设都能接入。

nanobot 原生支持 MCP,通过配置即可接入社区生态中数以百计的 MCP Server。

⚙️ 配置 MCP Server

~/.nanobot/config.json 中添加:

{}json
{
  "tools": {
    "mcpServers": {
      "filesystem": {
        "command": "npx",
        "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
      },
      "github": {
        "command": "npx",
        "args": ["-y", "@modelcontextprotocol/server-github"],
        "env": {
          "GITHUB_PERSONAL_ACCESS_TOKEN": "your_token"
        }
      },
      "sqlite": {
        "command": "uvx",
        "args": ["mcp-server-sqlite", "--db-path", "/path/to/db.sqlite"]
      }
    }
  }
}

🔌 常用 MCP Server 速查

MCP Server安装包功能
filesystem@modelcontextprotocol/server-filesystem文件读写、目录浏览
github@modelcontextprotocol/server-githubGitHub 仓库操作
sqlitemcp-server-sqlite(uvx)SQLite 数据库查询
postgres@modelcontextprotocol/server-postgresPostgreSQL 查询
brave-search@modelcontextprotocol/server-brave-searchBrave 搜索 API
puppeteer@modelcontextprotocol/server-puppeteer浏览器自动化
memory@modelcontextprotocol/server-memory持久化知识图谱

完整列表:MCP Server 官方目录

✅ 验证 MCP 是否生效

启动后在 nanobot 中询问:

"请列出你当前可用的工具"

应能看到 MCP Server 提供的工具出现在列表中。

🔐 安全注意事项

MCP Server 以本地进程方式运行,拥有你赋予的文件/网络权限。只使用来源可信的 MCP Server,并限制文件系统访问路径。

  • filesystem Server 只授权必要目录,不要给 /~
  • 带 API Key 的 Server 使用 env 字段注入,不要硬编码在命令行参数中

📝 实践记录

{{待填:接入过的 MCP Server 和使用体验}}


🔗 延伸阅读