Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Guidance for integrating MCP (Model Context Protocol) servers into Claude Code plugins.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/server-types.md
1# MCP Server Types: Deep Dive23Complete reference for all MCP server types supported in Claude Code plugins.45## stdio (Standard Input/Output)67### Overview89Execute local MCP servers as child processes with communication via stdin/stdout. Best choice for local tools, custom servers, and NPM packages.1011### Configuration1213**Basic:**14```json15{16"my-server": {17"command": "npx",18"args": ["-y", "my-mcp-server"]19}20}21```2223**With environment:**24```json25{26"my-server": {27"command": "${CLAUDE_PLUGIN_ROOT}/servers/custom-server",28"args": ["--config", "${CLAUDE_PLUGIN_ROOT}/config.json"],29"env": {30"API_KEY": "${MY_API_KEY}",31"LOG_LEVEL": "debug",32"DATABASE_URL": "${DB_URL}"33}34}35}36```3738### Process Lifecycle39401. **Startup**: Claude Code spawns process with `command` and `args`412. **Communication**: JSON-RPC messages via stdin/stdout423. **Lifecycle**: Process runs for entire Claude Code session434. **Shutdown**: Process terminated when Claude Code exits4445### Use Cases4647**NPM Packages:**48```json49{50"filesystem": {51"command": "npx",52"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path"]53}54}55```5657**Custom Scripts:**58```json59{60"custom": {61"command": "${CLAUDE_PLUGIN_ROOT}/servers/my-server.js",62"args": ["--verbose"]63}64}65```6667**Python Servers:**68```json69{70"python-server": {71"command": "python",72"args": ["-m", "my_mcp_server"],73"env": {74"PYTHONUNBUFFERED": "1"75}76}77}78```7980### Best Practices81821. **Use absolute paths or ${CLAUDE_PLUGIN_ROOT}**832. **Set PYTHONUNBUFFERED for Python servers**843. **Pass configuration via args or env, not stdin**854. **Handle server crashes gracefully**865. **Log to stderr, not stdout (stdout is for MCP protocol)**8788### Troubleshooting8990**Server won't start:**91- Check command exists and is executable92- Verify file paths are correct93- Check permissions94- Review `claude --debug` logs9596**Communication fails:**97- Ensure server uses stdin/stdout correctly98- Check for stray print/console.log statements99- Verify JSON-RPC format100101## SSE (Server-Sent Events)102103### Overview104105Connect to hosted MCP servers via HTTP with server-sent events for streaming. Best for cloud services and OAuth authentication.106107### Configuration108109**Basic:**110```json111{112"hosted-service": {113"type": "sse",114"url": "https://mcp.example.com/sse"115}116}117```118119**With headers:**120```json121{122"service": {123"type": "sse",124"url": "https://mcp.example.com/sse",125"headers": {126"X-API-Version": "v1",127"X-Client-ID": "${CLIENT_ID}"128}129}130}131```132133### Connection Lifecycle1341351. **Initialization**: HTTP connection established to URL1362. **Handshake**: MCP protocol negotiation1373. **Streaming**: Server sends events via SSE1384. **Requests**: Client sends HTTP POST for tool calls1395. **Reconnection**: Automatic reconnection on disconnect140141### Authentication142143**OAuth (Automatic):**144```json145{146"asana": {147"type": "sse",148"url": "https://mcp.asana.com/sse"149}150}151```152153Claude Code handles OAuth flow:1541. User prompted to authenticate on first use1552. Opens browser for OAuth flow1563. Tokens stored securely1574. Automatic token refresh158159**Custom Headers:**160```json161{162"service": {163"type": "sse",164"url": "https://mcp.example.com/sse",165"headers": {166"Authorization": "Bearer ${API_TOKEN}"167}168}169}170```171172### Use Cases173174**Official Services:**175- Asana: `https://mcp.asana.com/sse`176- GitHub: `https://mcp.github.com/sse`177- Other hosted MCP servers178179**Custom Hosted Servers:**180Deploy your own MCP server and expose via HTTPS + SSE.181182### Best Practices1831841. **Always use HTTPS, never HTTP**1852. **Let OAuth handle authentication when available**1863. **Use environment variables for tokens**1874. **Handle connection failures gracefully**1885. **Document OAuth scopes required**189190### Troubleshooting191192**Connection refused:**193- Check URL is correct and accessible194- Verify HTTPS certificate is valid195- Check network connectivity196- Review firewall settings197198**OAuth fails:**199- Clear cached tokens200- Check OAuth scopes201- Verify redirect URLs202- Re-authenticate203204## HTTP (REST API)205206### Overview207208Connect to RESTful MCP servers via standard HTTP requests. Best for token-based auth and stateless interactions.209210### Configuration211212**Basic:**213```json214{215"api": {216"type": "http",217"url": "https://api.example.com/mcp"218}219}220```221222**With authentication:**223```json224{225"api": {226"type": "http",227"url": "https://api.example.com/mcp",228"headers": {229"Authorization": "Bearer ${API_TOKEN}",230"Content-Type": "application/json",231"X-API-Version": "2024-01-01"232}233}234}235```236237### Request/Response Flow2382391. **Tool Discovery**: GET to discover available tools2402. **Tool Invocation**: POST with tool name and parameters2413. **Response**: JSON response with results or errors2424. **Stateless**: Each request independent243244### Authentication245246**Token-Based:**247```json248{249"headers": {250"Authorization": "Bearer ${API_TOKEN}"251}252}253```254255**API Key:**256```json257{258"headers": {259"X-API-Key": "${API_KEY}"260}261}262```263264**Custom Auth:**265```json266{267"headers": {268"X-Auth-Token": "${AUTH_TOKEN}",269"X-User-ID": "${USER_ID}"270}271}272```273274### Use Cases275276- REST API backends277- Internal services278- Microservices279- Serverless functions280281### Best Practices2822831. **Use HTTPS for all connections**2842. **Store tokens in environment variables**2853. **Implement retry logic for transient failures**2864. **Handle rate limiting**2875. **Set appropriate timeouts**288289### Troubleshooting290291**HTTP errors:**292- 401: Check authentication headers293- 403: Verify permissions294- 429: Implement rate limiting295- 500: Check server logs296297**Timeout issues:**298- Increase timeout if needed299- Check server performance300- Optimize tool implementations301302## WebSocket (Real-time)303304### Overview305306Connect to MCP servers via WebSocket for real-time bidirectional communication. Best for streaming and low-latency applications.307308### Configuration309310**Basic:**311```json312{313"realtime": {314"type": "ws",315"url": "wss://mcp.example.com/ws"316}317}318```319320**With authentication:**321```json322{323"realtime": {324"type": "ws",325"url": "wss://mcp.example.com/ws",326"headers": {327"Authorization": "Bearer ${TOKEN}",328"X-Client-ID": "${CLIENT_ID}"329}330}331}332```333334### Connection Lifecycle3353361. **Handshake**: WebSocket upgrade request3372. **Connection**: Persistent bidirectional channel3383. **Messages**: JSON-RPC over WebSocket3394. **Heartbeat**: Keep-alive messages3405. **Reconnection**: Automatic on disconnect341342### Use Cases343344- Real-time data streaming345- Live updates and notifications346- Collaborative editing347- Low-latency tool calls348- Push notifications from server349350### Best Practices3513521. **Use WSS (secure WebSocket), never WS**3532. **Implement heartbeat/ping-pong**3543. **Handle reconnection logic**3554. **Buffer messages during disconnection**3565. **Set connection timeouts**357358### Troubleshooting359360**Connection drops:**361- Implement reconnection logic362- Check network stability363- Verify server supports WebSocket364- Review firewall settings365366**Message delivery:**367- Implement message acknowledgment368- Handle out-of-order messages369- Buffer during disconnection370371## Comparison Matrix372373| Feature | stdio | SSE | HTTP | WebSocket |374|---------|-------|-----|------|-----------|375| **Transport** | Process | HTTP/SSE | HTTP | WebSocket |376| **Direction** | Bidirectional | Server→Client | Request/Response | Bidirectional |377| **State** | Stateful | Stateful | Stateless | Stateful |378| **Auth** | Env vars | OAuth/Headers | Headers | Headers |379| **Use Case** | Local tools | Cloud services | REST APIs | Real-time |380| **Latency** | Lowest | Medium | Medium | Low |381| **Setup** | Easy | Medium | Easy | Medium |382| **Reconnect** | Process respawn | Automatic | N/A | Automatic |383384## Choosing the Right Type385386**Use stdio when:**387- Running local tools or custom servers388- Need lowest latency389- Working with file systems or local databases390- Distributing server with plugin391392**Use SSE when:**393- Connecting to hosted services394- Need OAuth authentication395- Using official MCP servers (Asana, GitHub)396- Want automatic reconnection397398**Use HTTP when:**399- Integrating with REST APIs400- Need stateless interactions401- Using token-based auth402- Simple request/response pattern403404**Use WebSocket when:**405- Need real-time updates406- Building collaborative features407- Low-latency critical408- Bi-directional streaming required409410## Migration Between Types411412### From stdio to SSE413414**Before (stdio):**415```json416{417"local-server": {418"command": "node",419"args": ["server.js"]420}421}422```423424**After (SSE - deploy server):**425```json426{427"hosted-server": {428"type": "sse",429"url": "https://mcp.example.com/sse"430}431}432```433434### From HTTP to WebSocket435436**Before (HTTP):**437```json438{439"api": {440"type": "http",441"url": "https://api.example.com/mcp"442}443}444```445446**After (WebSocket):**447```json448{449"realtime": {450"type": "ws",451"url": "wss://api.example.com/ws"452}453}454```455456Benefits: Real-time updates, lower latency, bi-directional communication.457458## Advanced Configuration459460### Multiple Servers461462Combine different types:463464```json465{466"local-db": {467"command": "npx",468"args": ["-y", "mcp-server-sqlite", "./data.db"]469},470"cloud-api": {471"type": "sse",472"url": "https://mcp.example.com/sse"473},474"internal-service": {475"type": "http",476"url": "https://api.example.com/mcp",477"headers": {478"Authorization": "Bearer ${API_TOKEN}"479}480}481}482```483484### Conditional Configuration485486Use environment variables to switch servers:487488```json489{490"api": {491"type": "http",492"url": "${API_URL}",493"headers": {494"Authorization": "Bearer ${API_TOKEN}"495}496}497}498```499500Set different values for dev/prod:501- Dev: `API_URL=http://localhost:8080/mcp`502- Prod: `API_URL=https://api.production.com/mcp`503504## Security Considerations505506### Stdio Security507508- Validate command paths509- Don't execute user-provided commands510- Limit environment variable access511- Restrict file system access512513### Network Security514515- Always use HTTPS/WSS516- Validate SSL certificates517- Don't skip certificate verification518- Use secure token storage519520### Token Management521522- Never hardcode tokens523- Use environment variables524- Rotate tokens regularly525- Implement token refresh526- Document scopes required527528## Conclusion529530Choose the MCP server type based on your use case:531- **stdio** for local, custom, or NPM-packaged servers532- **SSE** for hosted services with OAuth533- **HTTP** for REST APIs with token auth534- **WebSocket** for real-time bidirectional communication535536Test thoroughly and handle errors gracefully for robust MCP integration.537