Claude Code - Lesson 16

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.

Model Context ProtocolMCP serversHTTP / stdioScopesclaude mcp add

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.

Without MCP

  1. 1.Open your database client
  2. 2.Copy query results
  3. 3.Paste into Claude chat
  4. 4.Ask your question
  5. 5.Repeat for every follow-up

With MCP

  1. 1.Add the MCP server once
  2. 2.Ask Claude in plain English: "How many users signed up today?"
  3. 3.Claude queries the database directly
  4. 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.

🧑‍💻

You

Natural language request

🧠

Claude Code

Decides which tool to call

⚙️

MCP Server

Translates to API/DB call

🗄️

External Tool

Database / API / 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. There are three transport options. Pick HTTP for cloud services, stdio for local tools, and avoid SSE (it's deprecated).

HTTP

Recommended

Connects to remote cloud-hosted MCP servers over HTTPS. Supports OAuth authentication and auto-reconnects if the connection drops.

Best for: Cloud services, SaaS APIs, any hosted MCP server

claude mcp add --transport http my-service https://mcp.example.com/mcp

stdio

Local tools

Starts a local process on your machine and communicates via stdin/stdout. Ideal for database clients, CLI wrappers, and scripts that need filesystem access.

Best for: Databases, local scripts, filesystem tools, dev utilities

claude mcp add --transport stdio my-tool -- npx -y some-mcp-package

SSE

Deprecated

Server-Sent Events transport. It works, but Anthropic recommends switching to HTTP where available. Only use it if the server has not yet added HTTP support.

Best for: Legacy servers that haven't moved to HTTP yet

claude 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.

local--scope local (default)Private to you

Available only in the current project, only to you. Good for personal credentials or experimental servers you aren't ready to share.

Stored in: ~/.claude.json

project--scope projectTeam-shared via Git

Saved in .mcp.json at the project root. Commit this file and every team member gets the same servers automatically when they open the project.

Stored in: .mcp.json in project root

user--scope userPrivate to you

Available to you across every project on your machine. Good for personal utility servers like a note-taking tool or a personal API key.

Stored in: ~/.claude.json

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.

OAuth 2.0 (browser flow)

  1. 1.Add the server with claude mcp add --transport http
  2. 2.Run /mcp inside Claude Code
  3. 3.Claude opens your browser for the login
  4. 4.Complete login — tokens are saved automatically

Works for most hosted services. Tokens refresh automatically in the background.

API key / Bearer token

  1. 1.Generate an API key in the service dashboard
  2. 2.Pass it as a header when adding the server:
  3. 3.claude mcp add --transport http svc https://mcp.svc.com --header "Authorization: Bearer YOUR_KEY"
  4. 4.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. You phrase requests in plain English and Claude figures out which tool to call.

🗄️ 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. Reference them like files:

> 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. They work exactly like skills:

# 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

Quick Reference

Add HTTP server

claude mcp add \
--transport http \
my-api https://mcp.api.com/mcp

Add stdio server

claude mcp add \
--transport stdio devdb \
-- npx -y server-pkg

Manage servers

claude mcp list
claude mcp get devdb
claude mcp remove devdb
/mcp # inside session

What's Next

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