𝗠𝗼𝗱𝗲𝗹 𝗖𝗼𝗻𝘁𝗲𝘅𝘁 𝗣𝗿𝗼𝘁𝗼𝗰𝗼𝗹 𝗘𝘅𝗽𝗹𝗮𝗶𝗻𝗲𝗱
If you connect an LLM to a database or an API, you write glue code. You write it for one model. Then you write it again for the next model. This creates a mess of integrations.
The Model Context Protocol (MCP) fixes this. It acts like a USB-C port for AI. Instead of custom cables for every device, everyone uses one standard connector.
MCP changes the math from M x N integrations to M + N.
- Tool authors write one MCP server.
- Application authors add one MCP client.
- Any host that speaks MCP can use any server.
The architecture has three roles:
• Host: The AI app you use, like Claude Code or an IDE. It decides which servers to connect to. • Client: The connector inside the host. It maintains the connection to the server. • Server: The program you build. It exposes tools, data, or prompts.
You use three main primitives:
- Tools: Functions the model calls to take action, like sending an email or querying a database.
- Resources: Read-only data the app pulls into context, like a file or a log.
- Prompts: Reusable templates that help users trigger specific tasks.
You can build a server in Python using the FastMCP SDK. Here is a simple example:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("demo-tools")
@mcp.tool() def word_count(text: str) -> int: """Count the words in a text.""" return len(text.split())
@mcp.resource("notes://team") def team_notes() -> str: """Expose team notes.""" return "Release freeze starts Friday."
@mcp.prompt() def code_review(language: str, code: str) -> str: """Template for reviewing code.""" return f"Review this {language} code: {code}"
if name == "main": mcp.run()
When you build servers, keep these rules in mind:
- Security: Use user approval for destructive tools. Validate all arguments.
- Context: Keep tool descriptions short. Long descriptions eat up your token budget.
- Errors: Return clear messages so the model can fix its own mistakes.
MCP makes tools a reusable asset. Write it once. Let every model use it.
Source: https://dev.to/galian/model-context-protocol-explained-build-your-first-mcp-server-in-python-ian
Optional learning community: https://t.me/GyaanSetuAi