How to Build an MCP Server: A Beginner's Walkthrough

Build a beginner MCP server with the official Python SDK: tools, resources, stdio transport, local testing in a desktop host, and the TypeScript v2 equivalent.

Summarize this post with AI

A 18-minute read, or the key points in about 30 seconds, in the assistant you already use.

Opens in a new tab with the prompt filled in. Nothing passes through this site.

An MCP server is a small program that exposes tools, resources and prompts to an AI host, such as Claude for Desktop or an IDE agent, over the Model Context Protocol. The host lists what the server can do, the model proposes a tool call, and (in a well-built client) you approve it before anything runs.

This is a beginner's walkthrough of that server side, from the official MCP docs. You'll scaffold a Python server with the official SDK, add a tool and a resource, run it over stdio, and hook it up to a desktop host.

I have not published a new production server for this post. The APIs and the setup steps come from the official "Build an MCP server" tutorial and the SDK pages.

If the protocol itself is still fuzzy, start with my plain-English guide to what MCP is. This post is the "how do I build one" follow-up.

Some links are affiliate links; they don't change your price.

Editorial cover showing an AI client plugged into an MCP server that exposes tools, resources and prompts

What does an MCP server actually do?

The official docs split a server's job into three capabilities:

  • Tools: actions the model can invoke, usually with your approval, such as "look up a note" or "fetch a forecast".
  • Resources: read-only data the client can list and attach as context, such as a file, a config, or a report.
  • Prompts: pre-written templates the user can run, to start a task the same way each time.

Tools are model-controlled, and resources are application-controlled. That difference matters: a tool is a verb the model asks to run, and a resource is data the client decides to read.

A server talks to a host over a transport. The official beginner path uses stdio: the host starts your process and exchanges JSON-RPC on standard input and output.

HTTP transports exist too, and they're the right next step once you want a remote server. Start with stdio, which is the path the official tutorial uses with Claude for Desktop.

This is also why logging is a trap. The official docs are blunt: on a stdio server, never write to stdout. A print() call corrupts the JSON-RPC stream and the host will look like it "just doesn't see your tools". Log to stderr with the standard logging module instead.

Which official SDK should I use?

MCP publishes official SDKs in several languages. The SDK page current in late November 2026 lists TypeScript, Python, C# and Go as Tier 1, with Java and Rust as Tier 2, and others at Tier 3.

For a first server, pick the language you already write. The official getting-started tutorial is in Python, using the Python MCP SDK 2.0 or newer, Python 3.10+, and the uv package manager.

The TypeScript v2 package is @modelcontextprotocol/server. It implements the 2026-07-28 spec and uses McpServer, registerTool and registerResource.

I'll walk through Python here, because that's the official beginner tutorial's path. The same three ideas, tools, resources and a transport, show up in TypeScript.

You do not need to learn a new agent framework first. If you already use AI coding CLI tools, several of them can act as an MCP host and load a local server the same way a desktop app does.

How do I scaffold a Python MCP server?

The official tutorial starts by installing uv, creating a project, and adding the SDK.

On macOS or Linux, after uv is installed and your terminal has been restarted so the shell can see it:

bash
uv init notes
cd notes
uv venv
source .venv/bin/activate
uv add "mcp[cli]"

The docs require Python 3.10 or higher, and Python MCP SDK 2.0.0 or higher. On Windows the flow is the same, with .venv\Scripts\activate and uv add mcp[cli].

Create a server file, for example notes.py. The official pattern is to construct an MCPServer, decorate tools, and run over stdio. Here's a small original server that follows that official API, a personal notes lookup, rather than a copy of the weather tutorial.

python
import logging
from mcp.server import MCPServer

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

mcp = MCPServer("notes")

NOTES = {
    "welcome": "MCP tools are model-invoked actions.",
    "resources": "Resources are read-only data the client attaches.",
}

@mcp.tool()
async def get_note(title: str) -> str:
    """Return a note by title.

    Args:
        title: The note title, such as welcome or resources
    """
    logger.info("get_note title=%s", title)
    key = title.strip().lower()
    if key not in NOTES:
        return f"No note titled {title}."
    return NOTES[key]

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

A few details from the official docs are doing the real work here:

  • MCPServer uses the function's type hints and docstring to build the tool definition the model sees. The "Args" section is how the model learns what title means.
  • get_note is async, which matches the official examples.
  • logging goes to stderr, never print().
  • mcp.run(transport="stdio") is how the host starts the process and talks to it.

The official weather tutorial then has you add real HTTP calls, in their case to the US National Weather Service, with tools named get_alerts and get_forecast. That's a good second exercise once this stub runs, because it forces you to handle network errors and to send a User-Agent. I used an in-memory dictionary so the first run has no API key and no external dependency.

Infographic of official MCP server building blocks: MCPServer instance, tools with type hints and docstrings, optional resources, stdio transport, and logs written to stderr not stdout
The official Python SDK turns type hints and docstrings into the tool schema the model sees.

How do I add a resource?

A resource is read-only. The TypeScript v2 docs describe it as data the client lists and reads, then attaches as context. The Python server can expose the same idea.

In the TypeScript SDK, you call registerResource with a name, a URI such as config://app, metadata, and a read callback that returns contents. The Python tutorial's first pass focuses on tools, which is enough to get a host to call you. Once tools work, add a resource for anything the user might attach on purpose, such as a README, a schema, or a static config.

