
MCP in Claude Code: How to Connect Databases and APIs
Published on:
Reading time: 6 min
Topic: Technology
Author: Leandro Valencia
Add MCP servers to Claude Code with claude mcp add, share them with your team in .mcp.json, and connect Git, PostgreSQL and APIs without exposing credentials.
Table of Contents
- Quick reference
- How MCP works
- Step 1: add a local server (stdio)
- Step 2: connect a remote server (HTTP)
- Step 3: choose the scope
- Step 4: share the configuration without sharing secrets
- Step 5: verify that it works
- 8 security rules before connecting anything serious
- And Superpowers, where does it fit?
- Plan for your team
Once installed, Claude Code reads files and runs commands in your terminal. For it to query your database, review your issues or call an API, you need MCP (Model Context Protocol), the open protocol Anthropic published to connect models with external tools.
This guide explains how to add MCP servers, how to share them with your team without committing credentials to Git, and which security rules to follow before you connect anything serious.
Quick reference
| Server | Transport | Command | Suggested scope | Key caution |
|---|---|---|---|---|
| Local Git | stdio (uvx) |
claude mcp add git -- uvx mcp-server-git |
user | Check which write operations it exposes |
| PostgreSQL | stdio (npx) |
claude mcp add db -- npx -y @bytebase/dbhub --dsn "$DATABASE_READONLY_URL" |
project | Only with a read-only user |
| Remote API | http | claude mcp add --transport http mi-api https://mcp.ejemplo.com/mcp |
project | The token goes in a variable, never in the file |
| File system | stdio (npx) |
claude mcp add archivos -- npx -y @modelcontextprotocol/server-filesystem . |
local | Limit the path to the project, never the root of the disk |
How MCP works
Claude Code acts as the client. Each MCP server is a process or service that exposes tools, for example run_query or list_issues. During the session, Claude sees those tools, decides when to call them and asks for your permission depending on your configuration.
There are two ways to connect:
- stdio: Claude Code starts the server as a local process (usually with
npxoruvx) and communicates through standard input and output. This is the usual approach for tools that run on your machine. - http: the server lives at a remote URL. This is the usual approach for cloud services. Many large services publish official MCP servers with OAuth authentication.
Step 1: add a local server (stdio)
The general form is:
claude mcp add <nombre> -- <comando> [argumentos...]
The -- separator is mandatory: it separates the options of claude from the command that starts the server. Without it, Claude Code tries to interpret the server's arguments as its own.
Example with a Git server:
claude mcp add git -- uvx mcp-server-git
Example with PostgreSQL using DBHub, pointing to an environment variable with a read-only user:
export DATABASE_READONLY_URL="postgresql://lectura:****@db.tuempresa.com:5432/analytics"
claude mcp add db -- npx -y @bytebase/dbhub --dsn "$DATABASE_READONLY_URL"
Step 2: connect a remote server (HTTP)
claude mcp add --transport http mi-api https://mcp.ejemplo.com/mcp \
--header "Authorization: Bearer $MI_API_TOKEN"
If the server uses OAuth, do not add the header: open a session, run /mcp and follow the authentication flow in the browser.
Step 3: choose the scope
Each server is saved in one of three scopes, which you choose with --scope:
local(default): only for you and only in this project. Useful for tests or servers with personal credentials.project: written to.mcp.jsonat the root of the repo. The whole team receives it when they clone. Claude Code asks for approval the first time someone uses a project server.user: for you in all your projects. Ideal for general tools such as Git.
claude mcp add --scope project db -- npx -y @bytebase/dbhub --dsn '${DATABASE_READONLY_URL}'
Step 4: share the configuration without sharing secrets
The .mcp.json file accepts environment variables with the ${VARIABLE} syntax (and ${VARIABLE:-default_value}). This way the file can go into the repo without credentials:
{
"mcpServers": {
"mi-api": {
"type": "http",
"url": "https://mcp.ejemplo.com/mcp",
"headers": {
"Authorization": "Bearer ${MI_API_TOKEN}"
}
},
"db": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@bytebase/dbhub", "--dsn", "${DATABASE_READONLY_URL}"]
}
}
}
Each developer exports their own variables (export MI_API_TOKEN=...) or loads them from a secrets manager, and nobody has to touch the file.
Step 5: verify that it works
claude mcp list # estado de todos los servidores
claude mcp get db # detalle de uno
claude mcp remove db # eliminarlo
Inside a session, /mcp shows which servers are connected and which tools they expose. If a server shows an error, the most common cause is an environment variable that is not defined in the shell where you opened Claude Code.
8 security rules before connecting anything serious
- Least privilege. Read-only database users, tokens with only the permissions they need. Never give the agent an administrator user.
- Zero secrets in the repo. Environment variables in
.mcp.json, always. - Bounded paths. The file server should only see the project folder.
- Official or reviewed servers. Prefer the ones published by the service's own provider. An MCP server runs code on your machine: check where it comes from before installing it.
- Human approval for anything that writes. Use Claude Code's permissions so that tools which modify data ask for confirmation, or a
PreToolUsehook with a matcher such asmcp__db__.*to block or log certain calls. - Reasonable timeouts. If a server takes a long time to start (the first download with
npxis usually slow), raise the timeout with theMCP_TIMEOUTvariable, in milliseconds. - Output limit. If a tool returns huge results, adjust
MAX_MCP_OUTPUT_TOKENSand ask for queries withLIMITso you do not fill the model's context. - Replicas before production. For analysis, connect a replica or a staging environment, not the main database.
And Superpowers, where does it fit?
MCP gives Claude Code access to tools. Superpowers gives it a method: a skills plugin that forces it to design before coding, write a step-by-step plan and work test-first. They are complementary: with MCP, Claude can query your database; with Superpowers, it does so inside a reviewed plan.
If you do not have it yet, the guide on how to install Superpowers in Claude Code explains how to install it from the marketplace in five minutes.
Plan for your team
- Standardize the tool. Install Claude Code on the team and decide which servers are for general use (
userscope) and which belong to the project. - Create credentials for the AI. Ask infrastructure for a dedicated database user, read-only and with access limited to the schemas needed.
- Version
.mcp.json. Commit it to the repo with environment variables and document in the README which variables each developer needs. - Measure the impact. If the team solves problems faster, that changes your cost structure. Run the numbers with the profit margin calculator.
Step-by-step guide
Add a local server (stdio)
claude mcp add <nombre> -- <comando>, with the -- separator before the command.
Connect a remote server (HTTP)
claude mcp add --transport http <nombre> <url>, with the token in a header.
Choose the right scope
local for you, project for the team (.mcp.json), user for all your projects.
Keep credentials out of the repo
Use ${VARIABLE} in .mcp.json and have each developer export it in their shell.
Verify and limit permissions
claude mcp list or /mcp, read-only users, and hooks for anything that writes.
Frequently asked questions
What is MCP in Claude Code?
MCP (Model Context Protocol) is an open protocol that lets Claude Code connect to external tools: databases, repositories, task managers or APIs. Each connection is an MCP server that exposes tools Claude can call during the session.
What is the difference between the local, project and user scopes?
local stores the server only for you and only in the current project; it is the default. project writes it to a .mcp.json file at the root of the repo so the whole team gets it. user makes it available to you in all your projects.
Is it safe to connect my production database?
Only with a read-only user and, preferably, against a replica. An agent with write access to production can run a destructive query because it misread an instruction. It is also worth reviewing which tools the server exposes before enabling it.
Do I need Superpowers to use MCP?
No. MCP is built into Claude Code. Superpowers is a skills plugin that enforces a working method (design, plan, tests). They complement each other, but each one works on its own.
Related Posts
Keep exploring similar content that may interest you

How to Install Superpowers in Claude Code (2026)
Install Superpowers in Claude Code via the official marketplace or GitHub: how to verify it is active and fix the common errors that actually appear.

Your Website Isn't Ready for AI Agents (Here's How to Check in 30 Seconds)
AI agents are already real visitors to your website, and most sites ignore them. Learn how to scan your domain with isitagentready.com, turn the report into an actionable improvement spec with a ready-to-copy prompt, and execute it without breaking anything using Superpowers' brainstorming workflow.

Manus vs Claude Code vs OpenCode: Pricing and Which to Pick (2026)
Manus works in the cloud; Claude Code and OpenCode work on your machine. We compare pricing, how each one bills, key features and which fits your profile.
Partnerships
Tools I use every day, on better terms for this community.