Skip to content
AI12 min read

Model Context Protocol (MCP) explained: what it is, how it works, and how to build a server

MCP is the open standard that lets AI apps like Claude, ChatGPT and Copilot plug into your tools and data the same way every time. Here is what it is, what an MCP server actually does, and how to build one in about twenty lines of Python.

By

Editor

Published

Updated

Cover image for “What is MCP?”: Model Context Protocol, explained, illustrated with an AI app connected to tools through MCP.

The short answer

MCP, short for Model Context Protocol, is an open standard for connecting AI applications to external systems such as files, databases, business apps and APIs. An MCP server exposes tools, data and prompt templates in one standard format, so any MCP-compatible app, including Claude, ChatGPT, Cursor and VS Code, can use them without a custom integration for each pair.

MCP, short for Model Context Protocol, is an open standard for connecting AI applications to external systems such as files, databases, business apps and APIs. An MCP server exposes tools, data and prompt templates in one standard format, so any MCP-compatible app, including Claude, ChatGPT, Cursor and VS Code, can use them without a custom integration for each pair.

Every useful AI assistant eventually hits the same wall: the model is smart, but your work lives somewhere it cannot reach. Your tickets are in Jira, your files in Google Drive, your data in Postgres. Before MCP, connecting an AI app to each of those meant a custom integration, rebuilt again for every other AI app you wanted to use. This guide explains how MCP fixes that, what an MCP server actually is, how MCP works step by step, the security questions to ask, and how to build a working server yourself.

What is MCP in AI?

The official documentation (opens in a new tab) describes MCP as an open-source standard that lets apps like Claude or ChatGPT connect to data sources, tools and workflows so they can access key information and perform tasks.

The docs compare MCP to a USB-C port for AI. Before USB-C, every device needed its own cable. Before MCP, every pairing of an AI app and a system needed its own connector. With a shared standard, a system only needs one MCP server to work with every compatible app, and an app only needs to support MCP once to reach every server.

A short history of MCP

  • November 2024: Anthropic announced MCP (opens in a new tab) as an open standard, releasing the specification, SDKs, local server support in the Claude desktop apps, and open-source servers for Google Drive, Slack, GitHub, Git, Postgres and Puppeteer.
  • 2025: Adoption spread beyond Anthropic. ChatGPT, Gemini, Microsoft Copilot, Cursor and Visual Studio Code all added support.
  • December 2025: Anthropic donated MCP to the Agentic AI Foundation (opens in a new tab), a fund under the Linux Foundation co-founded with Block and OpenAI. At that point there were more than 10,000 active public MCP servers and over 97 million monthly SDK downloads across Python and TypeScript.
  • July 2026: Protocol version 2026-07-28 made MCP stateless, so every request carries the information needed to handle it. That makes remote servers simpler to scale.

MCP architecture: hosts, clients and servers

MCP uses a client-server design with three participants, described in the architecture overview (opens in a new tab):

  • MCP host: the AI application you work in, such as Claude Desktop, Claude Code or VS Code. It coordinates one or more MCP clients.
  • MCP client: a connector inside the host. The host creates one client for each server it connects to, and each client keeps a dedicated connection to its server.
  • MCP server: the program that provides context and capabilities, such as a GitHub server, a database server or a file system server.

Under those participants sit two layers. The data layer defines the messages, built on JSON-RPC 2.0: discovery, the primitives a server offers, and notifications. The transport layer carries those messages. MCP defines two transports: stdio, which uses standard input and output between processes on the same machine, and Streamable HTTP, which uses HTTP POST (with optional Server-Sent Events for streaming) for servers on the network. For remote servers the docs recommend OAuth to obtain access tokens. The message format is the same on both transports.

What is an MCP server?

An MCP server is a program that provides context to AI applications. It sits in front of one system, such as GitHub, a database or your file system, and tells any connected app what it may do there: which tools it can call, which data it can read and which prompt templates it offers. The AI app talks to the server, and the server talks to the system.

MCP server diagram: an MCP host creates one MCP client per server, one connected to a local MCP server over stdio and one to a remote MCP server over Streamable HTTP, each exposing tools, resources and prompts in front of a real system
One host, one client per server. Each MCP server exposes tools, resources and prompts for the system behind it.

