Guide · MCP · ★★☆☆☆
How to add an MCP server to Claude Code
One command gives Claude Code a new tool. Here is the command, the three scopes and the Windows fix, shown with the servers I run every day.
By Arthur Hsiao · Last updated · 6 min read
What an MCP server is. A small program that gives Claude Code new tools, such as "ask Gemini" or "search Gmail". You add it once with one command. After that, Claude calls its tools when a task needs them.
1Add a local server
Most servers run on your own machine. The command has three parts: options, a name you choose, then -- and the command that starts the server.
claude mcp add -s user gemini-cli -- npx -y gemini-mcp-tool
This is the real one from my setup. It adds the Gemini server from Claude + Gemini via MCP.
Everything after -- belongs to the server, so Claude Code does not read it as its own options.
On Windows, put cmd /c in front of npx. Without it the server can fail to connect. This is the line I run on my PC:
claude mcp add -s user gemini-cli -- cmd /c npx -y gemini-mcp-tool
2Pick a scope
The scope decides where the server works and where it is saved.
| Scope | Flag | Where it works | Saved in |
|---|---|---|---|
| Local | none (the default) | This project, only for you | ~/.claude.json |
| Project | -s project | This project, for everyone who clones it | .mcp.json in the repo |
| User | -s user | Every project, only for you | ~/.claude.json |
I use -s user for my servers, because I want Gemini and ComfyUI in every project.
Use project scope when a team should share a server. Claude Code asks each person to approve it first.
.mcp.json goes into git, so keep API keys out of it.
3Pass a setting with -e
Some servers need a path or an API key. -e sets an environment variable for that one server:
claude mcp add -s user comfy-mcp -e COMFY_BIN=<path to comfy.exe> -- comfy-mcp
That line is from how to use ComfyUI with Claude Code. The server reads COMFY_BIN to find ComfyUI's command-line tool.
4Add a remote server
Some servers run on the web, not on your machine. Those take a URL:
claude mcp add --transport http <name> <url>
My own remote tools are connectors. You switch them on at claude.ai, and they show up in Claude Code by themselves when you log in with the same account. There is no API key and no code. Gmail is the one I use most, so here is that route.
5Connect Gmail as a connector
- Open claude.ai and go to Settings, then Connectors.
- Find Gmail and press Connect.
- Sign in to Google and allow access.
Google shows what Claude may do. Read it. You can remove the connection at any time from the same screen, or from your Google account's security page.
Use the same Claude account in Claude Code, start a session and type /mcp. You should see claude.ai Gmail in the list. If it says it needs sign-in, pick it and follow the link.
If it is missing, run /login to make sure Claude Code uses the same account, then restart the session.
Start with prompts that only read, then try writing, but only as a draft:
Summarize the unread emails from this week in 5 bullets. Do not reply to anything.
Write a polite reply to the latest email from Sam, asking to move the meeting to Friday. Save it as a draft. Do not send it.
The connector can search threads, read messages, create drafts, and also send. My rules:
- Say "draft" every time. If you do not, Claude may offer to send. Sending is not undoable. Don't tick "always allow" for sending mail.
- Ask for the part you need. "Find the invoice from March" is cheaper than "read my inbox", because every email Claude reads uses your tokens.
- Treat email text as untrusted. A message can contain lines that look like instructions. Claude should only follow what you typed.
Want to send mail from your own domain address too? See free custom domain email with Cloudflare and Gmail.
6Check it connected
claude mcp list
Part of what mine prints:
claude.ai Gmail: https://gmailmcp.googleapis.com/mcp/v1 - ✔ Connected gemini-cli: cmd /c npx -y gemini-mcp-tool - ✔ Connected comfy-mcp: C:\Users\<you>\.local\bin\comfy-mcp.exe - ✔ Connected
Inside a session, /mcp shows the same list. It is also where you sign in to a server that needs it.
Two more commands worth knowing:
claude mcp get gemini-cli # show one server's details claude mcp remove gemini-cli # remove it
7Try it
Start a new session and ask for something only that server can do:
Use Gemini to summarise @src in 10 bullet points.
You should see Claude call the server's tool, here ask-gemini, and come back with the answer.
8Know what it costs
Adding a server is cheap. Claude Code loads only the tool names at the start, and fetches a tool's full details when a task needs it.
What costs tokens is the output. A tool that returns a huge result fills your context, and Claude Code warns you when one result passes 10,000 tokens. So ask for the part you need: "the last 20 log lines", not "the log". More habits like this are in how to save tokens in Claude Code.
Only add servers you trust. A server is a program that runs on your machine with your access. One that reads web pages or email can also bring in text that tries to give Claude orders. Read what a server does before you add it, and read each tool call before you approve it.
I check what leaves my machine with a secret-scanning hook.
An MCP server adds tools. To change how Claude works instead, see skills vs subagents vs hooks vs slash commands.
Every server I use is on my tools page, with what to watch out for.