What is the Model Context Protocol (MCP)? Build your first MCP server in Python

By [PLACEHOLDER: Author name], [PLACEHOLDER: Author role] · Last updated: 22 November 2026

[DRAFT – trainer to review] This article is not published yet and is hidden from search engines.

Summary: MCP is an open standard that lets any compatible AI app use your tools and data through one server. Below: the core concepts and a working Python server with one tool and one resource.

What is MCP?

The Model Context Protocol (MCP) is an open standard for connecting AI applications to tools and data. Instead of writing a custom integration for every app and every tool, you write an MCP server once, and any MCP-compatible client (a chat app, an IDE assistant, your own agent) can discover and use it. It was introduced by Anthropic in November 2024 and is now supported by many AI tools.

The three parts

  • Host: the AI application the user works in.
  • Client: the connector inside the host that talks to one server.
  • Server: your program, which exposes capabilities.

A server can expose three kinds of capability:

  • Tools: functions the model can call, such as "look up an order" or "run this SQL query".
  • Resources: read-only data the app can load into context, such as a file or a record.
  • Prompts: reusable prompt templates the user can pick.

Servers usually run locally over stdio (the host starts your script) or remotely over HTTP.

Build your first MCP server in Python

Install the official Python SDK:

pip install "mcp[cli]" httpx

This server exposes one tool that fetches the next batch date from a course API, and one resource with a short course description. Replace the URL with any API you own.

# server.py
import httpx
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("course-helper")

API = "https://www.vipracubeai.com/api/batches/next"

@mcp.tool()
async def next_batch(program: str = "fullstack-generative-ai-developer") -> str:
    """Return the start date of the next batch for a course program slug."""
    async with httpx.AsyncClient(timeout=10) as client:
        r = await client.get(API, params={"program": program})
    if r.status_code == 404:
        return "No upcoming batch is scheduled for this program."
    r.raise_for_status()
    return f"The next batch starts on {r.json()['start_date']}."

@mcp.resource("course://{program}/summary")
def course_summary(program: str) -> str:
    """A one-line description of a course program."""
    summaries = {
        "fullstack-generative-ai-developer":
            "12 weeks: Python & backend, ML & deep learning, then Generative AI and agents.",
    }
    return summaries.get(program, "Unknown program.")

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

The function name, type hints and docstring become the tool's name, input schema and description, which is what the model reads when deciding whether to call it. Write docstrings for the model, not just for humans.

Test it

The SDK ships with a browser-based inspector for calling your tools by hand:

mcp dev server.py

To use it from a desktop AI app that supports MCP, add the server to that app's MCP configuration with the command that starts it, for example python /full/path/to/server.py, then restart the app.

Security basics

  • Least privilege. Expose narrow tools ("get order status"), not general ones ("run any SQL").
  • Validate every input inside the tool, exactly as you would for a public API.
  • Ask before acting. Tools that send email, spend money or delete data should require user confirmation in the host.
  • Treat tool output as untrusted. Text returned from the web or documents can contain prompt-injection attempts.
  • Only install servers you trust, because a local server runs with your permissions.

Where MCP fits with LangChain and LangGraph

MCP standardises how tools are exposed; frameworks like LangGraph decide how an agent uses them. Adapters let LangChain and LangGraph agents load tools from MCP servers, so one server can serve your own agent and off-the-shelf AI apps alike.

FAQ

Is MCP only for Claude?

No. MCP is an open protocol, and many AI applications and frameworks support it.

What is the difference between an MCP tool and function calling?

Function calling is how a model asks to run a function. MCP is a standard way to package and share those functions so any compatible app can discover and call them.

Do I need to know FastAPI to build an MCP server?

No. The Python SDK handles the protocol. Knowing how to write clean Python functions with type hints is enough to start.