A good rule: if the model should decide to act, make it a tool. (Which model sits on the other side matters too; see how to choose an LLM for an AI agent.) If the user or the host should decide to attach data, make it a resource. Don't hide a destructive action behind a resource read.

How do I test the server locally?

Run the file with uv:

bash
uv run notes.py

On its own, that process will sit and wait for JSON-RPC on stdin. That's expected. A host has to start it.

The official tutorial's first host is Claude for Desktop. You install or update the app, then edit the config file, creating it if it doesn't exist:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json
  • Windows: %AppData%\Claude\claude_desktop_config.json

Add your server under the mcpServers key, with the absolute path to the project folder:

json
{
  "mcpServers": {
    "notes": {
      "command": "uv",
      "args": [
        "--directory",
        "/ABSOLUTE/PATH/TO/PARENT/FOLDER/notes",
        "run",
        "notes.py"
      ]
    }
  }
}

The docs warn you may need the full path to the uv executable (which uv on macOS or Linux, where uv on Windows). They also warn that closing the Claude window is not enough: quit the app fully, then reopen, or the new config won't load.

If the tools don't appear, the official checklist is: confirm the JSON is valid, confirm the path is absolute, confirm the process starts by hand, and look at the host's logs. The most common self-inflicted failure on stdio is still a print() statement breaking the stream.

Infographic of local MCP server testing: run the server with uv, add it to the desktop host config with an absolute path, fully quit and reopen the host, then approve a tool call
The host starts your process. If the config path is relative, or you forget to fully quit the app, the tools never appear.

You can also test from an MCP client in code, which is what the TypeScript SDK docs do with an in-memory Client. That's a better fit once you want automated checks. For a first server, a desktop host is the fastest way to see a tool call and an approval prompt.

When you write the tool descriptions, be as specific as you would be in an agent prompt. The docstring is the model's only manual for that argument.

How would this look in TypeScript?

If you'd rather stay in TypeScript, the official v2 server package is @modelcontextprotocol/server. You construct McpServer with a name and version, then registerTool with a Zod input schema and a handler that returns content items.

The SDK derives the JSON Schema the model sees from that one Zod schema, validates arguments before your handler runs, and types the handler from the same schema. registerResource does the equivalent for read-only data, including ResourceTemplate for URI patterns such as users://{userId}/profile.

Transports are documented separately: stdio for local hosts, HTTP with official adapters for Express, Fastify, Hono and Node. Start on stdio here too. Move to HTTP when you have a reason, such as a shared remote server, not because it feels more "production".

The Python and TypeScript paths implement the same protocol. A host that speaks MCP can call either server.

What should I build first, and what should I skip?

Build something you can verify without a paid API, then add a single external call.

Good first tools: look up a record in a local file, return today's date in a given timezone, or fetch a public, documented API that allows your User-Agent. The official weather tutorial is the third kind.

Skip, at least on day one:

  • Unrestricted shell or SQL tools.
  • Anything that writes to production data.
  • Secrets baked into the source. Read them from the environment, and never return them in tool output.
  • Logging to stdout on stdio.
  • A public HTTP server on the open internet, until you have authentication and an allow-list of tools.
Comparison infographic of a safe first MCP tool versus a risky one, with rows for data source, side effects, secrets, logging and Best for, plus a takeaway about least privilege
A first server should be easy to verify and hard to misuse. Add writes and network only after listing works.

This is the same least-privilege idea I use when I build an AI agent in n8n: give the model a narrow tool, not the keys to the account.

Frequently asked questions

Do I need Claude to build an MCP server?▾
No. Claude for Desktop is the host the official tutorial uses, because the config path is documented and the approval UI is visible. Any MCP host can load the same server, including IDE agents and your own client. The server does not depend on one vendor's model.
Why can't my desktop app see the tools?▾
The usual causes are a relative path in the config, invalid JSON, the host not fully quit after a config change, the wrong uv path, or a print() call on stdout breaking stdio. Run the server by hand first, then fix the config, then fully quit and reopen the host.
Should I use stdio or HTTP?▾
Use stdio for a local server started by a desktop app or an IDE. Use HTTP when the server needs to run remotely or serve more than one client. The official beginner tutorial starts with stdio, and that's the right default.
What's the difference between a tool and a resource?▾
A tool is an action the model can invoke. A resource is read-only data the client lists and attaches. If the model should decide to act, use a tool. If the user or host should decide to include a file or a record, use a resource.
Can I write an MCP server in TypeScript instead?▾
Yes. The official TypeScript v2 SDK is @modelcontextprotocol/server, and it is listed as a Tier 1 SDK. The ideas are the same: register tools and resources, then serve them over stdio or HTTP. Pick the language you'll actually maintain.
Where should I put API keys?▾
In environment variables, not in the source and not in a tool response. The official weather tutorial talks to a public API and still sets a User-Agent. For anything authenticated, load the secret at process start and log only that a call happened, not the key. If you want a model in the host that already has a strong desktop MCP story, start with [Claude](/go/claude)

Get a stub server running, with one tool and logs on stderr, before you add a network call. The protocol is the easy part. The hard part is giving the model a narrow, boring tool it can't misuse.

Once that's working, the official weather tutorial is a solid second pass, and my MCP explainer is the concept map to keep next to it.

Share