tainanfidelis' blogby Tainan Fidelis

How to Build Your First MCP Server in 30 Minutes

29 de abril de 2026

How to Build Your First MCP Server in 30 Minutes

I built OpenClaw on MCP — and it changed how I think about AI tooling entirely. Before building my first MCP server, every agent I shipped was tightly coupled to specific API calls: one integration, one agent, one point of failure. After MCP, agents could discover and use tools dynamically. The same server I wrote in a Saturday afternoon now powers my entire DevFellowship platform, with 62 tools and 16 domains.

Here’s how to build your first MCP server in 30 minutes — and what I wish someone had told me before I scaled one to production.

What is the Model Context Protocol?

MCP (Model Context Protocol) is an open standard by Anthropic that lets AI models connect to external tools and data sources in a standardized way. Think of it as USB-C for AI agents — one protocol, any tool.

Instead of writing custom integration code every time you want an LLM to talk to your database, your APIs, or your filesystem, you build an MCP server once. Claude Code, Claude Desktop, and any MCP-compatible client can then discover and use it automatically.

In 2026, Anthropic, OpenAI, and Google have all adopted the standard. It’s the fastest-growing keyword cluster in AI tooling right now — and the quality gap between builders who understand it and those who don’t is only getting wider.

(I’ll cover the deeper theory — resources, prompts, context injection — in a future article. Link coming soon.)


What we’re building

A simple MCP server that exposes one tool: get_project_status. You’ll be able to ask Claude Code “what’s the status of project X?” and get a real answer from your own data source — no hallucination, no generic response.

By the end you’ll have:

  • A running MCP server in Python
  • The server connected to Claude Code
  • A mental model you can extend to build production tools (like the 62-tool server I run for DevFellowship)

Time: ~30 minutes
Prerequisites: Python 3.10+, Claude Code installed


Step 1: Install the MCP SDK (30 seconds)

pip install mcp

That’s it. The official MCP Python SDK handles the entire protocol. You focus on defining tools — not managing JSON-RPC, schema negotiation, or transport handshakes.


Step 2: Create your first MCP server (10 minutes)

Create a file called server.py:

import asyncio
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp import types
 
server = Server("project-status-server")
 
PROJECTS = {
    "devfellowship": {"status": "active", "fellows": 32, "pods": 5},
    "openclaw": {"status": "active", "version": "2.1.0"},
    "revera": {"status": "active", "lead": "William"},
}
 
@server.list_tools()
async def list_tools():
    return [
        types.Tool(
            name="get_project_status",
            description="Get the current status of a project by name",
            inputSchema={
                "type": "object",
                "properties": {
                    "project_name": {
                        "type": "string",
                        "description": "Name of the project to check"
                    }
                },
                "required": ["project_name"]
            }
        )
    ]
 
@server.call_tool()
async def call_tool(name: str, arguments: dict):
    if name == "get_project_status":
        project = arguments.get("project_name", "").lower()
        if project in PROJECTS:
            return [types.TextContent(
                type="text",
                text=f"Project '{project}': {PROJECTS[project]}"
            )]
        return [types.TextContent(
            type="text",
            text=f"Project '{project}' not found."
        )]
    raise ValueError(f"Unknown tool: {name}")
 
async def main():
    async with stdio_server() as (read_stream, write_stream):
        await server.run(
            read_stream,
            write_stream,
            server.create_initialization_options()
        )
 
if __name__ == "__main__":
    asyncio.run(main())

The structure is always the same:

  1. list_tools() — declares what tools exist and their JSON schema
  2. call_tool() — handles the actual execution when the model calls a tool
  3. main() — wires up the server to the stdio transport

That’s the entire protocol surface you need to learn to get started. Everything else is just your own logic inside call_tool.


Step 3: Connect to Claude Code (5 minutes)

Open (or create) your Claude Code MCP config. On macOS/Linux it lives at ~/.claude/claude_desktop_config.json:

{
  "mcpServers": {
    "project-status": {
      "command": "python",
      "args": ["/absolute/path/to/server.py"]
    }
  }
}

Restart Claude Code. You’ll see “project-status” appear in the MCP servers list (the plug icon in the toolbar).

Now ask:

“What’s the status of the devfellowship project?”

Claude Code sends a call_tool request to your server, gets back the data, and answers with real context — not a hallucination. That’s the whole loop.


Step 4: Connect to a real database (10 minutes)

The toy version above has hardcoded data. For production, replace the mock dictionary with a real DB call. Here’s the Supabase pattern I use in dfl-mcp-server:

import os
from supabase import create_client
 
supabase = create_client(
    os.environ["SUPABASE_URL"],
    os.environ["SUPABASE_KEY"]
)
 
@server.call_tool()
async def call_tool(name: str, arguments: dict):
    if name == "get_project_status":
        project = arguments.get("project_name")
        result = supabase.table("projects").select("*").eq("name", project).execute()
        if result.data:
            return [types.TextContent(type="text", text=str(result.data[0]))]
        return [types.TextContent(type="text", text="Not found")]

Pass env vars through the MCP config so Claude Code injects them at runtime:

{
  "mcpServers": {
    "project-status": {
      "command": "python",
      "args": ["/path/to/server.py"],
      "env": {
        "SUPABASE_URL": "https://yourproject.supabase.co",
        "SUPABASE_KEY": "your-anon-key"
      }
    }
  }
}

This keeps credentials out of your source code and lets different clients use different credentials with the same server binary.


Troubleshooting: the three things that will break (3 minutes)

If your server isn’t connecting or tools aren’t showing up, it’s almost always one of three things:

1. Path issues. Use the absolute path to server.py. Relative paths fail silently. Run which python and pwd to confirm exactly what you’re passing.

2. Import errors on startup. The MCP client starts your server as a subprocess and reads stderr. If there’s a Python import error (missing package, typo), the server crashes before responding to the handshake. Run python server.py directly in your terminal first to catch errors before wiring it up.

3. Schema validation failures. If call_tool receives arguments that don’t match your declared inputSchema, the call will fail. Make sure "required" lists only fields that are actually required, and test edge cases (empty strings, missing keys) before shipping.

When in doubt, add logging to call_tool — write to a file, not stdout, since stdout is used by the protocol transport.

import logging
logging.basicConfig(filename="/tmp/mcp-server.log", level=logging.DEBUG)
logger = logging.getLogger(__name__)
 
@server.call_tool()
async def call_tool(name: str, arguments: dict):
    logger.debug(f"call_tool: {name} {arguments}")
    # ...

What I learned building at production scale

OpenClaw is my AI agent orchestration system — and it’s built entirely on MCP. The production dfl-mcp-server powering DevFellowship has 62 tools across 16 domains: members, projects, deliveries, tasks, transactions, sandboxes, and more.

Three things I wish I’d known before hitting production:

Keep tools focused. When we had 62 tools in a single server, every agent loaded ~9,000 tokens of tool schema into its context window — even when it only needed 3 tools. Now I’m splitting into domain-specific servers: mcp-work for project management, mcp-learn for member and cohort data, mcp-payments for transactions. Each agent declares which MCPs it needs. Prompt overhead drops from 9k to under 2k tokens per agent.

Auth expiry will destroy you. Our Supabase JWTs expire after 1 hour. The original server didn’t handle token refresh. Agents would work perfectly for an hour, then start returning 401s on every call — with no clear error message pointing to auth. The fix: add auto-refresh logic in the client wrapper that checks token expiry before each request and rotates silently when needed.

stdio is for development; HTTP is for production. The tutorial above uses stdio transport — correct for local tools and single-user CLI workflows. For a server shared across agents and users, you want HTTP with SSE. Our Node.js + Fastify setup handles concurrent connections, middleware auth, and OpenTelemetry instrumentation. I’ll write that tutorial next.


What you can build next

Once the pattern clicks, MCP changes how you architect everything:

  • Multi-agent systems — each agent gets a scoped MCP server with only the tools relevant to its job. Agents stay small, fast, and focused.
  • Browser-native MCPs — we’re building Lesson Studio’s MCP to run in the browser + Supabase edge functions, no dedicated server required. Agents can control the UI directly.
  • Context engineering — MCP resources (not just tools) let you inject structured, version-controlled context into agent sessions. This is where the next generation of AI apps lives.

The protocol is still young. Most tutorials are generic. The builders who understand the edge cases — auth, transport, tool scoping, context overhead — are the ones building things that actually work at scale.


Resources


Build with people doing this for real

If you’re building AI-native products and want to learn from a team running 62-tool production MCP servers today, check out DevFellowship. We learn by building real things — not toy projects. Applications open for the next cohort.

Want more on AI engineering, MCP patterns, and building in public? Subscribe to the newsletter.

Thanks,
Tainan Fidelis.


Edit on GitHub