Dev tools

Build MCP Server Tools: A Step-by-Step Guide

Learn to build MCP server tools in Python: write your first server, test it with MCP Inspector, connect it to Claude, and take it remote safely.

By OmniAI Editorial · Nov 16, 2026 · 11 min read

If you want AI apps like Claude to work with your own data and tools, the cleanest way is to build MCP server code once and plug it into any app that supports the Model Context Protocol. An MCP server is a small program that tells an AI app "here are the things I can do," and then does them when asked. With the official Python SDK, a working server takes about 40 lines.

This guide explains what an MCP server is, then walks you through building one in Python. You'll test it, connect it to Claude Desktop and Claude Code, and learn what changes when you put it online. Every command and code sample here was run and tested against the current official SDK.

What is an MCP server?

The Model Context Protocol (MCP) is an open standard, introduced by Anthropic in late 2024, for connecting AI applications to outside tools and data. It's often described as a USB-C port for AI: instead of building a custom integration for every app, you build one MCP server, and any app that supports MCP can use it.

Many AI tools now support it, including Claude Desktop, Claude Code, Cursor, and VS Code, and the list keeps growing.

Hosts, clients, and servers

MCP has three roles:

  • Host: the AI app you use, such as Claude Desktop or an AI code editor.
  • Client: the connector inside the host that talks to one server.
  • Server: your program, which offers tools and data to the AI.
An app window on the left connected to three small servers, which in turn connect to a database, a document, and a cloud.
One AI app can connect to many MCP servers, and each server gives it access to a different source of data or set of actions.

When you ask the AI something, it sees the list of tools your server offers. If one is useful, the AI asks the host to call it. The host passes the request to your server, your code runs, and the result goes back to the AI.

MCP server vs API

People often ask about MCP server vs API, since both expose functionality to other software. The difference is who they're designed for.

A regular API is built for developers. Someone reads the documentation and writes code to call each endpoint. An MCP server is built for AI models. It describes its own tools in plain language, with names, descriptions, and input formats, so the AI can discover them and decide when to use them, with no custom code in each app.

In practice, many MCP servers are thin wrappers around existing APIs. The API does the work; the MCP server makes it usable by AI.

What an MCP server can offer

An MCP server can expose three kinds of things.

A wide box divided into three sections holding a wrench, a document, and a speech bubble.
The three things a server can offer: tools the AI can call, resources it can read, and prompts the user can pick.

Tools are actions the AI can take, such as "search notes," "create a ticket," or "query the database." The AI decides when to call them. Tools are by far the most used feature.

Resources are data the app can read, such as a file, a document, or a database record. Each has an address, like notes://shopping-list.

Prompts are ready-made instructions a user can pick from a menu in the app, such as "summarize my notes about a topic."

Most servers start with a few tools and add resources and prompts later, if at all.

What you need before you start

  • Python 3.11 or newer. The official Python SDK requires it.
  • uv or pip. The examples use uv, a fast Python package manager, but pip works too.
  • An MCP host to test with. Claude Desktop or Claude Code is the easiest, but any MCP-compatible app works.
  • Node.js (optional). The MCP Inspector, used for testing, runs on Node.js.

Official SDKs also exist for TypeScript and several other languages. This guide uses Python because it's the most common choice for a first server.

How to build MCP server tools in Python, step by step

We'll build a simple notes server. It lets the AI save notes, search them, and read them back. It's small, but it uses all three building blocks, and it's easy to adapt to your own data.

Step 1: Set up the project

Every MCP server Python project starts the same way: create a folder and install the official SDK with its command-line tools:

uv init notes-server
cd notes-server
uv add "mcp[cli]"

If you use pip instead, run pip install "mcp[cli]" inside a virtual environment.

Step 2: Write the server

Create a file called server.py:

import json
from pathlib import Path

from mcp.server import MCPServer

NOTES_FILE = Path(__file__).parent / "notes.json"

mcp = MCPServer("Notes")


def load_notes() -> dict[str, str]:
    if NOTES_FILE.exists():
        return json.loads(NOTES_FILE.read_text())
    return {}


def save_notes(notes: dict[str, str]) -> None:
    NOTES_FILE.write_text(json.dumps(notes, indent=2))


@mcp.tool()
def add_note(title: str, text: str) -> str:
    """Save a note under a short title. Overwrites a note with the same title."""
    notes = load_notes()
    notes[title] = text
    save_notes(notes)
    return f"Saved note '{title}'."


@mcp.tool()
def search_notes(query: str) -> list[str]:
    """Return the titles of notes whose title or text contains the query."""
    q = query.lower()
    return [t for t, body in load_notes().items() if q in t.lower() or q in body.lower()]


@mcp.resource("notes://{title}")
def read_note(title: str) -> str:
    """The full text of one note."""
    return load_notes().get(title, f"No note called '{title}'.")


@mcp.prompt()
def summarize_notes(topic: str) -> str:
    """Ask the AI to summarize everything saved about a topic."""
    return f"Search my notes for '{topic}', read the matching ones, and summarize them in five bullet points."


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

That's the whole MCP server in Python. A few things are worth noticing.

`MCPServer("Notes")` creates the server and gives it a name the app will show. Version 2 of the Python SDK uses MCPServer. Many older tutorials use the earlier name FastMCP, so update any code you copy from them.

