ike database connectors or local browser automation drivers. When both scopes define the same server, project scope overrides user scope. This separation prevents credential leakage across repositories and allows per-codebase tuning.
Step 2: Implement Credential Vaulting
Never embed secrets directly in configuration files. Use environment variable resolution with explicit prefixes to distinguish MCP credentials from application secrets. For production environments, inject tokens via a secrets manager or CI/CD pipeline. Always request the narrowest permission scope. For example, version control integrations should use fine-grained personal access tokens with repository and workflow scopes only. Database integrations must default to read-only connection strings unless write operations are explicitly required and audited.
The agent's decision quality degrades when tool descriptions compete for context window space. Cap active servers at six. Prioritize tools that expose unique, non-overlapping capabilities. If two servers provide similar functionality (e.g., two different search adapters), disable one. Monitor agent turn logs to identify unused tools and remove them during quarterly reviews.
Step 4: Select Integrations by Workflow Phase
Map servers to development stages rather than installing them reactively:
- Planning & Tracking: Issue management, ticket synchronization
- Code Generation: Documentation lookup, schema inspection
- Verification: Browser automation, error monitoring
- Deployment & Ops: Cloud storage, edge configuration, billing APIs
Architecture Rationale & Implementation
The following TypeScript configuration builder demonstrates a production-grade approach. It replaces raw JSON with a validated, environment-aware module that generates the final MCP settings object. This structure enforces type safety, prevents secret leakage, and makes tool budgeting explicit.
import { z } from 'zod';
// Schema definition for MCP server configuration
const McpServerSchema = z.object({
command: z.literal('npx'),
args: z.array(z.string()),
env: z.record(z.string()).optional(),
disabled: z.boolean().default(false),
});
type McpServerConfig = z.infer<typeof McpServerSchema>;
// Centralized registry with explicit tool budget tracking
const MCP_REGISTRY: Record<string, McpServerConfig> = {
versionControl: {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-github'],
env: {
VCS_AUTH_TOKEN: process.env.GITHUB_PAT ?? '',
VCS_SCOPE: 'repo,read:org,workflow',
},
},
documentationLookup: {
command: 'npx',
args: ['-y', '@upstash/context7-mcp'],
},
issueTracking: {
command: 'npx',
args: ['-y', '@linear/mcp-server'],
env: {
TRACKER_API_KEY: process.env.LINEAR_TOKEN ?? '',
},
},
databaseInspector: {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-postgres'],
env: {
DB_CONNECTION_URI: process.env.POSTGRES_READONLY_DSN ?? '',
},
},
uiVerifier: {
command: 'npx',
args: ['-y', '@executeautomation/playwright-mcp-server'],
disabled: true, // Disabled by default to preserve tool budget
},
errorMonitor: {
command: 'npx',
args: ['-y', '@sentry/mcp-server'],
env: {
OBSERVABILITY_TOKEN: process.env.SENTRY_AUTH ?? '',
OBSERVABILITY_ORG: process.env.SENTRY_ORG ?? '',
},
},
};
// Validation and export function
export function generateMcpConfig(): Record<string, McpServerConfig> {
const activeServers: Record<string, McpServerConfig> = {};
let activeCount = 0;
const MAX_TOOLS = 6;
for (const [alias, config] of Object.entries(MCP_REGISTRY)) {
if (config.disabled) continue;
if (activeCount >= MAX_TOOLS) {
console.warn(`Tool budget reached. Skipping ${alias}.`);
break;
}
// Validate required env vars are present
if (config.env) {
const missing = Object.keys(config.env).filter(
(key) => !process.env[key]
);
if (missing.length > 0) {
console.warn(`Skipping ${alias}: missing env vars [${missing.join(', ')}]`);
continue;
}
}
activeServers[alias] = config;
activeCount++;
}
return activeServers;
}
Why this architecture works:
- Type safety prevents malformed JSON from breaking the agent startup sequence.
- Explicit budget enforcement stops accidental tool inflation during team onboarding.
- Environment variable validation fails fast at configuration time rather than during agent execution.
- Alias-based registration decouples internal naming from external package names, allowing seamless server swaps without updating agent prompts.
Pitfall Guide
Explanation: Installing every available MCP server under the assumption that more capabilities equal better results. Each server adds tool descriptions to the context window, increasing parsing overhead and diluting the agent's focus.
Fix: Enforce a hard cap of six active servers. Use a configuration validator that rejects new registrations once the limit is reached. Audit unused tools monthly and remove them.
2. Over-Privileged Database Credentials
Explanation: Connecting the agent to a database using a write-capable or admin-level DSN. This creates a high-risk attack surface where malformed queries or prompt injection can trigger unintended mutations.
Fix: Always provision a dedicated read-only database role for MCP connections. If write operations are required, route them through a separate, audited service account with transaction logging enabled.
3. Scope Collision Between User and Project Configs
Explanation: Defining the same server in both ~/.claude/settings.json and .claude/settings.json without understanding override behavior. This causes unpredictable credential resolution and environment mismatches.
Fix: Reserve user scope for cross-project utilities (documentation fetchers, version control). Place environment-specific tools (database connectors, local automation drivers) exclusively in project scope. Document the override rule in team runbooks.
4. Stale Integration Dependencies
Explanation: Relying on MCP servers that haven't been updated in over three months. The protocol specification evolves frequently, and outdated servers often fail to serialize responses correctly or miss new capability flags.
Fix: Implement a quarterly dependency audit. Pin server versions in configuration where possible. Subscribe to release notes for critical integrations and test upgrades in a sandbox workspace before deploying to active projects.
5. Secret Leakage in Version Control
Explanation: Committing configuration files containing API keys, tokens, or connection strings. Even with .gitignore, accidental commits or forked repositories can expose credentials.
Fix: Never store secrets in repository-tracked files. Use environment variable injection via shell profiles or CI/CD pipelines. Commit a settings.example.json with placeholder values and enforce pre-commit hooks that scan for token patterns.
6. Cross-Client Assumption Fallacy
Explanation: Assuming that an MCP server configured for one AI coding assistant will work identically across all clients. While the protocol is standardized, client implementations differ in tool parsing, permission models, and sandboxing behavior.
Fix: Treat each client as a distinct runtime. Validate server compatibility against the specific client's documentation. Avoid sharing configuration files across different AI assistants without explicit compatibility testing.
7. Ignoring Read-Only Fallbacks
Explanation: Designing workflows that require write access for every integration, even when inspection or reporting would suffice. This increases risk and complicates permission management.
Fix: Default to read-only capabilities for monitoring, documentation, and tracking servers. Enable write access only for tools that directly support code generation or deployment pipelines, and require explicit user confirmation for destructive actions.
Production Bundle
Action Checklist
Decision Matrix
| Scenario | Recommended Approach | Why | Cost Impact |
|---|
| Solo developer working across multiple stacks | User-scope GitHub + Context7 + 1 tracking server | Minimizes setup friction while covering planning, docs, and version control | Low (single token management) |
| Team using Linear for sprint planning | Project-scope Linear + GitHub + Sentry | Aligns agent with team workflow and production error tracking | Medium (service account provisioning) |
| Database-heavy backend project | Project-scope Postgres (read-only) + GitHub + Context7 | Enables schema inspection and query optimization without write risk | Low-Medium (DB role creation) |
| Frontend/E2E testing focus | Project-scope Playwright + GitHub + Slack | Supports UI verification and async team communication | Medium (browser runtime overhead) |
| Multi-client AI assistant environment | Strict project-scope isolation + environment variable injection | Prevents cross-client configuration leakage and scope collisions | High (initial setup complexity) |
Configuration Template
Copy this structure into your project's .claude/settings.json or use the TypeScript builder above to generate it. Replace placeholder values with environment variable references.
{
"mcpServers": {
"version_control": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"VCS_AUTH_TOKEN": "${GITHUB_PAT}"
}
},
"doc_lookup": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"]
},
"issue_tracker": {
"command": "npx",
"args": ["-y", "@linear/mcp-server"],
"env": {
"TRACKER_API_KEY": "${LINEAR_TOKEN}"
}
},
"db_inspector": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"${POSTGRES_READONLY_DSN}"
]
}
}
}
Quick Start Guide
- Create environment variables: Export required tokens in your shell profile or
.env file (GITHUB_PAT, LINEAR_TOKEN, POSTGRES_READONLY_DSN).
- Initialize project scope: Create
.claude/settings.json in your repository root and paste the configuration template.
- Validate configuration: Run a syntax check or use the TypeScript builder to ensure all environment variables resolve and the tool count stays within budget.
- Launch agent: Start Claude Code in the project directory. Verify tool availability by requesting a simple workflow (e.g., "List recent issues and fetch the React 19 migration guide").
- Monitor and tune: Review agent turn logs for unused tools or latency spikes. Disable non-essential servers and rotate credentials quarterly.