Monday , November 30 2026
What the Model Context Protocol (MCP) is, hosts, clients and servers, a Python MCP server example, the 2026-07-28 stateless spec and security tips.

Model Context Protocol (MCP) Explained: Build an MCP Server in Python

Updated: 29 November 2026Level: IntermediateReading time: about 10 minutesMCP spec 2026-07-28

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 pair of AI app and service, a developer builds one MCP server (for GitHub, a database, Google Drive…) and any MCP-compatible client – Claude, ChatGPT, IDEs, agent frameworks – can use it.

What You Will Learn

  • The problem MCP solves
  • Hosts, clients and servers
  • Tools, resources and prompts
  • Build a small MCP server in Python
  • What changed in the 2026-07-28 specification
  • Security considerations

Prerequisites

Function Calling.

Why MCP?

Without a standard, M AI apps and N tools need M × N custom integrations. MCP turns that into M + N: each app implements the client side once and each tool implements a server once – similar to how USB-C standardised device connections. Anthropic introduced MCP in November 2024; it is now governed by the Agentic AI Foundation under the Linux Foundation.

Architecture

Part Role Example
Host The AI application the user interacts with Claude Desktop, an IDE, your agent
Client Connector inside the host that talks to one server One per connected server
Server Exposes capabilities over JSON-RPC GitHub, Postgres, filesystem, Slack servers
Server feature What it provides Controlled by
Tools Functions the model can call (search, create issue) Model
Resources Read-only context (files, records) Application / user
Prompts Reusable prompt templates User

A Minimal Server in Python

Python MCP SDK (not run here)
# pip install "mcp[cli]"
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("course-helper")

@mcp.tool()
def course_fee(course: str) -> str:
    """Return the fee for a course offered by the institute."""
    fees = {"python": "₹8,000", "data science": "₹25,000", "generative ai": "₹30,000"}
    return fees.get(course.lower(), "Course not found")

@mcp.resource("syllabus://{course}")
def syllabus(course: str) -> str:
    """Syllabus text for a course."""
    return f"Syllabus for {course}: basics, projects, interview prep."

if __name__ == "__main__":
    mcp.run()          # stdio transport by default; HTTP transports are also available

Explanation: Type hints and docstrings become the tool’s JSON Schema and description automatically. A host such as Claude Desktop or an IDE is configured with the command that starts this server; the model can then call course_fee like any other tool. Test servers with the MCP Inspector (mcp dev server.py).

The 2026-07-28 Specification

The latest revision, released on 28 July 2026, is the biggest change since launch. Key points:

  • Stateless core: each request carries its protocol version and client capabilities, so it can be served by any server instance behind an ordinary load balancer – easier serverless and edge deployment.
  • Header-based routing (e.g. Mcp-Method, Mcp-Name) so infrastructure can route without reading the body.
  • Multi round-trip requests for interactions that need extra user input.
  • Hardened OAuth authorization, a formal extensions framework and a feature-deprecation policy.

Older session-based servers keep working for now, but new servers should follow the current spec and an up-to-date SDK.

Security

  • Install servers only from trusted sources – a server can run code and read data.
  • Give least-privilege credentials (read-only database users, scoped tokens).
  • Watch for prompt injection: text returned by a tool (a web page, an issue comment) may try to instruct the model.
  • Require human approval for destructive tools.

MCP vs Function Calling vs A2A

Function calling MCP A2A
What API feature of one model provider Open protocol between apps and tools Protocol between agents
Tools defined Per app, per API Once, in a reusable server Agents advertise skills
Use when One app, few tools Many tools or many AI clients Agents from different vendors collaborate

Series

Generative AI series: Intro to GenAI · LLM Fundamentals · Tokenization · Embeddings · Prompt Engineering · RAG · Vector DBs · Function Calling · AI Agents · Agent Frameworks · MCP · Hallucinations · Run LLMs Locally · Diffusion Models

Interview Questions

Q: What problem does MCP solve?
It standardises how AI apps connect to tools and data, replacing M×N custom integrations with M+N.

Q: Tools vs resources in MCP?
Tools are actions the model can call; resources are data the application can read into context.

Q: What was the main change in MCP 2026-07-28?
A stateless protocol core where every request is self-contained, enabling horizontal scaling.

Practice Exercises

  1. Build an MCP server with a tool that searches a CSV of your products.
  2. Connect it to an MCP-capable client and ask questions about the data.

Summary

MCP is the open standard that lets any AI client use any tool server. Build servers with the official SDKs, follow the 2026-07-28 stateless spec and apply least privilege.

Next: AI Agent Frameworks

About Machine Learning

Check Also

LLM Hallucinations and Prompt Injection: Causes and Fixes

Why LLMs hallucinate, types of hallucination, techniques like RAG and grounding to reduce them, prompt injection risks and a safety checklist for LLM apps.