Skip to content

What is MCP? Explained Simply (Then We Build One in Python)

MCP (Model Context Protocol) explained in plain words: the problem it solves, host, client and server, tools, resources and prompts, and MCP vs function calling. Then we build our own MCP server in Python, for free.

Mahnoor 6 min read 12-item prompt pack

If you use AI tools like Cursor, Claude Code or Gemini, they are already using MCP behind the scenes. Whenever they connect to your GitHub, your database or your files, MCP is usually what is doing that. In this lesson we explain what MCP is in plain words, how it works, and then we build our own MCP server in Python, for free, in about 30 lines.

The problem MCP solves

Think about phone chargers a few years ago. Every phone had its own charger, so three phones meant three different cables. AI apps had exactly the same problem. If you built a tool that reads your files, you had to connect it one way for Claude, write it again for Cursor, and write it all over again when a new AI app came out.

Now imagine five AI apps and ten tools. That is 50 different connections, and every single one is written by hand.

What MCP is

MCP stands for Model Context Protocol. A protocol is just an agreement about how two things talk to each other. MCP fixes the charger problem the same way USB-C did: everyone agrees on one plug. You build your tool once as an MCP server, and every AI app that speaks MCP can use it. Five apps and ten tools are not 50 connections anymore, they are just 15 plugs.

The three parts: host, client, server

  • Host: the AI app you are using, like Claude Desktop, Cursor or VS Code.

  • Client: lives inside the host, and its only job is to talk to the servers.

  • Server: where your tools actually live.

A server can share three kinds of things: tools the AI can call (like "run this file"), resources the AI can read (like your files or a database), and prompts, which are ready-made instructions you can reuse.

MCP vs function calling

A lot of people mix these up. Function calling is how the model asks for a tool: it sends back a short message saying which tool it wants (we explain it with a Python example in What is function calling?). MCP is how that tool gets plugged into the app in the first place.

When the app starts, the client asks the server "what tools do you have?". The server sends back the name and description of every tool, and the app shows that list to the model. When the model asks for a tool, the client sends the call to the server, the server runs it, and the result goes back to the model. So function calling is the question, and MCP is the plug that makes any tool available to any app.

Build an MCP server in Python

We turn the four tools of a coding agent (list files, read file, write file and run python) into an MCP server. If you want to see how those tools work inside an agent first, watch Build Your Own AI Coding Agent in Python.

mkdir mcp-demo
cd mcp-demo
python -m venv .venv
.venv\Scripts\activate
pip install mcp

mcp is the official MCP package for Python. Now create server.py:

import os
import subprocess
import sys

from mcp.server.mcpserver import MCPServer

FOLDER = os.path.join(os.path.dirname(os.path.abspath(__file__)), "project")  # tools only touch this folder
mcp = MCPServer("coding-tools")


@mcp.tool()
def run_python(filename: str) -> str:
    """Run a Python file and get back everything it printed, including any error."""
    result = subprocess.run([sys.executable, os.path.basename(filename)], cwd=FOLDER,
                            capture_output=True, text=True, timeout=10)
    return (result.stdout + result.stderr)[-2000:] or "Ran with no output."


if __name__ == "__main__":
    mcp.run()  # talks to the AI app over stdin/stdout

If you see FastMCP in older tutorials, it is the same thing; it was renamed to MCPServer in version 2 of the package.

Here is the best part: a tool is just a normal Python function with @mcp.tool() on top. The function name becomes the tool name, the docstring becomes the description the AI reads, and the type hints become the parameters. So you do not write a long tool description by hand anymore; MCP builds it from your function. The other three tools work exactly the same way.

mcp.run() starts the server and talks to the AI app through standard input and output. You do not run this file yourself; the AI app starts it for you.

Test it like an AI app

A small client.py plugs into the server exactly like an AI app does: it asks for the tool list, then calls run_python on a broken file. The real output:

- list_files: List the files in the project folder.
- read_file: Read the full text of a file in the project folder.
- write_file: Replace a file in the project folder with new text. Always write the whole file.
- run_python: Run a Python file and get back everything it printed, including any error.
  File "...\mcp-demo\project\marks.py", line 23
    print(f"{row['name']}: {avg:.1f} ({grade(avg)})"
         ^
SyntaxError: '(' was never closed

The four descriptions came straight from our docstrings, and the tool ran a real file and sent back the real error. That is exactly what the model sees, so any AI app can now use these tools to read the code, fix it and run it again.

Use it in a real AI app

Add your server to the app's MCP settings with the command that starts it. In our test, Gemini CLI showed the server as connected straight away, and the same server works in any app that speaks MCP, like Claude Desktop, Cursor or VS Code.

One honest safety note

An MCP server runs on your computer with your permissions, so it can read your files and run code. Only install servers from people you trust, and read what the tools actually do before you plug them in. To understand the bigger picture of agents and tools, see Chatbot vs LLM vs AI Agent.

Prompt pack

Every prompt from this lesson

Turn my Python function into an MCP tool
Here is a Python function from my project:
[paste your function]

Turn it into an MCP tool using the official Python package (mcp, MCPServer, @mcp.tool()).
Give me:
1. The full server.py with this function as a tool.
2. A clear docstring, because it becomes the description the AI reads.
3. Type hints for every parameter, because they become the tool's parameters.
4. One safety limit (for example: only touch files in one folder, or a timeout).
Explain each new line in one short sentence. Keep it beginner friendly.
Explain MCP back to me (quiz)
Quiz me on MCP (Model Context Protocol), one question at a time, 5 questions, from easy to hard.
Cover: the problem MCP solves, host vs client vs server, tools vs resources vs prompts, and MCP vs function calling.
Wait for my answer each time. Tell me what I got right, fix what I got wrong in one or two sentences, then move on.
End with a score out of 5 and the one idea I should review.
Link Official MCP Python SDK (docs + examples) (opens in new tab)

9 more items in the full pack

Free. Sign in once and every prompt pack on Morow Global unlocks.

Sign in free to unlock

Already a member? Sign in

FAQ

What is MCP in simple words?

MCP (Model Context Protocol) is one standard plug between AI apps and tools. You build a tool once as an MCP server, and every AI app that speaks MCP, like Claude Desktop, Cursor or VS Code, can use it.

What is the difference between MCP and function calling?

Function calling is how the model asks for a tool: it sends back a message saying which tool it wants. MCP is how that tool gets plugged into the app in the first place, so any app can discover and call it.

What are the host, client and server in MCP?

The host is the AI app you use. The client lives inside the host and talks to the servers. The server is where your tools live, and it can share tools, resources and prompts.

Is FastMCP the same as MCPServer?

Yes. In version 2 of the official Python package, FastMCP was renamed to MCPServer (from mcp.server.mcpserver import MCPServer). Older tutorials still show FastMCP.

Is it safe to install MCP servers?

Only if you trust them. An MCP server runs on your computer with your permissions, so it can read files and run code. Read what its tools do before you plug it in, and try it in a test folder first.

#MCP #beginners #AI agents #Tool calling #Python #Model Context Protocol