What is MCP (Model Context Protocol), and what are its main parts?
Advertisement
🧩 Scenario
Concept Walkthrough
The problem MCP solves
Before MCP, every AI app wrote its own glue for every data source. If you had 3 AI apps and 4 systems (GitHub, Jira, your docs, your database), you were maintaining up to 12 integrations. MCP turns that into a common contract: each system ships one MCP server, and any MCP-aware app can use it. Think of it like a USB port, or like how any browser can talk to any website because both speak HTTP.
The three roles
- Host: the AI application the user sees, such as Claude Desktop, an IDE, or your own Next.js chatbot. The spec describes the host as the container and coordinator. It owns the model, the UI and the user's consent.
- Client: a connector that lives inside the host. Each client holds a connection to exactly one server. A host that uses three servers creates three clients.
- Server: a program that exposes capabilities. It can run locally as a child process or remotely behind a URL.
A React analogy: the host is your app shell, each client is like a typed API module for one backend, and each server is that backend.
What a server exposes
- Tools: functions the model can ask to call, like
createIssue. The spec calls them model-controlled. - Resources: read-only context the application decides to include, like a file or a schema. Application-driven.
- Prompts: reusable templates the user picks, often shown as slash commands. User-controlled.
Servers can also ask the client for help through client features: sampling (ask the host's model to generate text), elicitation (ask the user for input) and roots (learn which folders or URIs are in scope).
How messages move
MCP messages are JSON-RPC, with methods like tools/list and tools/call. There are two standard transports:
- stdio: the host starts the server as a child process and exchanges newline-delimited messages over stdin and stdout. Best for local tools.
- Streamable HTTP: each message is an HTTP POST to one MCP endpoint, and replies come back as JSON or a request-scoped SSE stream. Best for remote, shared servers.
The current spec (2026-07-28) describes MCP as stateless: every request carries its own protocol version and capabilities.
Key Code Explained (TypeScript)
// server.ts: a minimal MCP server using the v2 TypeScript SDK
import { McpServer } from '@modelcontextprotocol/server';
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
import * as z from 'zod/v4';
const components = ['Button', 'ButtonGroup', 'Card', 'Dialog', 'Tooltip'];
const server = new McpServer({ name: 'design-system', version: '1.0.0' });
// A tool: the model can discover it via tools/list and request it via tools/call
server.registerTool(
'search-components',
{
description: 'Search design system components by name.',
inputSchema: z.object({ query: z.string().min(1) }),
},
async ({ query }) => {
const matches = components.filter((c) =>
c.toLowerCase().includes(query.toLowerCase()),
);
return {
content: [{ type: 'text', text: matches.join(', ') || 'No matches' }],
};
},
);
// stdio: stdout is reserved for MCP messages, so log to stderr
console.error('design-system MCP server starting');
const transport = new StdioServerTransport();
await server.connect(transport);
The host launches this file as a child process. Its MCP client sends tools/list, sees search-components with its schema, and passes it to the model like any other tool. When the model asks for it, the client sends tools/call and gets back the content array. Notice that nothing here knows which AI app or model is on the other side. That is the whole point.
Tradeoffs
| Choice | Good for | Watch out for |
|---|---|---|
| stdio transport | Local tools, filesystem, CLIs, quick prototypes | Runs with the user's machine permissions, one user per process |
| Streamable HTTP transport | Shared remote servers, SaaS integrations, many users | Needs authentication, rate limiting and normal web security |
| One MCP server per system | Reuse across many hosts and teams | Extra process and protocol layer to run and version |
| Direct tools in your app | One app, one model, simple features | Integration code cannot be reused by other hosts |
What Interviewers Actually Check
- Whether you can explain the N apps times M systems problem MCP solves
- Whether you separate host, client and server correctly, including one client per server
- Whether you know the model never talks to the server directly
- Whether you can name tools, resources and prompts and who controls each
- Whether you know the stdio and Streamable HTTP transports and when to use each
Follow-Up Questions
- Why does each client connect to only one server?
- What is sampling, and why would a server want to use the host's model instead of its own?
- Why is logging to stdout a bug in a stdio server?
- How would your Next.js chatbot act as an MCP host?
- What changes when you move a server from stdio to Streamable HTTP?
Common Candidate Mistakes
- Describing MCP as "a new way for models to call APIs". The model still just produces tool calls; MCP is about how the host finds and runs them.
- Calling the AI app the client. The host contains clients; it is not one.
- Forgetting resources and prompts and describing MCP as tools only.
- Using
console.logfor debugging in a stdio server and breaking the connection. - Ignoring security because "it is just a protocol". Servers run real code with real permissions.
Interview Readiness Checklist
Before you leave this question, make sure you can answer:
- Can you explain MCP in one sentence?
- Can you draw a host with two clients connected to two servers?
- Can you name the three server primitives and the three client features?
- Can you choose between stdio and Streamable HTTP for a given use case?
- Can you write a minimal server with
McpServerandregisterTool?
Summary
MCP (Model Context Protocol) is an open, JSON-RPC based protocol that lets AI applications connect to tools and data through a common contract. The host is the AI app, it creates one client per server, and each server exposes tools (model-controlled), resources (application-driven) and prompts (user-controlled). Servers can also use client features such as sampling, elicitation and roots. Local servers usually run over stdio, and remote ones over Streamable HTTP. The model never talks to a server directly: the host lists and calls tools on its behalf, which is why one well-built server can be reused across many AI apps.
Is MCP a replacement for tool calling?
No. MCP sits on top of tool calling. The model still produces tool calls the normal way. MCP standardises how the host discovers those tools from a server and how it runs them, so the tool code can live in a separate, reusable process.
Does the model talk to the MCP server directly?
No. The model only talks to the host application. The host uses an MCP client to list tools, call them and read resources, then passes results back to the model. The model never opens a connection to the server.
Do I need to know JSON-RPC to build an MCP server?
Not in day-to-day work. The official TypeScript SDK handles the JSON-RPC messages and transports for you. Knowing the method names, such as tools/list and tools/call, helps a lot when you debug.
Advertisement
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.
Advertisement