MCP协议 进阶 MCP 官方工具 Filesystem GitHub

MCP官方工具集:Anthropic认证工具详解与实战

AIEng Hub
阅读约 20 分钟

引言

MCP生态拥有丰富的官方认证工具集。这些工具由Anthropic和社区合作伙伴维护,经过严格测试,可以直接用于生产环境。本文将逐一介绍最常用的官方工具。

官方工具概览

工具清单

工具名功能语言维护方
Filesystem文件系统读写TypeScriptAnthropic
GitHubGitHub API集成TypeScriptAnthropic
PostgreSQL数据库查询与管理PythonAnthropic
Puppeteer浏览器自动化TypeScriptAnthropic
SlackSlack消息与频道管理TypeScriptAnthropic
Brave Search网页搜索PythonAnthropic
Memory持久化记忆管理TypeScriptAnthropic
SqliteSQLite数据库操作PythonAnthropic
Sentry错误监控查询PythonSentry
CloudflareCDN和DNS管理TypeScriptCloudflare
ElevenLabs文本转语音TypeScriptElevenLabs

Filesystem工具

功能介绍

Filesystem工具为AI模型提供安全的文件系统访问能力。

安装与配置

# 直接使用npx运行
npx -y @modelcontextprotocol/server-filesystem \
  /path/to/allowed/dir1 \
  /path/to/allowed/dir2

Claude Desktop配置

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/home/user/projects",
        "/home/user/documents"
      ]
    }
  }
}

可用工具

工具名功能
read_file读取文件内容
write_file写入文件内容
edit_file编辑文件(精确替换)
create_directory创建目录
list_directory列出目录内容
move_file移动/重命名文件
search_files搜索文件
get_file_info获取文件信息

使用示例

// 调用Filesystem工具
// 读取文件
{
  "name": "read_file",
  "arguments": {
    "path": "/home/user/projects/README.md"
  }
}

// 搜索文件
{
  "name": "search_files",
  "arguments": {
    "pattern": "*.ts",
    "path": "/home/user/projects/src"
  }
}

GitHub工具

功能介绍

GitHub工具让AI模型可以直接操作GitHub仓库,包括代码管理、Issue处理和PR管理。

安装

npx -y @modelcontextprotocol/server-github

# 需要设置GitHub Token
export GITHUB_TOKEN=ghp_your_token_here

配置

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}"
      }
    }
  }
}

可用工具

工具名功能
create_or_update_file创建/更新文件
push_files推送文件到仓库
search_repositories搜索仓库
create_repository创建仓库
get_issue获取Issue详情
create_issue创建Issue
update_issue更新Issue
search_issues搜索Issues
list_pull_requests列出PR
get_pull_request获取PR详情
fork_repositoryFork仓库
create_branch创建分支
list_branches列出分支

PostgreSQL工具

功能介绍

PostgreSQL工具提供安全的数据库查询和管理能力。

安装

pip install mcp-server-postgres

配置

{
  "mcpServers": {
    "postgresql": {
      "command": "python",
      "args": ["-m", "mcp_server_postgres"],
      "env": {
        "DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"
      }
    }
  }
}

可用工具

工具名功能
query执行SQL查询(只读)
execute执行SQL语句(读写)
get_schema获取数据库Schema
list_tables列出所有表

使用示例

-- 通过MCP工具执行的SQL
SELECT table_name, table_schema
FROM information_schema.tables
WHERE table_schema NOT IN ('pg_catalog', 'information_schema');

Puppeteer工具

功能介绍

Puppeteer工具让AI模型可以控制无头浏览器,进行网页抓取、截图和自动化操作。

安装

npx -y @modelcontextprotocol/server-puppeteer

配置

{
  "mcpServers": {
    "puppeteer": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-puppeteer"]
    }
  }
}

可用工具

工具名功能
puppeteer_navigate导航到URL
puppeteer_screenshot页面截图
puppeteer_click点击元素
puppeteer_fill填写表单
puppeteer_select选择下拉选项
puppeteer_hover悬停元素
puppeteer_evaluate执行JavaScript

Brave Search工具

功能介绍

提供基于Brave搜索引擎的实时网络搜索能力。

安装

pip install mcp-server-brave-search

# 需要设置Brave API Key
export BRAVE_API_KEY=your_api_key

配置

{
  "mcpServers": {
    "brave-search": {
      "command": "python",
      "args": ["-m", "mcp_server_brave_search"],
      "env": {
        "BRAVE_API_KEY": "${BRAVE_API_KEY}"
      }
    }
  }
}

可用工具

工具名功能
brave_web_search网页搜索
brave_local_search本地搜索结果

Memory工具

功能介绍

Memory工具为AI应用提供持久化记忆管理能力,基于SQLite保存结构化信息。

安装

npx -y @modelcontextprotocol/server-memory

配置

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-memory"
      ],
      "env": {
        "MEMORY_FILE_PATH": "/path/to/memory.json"
      }
    }
  }
}

可用工具

工具名功能
add_memory添加记忆条目
search_memories搜索记忆
update_memory更新记忆
delete_memory删除记忆

工具对比与选择

按使用场景选择

场景推荐工具替代方案
文件操作Filesystem自定义Server
代码仓库GitHubGitLab (社区)
数据库查询PostgreSQLSqlite (轻量)
网页抓取PuppeteerPlaywright (社区)
实时搜索Brave Search自定义搜索API
持久化记忆Memory自定义向量数据库
错误监控Sentry-
内容管理Cloudflare-

安全级别

工具访问范围需要凭证网络访问
Filesystem本地文件系统
GitHubGitHub API是 (Token)
PostgreSQL数据库是 (密码)
PuppeteerWeb页面
Brave SearchBrave API是 (API Key)
Memory本地文件

多工具组合实战

完整工作流示例

# 使用MCP工具完成一个完整的工作流
async def code_review_workflow():
    """PR代码审查工作流"""
    # 1. GitHub:获取PR变更
    pr_changes = await github.call_tool(
        "get_pull_request",
        {"owner": "my-org", "repo": "my-repo", "pull_number": 42}
    )

    # 2. Filesystem:保存到本地
    await fs.call_tool(
        "write_file",
        {"path": "/tmp/pr-review/changes.diff", "content": pr_changes}
    )

    # 3. 进行审查...

    # 4. GitHub:在PR上评论
    await github.call_tool(
        "create_issue_comment",
        {
            "owner": "my-org",
            "repo": "my-repo",
            "issue_number": 42,
            "body": review_comments
        }
    )

    # 5. Memory:保存审查记录
    await memory.call_tool(
        "add_memory",
        {
            "content": f"Reviewed PR #42 on {datetime.now()}",
            "metadata": {"type": "code_review"}
        }
    )

最佳实践

实践说明
版本固定使用具体版本号而非latest
凭证安全使用环境变量,不硬编码
权限最小化限定Filesystem的可访问目录
只读优先数据库查询使用只读用户
限流配置对API工具设置调用频率限制

总结

MCP官方工具集为AI应用提供了开箱即用的能力:

工具核心能力适合场景
Filesystem文件系统操作代码编辑、文档处理
GitHub代码仓库管理DevOps、代码审查
PostgreSQL数据库查询数据分析、报表
Puppeteer浏览器自动化网页抓取、测试
Brave Search实时搜索信息检索、调研
Memory持久化记忆个性化体验、上下文

下一步学习建议:


本文最后更新于 2024-07-20。