"Server" describes the role, not the location. A local server runs on your own machine over stdio and typically serves a single client, which is how the official file system server works. A remote server runs on the vendor's platform over Streamable HTTP and typically serves many clients, which is how Sentry's hosted server works.

The three core MCP server primitives
PrimitiveWhat it isExample
ToolsFunctions the AI can call to take an actionCreate a GitHub issue, run a SQL query, send a Slack message
ResourcesData the AI can read for contextA file's contents, a database schema, a record from a CRM
PromptsReusable templates for common tasksA code review checklist, a bug report template

Clients can offer one primitive back. Elicitation lets a server ask the user for more information mid-task, for example to confirm an action. At the time of writing, the 2026-07-28 protocol version deprecates two older client features, roots and sampling, along with protocol logging, so you may still see them in older servers and tutorials.

How does MCP work?

Here is what happens when you ask an AI app to use a connected server, from setup to result. The example uses a GitHub server with a create_issue tool.

  1. The host connects. For each configured server, the host creates an MCP client. The client can send an optional server/discover request to learn the server's supported protocol versions and capabilities. Because MCP is stateless, every request also carries the protocol version and the client's capabilities.
  2. The client lists what the server offers. A tools/list request returns each tool's name, description and input schema, written in JSON Schema. The host merges the tools from all its servers into one list the model can see.
  3. You ask for something. For example: "Open an issue for the login bug we discussed."
  4. The model picks a tool. It matches your request to the create_issue description and drafts arguments that fit the schema, such as a title and a description.
  5. The host calls the tool. Usually after asking you to approve it, the host sends a tools/call request with the tool name and arguments through the GitHub client.
  6. The server does the work. It calls GitHub's API, creates the issue and returns the result, such as text with the issue link, which the model uses in its reply.
  7. Changes stay in sync. If the server's tools change later, a client that subscribed to updates receives a notifications/tools/list_changed message and fetches the list again.

Real test results: what MCP messages actually look like

Most explainers stop at diagrams. To see the real traffic, we ran the word-count server from the build section below on version 2.3 of the official Python SDK and talked to it over stdio by hand, one JSON line at a time, on 28 November 2026. Every MCP message is a JSON-RPC 2.0 (opens in a new tab) object. Here is the current, stateless 2026-07-28 flow, trimmed slightly for width.

A real server/discover and tools/call exchange on SDK 2.3 (>> is the client, << is the server)
>> {"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{
     "io.modelcontextprotocol/protocolVersion":"2026-07-28",
     "io.modelcontextprotocol/clientCapabilities":{}}}}
<< {"jsonrpc":"2.0","id":1,"result":{"supportedVersions":["2026-07-28"],
     "capabilities":{"tools":{"listChanged":true},"resources":{...},"prompts":{...}},
     "cacheScope":"private","ttlMs":0,"resultType":"complete",
     "_meta":{"io.modelcontextprotocol/serverInfo":{"name":"word-tools","version":""}}}}

>> {"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"_meta":{...same envelope...},
     "name":"count_words","arguments":{"text":"hello there MCP world"}}}
<< {"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"4 words, 21 characters"}],
     "structuredContent":{"result":"4 words, 21 characters"},"isError":false,"resultType":"complete"}}

Three things stood out that a spec summary does not make obvious:

  • The version travels in every request. There is no session to set up. Each call carries the protocol version and the client's capabilities in _meta. When we left out clientCapabilities, the server refused the call with JSON-RPC error -32602 and named the missing key.
  • Old clients still work. When we sent the older initialize handshake instead, the same server answered with protocol version 2025-11-25 and then rejected server/discover as "Method not found". A server on SDK 2.3 serves both kinds of client, but a tutorial written for the old handshake will not show you the new envelope.
  • Type hints become the contract. tools/list returned an input schema with text marked required, plus an output schema, both generated from the Python function. Nobody wrote JSON Schema by hand.

What happens when the model sends bad arguments

We then called the tool with no text argument, the kind of mistake a model makes when a tool description is vague. The server did not crash and did not return a protocol error. It returned a normal result flagged isError: true, with the validation message inside.

