Course navigation
Claude CodeLesson 16 of 25

MCP in Claude Code

The Model Context Protocol (MCP) is an open standard that lets Claude connect directly to your databases, APIs, and services. Instead of copy-pasting data into chat, Claude reads and acts on the live source.

Why MCP matters

Without MCP, getting Claude to work with external data means pasting that data into the chat manually — error-prone, tedious, and limited by what fits in the message. MCP removes that friction by giving Claude a direct connection to the source.

ApproachSteps
Without MCP
  1. Open your database client
  2. Copy query results
  3. Paste into Claude chat
  4. Ask your question
  5. Repeat for every follow-up
With MCP
  1. Add the MCP server once
  2. Ask Claude in plain English: “How many users signed up today?”
  3. Claude queries the database directly
  4. Done — no copy-pasting ever again
MCP is not limited to databases. You can connect Claude to issue trackers, design tools, monitoring dashboards, communication platforms, and any service that has an MCP server.

How MCP works

An MCP server is a small process that sits between Claude and an external system. It exposes a standard set of tools, resources, and prompts that Claude can call. Claude Code manages starting and stopping these servers automatically.

StepRoleWhat happens
1YouSend a natural-language request
2Claude CodeDecides which MCP tool to call
3MCP serverTranslates the request to an API or DB call
4External toolReturns data from the database, API, or service

The protocol is open source. Anyone can build an MCP server for their tool. Hundreds of community servers already exist on GitHub for databases, SaaS apps, local utilities, and more.

Transport types

When you add an MCP server you choose how Claude connects to it. Pick HTTP for cloud services, stdio for local tools, and avoid SSE (it is deprecated).

TransportStatusBest forExample command
HTTPRecommendedCloud services, SaaS APIs, hosted MCP serversclaude mcp add --transport http my-service https://mcp.example.com/mcp
stdioLocal toolsDatabases, local scripts, filesystem toolsclaude mcp add --transport stdio my-tool -- npx -y some-mcp-package
SSEDeprecatedLegacy servers that have not moved to HTTP yetclaude mcp add --transport sse legacy-service https://example.com/sse

Worked example: query your dev database

This example connects Claude to a local SQLite database so you can ask questions about your data in plain English instead of writing SQL by hand. It uses the stdio transport because the database lives on your machine.

1

Add the SQLite MCP server

The -- (double dash) separates Claude's flags from the command that launches the MCP server process. Everything after it is passed directly to the server.

Terminal
claude mcp add --transport stdio devdb \
-- npx -y @modelcontextprotocol/server-sqlite \
--db-path ./data/dev.db
# Confirm it was added
claude mcp list
devdb stdio ./data/dev.db
The server name devdb is just a label you choose. It appears in /mcp and in tool call logs so you can identify which server handled each request.
2

Check the connection inside Claude Code

Run /mcp in any Claude Code session to see the status of every connected server. A green indicator means it is running and ready to use.

Claude Code
> /mcp
Connected servers:
devdb stdio running
Tools available: query_database, list_tables,
describe_table, run_statement
3

Ask Claude about your data

Claude now has access to your database. Ask questions in natural language — it will call the right tool internally and return the answer.

> What tables are in this database?
Found 6 tables: users, orders, products, sessions, audit_log, settings
> How many new users signed up this week?
143 users registered between Mon Apr 28 – Fri May 2
> Find all orders that have been pending for more than 3 days
12 orders are stuck in pending. Oldest is order #8821 from April 28.

Installation scopes

Scope controls who can use the server and whether its configuration is shared with your team. Use the --scope flag when adding a server.

ScopeFlagStored inShared?
local--scope local (default)~/.claude.jsonPrivate to you
project--scope project.mcp.json in project rootTeam-shared via Git
user--scope user~/.claude.jsonPrivate to you

The generated .mcp.json file (project scope)

.mcp.json
{
"mcpServers": {
"devdb": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-sqlite",
"--db-path", "./data/dev.db"],
"env": {}
}
}
}

Authenticating with remote servers

Many cloud MCP servers require you to log in before Claude can use them. Claude Code handles this through /mcp — the built-in server management command.

MethodStepsNotes
OAuth 2.0 (browser flow)
  1. Add the server with claude mcp add --transport http
  2. Run /mcp inside Claude Code
  3. Claude opens your browser for the login
  4. Complete login — tokens are saved automatically
Works for most hosted services. Tokens refresh automatically in the background.
API key / Bearer token
  1. Generate an API key in the service dashboard
  2. Pass it as a header: claude mcp add --transport http svc https://mcp.svc.com --header "Authorization: Bearer YOUR_KEY"
  3. No browser flow needed — key is stored in config
Best for services that issue long-lived API keys rather than OAuth tokens.

Key commands

All server management happens through the claude mcp sub-command in your terminal, and through /mcp inside a Claude Code session.

CommandWhat it does
claude mcp add --transport http name urlAdd a remote HTTP MCP server
claude mcp add --transport stdio name -- cmdAdd a local stdio MCP server
claude mcp listShow all configured servers
claude mcp get <name>Show details for one server
claude mcp remove <name>Remove a server from config
/mcpView server status and authenticate inside a session

What you can ask once connected

Once an MCP server is running, Claude treats its tools as first-class capabilities — just like its built-in file editing and code search. Phrase requests in plain English and Claude figures out which tool to call.

CategoryExample prompts
Database
  • Show me the schema for the orders table
  • Which products haven't sold in 60 days?
  • Find duplicate email addresses in users
Issue tracker
  • What open bugs are assigned to me?
  • Create an issue for the error we just found
  • Summarise all issues closed this sprint
Monitoring
  • What errors happened in the last hour?
  • Which page has the highest error rate today?
  • Show me the stack trace for error ID xyz
Design / Docs
  • What changed in the latest Figma design?
  • Find the API docs for the payment endpoint
  • Summarise the last three Slack messages in #alerts

Resources and prompts

MCP servers can expose more than just tools. They can also provide resources (data you reference with @) and prompts (canned workflows you call with /).

Resources — @mention

Type @ in your prompt to see available resources from all connected servers.

> Can you analyse @devdb:table://orders
and spot any data quality issues?
> Compare @docs:file://api/v2
with @docs:file://api/v1 — what changed?

Prompts — /mcp__commands

MCP prompts become slash commands in the format /mcp__servername__promptname.

# List all MCP commands
> / (type / to see the full list)
# Call a specific MCP prompt
> /mcp__github__list_my_prs
> /mcp__linear__create_issue "Login bug" high

Before you continue

  • MCP gives Claude a direct connection to databases, APIs, and external services.
  • Use HTTP for cloud servers, stdio for local tools, and project scope to share with your team.
  • Manage servers with claude mcp in the terminal and /mcp inside a session.
  • Resources use @; MCP prompts appear as /mcp__server__prompt slash commands.
  • Next lesson: Hooks — automatic scripts that run before or after Claude takes an action.

What's Next

MCP opens Claude Code to any external service. Next: Hooks — automatic scripts that run before or after Claude takes an action.