Agent skill

mcp-builder

Build MCP servers for integrating external APIs with AI agents

Stars 3
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/48Nauts-Operator/opencode-baseline/tree/main/.opencode/skill/mcp-builder

Metadata

Additional technical details for this skill

audience
developers
workflow
development

SKILL.md

MCP Server Builder

Create high-quality MCP (Model Context Protocol) servers that enable AI agents to interact with external services through well-designed tools.

When to Use

  • Building integrations for external APIs
  • Creating tools for AI agent workflows
  • Connecting LLMs to databases, services, or custom systems
  • Extending Claude/OpenCode with new capabilities

Key Principles

Agent-Centric Design

  1. Build for workflows, not endpoints - Group related operations
  2. Optimize for context windows - Return concise, actionable data
  3. Actionable errors - Tell the agent what to do next
  4. Natural subdivisions - Match how tasks are mentally structured
  5. Evaluation-driven - Test with real agent interactions

Project Structure

Python (FastMCP)

my-mcp-server/
├── pyproject.toml
├── src/
│   └── my_mcp_server/
│       ├── __init__.py
│       ├── server.py      # Main MCP server
│       ├── tools/         # Tool implementations
│       ├── utils/         # Shared utilities
│       └── schemas/       # Pydantic models
└── tests/

TypeScript

my-mcp-server/
├── package.json
├── tsconfig.json
├── src/
│   ├── index.ts          # Main entry
│   ├── server.ts         # MCP server setup
│   ├── tools/            # Tool implementations
│   ├── utils/            # Shared utilities
│   └── types/            # Zod schemas
└── tests/

Implementation Process

Phase 1: Research & Plan

  1. Study the API

    • Authentication requirements
    • Rate limits and pagination
    • Error response formats
    • Available endpoints
  2. Plan Tools

    • Which operations are most useful for agents?
    • What workflows will agents perform?
    • What data format is most actionable?

Phase 2: Build Core Infrastructure

python
# Python example - shared utilities
from mcp.server import Server
from mcp.types import Tool, TextContent

class APIClient:
    """Handles auth, rate limiting, errors"""
    
    async def request(self, endpoint: str, **kwargs):
        # Retry logic, error handling
        pass

def format_response(data: dict) -> str:
    """Convert API response to agent-friendly format"""
    # Markdown or structured text
    pass

Phase 3: Implement Tools

python
from pydantic import BaseModel, Field

class SearchParams(BaseModel):
    """Input schema with validation"""
    query: str = Field(..., description="Search query")
    limit: int = Field(10, ge=1, le=100)

@server.tool()
async def search_items(params: SearchParams) -> str:
    """
    Search for items in the database.
    
    Use this when you need to find items matching specific criteria.
    Returns a list of matching items with their IDs and summaries.
    """
    results = await client.search(params.query, params.limit)
    return format_as_markdown(results)

Phase 4: Add Tool Annotations

python
@server.tool(
    annotations={
        "readOnlyHint": True,      # Doesn't modify data
        "destructiveHint": False,  # Safe operation
        "idempotentHint": True,    # Same result if repeated
        "openWorldHint": False     # Operates on known data
    }
)
async def get_item(item_id: str) -> str:
    ...

Best Practices

Input Design

Do Don't
Use Pydantic/Zod schemas Accept raw dicts
Add Field descriptions Leave params undocumented
Set sensible defaults Require all params
Validate at schema level Validate in handler

Output Design

Do Don't
Return markdown for readability Return raw JSON blobs
Include actionable next steps Leave agent guessing
Summarize large datasets Dump everything
Format for quick scanning Wall of text

Error Handling

python
class MCPError(Exception):
    """Base error with agent-friendly message"""
    
    def __init__(self, message: str, suggestion: str = None):
        self.message = message
        self.suggestion = suggestion

# Usage
raise MCPError(
    "Item not found",
    suggestion="Try searching with `search_items` first"
)

Testing

MCP servers run as long-lived processes. Test approaches:

  1. Unit tests - Test tools in isolation
  2. Integration tests - Run server, make tool calls
  3. Agent evaluation - Real agent interactions
bash
# Run server for testing
python -m my_mcp_server

# In another terminal, use MCP client to test

Quality Checklist

  • All tools have comprehensive docstrings
  • Input schemas validate edge cases
  • Errors include recovery suggestions
  • Outputs are concise and scannable
  • Rate limits are respected
  • Authentication is secure
  • Pagination is handled properly
  • Tool annotations are accurate

Expand your agent's capabilities with these related and highly-rated skills.

48Nauts-Operator/opencode-baseline

file-organizer

Organize files and folders intelligently with duplicate detection

3 0
Explore
48Nauts-Operator/opencode-baseline

nx-workspace-patterns

Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.

3 0
Explore
48Nauts-Operator/opencode-baseline

auth-implementation-patterns

Master authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.

3 0
Explore
48Nauts-Operator/opencode-baseline

sql-optimization-patterns

Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.

3 0
Explore
48Nauts-Operator/opencode-baseline

monorepo-management

Master monorepo management with Turborepo, Nx, and pnpm workspaces to build efficient, scalable multi-package repositories with optimized builds and dependency management. Use when setting up monorepos, optimizing builds, or managing shared dependencies.

3 0
Explore
48Nauts-Operator/opencode-baseline

git-advanced-workflows

Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from any situation. Use when managing complex Git histories, collaborating on feature branches, or troubleshooting repository issues.

3 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results