𝗠𝗼𝗱𝗲𝗹 𝗖𝗼𝗻𝘁𝗲𝘅𝘁 𝗣𝗿𝗼𝘁𝗼𝗰𝗼𝗹 𝗘𝘅𝗽𝗹𝗮𝗶𝗻𝗲𝗱

Stop writing the same integration code over and over.

If you connect an LLM to a database or an API, you often write custom glue code for every new model. This creates a mess. You end up managing many connections for many tools.

The Model Context Protocol (MCP) fixes this. It acts like a USB-C port for AI. You build a tool once, and any model can use it.

The architecture has three parts:

• Host: The app you use, like Claude Code or an IDE. • Client: The connector inside the host. • Server: The program you build to expose data or tools.

You can build an MCP server using three main primitives:

  • Tools: Functions the model calls to do work, like sending an email.
  • Resources: Read-only data the app pulls in, like a log file.
  • Prompts: Reusable templates for specific tasks.

Here is how to build a basic server in Python using the FastMCP SDK:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("demo-tools")

@mcp.tool() def word_count(text: str) -> int: """Count 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 code reviews.""" return f"Review this {language} code: {code}"

if name == "main": mcp.run()

This code handles the complex communication for you. Your docstrings become the instructions for the model.

Three tips for production:

  1. Security: Always ask for user approval before running a tool that changes data.
  2. Context: Keep tool descriptions short. Long descriptions waste tokens.
  3. Errors: Return clear messages. A model can fix a "User not found" error, but it cannot fix a raw code crash.

Stop building bespoke connectors. Build an MCP server once and let every model use it.

Source: https://dev.to/galian/model-context-protocol-explained-build-your-first-mcp-server-in-python-ian