Sub topic 1
What MCP is and why your application might use it
Prerequisites
This tutorial assumes you can already do the following:
- Read and write Python, including
async/await. - Read JSON and a basic JSON Schema (
type,properties,required). - Call an LLM API from code.
- Explain tool calling (also called function calling). You send the model a list of tool definitions. The model replies with a request to run one. Your code runs it and sends back the result.
You don't need any MCP experience. This chapter is conceptual. It explains what the Model Context Protocol is and when it is worth using. Later chapters build the code.
The problem: every tool is wired by hand
Suppose your application lets a model search tickets, read files, and query a database. With plain tool calling, you do the following for each capability:
- Write a JSON Schema describing the tool's inputs.
- Write the function that does the work, or a wrapper around a vendor's API.
- Write the glue that matches a model's tool call to that function.
- Repeat the work if another application wants the same tool, or if you switch to a different model provider.
Each application and each tool pair needs custom integration code. If you have N applications and M tools, you maintain up to N × M integrations. Tool authors also have to guess which applications will use their work, and each one ships a different interface.
What MCP is
The Model Context Protocol (MCP) is an open protocol that standardizes how an application connects to external capabilities. Anthropic introduced it in late 2024. The protocol uses JSON-RPC 2.0 messages. It defines how a program that offers capabilities (a server) describes them, and how an application that wants to use them (a client) discovers and invokes them.
The idea is the same one behind the Language Server Protocol for editors. Each side implements the protocol once. A tool author writes one MCP server. Any application that speaks MCP can then use it. The N × M problem becomes N + M.
What a server tells you about itself
The practical benefit is that a server describes its own capabilities in a machine-readable form. Your application asks, and the server answers. Here is the shape of a tools/list response for a server with one tool, add:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "add",
"description": "Add two integers.",
"inputSchema": {
"type": "object",
"properties": {
"a": { "type": "integer" },
"b": { "type": "integer" }
},
"required": ["a", "b"]
}
}
]
}
}inputSchema is a JSON Schema. It is the same kind of object an LLM API expects for a tool definition. This is why a host can pass server tools to a model with little translation. Your application doesn't hard-code a tool list. It asks the server at runtime, so adding a tool to a server makes it available without changing the application.
The three kinds of capability
Servers can offer three kinds of capability, called primitives. They differ in who decides when they are used. The next chapters cover them in detail.
| Primitive | What it is | Who controls it |
|---|---|---|
| Tool | A function the model can ask to run | The model decides, usually with user approval |
| Resource | Read-only data identified by a URI, such as a file or record | The application decides what to load |
| Prompt | A reusable message template with parameters | The user picks it, for example from a menu |
This tutorial focuses on tools, because they are the main way an MCP server plugs into an LLM's tool-calling feature.
What your application does with MCP
In MCP terms, your application is the host. It starts one client connection per server. The flow looks like this:
- The host connects to a server and performs an initialization handshake.
- The host lists the server's tools.
- The host converts each tool into the LLM API's tool format and sends them with the user's message.
- When the model requests a tool, the host forwards the call to the right server.
- The host returns the result to the model and repeats until the model gives a final answer.
The model never talks to MCP directly. The model only sees tool definitions and tool results. Your host sits in the middle, and that placement is why it is also where you enforce approvals, limits, and logging.
When MCP is a good fit
MCP is worth the extra layer in these situations:
- You want to reuse existing servers. Many servers already exist for common systems such as file systems, source control, and databases. You can connect to them instead of writing wrappers.
- Several applications share the same tools. One server can serve a chat app, a coding assistant, and a batch job.
- The tool set changes at runtime. Users or administrators can add servers without a code release.
- You want to switch model providers. The tool layer stays the same. Only the mapping to the model's tool format changes.
- Tool code should run in a separate process. A server can run with its own permissions, language, and dependencies.
When it may not be
MCP adds a process boundary, a protocol, and a new place for failures. Skip it when:
- You have two or three tools, used by one application, written in the same language. A plain Python function and a hand-written schema are simpler and faster.
- You need very low latency on each call. Inter-process messaging costs more than a function call.
- You can't trust or vet the servers you would connect to. A server's tool descriptions and outputs go into the model's context, so a malicious server can attempt to manipulate the model. The security chapter covers this.
What MCP does not do
MCP is not a model API. It does not choose when to call a tool, and it does not replace your provider's tool-calling feature. It is a layer beneath that feature. You still write the loop that sends tool definitions to the model and handles the model's tool-call requests. The tutorial builds that loop step by step, after covering the protocol pieces it depends on.
Exercise
An application has one hard-coded tool, written in Python, that only that application uses. A teammate suggests wrapping it in an MCP server. Name one benefit and one cost of doing so.
Show answer
Benefit: other applications and other model providers could reuse the tool through the same protocol, and the tool could run as a separate process with its own permissions. Cost: you add a process boundary, a protocol layer, and new failure modes (startup, connection, and timeout errors) for a tool that nothing else uses. For a single-use tool, a plain function with a hand-written schema is usually simpler.
Exercise
In the tools/list response shown in this chapter, which field would you pass to an LLM API as the tool's input schema, and why does that make MCP convenient for a host?
Show answer
The inputSchema field. It is already a JSON Schema, which is the format LLM APIs expect for tool parameters. The host only has to rename fields and does not have to write schemas by hand, and the tool list comes from the server at runtime.