Guide / Tutorial

MCP Explained: Connect Claude to Your Tools and Build Your First MCP Server

MCP is how an AI assistant reaches beyond the chat box into your files, databases and apps. Learn the three moving parts, connect your first server, build a small one, and know when not to use MCP at all.

Claude CodeThis guide is about Claude Code.
MCP Explained: Connect Claude to Your Tools and Build Your First MCP Server

MCP (Model Context Protocol) is the standard plug that lets an AI assistant use your files, databases and apps. This guide shows what it is, how to connect a ready-made server in two minutes, how to write a tiny one yourself, and how to stay safe.

Reading map

  • What MCP is — a common plug between an AI app and the outside world.
  • The three parts — host, server and tools, and who is allowed to do what.
  • Connect a server — one command in Claude Code, or one click as a connector.
  • Scope — local, user or project: who gets the server.
  • Build one — a small TypeScript server that answers questions about orders.
  • A real job — scrape, save to Notion and research with two servers working together.
  • Safety and limits — the fake email server that stole copies of messages, and when plain code is better.

The short answer

MCP stands for Model Context Protocol. It is an agreed way for an AI application (Claude, Codex, Cursor and others) to find and use outside tools: read a database, search the web, create a Notion page, check an order. The AI never touches those systems directly. It asks the app it runs in, the app calls a small program called an MCP server, and the answer comes back as plain text.

If you remember one picture, make it a USB hub. Your laptop is the AI app. Each device you plug in (a printer, a drive, a camera) is a service. MCP is the standard port, so every service does not need its own special cable.

Host, server and tools: the three parts of MCP
Host, server and tools: the three parts of MCP

Why MCP exists

An AI model knows a lot, but it cannot see your things. It does not know what is in your database, your Google Drive or your company’s order list, and by itself it cannot create a page in Notion.

Before MCP, every AI app needed a separate, hand-made connection (an “integration”) for every service. Ten apps and ten services meant up to a hundred connections. With MCP a service builds one server, and any AI app that speaks MCP can use it. That is the whole idea.

The three parts, in plain words

Part What it is Example
Host The AI application you talk to. It owns the model and decides what is allowed to run. Claude Code, Claude desktop, Codex, Cursor
Server A small program (on your computer, or hosted online) that exposes abilities. A Notion server, an Apify server, your own orders server
Tool One ability on a server: a named function with a description and a list of inputs. get-order-status(orderId)

A server can offer other things besides tools (readable resources and reusable prompt templates), but tools are what you will use 95% of the time, so this guide focuses on them.

Two facts that matter later:

  • 1. The model never talks to the server itself. It only asks the host to run a tool, and the host decides. Depending on your settings, you are asked to approve each call.
  • 2. A tool has a name, a description and an input schema. The description is how the model decides when to use it; the schema tells it what to send. Clear descriptions make a tool get used correctly.

MCP standardises the connection. It does not make a bad tool good and it does not make a dangerous action safe. You still have to trust the server.

Two ways to run a server

Local server Remote server
Runs On your own computer, started by the host On the provider’s computers
How the host talks to it “stdio” (standard input/output) HTTP
Typical use Your own files, your own code, your own database Notion, Google Docs, Apify, GitHub and other online services
Sign-in Usually none Usually OAuth: a browser window asks you to allow access

In the desktop apps, a hosted server added through the app’s marketplace is called a connector. A plugin is a bigger package that may bundle a server together with skills and other extras. Under the hood, connectors and plugins use the same MCP.

Connect your first server

In Claude Code you add a server with one command. The shape is always the same:

claude mcp add --transport <stdio|http> --scope <local|user|project> <name> -- <command or URL>

For a remote server, the last part is a URL:

claude mcp add --transport http --scope user my-server https://example.com/mcp

For a local server, the last part is the command that starts it. Everything after the double dash is the command, so flags for that command do not get mixed up with Claude‘s own:

claude mcp add --transport stdio --scope local order-status-server -- npm --silent --prefix /path/to/server run dev
The command being typed in a terminal: stdio transport, local scope, a name, then the start command
The command being typed in a terminal: stdio transport, local scope, a name, then the start command • 00:13:00

Why --silent? A local server talks to Claude through its output. If npm prints its usual chatter, that noise gets mixed into the conversation and can break it. Anything that is not the server’s own messages should be quiet.

