The MCP Guide
Build a server

How to build an MCP server

Building a server is where MCP pays off: expose a capability once and every client can use it. The SDKs handle the protocol; you write the logic.

Pick an SDK #

The official Python SDK and TypeScript SDK SDKs implement the protocol, the transports, and the message plumbing. In Python, FastMCP gives you a decorator-based API that is the quickest way to start.

A minimal Python server #

pythonfrom mcp.server.fastmcp import FastMCP

mcp = FastMCP("weather")

@mcp.tool()
def get_forecast(city: str) -> str:
    """Get the weather forecast for a city."""
    return f"Sunny, 72F in {city}"

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

The decorator turns the function signature and docstring into a tool schema and description automatically. That is the whole server.

Run and connect it #

Point a client at it with a stdio config (command: python, args: [server.py]), or test it directly with the MCP Inspector before wiring up a client at all.

What to expose #

Decide which capabilities fit which primitive: actions and computed lookups are tools, readable context is resources, and reusable workflows are prompts. The next pages cover each in turn.

Resources & further reading

  • Python SDK GitHubThe official Python SDK for building MCP servers and clients.
  • TypeScript SDK GitHubThe official TypeScript SDK for building MCP servers and clients.
  • FastMCP GitHubAn ergonomic Python framework for building MCP servers with decorators.