AI Agents & LLMsMedium
What is the Model Context Protocol (MCP)?
Learning path, stage 4 of 5: Agents, tools and MCP · question 6 of 10MCP is an open protocol, introduced by Anthropic in November 2024 and now governed by the Linux Foundation's Agentic AI Foundation, that standardises how AI applications connect to tools and data. An MCP server exposes tools, resources and prompts once, and any MCP-capable client (IDEs, chat apps, agent frameworks) can use them. It's often described as "USB-C for AI integrations".
The architecture
- Host: the AI app (for example an IDE or a desktop assistant).
- Client: one connection per server, inside the host.
- Server: exposes capabilities:
- Tools: functions the model can call.
- Resources: readable data such as files or database rows.
- Prompts: reusable templates.
- Transports: stdio for local processes, Streamable HTTP for remote servers (with OAuth for auth).
- Messages are JSON-RPC 2.0.
Why it matters
- It solves the N×M integration problem: build a GitHub server once and use it in every client.
- There's a large ecosystem of ready-made servers (GitHub, Slack, databases, browsers…).
Security points
- Treat third-party servers like dependencies: review them, pin versions, give them minimal permissions.
- Tool descriptions and results are untrusted input, so prompt injection can arrive through MCP.
- Ask for user consent before tools with side effects.
Sources
Code example
tsx
1// A tiny MCP server (stdio) exposing one tool, using the official TypeScript SDK.2import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";3import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";4import { z } from "zod";56const server = new McpServer({ name: "devqna-questions", version: "1.0.0" });78server.registerTool(9 "search_questions",10 {11 title: "Search interview questions",12 description: "Find DevQnA interview questions by keyword. Returns up to 5 titles.",13 inputSchema: { query: z.string(), topic: z.enum(["react", "nextjs", "javascript"]).optional() },14 },15 async ({ query, topic }) => {16 const hits = await findQuestions(query, topic);17 return { content: [{ type: "text", text: hits.slice(0, 5).join("\n") || "No matches" }] };18 },19);2021await server.connect(new StdioServerTransport());2223declare function findQuestions(q: string, topic?: string): Promise<string[]>;
To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk zod @modelcontextprotocol/sdk, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.