After adding a server:

  • 1. Restart your AI tool. Many tools only read their server list at start-up.
  • 2. In Claude Code, type /mcp. You see every server, whether it is connected, and how many tools it has. An exclamation mark means it still needs you to sign in.
  • 3. Press Enter on that server to sign in. Your browser opens, you pick an account and read the permission list.

Read that permission list. It often says “full access to your account”. Grant that to a company you trust, not to a name you found five minutes ago.

Other tools do the same job a different way. Cursor, for example, reads a JSON file called mcp.json inside its settings folder; Codex has its own mcp add command. The idea is identical: a name, how to start it or where it lives, and a scope.

Shortcut. If your app has a connector marketplace (Claude’s plus menu, or claude.ai on the web), search for the service and click it. You skip the command line and get the same result.

Scope: who gets the server?

Scope decides where a server is available. Claude Code has three:

Scope Available in Stored Use it for
local (default) Only you, only this project folder Your private settings for that project Trying something out; a server only one project needs
user Only you, in every project Your private settings Services you use all the time, such as Notion
project Everyone on the team, in this project A .mcp.json file in the project root that you commit A server the whole team should share

A simple rule: start local, promote to user once you rely on it, use project when a teammate says “how did you do that?” Never put secrets in the shared .mcp.json.

Build your own MCP server

A server is smaller than you think. The example below answers questions about orders. In real life the orders would come from your shop’s database; here they sit in a list. You need Node.js and the official TypeScript package for MCP.

npm init -y
npm install @modelcontextprotocol/server zod

Create index.ts (shortened, for understanding):

The real server code: imports, the server name, and the first registered tool
The real server code: imports, the server name, and the first registered tool • 00:11:20
import { McpServer } from "@modelcontextprotocol/server";
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
import * as z from "zod/v4";

const orders = [
  { id: "ORD-1042", customer: "Maya", item: "Wireless mouse", status: "shipped" },
  { id: "ORD-1043", customer: "Leo",  item: "Keyboard",       status: "packing" },
];

const server = new McpServer({ name: "order-status-server", version: "1.0.0" });

server.registerTool(
  "get-order-status",
  {
    title: "Get order status",
    description: "Look up one order by its ID, for example ORD-1042.",
    inputSchema: z.object({ orderId: z.string() }),
  },
  async ({ orderId }) => {
    const o = orders.find((x) => x.id === orderId);
    const text = o
      ? `${o.id}: ${o.item} for ${o.customer} is ${o.status}.`
      : `No order found with ID ${orderId}.`;
    return { content: [{ type: "text", text }] };
  }
);

server.registerTool(
  "get-all-orders",
  { title: "List orders", description: "Return every order." },
  async () => ({
    content: [{ type: "text", text: JSON.stringify(orders, null, 2) }],
  })
);

await server.connect(new StdioServerTransport());

Read it in four steps:

  • 1. Create the server with a name and a version.
  • 2. Register each tool: a name, a title, a description, and the inputs it accepts. The zod line checks that the input is what you promised.
  • 3. Return text. Every tool answers with a list of content items; the simplest is one item of type text.
  • 4. Connect it to the stdio transport, which means “talk through standard input and output”.

That is a complete server. Add it with claude mcp add as shown above, restart Claude, and ask: “Give me all my orders”, then “What is the status of ORD-1042?” Claude shows which tool it called and the answer arrives from your code.

Claude calls the order tool and answers from the server's data
Claude calls the order tool and answers from the server’s data • 00:14:00

The package name and import paths have changed between SDK versions (older tutorials import from @modelcontextprotocol/sdk/server/mcp.js), so check the package’s own README if something does not compile.

Tips for writing good tools

  • Name tools like verbs (get-order-status, create_ticket), and describe them as if for a new colleague.
  • Keep inputs small and specific. A single order ID beats a free-text “query”.
  • Return only what is needed. Long answers cost tokens and bury the useful part.
  • Say plainly when nothing is found, so the model does not guess.
  • Never write debug text to the normal output in a stdio server. Use the error stream; the normal output belongs to the protocol.

A real job: two servers, one task

