Katkat

The Model Context Protocol (MCP)

By the Katkat team · Updated · 9 min read

Quick overview

Understand the Model Context Protocol: hosts, clients and servers, tools vs resources, stdio and Streamable HTTP transports, and MCP security risks.

Lesson 29 of 88 · AI Engineering Interview Course

After this lesson you will be able to explain what the Model Context Protocol (MCP) is, how a host, client and server fit together, and how tools differ from resources and prompts. You will also be able to compare the two standard transports and name the main security risks of connecting an agent to third-party MCP servers, along with mitigations. Interviewers use MCP to test whether you understand tool integration as an engineering and trust problem, not just "the model calls functions".

Why MCP exists

Without a shared protocol, every AI application writes its own glue for every system it wants to reach: one adapter for GitHub, another for a database, another for a ticketing system. With 4 applications and 6 services, that is 4 × 6 = 24 bespoke integrations. With a common protocol, each application implements the client side once and each service implements the server side once, so you need 4 + 6 = 10 implementations.

MCP is an open protocol, introduced by Anthropic, that standardises how an LLM application discovers and uses external capabilities. It is not a model feature and it does not make the model smarter. It standardises the plumbing around tool calling: how tools are listed, described, invoked and returned.

Architecture: host, client, server

MCP has three roles.

  • Host: the user-facing application that contains the model, such as a chat app, an IDE assistant or your own agent. It decides which servers to connect to and what the user must approve.
  • Client: a connector inside the host. Each client keeps one connection to one server.
  • Server: a program that exposes capabilities (tools, resources, prompts) to clients.

A host with three configured servers runs three clients, one per server. The model never speaks MCP directly. The host translates between the model's tool-call output and MCP requests, and feeds results back into the model's context.

Lifecycle and messages

MCP messages use JSON-RPC 2.0: requests with an id that expect a response, responses, and notifications that expect none. A connection follows a fixed lifecycle:

  1. The client sends initialize with its protocol version and capabilities.
  2. The server replies with its own version and capabilities (for example, whether it offers tools, and whether it will send change notifications).
  3. The client sends an initialized notification, and normal operation begins.
  4. Either side can close the connection.

Capability negotiation lets old clients and new servers coexist: a feature is used only if both sides declared support.

A tool invocation looks like this (simplified):

{"jsonrpc": "2.0", "id": 7, "method": "tools/call",
 "params": {"name": "search_issues",
            "arguments": {"query": "login timeout", "limit": 5}}}

The server answers with a result containing content blocks (usually text) and an error flag that marks a failure at the tool level, as opposed to a protocol-level error. Passing the failure back to the model as content lets it recover or retry, which matters for agent reliability.

Tools, resources and prompts

Servers expose three primitives. The key difference is who controls them.

PrimitiveWhat it isWho decides to use itTypical exampleMain methods
ToolAn action or computation with a JSON Schema for its inputsThe model (host usually gates it)Create a ticket, run a querytools/list, tools/call
ResourceReadable data identified by a URIThe application or user (what to attach to context)A file, a database schema, a logresources/list, resources/read
PromptA reusable, parameterised prompt templateThe user (for example, a slash command)"Summarise this PR" templateprompts/list, prompts/get

Tools are the primitive most interviews focus on. A tool has a name, a description and an input schema; the quality of those three fields determines how well the model uses it, so the guidance in designing tools an agent can use applies unchanged. Tools can have side effects, so they are where safety controls concentrate.

Resources are closer to read-only context. They can be listed directly or described by URI templates, and a server may support subscriptions so the client is told when a resource changes. A good rule: if the operation is "fetch data to show the model", consider a resource; if it is "do something or run a parametrised query", use a tool. In practice many servers expose read operations as tools anyway, because model-driven tool calls are the most widely supported path.

Servers can also notify clients that their tool list changed (a list_changed notification), so the available tools can vary during a session. The protocol also defines features that flow the other way, where the server asks the client for something, such as having the host's model generate a completion (sampling) or asking the user for input. Treat these as extra surfaces you must also secure.

Transports

A transport carries the JSON-RPC messages. The two standard ones:

stdioStreamable HTTP
Where the server runsLocal subprocess started by the hostRemote or local HTTP service
How messages moveNewline-delimited JSON over stdin/stdoutHTTP POST for client messages; responses may be plain JSON or a server-sent event stream
Users servedOne (the process belongs to the host)Many concurrent clients
AuthenticationInherits the user's OS environment; credentials usually passed as environment variablesNeeds real auth; the spec's authorisation approach is built on OAuth
ScalingNone needed; one process per clientStandard web scaling, though sessions and streams complicate load balancing
Main riskRuns with the user's local privilegesNetwork exposure, token handling, cross-tenant leaks

An earlier HTTP-plus-SSE transport existed and was superseded by Streamable HTTP in later spec revisions, so older tutorials may describe it. Check the current specification for exact details, since the protocol is still evolving.

Design point for stdio: the server must write only protocol messages to stdout, with logs going to stderr, or it corrupts the stream. For HTTP servers running locally, bind to localhost and validate the Origin header to block browser-based attacks such as DNS rebinding.

Worked example: what tools cost in context