A missing argument comes back as a tool result, not a protocol error
>> {"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"count_words","arguments":{}}}
<< {"jsonrpc":"2.0","id":4,"result":{"isError":true,"content":[{"type":"text",
     "text":"Error executing tool count_words: 1 validation error for count_wordsArguments\ntext\n  Field required [type=missing, input_value={}, input_type=dict]"}]}}

That design matters: because the error arrives as content, the model can read it and retry with corrected arguments. Protocol errors are reserved for broken requests, such as an unknown method. When you write your own tools, return clear, specific error text the same way, because the model, not a person, is the one reading it.

What MCP is used for

  • Coding assistants that read your repository, run tests, open pull requests and check error trackers.
  • Personal assistants that read your calendar, email and notes. The MCP docs give the example of agents that access Google Calendar and Notion.
  • Enterprise chat that queries several internal databases in one conversation.
  • Workflow automation: chaining tools from different systems, such as reading a support ticket, checking the customer's account and drafting a reply.
  • Design to code: the docs mention Claude Code generating a web app from a Figma design through MCP.

MCP is a big part of why AI is shifting from answering questions to doing work. Tools are what turn a model into an agent, a difference we explain in agentic AI vs generative AI.

Advantages of MCP

  • Build once, use everywhere. A single MCP server works with every compatible AI app.
  • Less custom glue code. Developers stop rewriting the same integration for each assistant or framework.
  • Switch models freely. Because the protocol is model-agnostic, you can change AI providers without rebuilding your integrations.
  • Discoverable capabilities. Apps learn what a server can do at run time, so new tools appear without app updates.
  • A large ecosystem. Thousands of existing servers cover common tools, so you often only need to install one.
  • Open governance. MCP is managed under the Linux Foundation rather than by a single vendor.

MCP vs APIs, plugins and Skills

MCP does not replace APIs; most MCP servers call an existing API behind the scenes. What MCP adds is a standard description of that API's capabilities that any AI app can understand. Compared with the app-specific plugin systems that came before it, MCP is shared across vendors.

It also pairs well with Claude Skills. MCP gives an AI access to a system. A Skill teaches it how to do a task well with that access, such as your team's rules for writing release notes.

MCP security: what to watch for

Connecting an AI app to real systems means mistakes and attacks can have real effects. The specification's security best practices (opens in a new tab) cover the main risks:

  • Untrusted local servers. A local server runs with your user's permissions, so a malicious one can read files or run commands. The spec requires clients to show the exact command and get your approval before adding a server through one-click setup.
  • Over-broad permissions. Tokens with sweeping scopes increase the damage if they leak. The spec recommends starting with minimal scopes and asking for more only when a tool needs them.
  • Token passthrough. Servers must not accept tokens that were not issued for them, a shortcut that breaks audit trails and security controls.
  • Server-side request forgery. A malicious remote server can try to make a client fetch internal URLs, so clients should require HTTPS and block private network addresses.

How to build an MCP server

The official build a server tutorial (opens in a new tab) covers Python, TypeScript, Java, Kotlin, C#, Ruby and more. Here is the shortest useful version in Python, using the MCPServer class from the official SDK. It exposes one tool that counts words in a piece of text.

1. Set up the project

Create a project with uv and install the MCP Python SDK
uv init word-tools
cd word-tools
uv add "mcp[cli]"

2. Write the server

server.py: the type hints and docstring become the tool's schema and description
from mcp.server import MCPServer

mcp = MCPServer("word-tools")


@mcp.tool()
def count_words(text: str) -> str:
    """Count the words and characters in a piece of text.

    Args:
        text: The text to analyze
    """
    words = len(text.split())
    return f"{words} words, {len(text)} characters"


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

The SDK turns the function's type hints and docstring into the tool definition automatically. One rule catches almost everyone: a stdio server must never write to standard output, so no print() calls. Stdout carries the protocol messages, and stray output corrupts them. Log to stderr instead. In our test, version 2.3 of the Python SDK now guards against this: we added a print("debug") inside the tool and the text was diverted to stderr while the reply stayed valid. Older SDK versions and other languages do not all do this, so keep the habit. We ran this exact server against version 2.3 of the Python SDK: listing tools returns count_words, and calling it with "hello there MCP world" returns "4 words, 21 characters". If you are following an older tutorial, note that SDK 2.x renamed FastMCP to MCPServer.

3. Connect it to Claude Desktop

Open claude_desktop_config.json (on macOS in ~/Library/Application Support/Claude/, on Windows in %AppData%\Claude\), add the server under mcpServers, and restart the app:

Use the absolute path to your project folder
{
  "mcpServers": {
    "word-tools": {
      "command": "uv",
      "args": ["--directory", "/ABSOLUTE/PATH/TO/word-tools", "run", "server.py"]
    }
  }
}

Ask Claude to count the words in a paragraph and it will offer to call your tool. From here, swap the word counter for something useful: a lookup in your internal database, a call to your company's API, or a search over your documentation. The MCP Inspector (opens in a new tab) lets you test tools without an AI app in the loop.

Limitations of MCP

  • Quality varies. Anyone can publish a server, and many community servers are thin wrappers with little error handling or security review.
  • Too many tools hurt. Connecting dozens of servers floods the model with tool descriptions and makes it pick worse. Connect what a task needs.
  • It moves fast. The 2026-07-28 version changed core mechanics such as statelessness and deprecated features like sampling, so older tutorials and servers may not match the current spec.
  • It is plumbing, not judgment. MCP gets an AI to your systems. Whether it uses them well still depends on the model, the prompt and your guardrails.

The bottom line

MCP has become the default way to connect AI applications to the rest of your software. For most people that means turning on ready-made connectors in the apps they already use. For developers it means writing one server per system instead of one integration per app. Start with read-only tools from trusted sources, keep approvals on for anything that writes, and build your own server when an internal system has none. For more on the models and agents that use MCP, browse our AI guides.

Common questions

What does MCP stand for in AI?

MCP stands for Model Context Protocol. It is an open protocol, introduced by Anthropic in November 2024 and now governed under the Linux Foundation's Agentic AI Foundation, that standardizes how AI applications connect to tools and data.

What is an MCP server in simple terms?

An MCP server is a small program that sits in front of a system, such as GitHub, a database or your file system, and describes what an AI app may do with it: which tools it can call, which data it can read and which prompt templates it offers. The AI app connects to it instead of to the system directly.

Is MCP only for Claude?

No. Anthropic created MCP, but it is an open standard. ChatGPT, Gemini, Microsoft Copilot, Cursor and Visual Studio Code are among the platforms that support it, so one MCP server can work across all of them.

What is the difference between MCP and an API?

An API is the interface a single service exposes. MCP is a common layer on top of many APIs that describes tools and data in a way any AI application understands. An MCP server usually calls an existing API behind the scenes.

Is MCP secure?

The protocol includes OAuth-based authorization for remote servers, but security depends on how servers and clients are built and which servers you install. Only connect servers you trust, give them the narrowest permissions possible, and require approval before an AI app runs tools that change data.

Do I need to code to use MCP?

No. Most AI apps let you add ready-made MCP servers or connectors from a settings screen. Coding is only needed to build your own server for an internal system that has no existing one.

Sources

  1. JSON-RPC 2.0 Specification, JSON-RPC Working Group
  2. What is the Model Context Protocol (MCP)?, Model Context Protocol
  3. Architecture overview, Model Context Protocol
  4. Introducing the Model Context Protocol, Anthropic
  5. Donating the Model Context Protocol and establishing the Agentic AI Foundation, Anthropic
  6. Security Best Practices, Model Context Protocol Specification
  7. Build an MCP server, Model Context Protocol
  8. MCP Inspector, GitHub, modelcontextprotocol

Revision history

  • : Added a tested section showing the real JSON-RPC messages from a running server on Python SDK 2.3: the stateless 2026-07-28 flow, the fallback for older clients, and how bad arguments are returned. Noted that the SDK now diverts stray print() output to stderr.
  • : Opened with a direct answer to what MCP is, added a "What is an MCP server?" section with a diagram, rewrote "How does MCP work?" as numbered steps, and checked the architecture against the current MCP docs.

About A. Farooq

Qualified software engineer with 4+ years of experience in the software industry

A. Farooq is a qualified software engineer with 4+ years of experience in the software industry. A. Farooq edits GeeklyPlug and writes many of its AI and technology guides, from how AI agents are built to which laptop to buy and when. Every article lists its sources and shows when it was last updated; corrections go on the original piece.

mcpmodel context protocolai agentsclaude

Keep reading

More from AI, then the rest of the archive.