Mcp builder

From RedWoodOG/Hermes-Desktop · View interactive version

Mcp builder is an AI agent skill from the GitHub repository RedWoodOG/Hermes-Desktop. Build MCP (Model Context Protocol) servers that enable LLMs to interact with external services.

How to use this skill

Skill file

MCP Server Builder

You are an expert at building MCP (Model Context Protocol) servers. MCP is a protocol that enables LLMs to interact with external services through well-defined tools. You build servers in Python (using FastMCP) or TypeScript (using the MCP SDK).

What is MCP?

MCP servers expose tools that an LLM can call. Each tool has:

The server runs as a process that communicates with the LLM host via stdio or SSE.

Python Server (FastMCP)

Setup

pip install fastmcp

Basic Server Template

from fastmcp import FastMCP

mcp = FastMCP("my-service")

@mcp.tool()
def get_weather(city: str, units: str = "celsius") -> str:
    """Get the current weather for a city.

    Args:
        city: The city name (e.g., "San Francisco")
        units: Temperature units - "celsius" or "fahrenheit"
    """
    # Implementation here
    return f"Weather in {city}: 72F, sunny"

@mcp.tool()
def search_documents(query: str, max_results: int = 10) -> list[dict]:
    """Search the document database.

    Args:
        query: The search query string
        max_results: Maximum number of results to return
    """
    # Implementation here
    return [{"title": "Example", "snippet": "..."}]

if __name__ == "__main__":
    mcp.run()

Running

# stdio mode (for local LLM hosts)
python server.py

# SSE mode (for remote connections)
python server.py --transport sse --port 8000

TypeScript Server

Setup

npm init -y
npm install @modelcontextprotocol/sdk zod

Basic Server Template

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({
  name: "my-service",
  version: "1.0.0",
});

server.tool(
  "get_weather",
  "Get the current weather for a city",
  {
    city: z.string().describe("The city name"),
    units: z.enum(["celsius", "fahrenheit"]).default("celsius"),
  },
  async ({ city, units }) => {
    // Implementation here
    return {
      content: [{ type: "text", text: `Weather in ${city}: 72F, sunny` }],
    };
  }
);

async function main() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
}

main().catch(console.error);

Workflow for Building an MCP Server

Step 1: Define the Tools

List every tool the server should expose:

Step 2: Choose Python or TypeScript

Step 3: Implement the Server

Follow the template above. For each tool:

  1. Write a clear docstring/description - this is what the LLM reads to decide when to use the tool
  2. Type all parameters with descriptions
  3. Handle errors gracefully - return error messages, don't crash
  4. Return structured data when possible

Step 4: Handle Authentication

If the service requires API keys or tokens:

import os

@mcp.tool()
def api_call(query: str) -> str:
    """Call the external API."""
    api_key = os.environ.get("API_KEY")
    if not api_key:
        return "Error: API_KEY environment variable not set"
    # Use the key...

Step 5: Add Resources (Optional)

Resources provide read-only data the LLM can access:

@mcp.resource("config://settings")
def get_settings() -> str:
    """Current server configuration."""
    return json.dumps({"version": "1.0", "mode": "production"})

Step 6: Test

# Test with MCP inspector
npx @modelcontextprotocol/inspector python server.py

# Or test tools directly
python -c "from server import *; print(get_weather('London'))"

Step 7: Configure for Use

Add to the LLM host's MCP configuration (e.g., claude_desktop_config.json):

{
  "mcpServers": {
    "my-service": {
      "command": "python",
      "args": ["path/to/server.py"],
      "env": {
        "API_KEY": "your-key-here"
      }
    }
  }
}

Best Practices

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.