MCP Integration by anthropics/claude-code
npx skills add https://github.com/anthropics/claude-code --skill 'MCP Integration'模型上下文协议(MCP)通过提供结构化的工具访问,使 Claude Code 插件能够与外部服务和 API 集成。使用 MCP 集成可以将外部服务功能作为工具暴露在 Claude Code 内部。
主要功能:
插件可以通过两种方式捆绑 MCP 服务器:
在插件根目录创建 .mcp.json:
{
"database-tools": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/db-server",
"args": ["--config", "${CLAUDE_PLUGIN_ROOT}/config.json"],
"env": {
"DB_URL": "${DB_URL}"
}
}
}
优点:
在 plugin.json 中添加 mcpServers 字段:
{
"name": "my-plugin",
"version": "1.0.0",
"mcpServers": {
"plugin-api": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/api-server",
"args": ["--port", "8080"]
}
}
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
优点:
将本地 MCP 服务器作为子进程执行。最适合本地工具和自定义服务器。
配置:
{
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"],
"env": {
"LOG_LEVEL": "debug"
}
}
}
使用场景:
进程管理:
连接到支持 OAuth 的托管 MCP 服务器。最适合云服务。
配置:
{
"asana": {
"type": "sse",
"url": "https://mcp.asana.com/sse"
}
}
使用场景:
身份验证:
连接到使用令牌身份验证的 RESTful MCP 服务器。
配置:
{
"api-service": {
"type": "http",
"url": "https://api.example.com/mcp",
"headers": {
"Authorization": "Bearer ${API_TOKEN}",
"X-Custom-Header": "value"
}
}
}
使用场景:
连接到 WebSocket MCP 服务器以实现实时双向通信。
配置:
{
"realtime-service": {
"type": "ws",
"url": "wss://mcp.example.com/ws",
"headers": {
"Authorization": "Bearer ${TOKEN}"
}
}
}
使用场景:
所有 MCP 配置都支持环境变量替换:
${CLAUDE_PLUGIN_ROOT} - 插件目录(始终使用以确保可移植性):
{
"command": "${CLAUDE_PLUGIN_ROOT}/servers/my-server"
}
用户环境变量 - 来自用户的 shell:
{
"env": {
"API_KEY": "${MY_API_KEY}",
"DATABASE_URL": "${DB_URL}"
}
}
最佳实践: 在插件 README 中记录所有必需的环境变量。
当 MCP 服务器提供工具时,它们会自动添加前缀:
格式: mcp__plugin_<插件名称>_<服务器名称>__<工具名称>
示例:
asanaasanacreate_taskmcp__plugin_asana_asana__asana_create_task在命令 frontmatter 中预先允许特定的 MCP 工具:
---
allowed-tools: [
"mcp__plugin_asana_asana__asana_create_task",
"mcp__plugin_asana_asana__asana_search_tasks"
]
---
通配符(谨慎使用):
---
allowed-tools: ["mcp__plugin_asana_asana__*"]
---
最佳实践: 出于安全考虑,预先允许特定工具,而非使用通配符。
自动启动:
生命周期:
mcp__plugin_...__... 形式可用查看服务器: 使用 /mcp 命令查看所有服务器,包括插件提供的服务器。
OAuth 由 Claude Code 自动处理:
{
"type": "sse",
"url": "https://mcp.example.com/sse"
}
用户首次使用时在浏览器中进行身份验证。无需额外配置。
静态或环境变量令牌:
{
"type": "http",
"url": "https://api.example.com",
"headers": {
"Authorization": "Bearer ${API_TOKEN}"
}
}
在 README 中记录所需的环境变量。
将配置传递给 MCP 服务器:
{
"command": "python",
"args": ["-m", "my_mcp_server"],
"env": {
"DATABASE_URL": "${DB_URL}",
"API_KEY": "${API_KEY}",
"LOG_LEVEL": "info"
}
}
命令使用 MCP 工具与用户交互:
# Command: create-item.md
---
allowed-tools: ["mcp__plugin_name_server__create_item"]
---
Steps:
1. Gather item details from user
2. Use mcp__plugin_name_server__create_item
3. Confirm creation
适用于: 在调用 MCP 之前添加验证或预处理。
代理自主使用 MCP 工具:
# Agent: data-analyzer.md
Analysis Process:
1. Query data via mcp__plugin_db_server__query
2. Process and analyze results
3. Generate insights report
适用于: 无需用户交互的多步骤 MCP 工作流。
集成多个 MCP 服务器:
{
"github": {
"type": "sse",
"url": "https://mcp.github.com/sse"
},
"jira": {
"type": "sse",
"url": "https://mcp.jira.com/sse"
}
}
适用于: 跨多个服务的工作流。
始终使用安全连接:
✅ "url": "https://mcp.example.com/sse"
❌ "url": "http://mcp.example.com/sse"
应该:
不应该:
仅预先允许必要的 MCP 工具:
✅ allowed-tools: [
"mcp__plugin_api_server__read_data",
"mcp__plugin_api_server__create_item"
]
❌ allowed-tools: ["mcp__plugin_api_server__*"]
处理 MCP 服务器不可用的情况:
处理失败的 MCP 操作:
验证 MCP 配置:
MCP 服务器按需连接:
尽可能批处理类似请求:
# Good: Single query with filters
tasks = search_tasks(project="X", assignee="me", limit=50)
# Avoid: Many individual queries
for id in task_ids:
task = get_task(id)
.mcp.json 中配置 MCP 服务器.claude-plugin/)/mcp 以验证服务器出现claude --debug 日志以排查连接问题/mcp 输出中claude --debug
查找:
服务器未连接:
工具不可用:
/mcp 查看可用工具身份验证失败:
| 类型 | 传输方式 | 最适合 | 身份验证 |
|---|---|---|---|
| stdio | 进程 | 本地工具,自定义服务器 | 环境变量 |
| SSE | HTTP | 托管服务,云 API | OAuth |
| HTTP | REST | API 后端,令牌验证 | 令牌 |
| ws | WebSocket | 实时,流式传输 | 令牌 |
应该:
不应该:
有关详细信息,请查阅:
references/server-types.md - 每种服务器类型的深入探讨references/authentication.md - 身份验证模式和 OAuthreferences/tool-usage.md - 在命令和代理中使用 MCP 工具examples/ 中的工作示例:
stdio-server.json - 本地 stdio MCP 服务器sse-server.json - 支持 OAuth 的托管 SSE 服务器http-server.json - 使用令牌验证的 REST APIclaude --debug 和 /mcp 命令向插件添加 MCP 集成:
.mcp.json/mcp 命令进行本地测试对于自定义/本地服务器,重点关注 stdio;对于支持 OAuth 的托管服务,重点关注 SSE。
每周安装次数
0
代码仓库
GitHub 星标数
75.9K
首次出现
1970年1月1日
安全审计
Model Context Protocol (MCP) enables Claude Code plugins to integrate with external services and APIs by providing structured tool access. Use MCP integration to expose external service capabilities as tools within Claude Code.
Key capabilities:
Plugins can bundle MCP servers in two ways:
Create .mcp.json at plugin root:
{
"database-tools": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/db-server",
"args": ["--config", "${CLAUDE_PLUGIN_ROOT}/config.json"],
"env": {
"DB_URL": "${DB_URL}"
}
}
}
Benefits:
Add mcpServers field to plugin.json:
{
"name": "my-plugin",
"version": "1.0.0",
"mcpServers": {
"plugin-api": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/api-server",
"args": ["--port", "8080"]
}
}
}
Benefits:
Execute local MCP servers as child processes. Best for local tools and custom servers.
Configuration:
{
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"],
"env": {
"LOG_LEVEL": "debug"
}
}
}
Use cases:
Process management:
Connect to hosted MCP servers with OAuth support. Best for cloud services.
Configuration:
{
"asana": {
"type": "sse",
"url": "https://mcp.asana.com/sse"
}
}
Use cases:
Authentication:
Connect to RESTful MCP servers with token authentication.
Configuration:
{
"api-service": {
"type": "http",
"url": "https://api.example.com/mcp",
"headers": {
"Authorization": "Bearer ${API_TOKEN}",
"X-Custom-Header": "value"
}
}
}
Use cases:
Connect to WebSocket MCP servers for real-time bidirectional communication.
Configuration:
{
"realtime-service": {
"type": "ws",
"url": "wss://mcp.example.com/ws",
"headers": {
"Authorization": "Bearer ${TOKEN}"
}
}
}
Use cases:
All MCP configurations support environment variable substitution:
${CLAUDE_PLUGIN_ROOT} - Plugin directory (always use for portability):
{
"command": "${CLAUDE_PLUGIN_ROOT}/servers/my-server"
}
User environment variables - From user's shell:
{
"env": {
"API_KEY": "${MY_API_KEY}",
"DATABASE_URL": "${DB_URL}"
}
}
Best practice: Document all required environment variables in plugin README.
When MCP servers provide tools, they're automatically prefixed:
Format: mcp__plugin_<plugin-name>_<server-name>__<tool-name>
Example:
asanaasanacreate_taskmcp__plugin_asana_asana__asana_create_taskPre-allow specific MCP tools in command frontmatter:
---
allowed-tools: [
"mcp__plugin_asana_asana__asana_create_task",
"mcp__plugin_asana_asana__asana_search_tasks"
]
---
Wildcard (use sparingly):
---
allowed-tools: ["mcp__plugin_asana_asana__*"]
---
Best practice: Pre-allow specific tools, not wildcards, for security.
Automatic startup:
Lifecycle:
mcp__plugin_...__...Viewing servers: Use /mcp command to see all servers including plugin-provided ones.
OAuth handled automatically by Claude Code:
{
"type": "sse",
"url": "https://mcp.example.com/sse"
}
User authenticates in browser on first use. No additional configuration needed.
Static or environment variable tokens:
{
"type": "http",
"url": "https://api.example.com",
"headers": {
"Authorization": "Bearer ${API_TOKEN}"
}
}
Document required environment variables in README.
Pass configuration to MCP server:
{
"command": "python",
"args": ["-m", "my_mcp_server"],
"env": {
"DATABASE_URL": "${DB_URL}",
"API_KEY": "${API_KEY}",
"LOG_LEVEL": "info"
}
}
Commands use MCP tools with user interaction:
# Command: create-item.md
---
allowed-tools: ["mcp__plugin_name_server__create_item"]
---
Steps:
1. Gather item details from user
2. Use mcp__plugin_name_server__create_item
3. Confirm creation
Use for: Adding validation or preprocessing before MCP calls.
Agents use MCP tools autonomously:
# Agent: data-analyzer.md
Analysis Process:
1. Query data via mcp__plugin_db_server__query
2. Process and analyze results
3. Generate insights report
Use for: Multi-step MCP workflows without user interaction.
Integrate multiple MCP servers:
{
"github": {
"type": "sse",
"url": "https://mcp.github.com/sse"
},
"jira": {
"type": "sse",
"url": "https://mcp.jira.com/sse"
}
}
Use for: Workflows spanning multiple services.
Always use secure connections:
✅ "url": "https://mcp.example.com/sse"
❌ "url": "http://mcp.example.com/sse"
DO:
DON'T:
Pre-allow only necessary MCP tools:
✅ allowed-tools: [
"mcp__plugin_api_server__read_data",
"mcp__plugin_api_server__create_item"
]
❌ allowed-tools: ["mcp__plugin_api_server__*"]
Handle MCP server unavailability:
Handle failed MCP operations:
Validate MCP configuration:
MCP servers connect on-demand:
Batch similar requests when possible:
# Good: Single query with filters
tasks = search_tasks(project="X", assignee="me", limit=50)
# Avoid: Many individual queries
for id in task_ids:
task = get_task(id)
.mcp.json.claude-plugin/)/mcp to verify server appearsclaude --debug logs for connection issues/mcp outputclaude --debug
Look for:
Server not connecting:
Tools not available:
/mcp to see available toolsAuthentication failing:
| Type | Transport | Best For | Auth |
|---|---|---|---|
| stdio | Process | Local tools, custom servers | Env vars |
| SSE | HTTP | Hosted services, cloud APIs | OAuth |
| HTTP | REST | API backends, token auth | Tokens |
| ws | WebSocket | Real-time, streaming | Tokens |
DO:
DON'T:
For detailed information, consult:
references/server-types.md - Deep dive on each server typereferences/authentication.md - Authentication patterns and OAuthreferences/tool-usage.md - Using MCP tools in commands and agentsWorking examples in examples/:
stdio-server.json - Local stdio MCP serversse-server.json - Hosted SSE server with OAuthhttp-server.json - REST API with token authclaude --debug and /mcp commandTo add MCP integration to a plugin:
.mcp.json at plugin root with configuration/mcp commandFocus on stdio for custom/local servers, SSE for hosted services with OAuth.
Weekly Installs
0
Repository
GitHub Stars
75.9K
First Seen
Jan 1, 1970
Security Audits
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
138,300 周安装
OpenClaw技能安全审计指南:skill-vetter工具详解与安装前安全检查
12,200 周安装
Gemini Web API 客户端:文本与图像生成工具,支持多轮对话和逆向工程API
12,100 周安装
Google Workspace Drive API v3 命令行工具 - 管理云端硬盘文件与权限
12,200 周安装
知识漫画创作器 - AI漫画生成工具,支持多种画风和基调组合
12,600 周安装
URL转Markdown工具:Chrome CDP抓取网页并转换为干净Markdown
12,700 周安装
绕过反机器人检测,使用真实Chrome浏览器自动发布内容到X/Twitter
12,800 周安装