What is MCP (Model Context Protocol) and what is it for?
Published
Short answer
MCP is an open protocol that lets AI applications connect to tools and data in a common way. An MCP server exposes tools, resources and ready-made prompts; an MCP-capable application connects to it and makes those abilities available to the model. So instead of writing a separate integration for every application, you write the server once. MCP was announced by Anthropic in 2024.
The problem it solves
If every AI application had to connect to every tool separately, N applications and M tools would need N times M integrations. MCP defines a common interface: you write a tool once as an MCP server, and every MCP-capable application can use it.
The parts
- Host: the AI application the user runs (for example a chat app or a code editor).
- Client: the connection inside the host that talks to one MCP server.
- Server: the program that exposes the abilities.
A server can expose three kinds of things: tools (functions the model can call), resources (data the model can read) and prompts (ready-made prompt templates).
How messages travel
Messages are carried as JSON-RPC. Local servers usually connect over stdio, and remote servers over HTTP.
A simple server
The TypeScript example below exposes a tool that adds two numbers. Details can change with the SDK version, so check the current documentation.
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({ name: "demo", version: "1.0.0" });
server.tool("add", { a: z.number(), b: z.number() }, async ({ a, b }) => ({
content: [{ type: "text", text: String(a + b) }],
}));
await server.connect(new StdioServerTransport());Security
- Connect only to servers you trust. A server can return text that looks like an instruction to the model.
- Give a server only the permissions it needs and put irreversible actions behind approval.
- Treat tool descriptions and outputs as untrusted input.
Questions
- Are MCP and function calling the same thing?
- No. Function calling is a model's ability to call tools. MCP is a protocol for exposing tools and data to different applications in a common format.
- Who created MCP?
- Anthropic announced it in 2024 as an open protocol.
- Which language can I write an MCP server in?
- There are official SDKs; TypeScript and Python are the most common. Check the MCP documentation for the current list of languages.
Written by Mert Yılmaz, freelance fullstack developer.