MCP Inspector

repository·main·Indexed 27 days ago

https://github.com/modelcontextprotocol/inspector

A developer tool for testing and debugging Model Context Protocol (MCP) servers. It features a React-based web UI and a Node.js proxy to interact with servers via stdio, SSE, or streamable-http transports. The tool includes a CLI mode for programmatic interaction, automation, and CI/CD, allowing developers to list tools, resources, and prompts or call specific tools directly from the command line.

Tokens
8.7K
Snippets
10
Records
62
Agent score
93%

What's inside @modelcontextprotocol/inspector

  1. Understand the MCP Inspector Architecture

    main

    The MCP Inspector architecture consists of two primary components:

    1. MCP Inspector Client (MCPI): A React-based web UI that serves as the interactive interface for developers to test and debug servers.
    2. MCP Proxy (MCPP): A Node.js server that acts as a protocol bridge. It functions as both an MCP client (connecting to your MCP server) and an HTTP server (serving the web UI). This allows the browser-based UI to interact with MCP servers using various transport methods such as stdio, SSE, or streamable-http.
  2. Inspect an MCP Server via npx

    main

    To inspect a local MCP server implementation, pass the command used to start your server as arguments to npx @modelcontextprotocol/inspector.

    Passing Arguments and Environment Variables

    • Arguments only: Append arguments directly after the server command.
    • Environment variables only: Use the -e flag for each variable.
    • Both: Use -e for environment variables and append arguments at the end.
    • Separation: Use -- to separate inspector flags from your server's own arguments.

    Customizing Ports

    You can customize the client and server ports using environment variables: CLIENT_PORT=8080 SERVER_PORT=9000 npx @modelcontextprotocol/inspector <server-command>

  3. Workflow: Bumping version for a release

    main

    Follow these steps to perform a full version bump and release cycle within the monorepo:

    1. Update the version: Run npm run update-version <version>.
    2. Verify consistency: Run npm run check-version to ensure no mismatches occurred.
    3. Commit changes: Stage all files and commit with a version bump message.
    4. Tag the release: Create a git tag for the new version.
    5. Push: Push both the branch and the tags to the remote repository.
    # Update to new version
    npm run update-version 0.15.0
    
    # Verify everything is correct
    npm run check-version
    
    # Commit the changes
    git add -A
    git commit -m "chore: bump version to 0.15.0"
    
    # Create a tag
    git tag 0.15.0
    
    # Push changes and tag
    git push && git push --tags
  4. Update versions across the monorepo with update-version.js

    main

    Use the update-version.js script to synchronize the version number across all package.json files (root, client, server, and cli) and update the package-lock.json. This script also updates workspace dependencies in the root package.json and runs npm install to ensure the lockfile is current.

    npm run update-version <new-version>
    # Example:
    npm run update-version 0.14.3
  5. Tool Input Validation Guidelines for MCP Inspector

    main

    When implementing or modifying tool input parameter handling in the Inspector, follow these rules to ensure clean parameter passing and proper separation of concerns between the Inspector client and MCP servers:

    • Omit optional fields with empty values: Omit empty strings or null values for optional parameters, unless the field has an explicit default value in the schema that matches the current value.
    • Preserve explicit default values: If a field schema contains an explicit default (e.g., default: null), and the current value matches that default, include it in the request. This is considered a meaningful value.
    • Always include required fields: Preserve required field values even when empty. This allows the MCP server to perform its own validation and return appropriate error messages.
    • Defer deep validation to the server: The Inspector client should only implement basic field presence checking; rely on the MCP server for full parameter validation according to its schema.
  6. Verify version consistency with check-version-consistency.js

    main

    Use the check-version-consistency.js script to ensure that all packages in the monorepo share the same version, workspace dependencies in the root package.json are correct, and that package-lock.json is perfectly in sync with the package.json files.

    npm run check-version
  7. Run the Inspector in a Docker Container

    main

    You can run the inspector using a Docker container. This command maps the necessary ports for the client UI (6274) and the MCP Proxy (6277).

    docker run --rm \
      -p 127.0.0.1:6274:6274 \
      -p 127.0.0.1:6277:6277 \
      -e HOST=0.0.0.0 \
      -e MCP_AUTO_OPEN_ENABLED=false \
      ghcr.io/modelcontextprotocol/inspector:latest
  8. Configure eslint-plugin-react for the Inspector client

    main

    To use recommended React linting rules, install eslint-plugin-react and update your eslint.config.js to include the plugin, set the React version in settings, and spread the recommended rules into the rules object.

    // eslint.config.js
    import react from "eslint-plugin-react";
    
    export default tseslint.config({
      // Set the react version
      settings: { react: { version: "18.3" } },
      plugins: {
        // Add the react plugin
        react,
      },
      rules: {
        // other rules...
        // Enable its recommended rules
        ...react.configs.recommended.rules,
        ...react.configs["jsx-runtime"].rules,
      },
    });
  9. Enable type-aware ESLint rules in the Inspector client

    main

    For production application development, it is recommended to enable type-aware lint rules by updating the ESLint configuration. This involves configuring parserOptions to point to your TypeScript configuration files and switching to type-checked rule sets.

    export default tseslint.config({
      languageOptions: {
        // other options...
        parserOptions: {
          project: ["./tsconfig.node.json", "./tsconfig.app.json"],
          tsconfigRootDir: import.meta.dirname,
        },
      },
    });
  10. Configure Authentication and Security

    main

    Proxy Authentication

    By default, the MCP Inspector proxy requires authentication. A random session token is generated and printed to the console.

    • Automatic: The inspector opens the browser with the token pre-filled in the URL.
    • Manual: In the UI, click Configuration -> Proxy Session Token and enter the token from the console.
    • Environment Variable: Set MCP_PROXY_AUTH_TOKEN when starting.

    Security Warnings

    • DANGEROUSLY_OMIT_AUTH: Setting this to true disables authentication. This is highly discouraged as it exposes your machine to remote compromise via web browsers.
    • Local-only Binding: By default, services bind to localhost. Use HOST=0.0.0.0 to bind to all interfaces (only in trusted networks).
    • DNS Rebinding Protection: The inspector validates the Origin header. Use ALLOWED_ORIGINS (comma-separated) to allow additional origins.