Every team that connects an AI assistant to its tools ends up writing the same glue: one integration for the issue tracker, another for the database, another for the docs, each shaped differently for each AI application. Add a second assistant and you write it all again.
The Model Context Protocol (MCP) is an open protocol designed to remove that duplication. Build a server once, and any MCP-capable application can use it. This article explains what the Model Context Protocol is, how its pieces fit together, what changed in the latest specification, and how to write a small MCP server and client in Node.js. It is for developers building or evaluating AI integrations.
A note on freshness: MCP moves quickly. The details below were checked against the official specification and SDK documentation in November 2026 (specification version 2026-07-28). Verify against the official docs before you build, and treat the version-specific points as perishable.
Direct answer: what is MCP?
- MCP (Model Context Protocol) is an open protocol that standardises how AI applications connect to external tools and data.
- An MCP server exposes capabilities, mainly tools (functions the model can call), resources (data to read) and prompts (reusable templates). An MCP client inside an AI application talks to it using JSON-RPC messages.
- It runs over two standard transports: stdio (a local subprocess) and Streamable HTTP (remote servers).
- MCP does not replace function calling or APIs. It standardises how tools are discovered and invoked across applications, so one integration works with many hosts.
Table of contents
- The problem MCP solves
- How MCP works: hosts, clients and servers
- MCP primitives: tools, resources and prompts
- Transports: stdio and Streamable HTTP
- What changed in the 2026-07-28 specification
- Build an MCP server and client in Node.js
- MCP vs function calling vs REST APIs
- Security and production considerations
- Common mistakes
- Best practices
- Frequently asked questions
- Conclusion
- References
The problem MCP solves
Without a standard, N applications times M tools means N×M custom integrations. With MCP, each tool is wrapped once as a server and each application implements the client side once. The effort becomes N+M.
This is the same trick other protocols pulled off in their domains: the Language Server Protocol let one language server work across many editors, and MCP aims to do that for AI applications and the tools they use.
How MCP works: hosts, clients and servers
Three roles appear in the architecture:
- Host: the AI application the user interacts with (a coding assistant, a chat app, your own agent).
- Client: a component inside the host that maintains a connection to one server.
- Server: a program that exposes tools, resources and prompts.
flowchart TD U[User] --> H[Host application with LLM] H --> C1[MCP client A] H --> C2[MCP client B] C1 -- stdio --> S1[Local server: filesystem] C2 -- Streamable HTTP --> S2[Remote server: issue tracker] S1 --> D1[(Local files)] S2 --> D2[(SaaS API)]
The model itself never speaks MCP. The host asks servers what they offer, shows the model the tool descriptions, executes the tool calls the model requests through the right client, and returns results to the model. If you have read how an agent loop works, MCP is the standard way to fill the "tools" box in that loop.
MCP primitives: tools, resources and prompts
The specification overview lists three server features:
| Primitive | Controlled by | What it is | Example |
|---|---|---|---|
| Tools | The model | Functions with a name, description and input schema that the model can decide to call | create_issue, run_query |
| Resources | The application or user | Data identified by URI that can be read into context | A file, a database schema, a document |
| Prompts | The user | Templated messages or workflows a user can invoke | "Summarise this pull request" |
Tools are what most people mean when they say "MCP"; they map closely to function calling. Resources and prompts are less used but valuable for giving context and reusable workflows without letting the model trigger anything.
On the client side, the latest overview lists elicitation, which lets a server request additional information from the user. Earlier client features, sampling (a server asking the host's model to generate text) and roots, are deprecated in the latest spec, discussed next.
Transports: stdio and Streamable HTTP
The 2026-07-28 specification defines two standard transports:
- stdio. The client launches the server as a subprocess and they exchange newline-delimited JSON-RPC messages over standard input and output. The spec says the server must not write anything to stdout that is not a valid MCP message, so log to stderr. This is the usual choice for local tools.
- Streamable HTTP. The server exposes a single HTTP endpoint that accepts POST requests. Responses are either plain JSON or a Server-Sent Events stream. The spec requires servers to validate the
Originheader to prevent DNS-rebinding attacks and recommends binding to localhost when running locally and authenticating requests.
The older HTTP+SSE transport (from the 2024-11-05 spec) is now deprecated in favour of Streamable HTTP.
What changed in the 2026-07-28 specification
If you learned MCP from older tutorials, several things are different. The official changelog for 2026-07-28 lists these major changes relative to 2025-11-25:
- Stateless core. The
initialize/initializedhandshake is gone. Each request carries the protocol version and client capabilities in its_metafield, and servers implement aserver/discovermethod to advertise supported versions, capabilities and identity. - No protocol-level sessions. The
Mcp-Session-Idheader was removed from Streamable HTTP. If tools need state across calls, the spec's approach is server-issued handles passed as tool arguments. - Required HTTP headers.
Mcp-Method(andMcp-Namefortools/call,resources/readandprompts/get) must be sent on Streamable HTTP requests, which lets gateways route and filter without parsing bodies. - Subscriptions. A
subscriptions/listenrequest replaces the old GET endpoint and per-resource subscribe calls. - Tasks moved to an extension. Long-running work is handled by the
io.modelcontextprotocol/tasksextension, with polling throughtasks/get. - Server-to-client requests reworked. Sampling, roots and elicitation requests are replaced by a multi-round-trip pattern where a result of type
input_requiredlists what the server needs and the client retries with the answers. Roots, sampling and logging are deprecated. - Authorization. The spec deprecates OAuth Dynamic Client Registration in favour of Client ID Metadata Documents, and tightens validation around issuer identification.
- Caching hints. List and read results carry
ttlMsandcacheScopefields. - Deprecation policy. A lifecycle policy sets a minimum 12-month deprecation window.
I have not verified the details of every item beyond the changelog, so read the changelog when implementing the protocol directly. If you use an official SDK, much of this is handled for you.
Build an MCP server and client in Node.js
The official TypeScript SDK's main branch is v2, which implements the 2026-07-28 spec and is split into @modelcontextprotocol/server and @modelcontextprotocol/client. The older v1 line is a single package, @modelcontextprotocol/sdk, with a different API; many tutorials online still use it. The examples below follow the v2 documentation. Check the SDK repository for current package versions and run npm view @modelcontextprotocol/server version to see what you are installing.
mkdir mcp-notes && cd mcp-notes
npm init -y
npm pkg set type=module
npm install @modelcontextprotocol/server @modelcontextprotocol/client zod tsx
Node.js 20 or later is required. Here is a small server with one tool:
// src/server.ts
import { McpServer } from '@modelcontextprotocol/server';
import { serveStdio } from '@modelcontextprotocol/server/stdio';
import * as z from 'zod/v4';
const notes: string[] = [];
function createServer(): McpServer {
const server = new McpServer({ name: 'notes', version: '1.0.0' });
server.registerTool(
'add-note',
{
description: 'Save a short text note and return the new total count',
inputSchema: z.object({ text: z.string().min(1).max(500) }),
},
async ({ text }) => {
notes.push(text);
return { content: [{ type: 'text', text: `Saved. You now have ${notes.length} note(s).` }] };
},
);
return server;
}
void serveStdio(createServer);
console.error('notes MCP server running on stdio'); // stderr: stdout is reserved for protocol messages
The pieces: McpServer holds your server's identity; registerTool takes a name, a config with a description and a Zod input schema, and a handler returning content blocks; and serveStdio runs it over stdio. The SDK validates input against the schema before your handler runs. For failures, a tool result can set isError: true so the model sees the error and can react, rather than the call crashing.
Now a client that launches the server and calls the tool:
// src/client.ts
import { Client } from '@modelcontextprotocol/client';
import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';
const client = new Client({ name: 'notes-client', version: '1.0.0' });
const transport = new StdioClientTransport({ command: 'npx', args: ['tsx', 'src/server.ts'] });
try {
await client.connect(transport); // spawns the server process
const { tools } = await client.listTools();
console.log('tools:', tools.map((t) => t.name));
const result = await client.callTool({ name: 'add-note', arguments: { text: 'Buy milk' } });
for (const block of result.content) {
if (block.type === 'text') console.log(block.text);
}
} finally {
await client.close();
}
Run it with npx tsx src/client.ts. Expected output:
tools: [ 'add-note' ]
Saved. You now have 1 note(s).
For remote servers, the v2 docs provide createMcpHandler, which returns a web-standard fetch handler. On runtimes such as Cloudflare Workers, Deno or Bun, exporting that handler is the whole mount:
import { createMcpHandler, McpServer } from '@modelcontextprotocol/server';
import * as z from 'zod/v4';
const handler = createMcpHandler(() => {
const server = new McpServer({ name: 'notes', version: '1.0.0' });
server.registerTool(
'add-note',
{ description: 'Save a note', inputSchema: z.object({ text: z.string() }) },
async ({ text }) => ({ content: [{ type: 'text', text: `Saved: ${text}` }] }),
);
return server;
});
export default handler;
The SDK documentation is explicit that the handler does no Host, Origin or token validation. Authentication and origin checks are your responsibility, and they matter (see below). Connecting your server to an AI application is then a configuration step in that host: register the command for a stdio server or the URL for a remote one.
MCP vs function calling vs REST APIs
| Aspect | MCP | Function calling | REST API |
|---|---|---|---|
| What it is | A protocol between AI applications and tool servers | A model API feature for requesting a function call | A general interface for services |
| Who defines tools | The server, discovered at runtime | Your application code, passed on each request | Documented endpoints |
| Reuse across apps | High: one server, many hosts | Low: tied to one application's code | High, but needs per-app glue for the model |
| Discovery | Standardised (list tools/resources/prompts) | Manual | OpenAPI docs, manual wiring |
| Best for | Shared tool ecosystems and multi-host setups | A single app with a few custom tools | Service-to-service integration |
They are layers, not rivals. An MCP host typically uses function calling to let the model choose a tool, and an MCP server often wraps a REST API. If you have one application and three tools, plain function calling is simpler. If several applications or teams need the same tools, MCP pays for itself. For comparing API styles in general, see REST vs GraphQL.
Security and production considerations
MCP makes tools easy to connect, which makes security the main concern.
- Treat tool descriptions and outputs as untrusted. A malicious or compromised server can return text that tries to steer the model (prompt injection). Only connect servers you trust and keep their privileges narrow.
- Least privilege. Give each server only the scopes it needs. Prefer read-only tools unless writes are necessary, and require user confirmation for destructive actions.
- Authenticate remote servers. For Streamable HTTP, validate
Origin, require authentication and follow the spec's authorization guidance (OAuth-based). Our authentication chapter explains the underlying flows. - Authorization in code. Enforce per-user permissions inside the tool implementation. Do not rely on the model to decide who may do what (authorization and IDOR).
- Validate inputs. Schemas catch shape errors; you still need business validation and parameterised queries.
- Log and trace. Record which tool was called by whom with which arguments, with sensitive fields redacted.
- Plan for protocol change. Pin SDK versions, read the changelog before upgrading, and note the deprecation policy that gives deprecated features a minimum 12-month window.
Common mistakes
- Writing to stdout in a stdio server. Stray
console.logcalls corrupt the protocol stream. Log to stderr. - Following v1-era tutorials against the v2 SDK (or the reverse). Package names and APIs differ; check which version you install.
- Exposing a remote server with no authentication or origin validation.
- One giant "run anything" tool. Small, well-described tools are safer and easier for models to use correctly.
- Vague tool descriptions. The description is the model's only guide to when to call the tool.
- Trusting third-party servers blindly. Review what a server does and which data it can reach before connecting it.
- Returning huge tool outputs. Large payloads waste context. Return what the model needs, and paginate.
- Assuming MCP replaces your API. It sits in front of your existing services; those still need proper design and security.
Best practices
- Start with a local stdio server for one or two read-only tools and expand carefully.
- Describe each tool like API documentation: purpose, inputs, units, error cases.
- Keep schemas strict and return actionable error messages with
isError. - Reuse your existing service layer so MCP tools and your REST API share business rules and authorization.
- Pin SDK versions and test upgrades against the protocol version you target.
- Write tests that call your tools through a real client, not just unit tests of the handlers.
Conclusion
MCP is a standard connector between AI applications and the tools they need. Hosts, clients and servers each have a narrow job; servers expose tools, resources and prompts; and two transports cover local and remote use. The 2026-07-28 revision moves the core to a stateless design, so check which spec version your SDK and hosts speak.
The practical next step is small: wrap one read-only function from your own backend as an MCP tool, connect it to a host that supports MCP, and watch how the model uses the description you wrote. When you are ready to combine it with your own agent loop, revisit How to Build an AI Agent Using Node.js, or explore my AI integration services.
References
- Model Context Protocol: Specification (2026-07-28)
- Model Context Protocol: Changelog
- MCP transports: Streamable HTTP
- MCP transports: stdio
- MCP blog: the 2026-07-28 specification
- MCP TypeScript SDK on GitHub
- Build an MCP server (official tutorial)
Written by Shivam Thakur, a Software Engineer focused on web applications, SaaS platforms and modern software products. More at shivamthakur.me.

