agentleFS
THEROCKSSSTHEROCKSSS/hermes-skills-portfolio/skills/mcp-server-build/SKILL.md

mcp-server-build

Skill1 starsChanged 4 months agoMITView on GitHub

Use when the user wants to expose their tools, APIs, or data to an AI agent via the Model Context Protocol — building a new MCP server (tools/resources/prompts), choosing stdio vs HTTP transport, writing tool JSON Schemas, or connecting a built server to Hermes or another MCP client.

  • Installs packages

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every tool needs a clear JSON Schema so the agent knows what arguments to pass:

    line 140
  2. Distinctive:

    Forgetting the session is cached: After adding a new tool to a running server, some MCP clients (including Hermes) cache the tool list from …

    line 239

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

mcp-server-build

Overview

Build a Model Context Protocol (MCP) server that exposes your tools, resources, and prompts to AI agents. MCP is an open protocol that lets AI assistants interact with external systems through a standardized interface.

When to Use

  • The user wants to expose their tools or APIs to an AI agent via MCP.
  • The user wants to build an MCP server for a custom service.
  • The user says "build an MCP server", "make my tool work with MCP", or "I want my agent to call my API".

MCP Protocol Basics

MCP servers expose three types of capabilities:

CapabilityWhat it does
ToolsFunctions the agent can call (e.g., search_database, send_email)
ResourcesData the agent can read (e.g., file://config.json, db://schema)
PromptsPre-built prompt templates the agent can use

Servers communicate via JSON-RPC over one of two transports:

TransportUse case
stdioLocal servers, launched by the agent process
HTTPRemote servers, accessible over the network

Workflow

Step 1: Choose your language and SDK

LanguageSDKInstall
Pythonmcppip install mcp
TypeScript@modelcontextprotocol/sdknpm install @modelcontextprotocol/sdk

Step 2: Define your tools

Each tool has a name, description, and JSON Schema for its parameters:

from mcp import Server, Tool
from mcp.types import ToolSchema

server = Server("my-server")

@server.tool()
async def search_database(query: str, limit: int = 10) -> str:
    """Search the database for matching records.

    Args:
        query: The search query string
        limit: Maximum number of results to return
    """
    # Your search logic here
    results = await db.search(query, limit=limit)
    return json.dumps(results)

Step 3: Implement handlers

The handler is the function that runs when the agent calls the tool. It receives the arguments as a dict and returns a string (or structured content).

@server.tool()
async def get_file(path: str) -> str:
    """Read a file from the local filesystem."""
    try:
        with open(path, 'r') as f:
            return f.read()
    except FileNotFoundError:
        return f"Error: File not found at {path}"
    except PermissionError:
        return f"Error: Permission denied for {path}"

Step 4: Register resources (optional)

Resources are URIs the agent can read:

@server.resource("config://app")
async def get_config() -> str:
    """Return the application configuration."""
    return json.dumps({"version": "1.0", "debug": False})

Step 5: Choose transport and run

stdio (local):

import asyncio
from mcp.server.stdio import stdio_server

async def main():
    async with stdio_server() as (read_stream, write_stream):
        await server.run(read_stream, write_stream)

asyncio.run(main())

HTTP (remote):

from mcp.server.sse import sse_server

async def main():
    async with sse_server("0.0.0.0", 8080) as (read_stream, write_stream):
        await server.run(read_stream, write_stream)

asyncio.run(main())

Step 6: Test with an MCP client

# Using the MCP inspector (comes with the SDK)
mcp inspect python my_server.py

# Or connect from an agent that supports MCP
# Hermes: hermes mcp add my-server --command "python my_server.py"
# Claude Desktop: add to claude_desktop_config.json

Tool Schema

Every tool needs a clear JSON Schema so the agent knows what arguments to pass:

TOOL_SCHEMA = {
    "name": "search_database",
    "description": "Search the database for matching records.",
    "inputSchema": {
        "type": "object",
        "properties": {
            "query": {
                "type": "string",
                "description": "The search query string"
            },
            "limit": {
                "type": "integer",
                "description": "Maximum results to return",
                "default": 10
            }
        },
        "required": ["query"]
    }
}

Good descriptions are critical — the agent uses them to decide when to call the tool.

Full Example: File Search Server

#!/usr/bin/env python3
import asyncio
import json
import os
from mcp import Server
from mcp.server.stdio import stdio_server

server = Server("file-search")

@server.tool()
async def search_files(directory: str, pattern: str) -> str:
    """Search for files matching a pattern in a directory.

    Args:
        directory: The root directory to search in
        pattern: Filename pattern (e.g., '*.py', '*.json')
    """
    import fnmatch
    matches = []
    for root, dirs, files in os.walk(directory):
        for filename in fnmatch.filter(files, pattern):
            matches.append(os.path.join(root, filename))
    return json.dumps(matches[:50], indent=2)

@server.tool()
async def read_file(path: str) -> str:
    """Read the contents of a file."""
    try:
        with open(path, 'r') as f:
            return f.read()[:10000]  # cap at 10k chars
    except Exception as e:
        return f"Error: {e}"

@server.resource("stats://file-search")
async def get_stats() -> str:
    """Return search statistics."""
    return json.dumps({"server": "file-search", "version": "1.0"})

async def main():
    async with stdio_server() as (read_stream, write_stream):
        await server.run(read_stream, write_stream)

if __name__ == "__main__":
    asyncio.run(main())

Connecting to Hermes

# Add as a stdio server
hermes mcp add file-search --command "python /path/to/file_search_server.py"

# Add as an HTTP server
hermes mcp add file-search --url http://localhost:8080

# Test the connection
hermes mcp test file-search

# List available tools from the server
hermes mcp list

Common Pitfalls

  1. Vague tool descriptions. The agent decides whether to call a tool based on its description alone. "Searches stuff" won't get called. "Searches the database for records matching a query string, returns up to N results as JSON" will.
  2. No error handling. Tools that crash on bad input break the agent's whole turn. Always catch exceptions and return error messages as strings — never let a handler raise unhandled.
  3. Returning too much data. Agents have context limits. Cap returns at a reasonable size (10k chars, 50 results as shown above) and let the agent ask for more if needed.
  4. No input validation. Validate paths, queries, and parameters before processing. Don't trust the agent to send valid input — it will occasionally pass malformed or out-of-range values.
  5. Blocking operations inside async handlers. MCP handlers should be async. Blocking I/O (file reads, database queries) run inline stalls the whole server; run them in a thread executor.
  6. Transport mismatch. stdio servers are launched by the agent process and read/write over the process pipes; HTTP servers must be running independently before the agent connects. Don't try to serve HTTP over stdio or vice versa.
  7. Forgetting the session is cached. After adding a new tool to a running server, some MCP clients (including Hermes) cache the tool list from initial connection — reconnect or restart the client to see new tools.

Verification Checklist

  • mcp inspect python my_server.py (or equivalent) lists every tool with its schema and description
  • Each tool returns a string/structured result for both valid and invalid input — no unhandled exception in the server logs
  • stdio servers are invoked by the client's own command (not left running as an orphan process); HTTP servers are confirmed reachable with curl before wiring into the client
  • hermes mcp test <name> (or the equivalent client-side test) succeeds and the tool list matches what the server defines
  • A sample call to at least one tool returns the expected data end-to-end, not just a schema-level pass

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.