`@mcp.tool()` turns a normal function into a tool. The SDK reads the function name, the type hints, and the docstring, and builds the tool description the AI sees. You don't write any JSON schemas by hand. That's why clear names and docstrings matter: they're the instructions the AI uses to decide when to call each tool.

`@mcp.resource("notes://{title}")` exposes each note as a readable resource. The {title} part becomes a function argument.

`@mcp.prompt()` adds a reusable prompt that users can pick in apps that support prompts.

`mcp.run()` starts the server. By default it uses stdio, meaning it talks to the app through standard input and output. This is the normal setup for a server running on your own computer.

Step 3: Test it with MCP Inspector

Before connecting to an AI app, test the server with the MCP Inspector, a browser-based tool for trying out servers. With the CLI extras installed, run:

uv run mcp dev server.py

The Inspector opens in your browser. Connect, open the Tools tab, and call add_note with a title and some text. Then call search_notes and check that your note comes back. You can also browse the resource and the prompt.

Testing in the MCP Inspector first is much faster than debugging through an AI app. You see exactly what your server receives and returns, with no AI in the middle.

Step 4: Connect it to Claude Code

In Claude Code, add a local server with claude mcp add. Give it a name, then put the command that starts your server after --:

claude mcp add notes -- uv run --directory /full/path/to/notes-server server.py

Start a Claude Code session and type /mcp to check that the server is connected. Then ask something like "save a note called ideas with the text 'try MCP resources'." Claude will ask permission to use your tool.

Step 5: Connect it to Claude Desktop

In Claude Desktop, open Settings, go to the Developer section, and edit the configuration file. Add your server under mcpServers:

{
  "mcpServers": {
    "notes": {
      "command": "uv",
      "args": ["run", "--directory", "/full/path/to/notes-server", "server.py"]
    }
  }
}

Use the full path to your project. Restart Claude Desktop, and your notes tools will appear in the tools menu.

If uv isn't found, use the full path to the uv program. Apps launched from the desktop don't always see the same settings as your terminal.

Local vs remote MCP server

So far your server runs on your own computer, started by the app itself. That's a local server, and it's ideal for personal tools and anything that touches your own files.

On the left, a laptop with a small server inside it. On the right, a laptop linked by a dashed line to a server inside a cloud.
A local server runs on your own machine and talks over stdio. A remote server runs online and is reached over HTTP.

A remote MCP server runs online, and apps connect to it by URL over HTTP. This is how companies offer MCP access to their products, and it lets you share one server with a whole team.

To run the same server over HTTP, change the last line to:

mcp.run(transport="streamable-http")

By default, this serves your MCP endpoint at http://localhost:8000/mcp. Streamable HTTP is the standard transport for remote servers.

Going remote adds real responsibilities:

  • Authentication. Anyone who can reach your URL can call your tools. Remote servers should require sign-in; the MCP specification uses OAuth for this.
  • HTTPS. Always serve remote servers over HTTPS.
  • Hosting. You need somewhere to run the server, such as a cloud platform, a container, or your own hardware.

For your first server, stay local. Move to remote once your tools are stable and you know who needs access.

Tips to build MCP server tools the AI uses well

Design a few clear tools

A handful of focused tools works better than dozens of overlapping ones. Give each tool a specific name and a docstring that says what it does and when to use it.

Return helpful errors

If something goes wrong, return a clear message such as "No note called 'ideas'" instead of crashing. The AI can read the message and try something else.

Never print to stdout in a stdio server

This is the most common beginner bug. A stdio server uses standard output to talk to the app, so a stray print() corrupts the conversation and the connection breaks. Log to standard error or a file instead.

Keep results short

Everything a tool returns goes into the AI's working memory. Return what the AI needs, not entire database dumps. Paginate or summarize large results.

Security for MCP servers

An MCP server gives an AI the power to act, so treat it like any other code with access to your systems.

  • Give the least access needed. If the AI only needs to read data, don't add tools that write or delete.
  • Validate inputs. Never pass tool input straight into a database query, a shell command, or a file path without checking it.
  • Protect secrets. Read API keys from environment variables, never from the code.
  • Be careful with untrusted content. If your tools return web pages or emails, they may contain hidden instructions aimed at the AI, a trick called prompt injection. Keep risky tools that send, delete, or pay behind user confirmation.
  • Only install servers you trust. Third-party MCP servers run code on your machine. Check the source before you add one.

Once your server works, you can use it inside your own agents too. Our guide on how to build an AI agent explains the agent loop that calls tools like these. If you're new to Claude Code, see our beginner's guide to using Claude Code.

FAQ

What is the difference between an MCP server and an MCP client?

The server offers tools, resources, and prompts. The client lives inside the AI app and connects to the server to use them. When you build MCP server code, you're writing the server; apps like Claude Desktop already include the client.

Which language is best for building an MCP server?

Python and TypeScript are the most popular, and both have official SDKs with good documentation. Official SDKs also exist for several other languages. Pick the one your team already uses.

Is MCP free to use?

Yes. MCP is an open standard, and the official SDKs and the MCP Inspector are free and open source. You only pay for the AI app you connect to and for any hosting if you run a remote server.

Do I need Claude to use an MCP server?

No. MCP works with any app that supports the protocol, including AI code editors and other assistants. Claude Desktop and Claude Code are simply easy places to test.

How do I debug an MCP server?

Start with the MCP Inspector to test each tool on its own. If the server works there but not in your app, check the app's MCP logs, confirm the command and full paths in your config, and make sure nothing prints to standard output.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog