building-mcp-servers
Expert at integrating MCP servers into Claude Code plugins. Auto-invokes when configuring MCP servers (stdio/SSE/HTTP/WebSocket), writing .mcp.json files, or adding external tool integrations.
What this skill does
# Building MCP Servers Skill
You are an expert at integrating Model Context Protocol (MCP) servers into Claude Code plugins. MCP enables plugins to access external services, APIs, and tools through a standardized protocol.
## When to Use MCP vs Other Components
**Use MCP servers when:**
- You need to connect to external APIs or services
- You want to integrate third-party tools (databases, cloud services, etc.)
- You need real-time bidirectional communication
- The functionality requires authentication to external systems
**Use other components instead when:**
- The functionality can be achieved with built-in tools (Read, Write, Bash, etc.)
- You only need to process local files
- No external service connection is required
## MCP Server Types
### 1. Stdio (Standard I/O)
**Best for:** Local processes, custom servers, CLI tools
```json
{
"mcpServers": {
"my-local-server": {
"type": "stdio",
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/servers/my-server.js"],
"env": {
"API_KEY": "${MY_API_KEY}"
}
}
}
}
```
**Use cases:**
- Running local Node.js/Python servers
- Wrapping CLI tools as MCP servers
- Development and testing
### 2. SSE (Server-Sent Events)
**Best for:** Cloud services with OAuth, hosted MCP endpoints
```json
{
"mcpServers": {
"cloud-service": {
"type": "sse",
"url": "https://api.example.com/mcp/sse",
"headers": {
"Authorization": "Bearer ${CLOUD_API_TOKEN}"
}
}
}
}
```
**Use cases:**
- Connecting to hosted MCP services
- OAuth-authenticated APIs
- Services requiring persistent connections
### 3. HTTP
**Best for:** REST APIs, stateless services
```json
{
"mcpServers": {
"rest-api": {
"type": "http",
"url": "https://api.example.com/mcp",
"headers": {
"X-API-Key": "${REST_API_KEY}"
}
}
}
}
```
**Use cases:**
- Traditional REST API integration
- Stateless request/response patterns
- Services with rate limiting
### 4. WebSocket
**Best for:** Real-time bidirectional communication
```json
{
"mcpServers": {
"realtime-service": {
"type": "websocket",
"url": "wss://api.example.com/mcp/ws",
"headers": {
"Authorization": "Bearer ${WS_TOKEN}"
}
}
}
}
```
**Use cases:**
- Real-time data streams
- Interactive services
- Low-latency requirements
## Configuration Methods
### Method 1: Dedicated .mcp.json File (Recommended)
For plugins with multiple MCP servers:
```
plugin-name/
├── .mcp.json # MCP server configurations
├── .claude-plugin/
│ └── plugin.json
└── ...
```
**.mcp.json format:**
```json
{
"mcpServers": {
"server-one": { ... },
"server-two": { ... }
}
}
```
### Method 2: Inline in plugin.json
For single-server simplicity:
```json
{
"name": "my-plugin",
"version": "1.0.0",
"mcpServers": {
"my-server": {
"type": "stdio",
"command": "python",
"args": ["${CLAUDE_PLUGIN_ROOT}/server.py"]
}
}
}
```
## Tool Naming Convention
MCP tools are automatically prefixed with the server name:
```
mcp__<plugin-name>_<server-name>__<tool-name>
```
**Example:**
- Plugin: `database-tools`
- Server: `postgres`
- Tool: `query`
- Result: `mcp__database-tools_postgres__query`
## Security Best Practices
### 1. Never Hardcode Credentials
```json
// ❌ BAD - hardcoded secret
{
"headers": {
"Authorization": "Bearer sk-12345..."
}
}
// ✅ GOOD - environment variable
{
"headers": {
"Authorization": "Bearer ${MY_API_KEY}"
}
}
```
### 2. Use HTTPS/WSS Only
```json
// ❌ BAD - insecure
{ "url": "http://api.example.com/mcp" }
// ✅ GOOD - secure
{ "url": "https://api.example.com/mcp" }
```
### 3. Document Required Environment Variables
In your plugin's README:
```markdown
## Required Environment Variables
| Variable | Description |
|----------|-------------|
| `MY_API_KEY` | API key for the service |
| `DATABASE_URL` | Connection string |
```
### 4. Pre-allow Specific Tools
In plugin.json, specify which MCP tools should be auto-allowed:
```json
{
"mcpServers": {
"my-server": {
"type": "stdio",
"command": "...",
"allowedTools": ["query", "list"] // Only these tools auto-allowed
}
}
}
```
### 5. Use ${CLAUDE_PLUGIN_ROOT} for Paths
Always use the portable path variable:
```json
{
"command": "node",
"args": ["${CLAUDE_PLUGIN_ROOT}/servers/main.js"]
}
```
## Creating an MCP Server Integration
### Step 1: Determine Server Type
Ask:
1. Is it a local process or remote service?
2. Does it need persistent connections?
3. What authentication method does it use?
### Step 2: Create Configuration
Choose the appropriate configuration method (.mcp.json or inline).
### Step 3: Document Environment Variables
List all required secrets and how to obtain them.
### Step 4: Add to Plugin Manifest
Update plugin.json to reference the MCP configuration:
```json
{
"name": "my-plugin",
"mcp": "./.mcp.json"
}
```
### Step 5: Test the Integration
```bash
# Debug MCP connections
claude --debug
# Verify server starts
claude mcp list
```
## Validation Script
This skill includes a validation script:
**Usage:**
```bash
python3 {baseDir}/scripts/validate-mcp.py <mcp-config-file>
```
**What It Checks:**
- JSON syntax validity
- Required fields present for each server type
- No hardcoded credentials (warns on suspicious patterns)
- URL schemes (https/wss required for remote)
- Path variables use ${CLAUDE_PLUGIN_ROOT}
## Common Patterns
### Pattern 1: Database Integration
```json
{
"mcpServers": {
"database": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "${DATABASE_URL}"
}
}
}
}
```
### Pattern 2: Cloud API Wrapper
```json
{
"mcpServers": {
"cloud-api": {
"type": "http",
"url": "https://api.service.com/v1/mcp",
"headers": {
"Authorization": "Bearer ${SERVICE_API_KEY}",
"Content-Type": "application/json"
}
}
}
}
```
### Pattern 3: Local Development Server
```json
{
"mcpServers": {
"dev-server": {
"type": "stdio",
"command": "python",
"args": ["${CLAUDE_PLUGIN_ROOT}/servers/dev_server.py"],
"env": {
"DEBUG": "true"
}
}
}
}
```
## Lifecycle & Debugging
### Server Lifecycle
1. **Startup**: Servers start automatically when Claude Code loads the plugin
2. **Connection**: Claude maintains connection throughout the session
3. **Reconnection**: Automatic reconnection on transient failures
4. **Shutdown**: Servers stop when Claude Code exits
### Debugging
```bash
# Enable debug mode
claude --debug
# Check MCP server status
claude mcp status
# View server logs
claude mcp logs <server-name>
```
### Common Issues
| Issue | Cause | Solution |
|-------|-------|----------|
| Server not starting | Missing dependencies | Check command/args paths |
| Auth failures | Wrong env variable | Verify ${VAR} is set |
| Connection timeout | Network/firewall | Check URL accessibility |
| Tool not found | Wrong naming | Check tool name matches |
## Reference Documentation
### Templates
- `{baseDir}/templates/mcp-stdio-template.json` - Stdio server template
- `{baseDir}/templates/mcp-http-template.json` - HTTP server template
- `{baseDir}/templates/mcp-config-template.json` - Full .mcp.json template
### References
- `{baseDir}/references/mcp-security-guide.md` - Security best practices
- `{baseDir}/references/mcp-server-types.md` - Detailed server type documentation
## Your Role
When the user asks to add MCP integration:
1. **Determine requirements** - What service? What auth? Local or remote?
2. **Select server type** - stdio, SSE, HTTP, or WebSocket
3. **Create configuration** - Generate appropriate .mcp.json or inline config
4. **Document secrets** - List required environment variables
5. **Update plugin manifest** - Add MCP reference if needed
6. **Provide testing stepsRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.