Ravindra BagaleCourses & study guides Track your progress

Guides · Generative AI

What Is an MCP Server? Build Your First One in Python (Beginners)

MCP (Model Context Protocol) is an open standard that lets AI apps use outside tools and data in one common way. An MCP server is a small program that offers tools (like “add two numbers” or “search my notes”); an MCP client (Claude Desktop, VS Code, Cursor and others) connects and lets the AI call them. With the official Python SDK (pip install "mcp[cli]") you can write a working server in about 10 lines using FastMCP. Only install MCP servers you trust.

Suppose Nikhil in Bengaluru wants his AI assistant to read his shop’s price list, and Sara in Toronto wants it to check her study timetable. Instead of copy-pasting, each writes a tiny MCP server with one tool, connects it, and asks the AI a question that uses the tool.

Related pages

See also Claude Code Skills Examples, and AGENTS.md vs CLAUDE.md vs Cursor Rules.

What you will learn in this guide

  • MCP in plain words
  • Server vs client
  • A 10-line server
  • Test with the Inspector
  • Connect safely

1. Why: one plug for many tools

Without a standard, every AI app needs custom code for every tool. MCP is like a common plug: write a tool once and many AI apps can use it.

2. What: the parts

Part Meaning
MCP server Your program that offers tools, resources or prompts
MCP client The AI app that connects (e.g. Claude Desktop, VS Code)
Tool A function the AI can call
stdio transport Client starts your server as a local program
Inspector Official test UI for servers
First MCP server in five steps Steps from top to bottom: 1 Install Python SDK, pip install mcp; 2 Write one tool, FastMCP decorator; 3 Test in Inspector, mcp dev; 4 Add to an AI app, Config file; 5 Ask a question, AI calls the tool. 1Install Python SDKpip install mcp 2Write one toolFastMCP decorator 3Test in Inspectormcp dev 4Add to an AI appConfig file 5Ask a questionAI calls the tool

Figure 1. First MCP server in five steps: install the SDK, write one tool, test it, add it to an AI app, ask a question.

3. How: build it

  1. Install Python 3.10+ and create a virtual environment.
  2. Run pip install "mcp[cli]".
  3. Save the server code below as server.py.
  4. Test with mcp dev server.py (opens the Inspector).
  5. Add it to your AI app’s MCP settings and ask a question.

4. Notes

  • MCP is an open protocol with official SDKs (Python, TypeScript and more) at modelcontextprotocol.io.
  • Each client has its own config screen or file; follow its docs.

5. Worked example 1: install (start here)

In a new folder:

python3 -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install "mcp[cli]"

Expected output (yours will be similar, not the same):

Successfully installed mcp-1.x.x ...

6. Worked example 2: a 10-line server

Save as server.py:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("shop")

PRICES = {"pen": 10, "notebook": 45, "bag": 600}

@mcp.tool()
def price(item: str) -> str:
    """Return the price of a shop item in rupees."""
    p = PRICES.get(item.lower())
    return f"{item}: Rs {p}" if p else f"{item}: not found"

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

Prices here are made up.

7. Worked example 3: test and connect

Open the Inspector, then call the tool:

mcp dev server.py

Expected output (yours will be similar, not the same):

Inspector opens in your browser. Tools → price → item = notebook → Run
Result: notebook: Rs 45

Then add a server entry in your AI app with command python and args [path/to/server.py], and ask: “What is the price of a bag?”

Names, amounts and companies in the examples are made up for practice.

8. Common mistakes

Mistake Risk Fix
Installing random MCP servers Malware or data leak Trusted sources only
Putting secrets in code Leak Use env vars
No docstring on the tool AI misuses it Describe clearly
Wrong Python path in config Server fails Use full path
Giving write access too early Risky changes Start read-only

9. Try at home

Try at home

  1. Run the price server.
  2. Call it in the Inspector.
  3. Add one more tool.

Recap

In short

  1. MCP is a common plug between AI apps and tools.
  2. Server offers tools; client calls them.
  3. FastMCP makes a server in ~10 lines.
  4. Test with mcp dev.
  5. Install only trusted servers.

Write a tool once, use it in many AI apps.

Frequently asked questions

Do I need to pay for MCP?

No, the protocol and SDKs are open source. The AI app you connect may have its own plans.

Which apps support MCP?

Many, including Claude Desktop, Claude Code, VS Code with Copilot, Cursor and others. Check each app’s docs.

Can I write it in JavaScript?

Yes, there is an official TypeScript SDK.

Is it safe?

Only as safe as the server. Read the code or use trusted publishers.

Related: What Is MCP (Model Context Protocol)? Connect AI to Your Tools