Ardrey 情報マガジン

mcpjson

📅 November 6, 2026📖 Verified Publication

The Complete Guide to the mcp.json Configuration File

The mcp.json file is the backbone of modern Large Language Model (LLM) integrations that require access to local files, databases, or APIs. By standardizing how AI agents request and receive context, this configuration file reduces boilerplate code and enhances security. This guide provides a practical playbook for structuring, securing, and deploying MCP configurations effectively.

Understanding the mcp.json Architecture

The Model Context Protocol structure is hierarchical. The root object typically contains server definitions, transport types, and specific tool registrations. Understanding this hierarchy allows you to debug connectivity issues faster and scale your AI applications.

Anatomy of the JSON Structure

A standard mcp.json file follows this logical flow. Note that specific keys may vary slightly depending on your client implementation (e.g., Claude Desktop, VS Code, or custom clients), but the core concepts remain consistent.

  • version: Specifies the MCP protocol version to ensure compatibility between client and server.
  • mcpServers: An object where each key is a unique server name (e.g., "database-tool", "weather-api").
  • command & args: Defines how to launch the server process (stdio transport).
  • url: Defines the endpoint for HTTP/SSE transports.
  • env: Securely injects environment variables required by the server.

Practical Implementation Playbook

Setting up mcp.json is not just about writing valid JSON; it is about defining a secure boundary. Use the checklist below to build a robust configuration from scratch.

Step 1: Environment & Prerequisites

  • Ensure Node.js v18+ or Python 3.10+ is installed, depending on your server choice.
  • Verify that your LLM client supports MCP (e.g., recent versions of Claude Desktop or VS Code with MCP extensions).
  • Create a dedicated directory for your MCP configuration to isolate it from your main project source code.

Step 2: Define Server Configurations

  • Start with one server to minimize debugging complexity.
  • Use absolute paths for local files to avoid working directory issues.
  • Specify transport type:
    • Stdio: Best for local tools (filesystem, local databases). Low latency.
    • SSE/HTTP: Best for remote services. Requires secure token handling.

Step 3: Security & Permissions

  • Least Privilege: Only grant the server access to the specific directories or API endpoints it needs.
  • No Secrets in JSON: Never hardcode API keys in mcp.json. Use the "env" block to reference system environment variables (e.g., "DB_PASSWORD": "${DB_PASSWORD}").
  • Sandboxing: If using local file systems, configure the server to run in a restricted container or user account without root privileges.

Comparison: Local vs. Remote MCP Servers

Choosing the right transport method depends on your latency requirements and security constraints. Use the table below to decide which configuration style fits your use case.

Feature Local (Stdio) Remote (HTTP/SSE)
Configuration Key "command", "args" "url", "headers"
Best For Filesystems, local SQL DBs, CLI tools Cloud APIs, shared team services, SaaS integrations
Security Model OS-level sandboxing, user permissions Network firewalls, OAuth2/API Keys
Latency Low (sub-millisecond) Variable (depends on network speed)
Setup Complexity Medium (requires local runtime) Low (just endpoint URL)

Troubleshooting & Validation

Most mcp.json errors stem from syntax mistakes or misconfigured environment variables. Implement this validation routine to catch issues early.

Diagnostic Checklist

  • JSON Syntax: Run the file through a validator (e.g., jq or VS Code JSON extension) to check for trailing commas or unquoted keys.
  • Binary Path: If using command, ensure the executable path is correct and included in your system PATH. On Linux/macOS, use /usr/local/bin/... or verify with which node.
  • Environment Variables: Confirm that variables referenced in the "env" block are actually set in your shell or CI environment. Use printenv to debug.
  • Server Logs: Enable verbose logging in your LLM client to see if the server process is crashing on startup. Look for "spawn ENOENT" errors, which usually indicate a missing binary.

Frequently Asked Questions

What is the difference between mcp.json and traditional API configuration files?

Unlike traditional API configs that define static endpoints, mcp.json defines a dynamic communication protocol. It tells the LLM client how to interact with the tool (via stdio or HTTP) and what tools are available. This allows for richer, context-aware interactions where the LLM can autonomously decide which tool to call, rather than just fetching a static URL.

Can I use multiple mcp.json files in one project?

It is best practice to maintain a single source of truth for your MCP configuration to avoid conflicts. However, advanced setups can use "config files" to merge settings. For most users, stick to one primary mcp.json and manage different environments (Dev/Prod) by swapping files or using environment variable overrides for sensitive data like URLs and API keys.

How do I update my mcp.json after a protocol version change?

Always check the release notes of your specific LLM client and the MCP servers you are using. Protocol changes may alter required fields (e.g., adding a "type" field). To update: 1) Backup your current file, 2) Review the new JSON Schema for the updated protocol, 3) Apply necessary field changes, 4) Run your local validation script to ensure the new structure is valid before reconnecting your LLM client.