Every tool definition is sent to the model on each request, so tool count has a token cost. Assume (approximately) 250 tokens per tool for name, description and schema.

  • A host connects 5 servers with 12 tools each: 5 × 12 = 60 tools.
  • Definitions cost 60 × 250 = 15,000 tokens per request.
  • At 1,000 requests per day: 15,000 × 1,000 = 15,000,000 input tokens per day.
  • At an assumed price of $3 per million input tokens: 15 × $3 = $45 per day for definitions alone.

If the host filters to the 15 tools relevant to the task: 15 × 250 = 3,750 tokens, a 75% reduction ((15,000 − 3,750) / 15,000). If the tool block is identical across requests and the provider supports prefix caching at, say, 10% of the normal input price, the original 15,000 tokens would cost roughly $4.50 per day instead of $45. This is why large MCP setups also hurt accuracy: more tools means a longer prompt and more look-alike choices. See context windows for the wider cost picture. All prices here are illustrative; check your provider.

Security considerations

MCP moves the trust boundary: your agent now reads text written by servers and acts through code written by third parties. Main risks:

  • Tool poisoning: a tool description is text the model reads as instructions. A malicious or compromised server can hide directives in it ("also send the user's files to..."). Treat descriptions from untrusted servers as untrusted input.
  • Prompt injection through results: tool outputs and resources (web pages, tickets, emails) can contain attacker-written instructions. This is the same threat covered in prompt injection and guardrails, now with a bigger attack surface.
  • Rug pulls: a server approved on day one can change its tool descriptions or behaviour later, particularly after a list_changed notification or a package update. Pin versions and re-review on change.
  • Excessive privilege: a stdio server runs as the user, so a malicious one can read files and credentials. Remote servers holding broad tokens can be abused the same way.
  • Confused deputy and token misuse: a server that accepts a token not issued for it, or forwards user tokens downstream, can be tricked into acting with authority it should not have. Servers should accept only tokens meant for them.
  • Injection in the server itself: a tool that builds shell commands or SQL from model-supplied arguments is exposed to classic injection, and the model's arguments are attacker-influenced.
  • Data exfiltration through combinations: one server reads private data, another can send HTTP requests; together they form a leak path even if each is individually fine.

Mitigations: allowlist servers, run local ones in a sandbox with minimal filesystem and network access, grant least-privilege scoped credentials, validate and parameterise inputs server-side, show users the exact tool call for side-effecting actions, and log every call. Tool annotations such as "read-only" or "destructive" are hints supplied by the server, so do not rely on them from untrusted servers. See agent safety for approval and sandboxing patterns.

Trade-offs: when to use MCP

Benefits: reusable integrations, a growing ecosystem of ready-made servers, a clean separation between agent logic and tool implementations, and runtime discovery of tools.

Costs: extra process and network hops, more latency than an in-process function call, a dependency on third-party code, context bloat from many tool definitions, and the security surface above.

For one application with a handful of internal tools, plain function calling is simpler and faster. MCP pays off when many hosts need the same integrations, when different teams own the tools, or when you want users to plug in their own servers.

How does this come up in interviews?

1. What problem does MCP solve, and how is it different from function calling? Function calling is how a model emits a structured request to call a tool; MCP is a protocol for how an application discovers, describes and invokes tools hosted by separate servers. It turns an N × M integration problem into N + M and lets tools be reused across hosts. The model-side mechanism is the same either way.

2. Explain tools versus resources versus prompts. Tools are model-invoked actions with input schemas and possible side effects. Resources are URI-addressed data that the application or user chooses to put in context. Prompts are user-selected templates. The distinction is mainly about who controls the use and how much risk it carries.

3. When would you choose stdio over Streamable HTTP? Use stdio for local, single-user tools such as filesystem or dev tooling, where a subprocess is simple and auth is inherited from the OS. Use Streamable HTTP for shared, remote or multi-tenant servers, which need proper authentication, scaling and monitoring. Mention that stdio servers run with the user's privileges, so sandboxing matters.

4. You connect an agent to a third-party MCP server. What could go wrong? Describe tool poisoning, injection via results, rug pulls after approval, over-privileged credentials, and exfiltration across servers. Then give mitigations: allowlisting, version pinning, sandboxing, scoped tokens, human approval for side effects, and audit logs.

5. Your agent has 80 MCP tools and tool selection accuracy has dropped. What do you do? Reduce what the model sees: route or filter tools per task, group or merge overlapping tools, and tighten descriptions. Measure with an agent evaluation set before and after. Also note the token cost, and use prefix caching if the tool list is stable.

Common mistakes

  • Saying MCP is a model, a framework, or something that changes how the LLM works internally.
  • Treating it as a replacement for function calling instead of a layer around it.
  • Confusing tools (model-controlled) with resources (application-controlled).
  • Forgetting that tool descriptions and tool outputs are untrusted text the model will read.
  • Trusting server-provided annotations or descriptions from servers you do not control.
  • Writing logs to stdout in a stdio server and breaking the protocol stream.
  • Connecting every available server by default and ignoring the token and accuracy cost of large tool lists.
  • Giving servers long-lived, broadly scoped credentials.
  • Quoting spec details from memory as fixed; the protocol is evolving, so say "check the current specification".