In short
To build an MCP server, install an official SDK, define tools as functions with clear names, descriptions and typed inputs, then run the server and connect a client. In Python, FastMCP needs only a few lines. Use stdio for local tools and HTTP for remote ones. Begin with read-only tools, write descriptions for a model to read, enforce permissions on the server, and log every call.
What you're building
An MCP server exposes capabilities to AI applications through the Model Context Protocol. The official tutorial describes three kinds:
- Tools: functions that the model can call, with user approval
- Resources: file-like data that clients can read
- Prompts: pre-written templates for common tasks
Most first servers just need tools. If you're not sure that you need one at all, see MCP server vs API. For the concepts, see what MCP is.
A minimal server in Python
This uses the official Python SDK's FastMCP interface. Details can change, so check the current tutorial if something fails.
# server.py
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("orders")
ORDERS = {"1042": {"status": "shipped", "eta": "2026-11-12"}}
@mcp.tool()
def get_order_status(order_id: str) -> str:
"""Get the current status and delivery estimate for an order.
Args:
order_id: The order number, for example 1042.
"""
order = ORDERS.get(order_id)
if not order:
return f"No order found with ID {order_id}. Check the number and try again."
return f"Order {order_id} is {order['status']}, due {order['eta']}."
if __name__ == "__main__":
mcp.run(transport="stdio")
The name, type hints and docstring all become part of what the client and model see, so they're doing real work here. Install and run:
uv add "mcp[cli]"
uv run server.py
Nothing much appears to happen, because the server is waiting for a client. There's an important catch: on stdio servers, don't write to standard output with print(), as that corrupts the protocol messages. Log to standard error or to a file instead.
Connecting a client
Different clients configure this in different ways. In Claude Code, you can add a local server with a command like this:
claude mcp add orders -- uv run /full/path/to/server.py
Other clients, including VS Code, Cursor and Claude Desktop, use similar settings or a JSON file. Check the client's documentation. Then try a prompt: “What's the status of order 1042?”, and approve the tool call.
The MCP project also provides an Inspector tool, which lets you call your tools without a model. It's the quickest way of testing them:
npx @modelcontextprotocol/inspector uv run server.py
stdio or HTTP?
| stdio | Streamable HTTP | |
|---|---|---|
| Runs | On the user's machine, started by the client | On a server, reached over the network |
| Good for | Local tools, files, personal scripts | Shared services, products, teams |
| Authentication | Usually local credentials | Needs proper auth, usually OAuth |
| Effort | Very low | You run and secure a service |
Start with stdio. Move to HTTP when others need to use it. A remote server is a public API, and it needs treating as one.
Designing good tools
This is where most of the real value lies.
Design around tasks, not endpoints. Don't simply wrap each API route. A tool called get_customer_overview that combines several calls may be far more useful than four separate ones.
Write descriptions for a reader who knows nothing. The model chooses based on what you write. Explain what the tool does, when to use it, and what each input means. See how to write a tool description for an agent.
Keep the list short. Too many tools confuse the model and use up context. Five good ones usually beat fifty thin ones.
Return what's useful, not everything. A short result saves tokens, and helps the model to focus. Offer filters and limits for long lists.
Make errors useful. “No order found. Check the number and try again” helps the model to recover, whereas a stack trace doesn't.
Separate read and write tools, with clear names, such as get_invoice and send_invoice.
get_customer_orders
get_customer_invoices
get_customer_tickets
Security: read before sharing
Your server hands real capabilities to something that can be manipulated. See is MCP secure? for the full picture.
- Start read-only. Add write actions only when you need them.
- Enforce permissions on the server. Never rely on the model to behave properly, or on a description saying “only use this for your own data”.
- Validate all inputs. Treat them as untrusted, because they are. Avoid shell commands built from input, and use parameterised queries.
- Least privilege. Use a database account or API key with the minimum rights needed. Don't connect production admin credentials.
- Confirm dangerous actions. Deleting, paying or emailing should need a human's approval. See how to put a human in the loop.
- Consider prompt injection. A tool that reads web pages or emails can bring malicious instructions into the conversation. See how to stop prompt injection.
- Log every call, including who made it and with what arguments, while being careful with sensitive data.
- Protect secrets. Read them from the environment, and never return them in results. See how to handle secrets and API keys.
- For remote servers, follow the protocol's authorisation guidance, use HTTPS and add rate limits.
Testing
- Use the Inspector to call each tool, with both valid and invalid inputs.
- Test with a real model, using natural requests. Does it pick the right tool?
- Try awkward prompts, including attempts to misuse it.
- Check that errors are helpful.
- Add unit tests for the underlying functions, and keep them independent of MCP.
Next steps
- Connect to real data, with a read-only account.
- Add your second and third tools only when needed.
- Check for an existing server before building one, as many exist. Review them carefully before installing, as you would any code.
- Publish it, if it's useful to customers. Document what it does and what permissions it needs.
If you're thinking about an MCP server for your product, book a call.
Common questions
How hard is it to build an MCP server?
A basic one is easy: an official SDK lets you define a tool in a few lines. The harder parts are designing useful tools, writing good descriptions and, for remote servers, handling authentication and security. Start small, with a local read-only tool.
What language should I use for an MCP server?
Whichever suits your team. There are official SDKs for several languages, including Python and TypeScript. Python's FastMCP is a very quick way to start. If you're wrapping an existing service, use the language that it's already written in.
Why does my MCP server fail when I print something?
On stdio servers, standard output carries protocol messages, so a print statement can corrupt them. Log to standard error or to a file. This is one of the most common beginner mistakes, and the official documentation warns about it.
Should my MCP server run locally or remotely?
Use a local stdio server for personal tools and files, since it's the simplest option. Use a remote HTTP server when others need access, such as customers or a team. Remote servers need proper authentication, HTTPS, rate limits and monitoring.