arrow_backGuides / Building an MCP Server
Updated July 2026 15 min read Advanced

Building an MCP Server
— connecting your tools to AI

MCP has become the "USB-C of AI" — one protocol that connects any model to any tool. This guide will not stop at concepts: we will build your own MCP server step by step — tools, resources, prompts, the right transport, connecting to Claude and agents, and the security pitfalls you must know.

Tools
Actions
Resources
Data
Prompts
Templates

What an MCP server is, and why build one

Model Context Protocol (MCP) is an open protocol that defines how a language model (or agent) talks to external sources — databases, APIs, files, internal systems. Instead of writing a dedicated integration for each model, you write one MCP server, and any client that supports MCP (Claude Desktop, IDEs, agents) can use it immediately.

When is it worth building your own server? When you have an internal capability you want to expose to AI — for example access to the company CRM, database queries, or triggering a workflow inn8n. The server wraps the capability in a standard interface, and the AI gets safe, controlled access to it.

lan
Client vs Server

MCP has two sides: thehost/client (Claude Desktop, an agent) that manages the conversation, and theserver (what you build) that exposes capabilities. They communicate over JSON-RPC. You build the server; the client already exists.

The three primitives: Tools, Resources, Prompts

An MCP server exposes three kinds of capability. Understanding the distinction matters — it determines how the model uses each one:

build
Tools — actions the model invokes
Functions the model chooses to call: "send email", "search the database", "create a ticket". They have a structured input (schema) and an output. This is the most common primitive.
description
Resources — data to read
Data the client can load into context: file contents, a record, a log. Identified by a URI. Unlike tools, they are usually controlled by the client/user, not by the model.
auto_awesome
Prompts — ready-made templates
Conversation templates the user picks ("summarize this report"). They appear in the client as quick commands. Less used than tools, but excellent for recurring workflows.

Transport — stdio vs HTTP

How do the client and server physically talk? There are two main options, and it is an important architectural decision:

Transport Where it runs Best for
stdioLocal, on the same machinePersonal tools, Claude Desktop
Streamable HTTPA remote serverA multi-user service, cloud

stdio — the server runs as a local process and communication is over stdin/stdout. The simplest to start with, perfect for a personal tool running alongside Claude Desktop. Streamable HTTP — the server runs remotely and is reachable over HTTP; suited to serving multiple users or deploying to the cloud. Start with stdio, move to HTTP when you need scale.

Build your first server — with the official SDK

The easiest path is the official SDK. In Python, FastMCP lets you define a tool with a single decorator — the schema is derived automatically from the type hints and the docstring:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("weather-server")

@mcp.tool()
def get_weather(city: str) -> str:
    """Returns the current weather for a given city."""
    # the real logic goes here — a call to a real API
    return f"In {city}: 24°C, clear"

if __name__ == "__main__":
    mcp.run()  # default: stdio transport

That is it — you have a working MCP server with one tool. Three principles that make a tool good:

tips_and_updates
Test before connecting

Before connecting to a client, test the server with the MCP Inspector — an official tool that runs the server and lets you call tools manually and see the responses. It saves hours of debugging against Claude.

Connecting to Claude & agents

Once the server works, you connect it to a client. Claude Desktop reads a JSON config file where you register the server’s launch command — the client runs it automatically and discovers the tools. Agents (LangGraph, the Claude Agent SDK and others) can connect to MCP servers as a source of tools, so the same server serves both a human chat and automation.

This is exactly the power of MCP: you wrote the server once, and now it is available to Claude Desktop, an IDE, and any agent you build — without duplicating code. Theagent’s framework only needs to know how to speak MCP.

Security & common pitfalls

An MCP server exposes real capabilities to AI — which also makes it an attack surface. These are the things you must not miss:

warning
The most common pitfall: too many tools

It is tempting to expose dozens of tools "just in case". But every tool consumes tokens in context and confuses the model’s choice. A server with 5 focused tools beats one with 30. Expose only what is truly needed.