引言
MCP生态拥有丰富的官方认证工具集。这些工具由Anthropic和社区合作伙伴维护,经过严格测试,可以直接用于生产环境。本文将逐一介绍最常用的官方工具。
官方工具概览
工具清单
| 工具名 | 功能 | 语言 | 维护方 |
|---|
| Filesystem | 文件系统读写 | TypeScript | Anthropic |
| GitHub | GitHub API集成 | TypeScript | Anthropic |
| PostgreSQL | 数据库查询与管理 | Python | Anthropic |
| Puppeteer | 浏览器自动化 | TypeScript | Anthropic |
| Slack | Slack消息与频道管理 | TypeScript | Anthropic |
| Brave Search | 网页搜索 | Python | Anthropic |
| Memory | 持久化记忆管理 | TypeScript | Anthropic |
| Sqlite | SQLite数据库操作 | Python | Anthropic |
| Sentry | 错误监控查询 | Python | Sentry |
| Cloudflare | CDN和DNS管理 | TypeScript | Cloudflare |
| ElevenLabs | 文本转语音 | TypeScript | ElevenLabs |
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_repository | Fork仓库 |
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 |
| 代码仓库 | GitHub | GitLab (社区) |
| 数据库查询 | PostgreSQL | Sqlite (轻量) |
| 网页抓取 | Puppeteer | Playwright (社区) |
| 实时搜索 | Brave Search | 自定义搜索API |
| 持久化记忆 | Memory | 自定义向量数据库 |
| 错误监控 | Sentry | - |
| 内容管理 | Cloudflare | - |
安全级别
| 工具 | 访问范围 | 需要凭证 | 网络访问 |
|---|
| Filesystem | 本地文件系统 | 否 | 否 |
| GitHub | GitHub API | 是 (Token) | 是 |
| PostgreSQL | 数据库 | 是 (密码) | 是 |
| Puppeteer | Web页面 | 否 | 是 |
| Brave Search | Brave 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。