MCP Server Development
Guide for building Model Context Protocol servers: project structure, tool design, error handling, testing with MCP Inspector, and evaluation patterns.
Tags
README
mcp-development
Guide for building Model Context Protocol (MCP) servers.
What It Does
Installs a rules file covering MCP server development:
- Project setup - Language choice (TypeScript recommended), transport selection (stdio vs HTTP)
- Tool design - Naming conventions, input schemas with Zod/Pydantic, output design, error messages
- Tool annotations - readOnlyHint, destructiveHint, idempotentHint, openWorldHint
- Implementation patterns - Shared utilities, authentication, rate limiting
- Testing - MCP Inspector usage, build verification, input validation
- Quality checklist - Pre-ship verification steps
Manual Installation
# Global (all projects)
mkdir -p ~/.claude/rules
cp rules/mcp-development.md ~/.claude/rules/mcp-development.md
# Project-level
mkdir -p .claude/rules
cp rules/mcp-development.md .claude/rules/mcp-development.md
Files
| File | Description |
|---|---|
rules/mcp-development.md |
MCP server development guide with tool design patterns and quality checklist |
Will install
| Path | Action | Target | Type |
|---|---|---|---|
rules/mcp-development.md | → | rules/mcp-development.md | rule |
Dependencies
No dependencies.
Required by
No other module depends on this one.
Included in presets
Install this module
Agent prompt
Recommended for agent users -- hands the whole install off to your assistant.
Fetch https://cd23a9be.ccgm-site.pages.dev/modules/mcp-development.md and install this module into my Claude Code setup.
Native plugin marketplace
One command via the native plugin marketplace -- additive, does not merge settings.json.
claude plugin install mcp-development@ccgm
The marketplace path is additive, not a replacement: it installs commands, agents, and skills as native plugin components, but it does not perform the bash installer's deep settings.json merge, and it does not write the always-loaded global CLAUDE.md context. Rules are only injected via an opt-in SessionStart hook rather than being auto-loaded. Use the bash installer when those pieces matter to you.
Files
rule (1)
rules/mcp-development.md
# MCP Server Development
Guidelines for building Model Context Protocol (MCP) servers that enable LLMs to interact with external services.
## Project Setup
### Language Choice
- **TypeScript** (recommended): Better SDK quality, type safety, and LLM compatibility. Use `@modelcontextprotocol/sdk`.
- **Python**: Use `fastmcp` for rapid development.
### Transport
- **stdio**: For local servers (CLI tools, desktop integrations)
- **Streamable HTTP**: For remote/shared servers
## Tool Design
### Naming
- Use clear, descriptive names with consistent prefixes per service
- Pattern: `{service}_{action}_{resource}` (e.g., `github_create_issue`, `slack_send_message`)
- Avoid ambiguous names - the LLM reads these to decide which tool to call
### Input Schemas
- Define strict schemas with Zod (TypeScript) or Pydantic (Python)
- Include constraints (min/max, enums, patterns) in the schema itself
- Add descriptions to every field - these become the tool's documentation for the LLM
- Include examples in field descriptions for complex types
### Output Design
- Return focused, relevant data (not raw API dumps)
- Support filtering and pagination for list operations
- Use structured output schemas when the consumer needs to parse results programmatically
### Error Messages
- Make errors actionable: tell the LLM what went wrong AND what to try next
- Include the specific constraint that was violated
- Suggest alternative tool calls when appropriate
- Never return raw stack traces or internal error details
## Tool Annotations
Annotate every tool to help clients make safety decisions:
```typescript
{
readOnlyHint: true, // Does not modify external state
destructiveHint: false, // Does not delete or overwrite
idempotentHint: true, // Safe to retry
openWorldHint: false // Interacts with external services
}
```
## Implementation Patterns
### Shared Utilities
Create reusable modules for:
- API client with auth, rate limiting, and retry logic
- Error formatting (consistent structure across all tools)
- Response formatting (pagination, truncation, summarization)
- Input validation helpers
### Authentication
- Support environment variables for API keys/tokens
- Document required credentials clearly in the README
- Never log or expose credentials in error messages
### Rate Limiting
- Implement client-side rate limiting to stay within API quotas
- Return clear errors when rate limited (include retry-after timing if available)
## Testing
### MCP Inspector
Use `npx @modelcontextprotocol/inspector` to:
- Verify tool schemas are correctly defined
- Test tool execution with sample inputs
- Confirm error handling works as expected
### Build Verification
- Run the build (`npm run build` / type checking) before testing
- Test every tool with both valid and invalid inputs
- Verify error messages are helpful and actionable
## Quality Checklist
Before shipping an MCP server:
- [ ] Every tool has a clear description and annotated inputs
- [ ] Error messages guide the LLM toward resolution
- [ ] Authentication is via environment variables (not hardcoded)
- [ ] Rate limiting prevents API quota exhaustion
- [ ] Tool annotations (readOnly, destructive, idempotent) are set correctly
- [ ] README documents all tools, required credentials, and setup steps
- [ ] Inspector testing confirms all tools work