
The Model Context Protocol (MCP) is an open standard for connecting AI apps to tools and data. Build an MCP server once, and many AI clients can use it. New to MCP? Read MCP explained first. This guide shows how to build your own server in Python.
The three building blocks
An MCP server can offer:
- Tools: actions the AI model can call, such as “look up an order” or “create a ticket”.
- Resources: read-only data the app can load, such as files, records or documentation.
- Prompts: reusable templates a user can pick, such as “summarise this ticket”.
The AI app (the host) contains an MCP client that connects to your server, discovers what it offers and passes it to the model.
Step 1: Set up the project
Create a new Python project and virtual environment, then install the official MCP Python SDK from PyPI (the package is called mcp). Check the SDK’s README for the current install command and Python version.
Step 2: Write your first tool
The SDK’s FastMCP class turns ordinary functions into tools. The function name, type hints and docstring become the tool’s name, input schema and description.
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("store")
@mcp.tool()
def order_status(order_id: str) -> str:
"""Look up the delivery status of an order by its ID."""
orders = {"A100": "Shipped, arriving Friday", "A101": "Processing"}
return orders.get(order_id, "No order found with that ID.")
if __name__ == "__main__":
mcp.run() # communicates over stdio by default
Why the docstring matters: the model reads the tool’s description to decide when to use it. A clear, specific description is the difference between a tool that gets used correctly and one that doesn’t.
Step 3: Add a resource and a prompt
@mcp.resource("policy://returns")
def returns_policy() -> str:
"""The store's return policy."""
return "Items can be returned within 30 days in original condition."
@mcp.prompt()
def summarise_complaint(text: str) -> str:
"""Summarise a customer complaint and suggest a reply."""
return f"Summarise this complaint in 3 bullet points, then draft a polite reply:\n\n{text}"
Use tools actions or lookups with parameters, and ਲਈ resources data the app or user chooses to load. ਲਈ
Step 4: Test with an inspector
Before connecting to an AI app, test your server with the MCP Inspector, a developer tool that connects to your server, lists its tools, resources and prompts, and lets you call them by hand. Fix any errors here first; it is much easier than debugging through a chatbot.
Step 5: Connect it to an AI app
Many AI desktop apps, code editors and coding agents support MCP. Add your server in the app’s MCP settings, usually by giving the command that starts it (for example, running your Python file). Then ask something like “What’s the status of order A100?” and watch the model call your tool.
Step 6: Run it remotely over HTTP
Local servers use stdio: the app starts your server as a process on the same machine. To share a server with many users, run it over HTTP (the SDK supports the streamable HTTP transport) and deploy it like any web service. Remote servers must use authentication so each user only reaches their own data.
Step 7: Make it safe
Tools give AI models real power, so design them carefully:
- Least privilege: give each tool only the access it needs. Prefer read-only tools.
- Validate inputs: never pass model-generated arguments straight into SQL or shell commands.
- Human approval: require confirmation for actions that send, pay or delete.
- Untrusted content: text returned by tools (web pages, emails) may contain instructions meant to hijack the model. Treat it as data, not commands.
- Logs: record every tool call for auditing.
Ideas for your first MCP servers
- Your notes or documents (search as a tool, files as resources)
- A database you query often (read-only first)
- Your company’s internal API, such as orders or tickets
- A RAG retriever, so any AI app can search your documents (how to build a RAG app)
Learn MCP step by step
Our free MCP roadmap covers each step with notes, tips and tricks and practice projects. Then use your server in an agent: see how to build an AI agent.
ਅਕਸਰ ਪੁੱਛੇ ਜਾਂਦੇ ਸਵਾਲ
an MCP server ਕੀ ਹੈ?
An MCP server is a small program that exposes tools, data (resources) and prompt templates to AI applications through the Model Context Protocol, an open standard. Any MCP-compatible AI app can then discover and use them.
Which language can I use to build an MCP server?
Official SDKs exist for several languages, including Python and TypeScript. Python is a good start because the SDK turns ordinary functions into tools with a decorator.
Is it safe to install MCP servers from the internet?
Only install servers from sources you trust. A server can run code and access data with your permissions, so review what it does, limit its access and require approval for risky actions.


