What MCP Is: Your First Tool
An AI assistant becomes far more useful once it can reach things outside the conversation: your files, a task list, a database, a service at work. The Model Context Protocol, or MCP, is an open standard for that connection: a small program written once gives its abilities to any assistant that speaks the protocol, and in Python such a program can be as short as a single function.
One connector per pair, or one protocol for all
Picture three AI applications: a chat assistant, a code editor with an assistant built in, and a coding agent in the terminal. Each of them would like to use the same three systems: a code host such as GitHub, a company database and a calendar. Before a shared standard existed, every application had to write its own connector for every system, in its own way. Three applications and three systems meant nine separate pieces of integration code. Each new application then needed three more connectors, one per system, and each new system needed one more connector in every application. Anthropic described it plainly when it released MCP in November 2024: every new data source required its own custom implementation.
MCP replaces those private connectors with one protocol, a fixed set of messages both sides agree on. A system is wrapped once in a small program called an MCP server. An application learns to speak MCP once. From then on, any application that speaks MCP can use any MCP server, including servers written years later by people it has never heard of. The official documentation compares it to a USB-C port: one kind of socket, and any device that has the plug fits.
- Chat assistant
- Code editor
- Coding agent
- Code host
- Database
- Calendar
- Chat assistant to Code host
- Chat assistant to Database
- Chat assistant to Calendar
- Code editor to Code host
- Code editor to Database
- Code editor to Calendar
- Coding agent to Code host
- Coding agent to Database
- Coding agent to Calendar
- Chat assistant speaks MCP
- Code editor speaks MCP
- Coding agent speaks MCP
- MCP one shared protocol
- Code host MCP server
- Database MCP server
- Calendar MCP server
- Chat assistant to MCP
- Code editor to MCP
- Coding agent to MCP
- MCP to Code host
- MCP to Database
- MCP to Calendar
The box in the middle of the second picture is the protocol itself, not a program the messages pass through: an application still connects straight to each server it uses, but every one of those connections follows the same rules. The first picture needs nine different integrations. The second needs six pieces of work: three applications that speak MCP and three servers. A new server then works with every application at once. That is why a developer who writes one MCP server can offer it to many AI applications without writing anything special for any of them.
MCP was created at Anthropic and is now an open project under the Linux Foundation, and the messages it defines are written in JSON-RPC 2.0, a small standard format for requests and responses in JSON.
True or false?
An MCP server written for one AI application has to be rewritten before another application can use it.
False. Both applications speak the same protocol, so the same server works with each of them unchanged. Removing that rewriting is the point of MCP.
MCP is a protocol: an agreed set of messages, not a product or a library you must buy into.
True. MCP is an open specification. Libraries in many languages implement it, but any program that sends and answers its messages takes part.
Hosts, clients and servers
Every MCP setup has three roles, and the names are easy to mix up, so it helps to attach each one to something concrete.
- The host is the AI application the user works in: a chat app such as Claude Desktop, an editor such as VS Code, a coding agent such as Claude Code. It holds the conversation with the model and decides what the model gets to see and do.
- A client is a component inside the host that holds the connection to one server. It sends that server requests and brings back its answers for the host to use.
- A server is a program that offers capabilities, such as tools to call or data to read, to any client that connects.
The official example uses VS Code as the host. When VS Code connects to a server for the Sentry error-tracking service, it creates one client for that connection. When it also connects to a server that gives access to files on the local disk, it creates a second client. A host with five servers has five clients, each with its own dedicated connection.
- User
- The model
- Client 1
- Client 2
- Sentry server over the network
- Filesystem server same machine
- User to The model: asks
- The model to Client 1
- The model to Client 2
- Client 1 to Sentry server: MCP
- Client 2 to Filesystem server: MCP
The word server can be misleading. An MCP server is the program that offers capabilities, wherever it runs. Some run on another machine and are reached over the network. Many run on the same computer as the host: the host starts the server program itself and talks to it directly, and such a local server usually serves just that one client. Writing your first server means writing one of these local programs, and you need no web hosting for it.
True or false?
In a setup where a chat application uses two MCP servers, the chat application is the client.
False. The application is the host. It contains two clients, one per server.
A host connected to three servers holds three clients, each with its own connection.
True. The host creates one client per server, and each client keeps a dedicated connection to its server.
An MCP server must run on a remote machine.
False. A server is a program wherever it runs. Many servers run on the same machine as the host, which starts them itself.
Tools, resources and prompts
A server can offer three kinds of things. What separates them is less what they contain than who decides to use them: the model, the application or the user.
| What the server offers | Who decides to use it | Example |
|---|---|---|
| Tools: functions that do something | The model | Search the code host, write a file, add a task |
| Resources: data to read | The application | The contents of a file, the history of a repository |
| Prompts: ready-made message templates | The user | A command the user picks from a menu or types as a slash command |
A tool is an action. The host shows the model the list of tools with a description of each, and while it answers the user, the model decides on its own whether calling one would help and with which values. Because a tool can change things in the world, the specification asks hosts to keep a human in the loop: the user can approve or refuse a call before it runs.
A resource is data the application reads and places in the model's context (the text the model sees while it answers), for example a file the user attached. The application chooses which resources to load; the model does not call them as actions.
A prompt is a template the user starts deliberately, such as a "review this code" command. The user decides when it is used, while its wording comes from the server.
Of the three, a tool is the quickest way to see a server do something, so the rest of this page stays with tools.
True or false?
The user has to tell the model each time it should call a tool.
False. Tools are model-controlled: the model decides when a call would help. The host may ask the user to approve the call, but the choice to call comes from the model.
A prompt is called user-controlled because the user picks when to use it, even though the server wrote its text.
True. User-controlled refers to who decides when the prompt is used, not who wrote it. The content of a prompt is defined by the server.
A tool is a function with a description
To be useful to a model, a tool needs three pieces of information: a name to call it by, a description that says what it does, and a list of parameters with the type of each, so the caller knows what values to pass. The protocol carries the parameters as an input schema, a description of the expected arguments written in the JSON Schema format.
A Python function already holds all three. The official mcp Python SDK (a software development kit: the library that implements the protocol for you) reads them straight from the function. Here is a complete server with one tool:
from mcp.server import MCPServer
mcp = MCPServer("Demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
if __name__ == "__main__":
mcp.run()Line by line, from the top. MCPServer("Demo") creates a server named Demo.
The line @mcp.tool() just above the function is a decorator. It hands the function to the server, which registers it as a tool. The function itself stays as it is.
The text in triple quotes right under the def line is the function's docstring, its built-in description.
a: int and b: int are type hints. They state that each parameter expects a whole number, and -> int states that the function returns one. Python itself does not check type hints when it runs ordinary code. The SDK reads them, though, and so they become part of what the server announces.
| In the function | In the tool | For this example |
|---|---|---|
| Function name | Tool name | add |
| Docstring | Description the model reads | Add two numbers. |
| Parameters and type hints | Input schema | a and b, both integers, both required |
You never write the schema by hand: change the function and the tool changes with it. A parameter without a default value becomes a required argument, which is why both a and b are required here.
The decorator also accepts name= and description= when you want the tool to differ from the function, but the defaults are usually what you want. That has a consequence. The function name and the docstring are now text a model reads to decide when to call the tool, so they deserve the same care as a message to a colleague.
The last two lines start the server. mcp.run() keeps the program running and answers requests until it is stopped. With no argument it uses stdio, the standard input and output of the process. That is how a host talks to a server it started on the same machine. The guard if __name__ == "__main__": runs the server only when the file is executed as a program, not when another program imports it.
A note on names you will meet: in the 1.x versions of this SDK, and in many older tutorials, the server class was called FastMCP. Version 2 renamed it MCPServer, and the old import no longer works. FastMCP is also the name of a separate, independent framework for building MCP servers, so a tutorial that imports FastMCP uses either the old SDK or that other framework.
True or false?
With the SDK, the description a model sees for the add tool comes from its docstring.
True. The SDK takes the tool name from the function name, the description from the docstring and the input schema from the type hints.
Besides the function, you also write a JSON schema that lists the parameters of the tool.
False. The SDK generates the input schema from the parameters and their type hints. The function is the single place they are defined.
Calling the tool from the MCP Inspector
A server waits for a client, so to try one you need a client. The MCP Inspector is the official developer tool for that: it connects to a server as a client, lists everything the server offers, and lets you call a tool with values you type in. No model and no API key take part. You play the part the model would play, and you see exactly what the server answers.
The Inspector is a Node.js program, so it needs Node.js installed. Node.js provides the npx command that runs it. The SDK itself is a Python package named mcp, and its command-line extra, mcp[cli], adds an mcp command. One way to install it is uv, a Python package and project manager: in your project folder, uv init creates a project and uv add "mcp[cli]" adds the SDK with that extra to it. uv run then runs a command with the project's packages, so one command starts the Inspector with your server:
uv run mcp dev server.pyThe mcp dev command finds the server object in the file and hands it to the Inspector. The Inspector then does what a real host does: it starts the server as a separate process and talks to it over stdio. It prints a web address that contains a one-time access token, and opens that address in the browser. If the page does not open, use the printed address rather than typing the port from memory.
- You
- MCP Inspector a client
- Your server server.py
- MCP Inspector to Your server: start as a process
- MCP Inspector to Your server: which tools exist?
- Your server to MCP Inspector: add: a and b, integers
- You to MCP Inspector: a = 1, b = 2, Execute Tool
- MCP Inspector to Your server: call add
- Your server to MCP Inspector: result: 3
In the web page, the Tools tab lists the tools the server announced. Select add and you see its description, "Add two numbers.", and its input schema drawn as a form with a required integer field for a and one for b. Fill them in, press Execute Tool, and the result appears below the form.
The Inspector has other tabs too: Protocol shows the raw JSON-RPC requests and responses that went back and forth, and Console shows what the server wrote to its error output, which is where to look when a server fails to start. The Inspector may also list a few sample servers of its own next to yours; they are there for exploring and can be ignored.
Because the form is built from the schema the server announced, the Inspector is also a quick way to check the work of the previous section: if a type hint or a docstring is wrong, you see it in the form before any model ever reads it. For scripts and quick checks without a browser, the same Inspector has a command-line mode, started with --cli, that sends a single request such as tools/list and prints the answer.
True or false?
To try a tool in the MCP Inspector you first need an API key for a language model.
False. The Inspector is a client that lists and calls tools directly. You choose the arguments yourself, so no model is involved.
The Inspector starts your server as a separate process and talks to it the same way a host on your machine would.
True. It launches the server as a subprocess and connects over stdio, so a server that works in the Inspector speaks the protocol correctly.
If the add function had no type hints, the Inspector form would still know that a and b must be integers.
False. The form is drawn from the input schema, and the schema comes from the type hints. Without them the server cannot announce the types.