To show remote servers at work, the same session chained two of them, and a single AI agent coordinated everything:

  • 1. Find a tool. Connect a scraping service’s server (Apify, which offers thousands of ready-made cloud programs called actors). Ask the AI to find the best actor for “web development agencies in Boston via Google Maps” and to check the actor’s inputs and price before running anything.
  • 2. Run it with a small limit. Ask for five results. The cost on the free tier was a few cents, and the AI warned that its own spending limit was below the service’s minimum.
  • 3. Save to Notion. Connect Notion (a connector, one click) and ask the AI to create a database and store one agency per row.
  • 4. Research one result. Use a “RAG web browser” actor: it searches, opens three pages and returns clean text in a single call. RAG (“retrieval-augmented generation”) only means “fetch real content and answer from it instead of guessing”.
  • 5. Write the research back to the Notion row.
After signing in, /mcp shows the new server with its 14 tools
After signing in, /mcp shows the new server with its 14 tools • 00:19:40

Why a special browsing tool instead of letting the AI open pages? A normal AI browser works step by step (load, look, decide, click), and every step spends tokens. A fetch tool does it in one call. The trade-off: it cannot click or log in.

Notice the good habits in this example: ask for a plan and a cost before a tool runs, start with a tiny batch, and break a big job into steps so you can see which tool did what.

Security: the part people skip

Anyone can publish an MCP server, including under a company’s name. The first widely reported malicious server was an imitation of a real email-service package. It copied the genuine code and behaved correctly for fifteen versions, so people trusted it. In version 1.0.16 a single line was added that quietly sent a blind copy of every email to the attacker: password resets, invoices, anything the agent sent. It was downloaded around 1,500 times a week.

A checklist you can use today:

  • Get servers from the owner’s own documentation, repository or the official connector in your app. Do not search “Google Docs MCP” and paste the first command you find.
  • Read the permission screen before you click Allow, especially for “full access”.
  • Pin or check versions for local packages, and be suspicious of a sudden update.
  • Give each server the least access it needs. A read-only key beats an admin key.
  • Keep the approval prompts on for tools that send, delete or pay.
  • Remember the server sees everything you send it, and text it returns can contain hidden instructions. Treat web pages and documents fetched by tools as untrusted.

When MCP is the wrong tool

MCP adds setup, permissions, extra moving parts and a little delay. Compare it with the alternatives:

Need Best choice
One fixed integration inside your own app A normal function or API call. Simpler and faster.
A command that already exists (git, a cloud CLI) Let the AI run the command line.
Teach the AI how you work (style, checklists) A skill or instructions file, not a server.
Many services, or the AI needs to discover tools by itself, or the same tools across several AI apps MCP

The real question is not “is MCP new and exciting” but “does a shared, discoverable contract between the AI and this service solve my problem?” If you control both sides of the connection, probably not.

FAQ

What does MCP stand for?

Model Context Protocol, an open standard for connecting AI applications to tools and data.

Is MCP the same as an API?

No. An API is how programs talk to one service. MCP is a layer on top that lets an AI discover what a service can do and call it in a uniform way. Many MCP servers call ordinary APIs inside.

Do I need to code to use MCP?

No. To use servers you only need one command or a click on a connector. You need code only to build your own.

Which AI tools support it?

Claude Code and the Claude apps, Codex, Cursor, Open Code and many others. The configuration differs; the idea does not.

Is it safe?

It is as safe as the servers you install and the permissions you give. Use official sources, read permissions, and keep approvals on for risky actions.

What is the difference between a connector, a plugin and an MCP server?

A server is the program. A connector is a hosted server wired to your account in an app. A plugin is a package that may include a server plus skills and extras.

Final perspective

MCP is simply a standard way to give an AI hands. Learn the three parts (host, server, tool), keep the scope as narrow as it can be, and treat every server like software you let into your house. Start with one connector that solves a real task, then try writing the 30-line server above to see that there is no magic inside.

Quick reference

  • Add a remote server: claude mcp add --transport http --scope user <name> <URL>
  • Add a local server: claude mcp add --transport stdio --scope local <name> -- <command>
  • List servers and sign in: type /mcp inside Claude Code
  • Scopes: local (you, this folder), user (you, everywhere), project (team, .mcp.json)
  • Always: restart after adding, read permissions, install only from official sources

Educational guide. Commands were checked against the way Claude Code works at the time of writing; options change quickly, so run `claude mcp –help` on your own machine before relying on a flag.

Claude Code GUIDES

More Claude Code guides

Continue with practical guides about Claude Code.

View all AI Coding guides