### Development Setup and Commands Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Commands for setting up the local development environment for the MCP Inspector, including cloning the repository, installing dependencies, running in development mode, building for production, and executing tests. ```bash git clone https://github.com/modelcontextprotocol/inspector cd inspector npm install ``` ```bash npm run dev ``` ```bash npm run dev:sdk "cd sdk && npm run examples:simple-server:w" ``` ```bash npm run build npm start ``` ```bash npm test npm run test-cli ``` ```bash npm run test:e2e ``` ```bash npm run prettier-check ``` ```bash npm run prettier-fix ``` -------------------------------- ### Start Development Server Source: https://github.com/modelcontextprotocol/inspector/blob/main/AGENTS.md Use this command for development mode. Use `npm run dev:windows` on Windows. ```bash npm run dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/modelcontextprotocol/inspector/blob/main/CONTRIBUTING.md Run this command in your terminal to install project dependencies. ```bash npm install ``` -------------------------------- ### Build and Start Inspector in Production Mode Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Build the inspector for production and then start the server. This is the standard procedure for deploying or running the inspector in a production environment. ```bash npm run build npm start ``` -------------------------------- ### Example MCP Server Configuration Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md This JSON structure defines configurations for multiple MCP servers, including their commands, arguments, and environment variables. ```json { "mcpServers": { "everything": { "command": "npx", "args": ["@modelcontextprotocol/server-everything"], "env": { "hello": "Hello MCP!" } }, "my-server": { "command": "node", "args": ["build/index.js", "arg1", "arg2"], "env": { "key": "value", "key2": "value2" } } } } ``` -------------------------------- ### MCP Server Configuration Example Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md A JSON configuration defining multiple MCP servers, including their commands and arguments. This allows the inspector to manage different server instances. ```json { "mcpServers": { "default-server": { "command": "npx", "args": ["@modelcontextprotocol/server-everything"] }, "other-server": { "command": "node", "args": ["other.js"] } } } ``` -------------------------------- ### Run MCP Inspector with npx Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Execute this command to start the MCP Inspector in UI mode. The UI will be accessible at http://localhost:6274. ```bash npx @modelcontextprotocol/inspector ``` -------------------------------- ### Initialize Inspector CLI Mode Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Start the inspector in CLI mode, enabling programmatic interaction from the command line. This is ideal for scripting and automation. ```bash npx @modelcontextprotocol/inspector --cli node build/index.js ``` -------------------------------- ### Connect to Remote MCP Server (Streamable HTTP) Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Connect to a remote MCP server using the Streamable HTTP transport. This example also specifies a method to call upon connection. ```bash npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --transport http --method tools/list ``` -------------------------------- ### Inspector URL with Transport and Server Settings Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Examples of how to configure the inspector's transport type and server URL via URL query parameters. This allows for dynamic configuration without modifying the config file. ```http http://localhost:6274/?transport=sse&serverUrl=http://localhost:8787/sse ``` ```http http://localhost:6274/?transport=streamable-http&serverUrl=http://localhost:8787/mcp ``` ```http http://localhost:6274/?transport=stdio&serverCommand=npx&serverArgs=arg1%20arg2 ``` -------------------------------- ### Retrieve Specific Prompt Content (CLI) Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Fetch the content of a specific prompt by its name and provide required arguments. This is useful for getting prompt templates for specific tasks like code review. ```bash npx @modelcontextprotocol/inspector --cli node build/index.js \ --method prompts/get \ --prompt-name code_review \ --prompt-args language=python \ --prompt-args 'code=def hello(): print("world")' ``` ```json { "messages": [ { "role": "user", "content": { "type": "text", "text": "Please review this Python code:\ndef hello(): print(\"world\")" } } ] } ``` -------------------------------- ### Set MCP Inspector Auth Token via Environment Variable Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Set the authentication token using the MCP_PROXY_AUTH_TOKEN environment variable when starting the server. This is an alternative to manual configuration. ```bash MCP_PROXY_AUTH_TOKEN=$(openssl rand -hex 32) npm start ``` -------------------------------- ### Update Monorepo Version Source: https://github.com/modelcontextprotocol/inspector/blob/main/scripts/README.md Use this script to update the version across all package.json files and package-lock.json in the monorepo. It also updates workspace dependencies and runs npm install. ```bash npm run update-version ``` ```bash # Example: npm run update-version 0.14.3 ``` -------------------------------- ### Build All Project Components Source: https://github.com/modelcontextprotocol/inspector/blob/main/AGENTS.md Run this command to build all components of the project. ```bash npm run build ``` -------------------------------- ### Build Server Component Source: https://github.com/modelcontextprotocol/inspector/blob/main/AGENTS.md Run this command to build only the server-side components. ```bash npm run build-server ``` -------------------------------- ### Build Client Component Source: https://github.com/modelcontextprotocol/inspector/blob/main/AGENTS.md Run this command to build only the client-side components. ```bash npm run build-client ``` -------------------------------- ### List Available Prompts (CLI) Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Use this command to list all available prompts and their arguments. The output is a JSON object detailing prompt names, descriptions, and required arguments. ```bash npx @modelcontextprotocol/inspector --cli node build/index.js --method prompts/list ``` ```json { "prompts": [ { "name": "code_review", "description": "Review code for issues", "arguments": [ { "name": "language", "required": true }, { "name": "code", "required": true } ] } ] } ``` -------------------------------- ### Inspect an MCP server from its repository Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Use npx to inspect an MCP server implementation directly from its build output. This command specifies the server's entry point. ```bash npx @modelcontextprotocol/inspector node build/index.js ``` -------------------------------- ### Run Unit Tests Source: https://github.com/modelcontextprotocol/inspector/blob/main/CONTRIBUTING.md Use this command to run the project's unit tests. ```bash npm test ``` -------------------------------- ### Run Inspector with Config File Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Execute the inspector using a specified configuration file. This is useful for setting up custom server configurations. ```bash npx @modelcontextprotocol/inspector --config mcp.json ``` -------------------------------- ### Launch MCP Inspector with Config File Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Use this command to launch the MCP Inspector with a specified configuration file and target server. ```bash npx @modelcontextprotocol/inspector --config path/to/config.json --server everything ``` -------------------------------- ### List MCP Resources via CLI Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Lists all available resources exposed by an MCP server. Resources provide data that can be read by clients. Use this to discover available data endpoints. ```bash # List resources from a local server npx @modelcontextprotocol/inspector --cli node build/index.js --method resources/list ``` ```bash # List resources from a remote SSE server npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com/sse --method resources/list ``` ```json { "resources": [ { "uri": "file:///config/settings.json", "name": "Settings", "mimeType": "application/json" }, { "uri": "db://users/current", "name": "Current User", "description": "Currently authenticated user data" } ] } ``` -------------------------------- ### List Available Resources via Inspector CLI Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Query the inspector's CLI to list all available resources. This is useful for understanding the data or services accessible through the MCP. ```bash npx @modelcontextprotocol/inspector --cli node build/index.js --method resources/list ``` -------------------------------- ### List MCP Tools via CLI Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Lists all available tools from an MCP server using the CLI interface. Returns JSON output, suitable for scripting. ```bash # List tools from a local server npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/list ``` ```bash # List tools from a remote HTTP server npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --transport http --method tools/list ``` ```bash # List tools with custom authentication header npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --transport http --method tools/list --header "X-API-Key: your-api-key" ``` ```json { "tools": [ { "name": "get_weather", "description": "Get current weather for a location", "inputSchema": { "type": "object", "properties": { "location": { "type": "string" } }, "required": ["location"] } } ] } ``` -------------------------------- ### Using Configuration File with CLI Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Execute MCP Inspector commands using a specified configuration file and server. If only one server is defined in the config, it can be auto-selected. ```bash npx @modelcontextprotocol/inspector --config mcp.json --server my-local-server ``` ```bash npx @modelcontextprotocol/inspector --cli --config mcp.json --server my-http-server --method tools/list ``` ```bash npx @modelcontextprotocol/inspector --config mcp.json ``` -------------------------------- ### Launch MCP Inspector UI Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Launches the MCP Inspector web UI for interactive connection to any MCP server. Use this for quick testing and debugging. ```bash npx @modelcontextprotocol/inspector ``` ```bash npx @modelcontextprotocol/inspector node build/index.js ``` ```bash npx @modelcontextprotocol/inspector -e API_KEY=your-key -e DEBUG=true node build/index.js arg1 arg2 ``` ```bash CLIENT_PORT=8080 SERVER_PORT=9000 npx @modelcontextprotocol/inspector node build/index.js ``` -------------------------------- ### List Available Tools via Inspector CLI Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Use the inspector's CLI mode to list all available tools. This command helps in discovering the functionalities that can be invoked. ```bash npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/list ``` -------------------------------- ### Web UI Configuration via URL Parameters Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Configure the MCP Inspector web UI by appending query parameters to the URL. This allows direct linking and automation for connecting to different server types and setting timeouts. ```bash open "http://localhost:6274/?transport=sse&serverUrl=http://localhost:8787/sse" ``` ```bash open "http://localhost:6274/?transport=streamable-http&serverUrl=http://localhost:8787/mcp" ``` ```bash open "http://localhost:6274/?transport=stdio&serverCommand=npx&serverArgs=@modelcontextprotocol/server-everything" ``` ```bash open "http://localhost:6274/?MCP_SERVER_REQUEST_TIMEOUT=60000&MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS=false" ``` ```bash open "http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=your-session-token" ``` -------------------------------- ### Check Code Formatting Source: https://github.com/modelcontextprotocol/inspector/blob/main/CONTRIBUTING.md Run this command to check if the code adheres to the project's formatting standards. ```bash npm run prettier-check ``` -------------------------------- ### Format Code with Prettier Source: https://github.com/modelcontextprotocol/inspector/blob/main/AGENTS.md Run this command to automatically format the project's code using Prettier. ```bash npm run prettier-fix ``` -------------------------------- ### Lint Client Code Source: https://github.com/modelcontextprotocol/inspector/blob/main/AGENTS.md Navigate to the client directory and run this command to lint the client-side code. ```bash cd client && npm run lint ``` -------------------------------- ### List Available Prompts via Inspector CLI Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Use the inspector's CLI to list all available prompts. This helps in identifying predefined conversational or task-oriented prompts. ```bash npx @modelcontextprotocol/inspector --cli node build/index.js --method prompts/list ``` -------------------------------- ### Run End-to-End Tests Source: https://github.com/modelcontextprotocol/inspector/blob/main/CONTRIBUTING.md Execute this command to run the end-to-end tests for the project. ```bash npm run test:e2e ``` -------------------------------- ### Authentication and Security Settings Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Configure authentication and security for the MCP Proxy server using environment variables. This includes setting proxy authentication tokens, disabling authentication (not recommended), binding to specific interfaces, and configuring allowed origins. ```bash MCP_PROXY_AUTH_TOKEN=$(openssl rand -hex 32) npm start ``` ```bash DANGEROUSLY_OMIT_AUTH=true npm start ``` ```bash HOST=0.0.0.0 npm start ``` ```bash ALLOWED_ORIGINS=http://localhost:6274,http://localhost:8000 npm start ``` -------------------------------- ### Notify Host that Sandbox is Ready Source: https://github.com/modelcontextprotocol/inspector/blob/main/server/static/sandbox_proxy.html This code snippet sends a notification to the parent window (host) indicating that the sandbox is ready to receive view HTML. It uses a specific origin for the postMessage call to ensure only the expected host receives this notification, enhancing security. ```javascript // Notify the Host that the Sandbox is ready to receive view HTML. // Use specific origin instead of "*" to ensure only the expected host receives this. window.parent.postMessage( { jsonrpc: "2.0", method: PROXY_READY_NOTIFICATION, params: {}, }, EXPECTED_HOST_ORIGIN, ); ``` -------------------------------- ### Check Version Consistency Source: https://github.com/modelcontextprotocol/inspector/blob/main/scripts/README.md Run this script to verify that all packages have consistent versions, workspace dependencies are up-to-date, and package-lock.json is in sync. This check is automated in CI. ```bash npm run check-version ``` -------------------------------- ### Inspector URL with Configuration Settings Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Configure inspector settings such as timeouts and proxy addresses directly through URL query parameters. These settings take precedence over localStorage items. ```http http://localhost:6274/?MCP_SERVER_REQUEST_TIMEOUT=60000&MCP_REQUEST_TIMEOUT_RESET_ON_PROGRESS=false&MCP_PROXY_FULL_ADDRESS=http://10.1.1.22:5577 ``` -------------------------------- ### Run Specific CLI Test Files Source: https://github.com/modelcontextprotocol/inspector/blob/main/cli/__tests__/README.md Execute individual test files based on their functionality. Use these commands to target specific areas of the CLI. ```bash npm run test:cli # cli.test.ts ``` ```bash npm run test:cli-tools # tools.test.ts ``` ```bash npm run test:cli-headers # headers.test.ts ``` ```bash npm run test:cli-metadata # metadata.test.ts ``` -------------------------------- ### List Resources from a Remote Server Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Retrieve a list of available resources from a remote MCP server. This command is useful for exploring the data and services offered by the remote instance. ```bash npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --method resources/list ``` -------------------------------- ### Pass arguments and environment variables to MCP server Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Demonstrates how to pass arguments and environment variables to your MCP server when running the inspector. Use the -e flag for environment variables and standard command-line arguments for server arguments. The '--' separator can distinguish inspector flags from server arguments. ```bash # Pass arguments only npx @modelcontextprotocol/inspector node build/index.js arg1 arg2 # Pass environment variables only npx @modelcontextprotocol/inspector -e key=value -e key2=$VALUE2 node build/index.js # Pass both environment variables and arguments npx @modelcontextprotocol/inspector -e key=value -e key2=$VALUE2 node build/index.js arg1 arg2 # Use -- to separate inspector flags from server arguments npx @modelcontextprotocol/inspector -e key=$VALUE -- node build/index.js -e server-flag ``` -------------------------------- ### Bind MCP Inspector to All Interfaces Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Override the default localhost binding to bind to all network interfaces by setting the HOST environment variable. Use this only in trusted network environments. ```bash HOST=0.0.0.0 npm start ``` -------------------------------- ### Run Inspector CLI with Config and Server Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Execute the inspector in CLI mode using a specific configuration file and targeting a named server. This allows for controlled execution of CLI commands with predefined settings. ```bash npx @modelcontextprotocol/inspector --cli --config path/to/config.json --server myserver ``` -------------------------------- ### Connect to Remote MCP Server (SSE) Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Establish a connection to a remote MCP server using the default SSE (Server-Sent Events) transport. This is the standard way to connect to remote services. ```bash npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com ``` -------------------------------- ### MCP Server Configuration File Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Define multiple MCP server configurations in a JSON file. Supports STDIO, SSE, and Streamable HTTP transport types with options for commands, environment variables, and URLs. ```json { "mcpServers": { "my-local-server": { "type": "stdio", "command": "node", "args": ["build/index.js", "--debug"], "env": { "API_KEY": "your-api-key", "DEBUG": "true" } }, "my-sse-server": { "type": "sse", "url": "http://localhost:3000/sse" }, "my-http-server": { "type": "streamable-http", "url": "http://localhost:3000/mcp" } } } ``` -------------------------------- ### Deploy MCP Inspector with Docker Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Runs the MCP Inspector in a Docker container, mapping ports and setting environment variables for isolation and configuration. ```bash 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 ``` -------------------------------- ### Export Complete Servers File (STDIO) Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md This JSON represents a complete mcp.json file structure with a single server entry configured for STDIO transport. Save this directly as mcp.json. ```json { "mcpServers": { "default-server": { "command": "node", "args": ["build/index.js", "--debug"], "env": { "API_KEY": "your-api-key", "DEBUG": "true" } } } } ``` -------------------------------- ### Run Inspector in Development Mode with SDK Co-development Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Enable co-development with the typescript-sdk package by running the inspector in development mode and linking the SDK. This is useful for simultaneous development of the inspector and its SDK. ```bash npm run dev:sdk "cd sdk && npm run examples:simple-server:w" ``` -------------------------------- ### Export Single Server Entry (STDIO) Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Use this JSON configuration for a single server entry when using STDIO transport. Add this to your mcp.json file under the mcpServers object with your preferred server name. ```json { "command": "node", "args": ["build/index.js", "--debug"], "env": { "API_KEY": "your-api-key", "DEBUG": "true" } } ``` -------------------------------- ### Export Single Server Entry (SSE) Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Use this JSON configuration for a single server entry when using SSE transport. Add this to your mcp.json file under the mcpServers object with your preferred server name. For SSE connections, add the URL directly in your client. ```json { "type": "sse", "url": "http://localhost:3000/events", "note": "For SSE connections, add this URL directly in Client" } ``` -------------------------------- ### STDIO Transport Configuration Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Configure an MCP server to use the standard input/output (STDIO) transport type. This is the default if no type is specified. ```json { "mcpServers": { "my-stdio-server": { "type": "stdio", "command": "npx", "args": ["@modelcontextprotocol/server-everything"] } } } ``` -------------------------------- ### Export Complete Servers File (SSE) Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md This JSON represents a complete mcp.json file structure with a single server entry configured for SSE transport. Save this directly as mcp.json. For SSE connections, add the URL directly in your client. ```json { "mcpServers": { "default-server": { "type": "sse", "url": "http://localhost:3000/events", "note": "For SSE connections, add this URL directly in Client" } } } ``` -------------------------------- ### Call MCP Tool via CLI Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Executes a specific tool with arguments. Supports simple key=value pairs and complex JSON arguments. Use for invoking server-side functionality. ```bash # Call a tool with simple arguments npx @modelcontextprotocol/inspector --cli node build/index.js \ --method tools/call \ --tool-name get_weather \ --tool-arg location=Seattle ``` ```bash # Call a tool with JSON arguments npx @modelcontextprotocol/inspector --cli node build/index.js \ --method tools/call \ --tool-name search \ --tool-arg 'options={"format": "json", "max_results": 10}' ``` ```bash # Call a remote tool with authentication npx @modelcontextprotocol/inspector --cli https://api.example.com/mcp \ --transport http \ --method tools/call \ --tool-name create_document \ --tool-arg title="My Document" \ --tool-arg 'content={"body": "Document content here"}' \ --header "Authorization: Bearer your-token" ``` ```json { "content": [ { "type": "text", "text": "Weather in Seattle: 65°F, Partly cloudy" } ] } ``` -------------------------------- ### Export Single Server Entry (Streamable HTTP) Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Use this JSON configuration for a single server entry when using Streamable HTTP transport. Add this to your mcp.json file under the mcpServers object with your preferred server name. For Streamable HTTP connections, add the URL directly in your MCP Client. ```json { "type": "streamable-http", "url": "http://localhost:3000/mcp", "note": "For Streamable HTTP connections, add this URL directly in your MCP Client" } ``` -------------------------------- ### Release Version Bumping Workflow Source: https://github.com/modelcontextprotocol/inspector/blob/main/scripts/README.md A common workflow for releasing new versions, involving updating the version, checking consistency, committing changes, tagging, and pushing. ```bash # 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 ``` -------------------------------- ### Call a Tool with JSON Arguments via Inspector CLI Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Execute a tool with complex JSON arguments passed as a string. This allows for structured data to be sent to the tool. ```bash npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call --tool-name mytool --tool-arg 'options={"format": "json", "max_tokens": 100}' ``` -------------------------------- ### Configure Allowed Origins for DNS Rebinding Protection Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Set the ALLOWED_ORIGINS environment variable to a comma-separated list of origins to allow requests from, in addition to the default client origin. This helps prevent DNS rebinding attacks. ```bash ALLOWED_ORIGINS=http://localhost:6274,http://localhost:8000 npm start ``` -------------------------------- ### Run Inspector in Development Mode (Windows) Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md The Windows-specific command to run the inspector in development mode. Use this if the standard 'npm run dev' command does not work on your Windows system. ```bash npm run dev:windows ``` -------------------------------- ### Export Complete Servers File (Streamable HTTP) Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md This JSON represents a complete mcp.json file structure with a single server entry configured for Streamable HTTP transport. Save this directly as mcp.json. For Streamable HTTP connections, add the URL directly in your MCP Client. ```json { "mcpServers": { "default-server": { "type": "streamable-http", "url": "http://localhost:3000/mcp", "note": "For Streamable HTTP connections, add this URL directly in your MCP Client" } } } ``` -------------------------------- ### Read MCP Resource via CLI Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Reads the content of a specific resource by its URI. Use this to retrieve data from server-side resources. ```bash # Read a specific resource npx @modelcontextprotocol/inspector --cli node build/index.js \ --method resources/read \ --uri "file:///config/settings.json" ``` ```bash # Read from a remote server npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com \ --transport http \ --method resources/read \ --uri "db://users/current" ``` ```json { "contents": [ { "uri": "file:///config/settings.json", "mimeType": "application/json", "text": "{\"theme\": \"dark\", \"language\": \"en\"}" } ] } ``` -------------------------------- ### Customize MCP Inspector ports Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Run the MCP Inspector with custom ports for the client UI and proxy server by setting the CLIENT_PORT and SERVER_PORT environment variables. ```bash CLIENT_PORT=8080 SERVER_PORT=9000 npx @modelcontextprotocol/inspector node build/index.js ``` -------------------------------- ### Integrate ESLint React Plugin Source: https://github.com/modelcontextprotocol/inspector/blob/main/client/README.md Integrate the eslint-plugin-react into your ESLint configuration to enable its recommended rules and JSX runtime rules. Set the React version in settings. ```javascript // 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, }, }); ``` -------------------------------- ### Inner Iframe Creation and Configuration Source: https://github.com/modelcontextprotocol/inspector/blob/main/server/static/sandbox_proxy.html Creates and configures an inner iframe for untrusted HTML content within a sandboxed environment. Sets the 'sandbox' attribute and appends it to the document body. ```javascript const inner = document.createElement("iframe"); inner.style = "width:100%; height:100%; border:none;"; inner.setAttribute( "sandbox", "allow-scripts allow-same-origin allow-forms", ); // Note: allow attribute is set later when receiving sandbox-resource-ready notification // based on the permissions requested by the app document.body.appendChild(inner); ``` -------------------------------- ### Call a Tool on a Remote Server Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Invoke a specific tool on a remote MCP server. This demonstrates how to interact with remote functionalities using the CLI. ```bash npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --method tools/call --tool-name remotetool --tool-arg param=value ``` -------------------------------- ### Connect to Remote MCP Server with Custom Headers Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Connect to a remote MCP server using HTTP transport and include custom headers, such as an API key for authentication. This is essential for secure access to remote services. ```bash npx @modelcontextprotocol/inspector --cli https://my-mcp-server.example.com --transport http --method tools/list --header "X-API-Key: your-api-key" ``` -------------------------------- ### Run CLI Tests in Watch Mode Source: https://github.com/modelcontextprotocol/inspector/blob/main/cli/__tests__/README.md Run tests continuously, automatically re-running them when test files change. Note that this mode may not detect changes in CLI source files without a rebuild. ```bash npm run test:watch ``` -------------------------------- ### Build Allow Attribute for Permissions Source: https://github.com/modelcontextprotocol/inspector/blob/main/server/static/sandbox_proxy.html Constructs the 'allow' attribute string for an iframe based on provided permissions. Only includes permissions explicitly granted in the input object. ```javascript function buildAllowAttribute(permissions) { if (!permissions) return ""; const allowList = []; if (permissions["camera"]) allowList.push("camera"); if (permissions["microphone"]) allowList.push("microphone"); if (permissions["geolocation"]) allowList.push("geolocation"); if (permissions["clipboardWrite"]) allowList.push("clipboard-write"); return allowList.join("; "); } ``` -------------------------------- ### SSE Transport Configuration Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Configure an MCP server to use the Server-Sent Events (SSE) transport type, specifying the URL for the SSE endpoint. ```json { "mcpServers": { "my-sse-server": { "type": "sse", "url": "http://localhost:3000/sse" } } } ``` -------------------------------- ### MCP-UI Proxy CSS Styling Source: https://github.com/modelcontextprotocol/inspector/blob/main/server/static/sandbox_proxy.html Applies transparent styling to the MCP-UI Proxy's HTML elements, allowing parent pages to show through. Ensures elements take up full viewport space and inherit color schemes. ```css MCP-UI Proxy html, body { margin: 0; height: 100vh; width: 100vw; /* Transparent background allows parent page to show through */ background-color: transparent; } body { display: flex; flex-direction: column; } * { box-sizing: border-box; } iframe { background-color: transparent; border: 0px none transparent; padding: 0px; overflow: hidden; flex-grow: 1; /* Inherit color scheme from parent for consistent transparency */ color-scheme: inherit; } ``` -------------------------------- ### Streamable HTTP Transport Configuration Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Configure an MCP server to use the Streamable HTTP transport type, specifying the URL for the MCP endpoint. ```json { "mcpServers": { "my-http-server": { "type": "streamable-http", "url": "http://localhost:3000/mcp" } } } ``` -------------------------------- ### Configure ESLint for Type-Aware Linting Source: https://github.com/modelcontextprotocol/inspector/blob/main/client/README.md Configure the top-level parserOptions property in your ESLint configuration to enable type-aware lint rules. Ensure tsconfig.node.json and tsconfig.app.json are included. ```javascript export default tseslint.config({ languageOptions: { // other options... parserOptions: { project: ["./tsconfig.node.json", "./tsconfig.app.json"], tsconfigRootDir: import.meta.dirname, }, }, }); ``` -------------------------------- ### MCP Proxy Server Endpoints Source: https://context7.com/modelcontextprotocol/inspector/llms.txt Interact with the MCP Proxy server's HTTP endpoints for health checks, configuration retrieval, and proxying requests. Authentication is required for most endpoints. ```bash curl http://localhost:6277/health # Response: {"status":"ok"} ``` ```bash curl -H "x-mcp-proxy-auth: Bearer your-token" http://localhost:6277/config # Response: {"defaultEnvironment":{...},"defaultCommand":"","defaultArgs":"","defaultTransport":"","defaultServerUrl":""} ``` ```bash curl -X POST http://localhost:6277/fetch \ -H "Content-Type: application/json" \ -H "x-mcp-proxy-auth: Bearer your-token" \ -d '{"url":"https://api.example.com/data","init":{"method":"GET"}}' ``` -------------------------------- ### Call a Specific Tool via Inspector CLI Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Invoke a specific tool using its name and providing arguments. This is a fundamental operation for executing tasks through the CLI. ```bash npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call --tool-name mytool --tool-arg key=value --tool-arg another=value2 ``` -------------------------------- ### Disable MCP Inspector Authentication Source: https://github.com/modelcontextprotocol/inspector/blob/main/README.md Use this environment variable to disable authentication. This is not recommended due to security risks. Ensure you understand the implications before using. ```bash DANGEROUSLY_OMIT_AUTH=true npm start ``` -------------------------------- ### Message Relay Event Listener Source: https://github.com/modelcontextprotocol/inspector/blob/main/server/static/sandbox_proxy.html Listens for messages from the parent window and the inner iframe, relaying them between the two. It intercepts specific notifications like 'sandbox-resource-ready' to configure the inner iframe. ```javascript const RESOURCE_READY_NOTIFICATION = "ui/notifications/sandbox-resource-ready"; const PROXY_READY_NOTIFICATION = "ui/notifications/sandbox-proxy-ready"; // Message relay: This Sandbox (outer iframe) acts as a bidirectional bridge, // forwarding messages between: // // Host (parent window) ↔ Sandbox (outer frame) ↔ View (inner iframe) // // Reason: the parent window and inner iframe have different origins and can't // communicate directly, so the outer iframe forwards messages in both // directions to connect them. // // Special case: The "ui/notifications/sandbox-proxy-ready" message is // intercepted here (not relayed) because the Sandbox uses it to configure and // load the inner iframe with the view HTML content. // // Security: CSP is enforced via HTTP headers on sandbox.html (set by serve.ts // based on ?csp= query param). This is tamper-proof unlike meta tags. window.addEventListener("message", async (event) => { if (event.source === window.parent) { // Validate that messages from parent come from the expected host origin. // This prevents malicious pages from sending messages to this sandbox. if (event.origin !== EXPECTED_HOST_ORIGIN) { console.error( "[Sandbox] Rejecting message from unexpected origin:", event.origin, "expected:", EXPECTED_HOST_ORIGIN, ); return; } if (event.data && event.data.method === RESOURCE_READY_NOTIFICATION) { const { html, sandbox, permissions } = event.data.params; if (typeof sandbox === "string") { inner.setAttribute("sandbox", sandbox); } // Set Permission Policy allow attribute if permissions are requested const allowAttribute = buildAllowAttribute(permissions); if (allowAttribute) { console.log("[Sandbox] Setting allow attribute:", allowAttribute); inner.setAttribute("allow", allowAttribute); } if (typeof html === "string") { // Use document.write instead of srcdoc (which the CesiumJS Map won't work with) const doc = inner.contentDocument || inner.contentWindow?.document; if (doc) { doc.open(); doc.write(html); doc.close(); } else { // Fallback to srcdoc if document is not accessible console.warn( "[Sandbox] document.write not available, falling back to srcdoc", ); inner.srcdoc = html; } } } else { if (inner && inner.contentWindow) { inner.contentWindow.postMessage(event.data, "*"); } } } else if (event.source === inner.cont ``` -------------------------------- ### Relay Messages from Inner Frame to Parent Window Source: https://github.com/modelcontextprotocol/inspector/blob/main/server/static/sandbox_proxy.html This code snippet listens for messages from an inner iframe. It validates the message origin to ensure it matches the expected origin before relaying the message to the parent window. This is crucial for security to prevent message interception. ```javascript window.addEventListener("message", (event) => { if (event.origin !== OWN_ORIGIN) { console.error( "[Sandbox] Rejecting message from inner iframe with unexpected origin:", event.origin, "expected:", OWN_ORIGIN, ); return; } // Relay messages from inner frame to parent window. // Use specific origin instead of "*" to prevent message interception. window.parent.postMessage(event.data, EXPECTED_HOST_ORIGIN); }); ``` -------------------------------- ### Iframe Sandbox Security Validation Source: https://github.com/modelcontextprotocol/inspector/blob/main/server/static/sandbox_proxy.html Validates that the script is running within an iframe and that the sandbox environment is secure. It throws errors if the script is not sandboxed or if the sandbox configuration is compromised. ```javascript const ALLOWED_REFERRER_PATTERN = /^http:\/\/(localhost|127\.0\.0\.1)(:|\/|$)/; if (window.self === window.top) { throw new Error("This file is only to be used in an iframe sandbox."); } if (!document.referrer) { throw new Error("No referrer, cannot validate embedding site."); } if (!document.referrer.match(ALLOWED_REFERRER_PATTERN)) { throw new Error( `Embedding domain not allowed in referrer ${document.referrer}. (Consider updating the validation logic to allow your domain.)`, ); } // Extract the expected host origin from the referrer for origin validation. // This is the origin we expect all parent messages to come from. const EXPECTED_HOST_ORIGIN = new URL(document.referrer).origin; const OWN_ORIGIN = new URL(window.location.href).origin; // Security self-test: verify iframe isolation is working correctly. // This MUST throw a SecurityError -- if `window.top` is accessible, the sandbox // configuration is dangerously broken and untrusted content could escape. try { window.top?.alert( "If you see this, the sandbox is not setup securely.", ); throw "FAIL"; } catch (e) { if (e === "FAIL") { throw new Error("The sandbox is not setup securely."); } // Expected: SecurityError confirms proper sandboxing. } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.