Project-Scoped MCP Config with .mcp.json: Share Servers with Your Team
A .mcp.json file at the root of a repository lists the MCP servers a project needs, so everyone who opens the project in a supporting client gets the same setup. Claude Code reads this file, and other tools have adopted similar project-level files. You commit it to version control like any other config.
The file format
The structure matches the mcpServers object you saw in the Claude Desktop config. Each key is a server name.
{
"mcpServers": {
"project-db": {
"command": "node",
"args": ["./tools/db-server/build/index.js"],
"env": {
"DATABASE_URL": "${DATABASE_URL}"
}
},
"docs": {
"type": "http",
"url": "https://mcp.example.com/mcp"
}
}
}
The first entry is a local stdio server. The second is a remote Streamable HTTP server, marked with "type": "http". Local entries may omit the type, because stdio is the default.
Why use relative paths here
Unlike the desktop app, a project file is read in the context of a project, and the client starts servers from the project directory. That makes relative paths like ./tools/db-server/build/index.js reasonable, and it is what lets the file work on every teammate's machine. If your client does not start servers from the project root, use a path variable or a small wrapper script instead.
Keep secrets out of the file
The file is committed, so it must not contain tokens. Claude Code supports environment variable expansion in this file with the ${VAR} syntax, and a default form ${VAR:-fallback}. Each developer sets the variable in their own shell or a git-ignored env file. The example above reads DATABASE_URL from the environment of the person who runs the client. Check your client's documentation to confirm which fields support expansion before relying on it.
Create it from the command line
You do not have to write the file by hand. Adding a server with the project scope writes the entry for you:
claude mcp add --scope project project-db -- node ./tools/db-server/build/index.js
git add .mcp.json
git commit -m "Add project MCP servers"
Approval prompts
A repository file that launches programs is a security risk. Imagine cloning an unknown repository whose .mcp.json starts a command that reads your home folder. For this reason, Claude Code asks you to approve project servers before using them. Read each entry before you approve, and treat the file in a pull request as executable code during review.
Team conventions that help
- Add a section to the README that lists each project server, what it does, and which environment variables it needs.
- Provide a
.env.examplefile with variable names and no values. - Pin versions for packages launched with npx or uvx, for example
@scope/server@1.4.2, so the whole team runs the same code. - Prefer servers that only need read access in shared files. A write-capable server should be an explicit choice by each person.
- Review changes to
.mcp.jsonlike changes to a CI workflow file.
Example: a team setup
Suppose a team builds a web app. Their file might list three servers: one for the database schema (read-only), one for the internal documentation site over HTTP, and one that wraps the team's issue tracker. A new developer clones the repository, exports the variables from the README, starts the client and approves the servers. In minutes they have the same context as everyone else, with no per-person setup instructions to maintain.
Common mistakes
- Committing a real API key in
env. Rotate it immediately if that happens. - Using absolute paths from your own machine.
- Adding many servers by default. Every tool a server lists takes space in the model's context, so enable only what the project needs.
- Forgetting to document the build step for a local server, so the path in the file points to a missing build folder.
Comments
No comments yet. Have a question or a tip? Be the first to share it.