$npx -y skills add anthropics/claude-code --skill mcp-integrationThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context Protocol", "connect external service", mentions "${CLAUDE_PLUGIN_ROOT} with MCP", or discusses MCP server types (SSE, stdio, HTTP,
| 1 | # MCP Integration for Claude Code Plugins |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | **Key capabilities:** |
| 8 | - Connect to external services (databases, APIs, file systems) |
| 9 | - Provide 10+ related tools from a single service |
| 10 | - Handle OAuth and complex authentication flows |
| 11 | - Bundle MCP servers with plugins for automatic setup |
| 12 | |
| 13 | ## MCP Server Configuration Methods |
| 14 | |
| 15 | Plugins can bundle MCP servers in two ways: |
| 16 | |
| 17 | ### Method 1: Dedicated .mcp.json (Recommended) |
| 18 | |
| 19 | Create `.mcp.json` at plugin root: |
| 20 | |
| 21 | ```json |
| 22 | { |
| 23 | "database-tools": { |
| 24 | "command": "${CLAUDE_PLUGIN_ROOT}/servers/db-server", |
| 25 | "args": ["--config", "${CLAUDE_PLUGIN_ROOT}/config.json"], |
| 26 | "env": { |
| 27 | "DB_URL": "${DB_URL}" |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | ``` |
| 32 | |
| 33 | **Benefits:** |
| 34 | - Clear separation of concerns |
| 35 | - Easier to maintain |
| 36 | - Better for multiple servers |
| 37 | |
| 38 | ### Method 2: Inline in plugin.json |
| 39 | |
| 40 | Add `mcpServers` field to plugin.json: |
| 41 | |
| 42 | ```json |
| 43 | { |
| 44 | "name": "my-plugin", |
| 45 | "version": "1.0.0", |
| 46 | "mcpServers": { |
| 47 | "plugin-api": { |
| 48 | "command": "${CLAUDE_PLUGIN_ROOT}/servers/api-server", |
| 49 | "args": ["--port", "8080"] |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | ``` |
| 54 | |
| 55 | **Benefits:** |
| 56 | - Single configuration file |
| 57 | - Good for simple single-server plugins |
| 58 | |
| 59 | ## MCP Server Types |
| 60 | |
| 61 | ### stdio (Local Process) |
| 62 | |
| 63 | Execute local MCP servers as child processes. Best for local tools and custom servers. |
| 64 | |
| 65 | **Configuration:** |
| 66 | ```json |
| 67 | { |
| 68 | "filesystem": { |
| 69 | "command": "npx", |
| 70 | "args": ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"], |
| 71 | "env": { |
| 72 | "LOG_LEVEL": "debug" |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | ``` |
| 77 | |
| 78 | **Use cases:** |
| 79 | - File system access |
| 80 | - Local database connections |
| 81 | - Custom MCP servers |
| 82 | - NPM-packaged MCP servers |
| 83 | |
| 84 | **Process management:** |
| 85 | - Claude Code spawns and manages the process |
| 86 | - Communicates via stdin/stdout |
| 87 | - Terminates when Claude Code exits |
| 88 | |
| 89 | ### SSE (Server-Sent Events) |
| 90 | |
| 91 | Connect to hosted MCP servers with OAuth support. Best for cloud services. |
| 92 | |
| 93 | **Configuration:** |
| 94 | ```json |
| 95 | { |
| 96 | "asana": { |
| 97 | "type": "sse", |
| 98 | "url": "https://mcp.asana.com/sse" |
| 99 | } |
| 100 | } |
| 101 | ``` |
| 102 | |
| 103 | **Use cases:** |
| 104 | - Official hosted MCP servers (Asana, GitHub, etc.) |
| 105 | - Cloud services with MCP endpoints |
| 106 | - OAuth-based authentication |
| 107 | - No local installation needed |
| 108 | |
| 109 | **Authentication:** |
| 110 | - OAuth flows handled automatically |
| 111 | - User prompted on first use |
| 112 | - Tokens managed by Claude Code |
| 113 | |
| 114 | ### HTTP (REST API) |
| 115 | |
| 116 | Connect to RESTful MCP servers with token authentication. |
| 117 | |
| 118 | **Configuration:** |
| 119 | ```json |
| 120 | { |
| 121 | "api-service": { |
| 122 | "type": "http", |
| 123 | "url": "https://api.example.com/mcp", |
| 124 | "headers": { |
| 125 | "Authorization": "Bearer ${API_TOKEN}", |
| 126 | "X-Custom-Header": "value" |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | ``` |
| 131 | |
| 132 | **Use cases:** |
| 133 | - REST API-based MCP servers |
| 134 | - Token-based authentication |
| 135 | - Custom API backends |
| 136 | - Stateless interactions |
| 137 | |
| 138 | ### WebSocket (Real-time) |
| 139 | |
| 140 | Connect to WebSocket MCP servers for real-time bidirectional communication. |
| 141 | |
| 142 | **Configuration:** |
| 143 | ```json |
| 144 | { |
| 145 | "realtime-service": { |
| 146 | "type": "ws", |
| 147 | "url": "wss://mcp.example.com/ws", |
| 148 | "headers": { |
| 149 | "Authorization": "Bearer ${TOKEN}" |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | ``` |
| 154 | |
| 155 | **Use cases:** |
| 156 | - Real-time data streaming |
| 157 | - Persistent connections |
| 158 | - Push notifications from server |
| 159 | - Low-latency requirements |
| 160 | |
| 161 | ## Environment Variable Expansion |
| 162 | |
| 163 | All MCP configurations support environment variable substitution: |
| 164 | |
| 165 | **${CLAUDE_PLUGIN_ROOT}** - Plugin directory (always use for portability): |
| 166 | ```json |
| 167 | { |
| 168 | "command": "${CLAUDE_PLUGIN_ROOT}/servers/my-server" |
| 169 | } |
| 170 | ``` |
| 171 | |
| 172 | **User environment variables** - From user's shell: |
| 173 | ```json |
| 174 | { |
| 175 | "env": { |
| 176 | "API_KEY": "${MY_API_KEY}", |
| 177 | "DATABASE_URL": "${DB_URL}" |
| 178 | } |
| 179 | } |
| 180 | ``` |
| 181 | |
| 182 | **Best practice:** Document all required environment variables in plugin README. |
| 183 | |
| 184 | ## MCP Tool Naming |
| 185 | |
| 186 | When MCP servers provide tools, they're automatically prefixed: |
| 187 | |
| 188 | **Format:** `mcp__plugin_<plugin-name>_<server-name>__<tool-name>` |
| 189 | |
| 190 | **Example:** |
| 191 | - Plugin: `asana` |
| 192 | - Server: `asana` |
| 193 | - Tool: `create_task` |
| 194 | - **Full name:** `mcp__plugin_asana_asana__asana_create_task` |
| 195 | |
| 196 | ### Using MCP Tools in Commands |
| 197 | |
| 198 | Pre-allow specific MCP tools in command frontmatter: |
| 199 | |
| 200 | ```markdown |
| 201 | --- |
| 202 | allowed-tools: [ |
| 203 | "mcp__plugin_asana_asana__asana_create_task", |
| 204 | "mcp__plugin_asana_asana__asana_search_tasks" |
| 205 | ] |
| 206 | --- |
| 207 | ``` |
| 208 | |
| 209 | **Wildcard (use sparingly):** |
| 210 | ```markdown |
| 211 | --- |
| 212 | allowed-tools: ["mcp__plugin_asana_asana__*"] |
| 213 | --- |
| 214 | ``` |
| 215 | |
| 216 | **Best practice:** Pre-allow specific tools, not wildcards, for security. |
| 217 | |
| 218 | ## Lifecycle Management |
| 219 | |
| 220 | **Automatic |