Test and Debug an MCP Server

hatzisn

Expert
Licensed User
Longtime User
Following @aeric on this post on how to build an MCP Server to use it with an LLM I found that there is already a tool to debug both stdio and http access of the MCP Server. Here is @aeric 's thread:


In order to test and debug an MCP Server you are building, there is the tool "MCP Inspector".

 

hatzisn

Expert
Licensed User
Longtime User
Here is the answer from Gemini on the question "Can I use MCP Inspector with an mcp server that has not been built on python or node js;

Yes, you can use the MCP Inspector with a Model Context Protocol (MCP) Server that was not built using Python or Node.js.
This is a core design principle of the Model Context Protocol (MCP) and the JSON-RPC 2.0 standard it is built upon: it is language-agnostic.

🔑 Why It Works: Protocol Over Implementation​

The MCP Inspector is a visual tool (often running locally in a browser, served by a Node.js proxy) designed to facilitate the testing and debugging of MCP Servers. However, it is completely indifferent to the language the server is written in.

1. Based on JSON-RPC 2.0​

The fundamental communication method of MCP is JSON-RPC 2.0.
  • JSON-RPC is simply a specification for exchanging structured JSON messages between a client (like the LLM or the MCP Inspector) and a server (your custom MCP Server).
  • As long as your server (whether written in Go, Rust, Java, C#, or any other language) can correctly parse incoming JSON-RPC Requests and generate correctly formatted JSON-RPC Responses (including Results and Error objects) according to the MCP specification, the implementation language does not matter.

2. Standard Transport Layers​

The MCP Inspector only needs to know how to communicate with your server (the "Transport" layer). It supports standard methods that are available across virtually all modern languages:
  • STDIO (Standard Input/Output):If your server is a command-line executable (e.g., a compiled Go or Rust binary), the Inspector launches it as a sub-process and exchanges JSON-RPC messages via its Standard Input and Standard Output streams. [Source 1.2]
    • In the Inspector configuration, you simply provide the path to your compiled executable file.
  • HTTP (or SSE/Streamable HTTP): If your server is a networked service (e.g., a web server written in Java/Spring or Go/Gin), the Inspector sends HTTP requests to the designated endpoint. [Source 1.2]
In Summary:
The MCP Inspector works by checking for protocol compliance (the JSON messages), not language compliance. If your Go or Rust application adheres to the MCP JSON-RPC message structure and uses a supported transport (like STDIO or HTTP), the Inspector will function perfectly as your debugging tool.
The linked video provides an overview of the MCP Inspector, which is essential for debugging any MCP Server implementation, regardless of the programming language used. [How to Use MCP Inspector: The Developer's Guide to Exploring MCP Servers!]

And Here is the answer in the question "Can you show me how to do this? Your answer must include the following sections:
* to start mcp inspector you will have to do this...
* to connect mcp inspector with your mcp server you will have to do this..."

That's an excellent request! Since the Model Context Protocol (MCP) Inspector is an application that helps you test and debug your MCP Server, I will guide you through the process, assuming you are using the commonly available command-line or desktop environment setup.
The specific steps might vary slightly depending on the official source (e.g., Anthropic's SDK), but the general process remains consistent.

🛠️ How to Use the MCP Inspector​

The MCP Inspector is usually launched as a web interface from your local machine, which then connects to your running (or executable) MCP Server.

1. To Start MCP Inspector You Will Have to Do This...​

You typically start the MCP Inspector using a command-line tool provided by the SDK or by running a dedicated server application.

A. Installation (if not already done)​

If you are using a Node.js-based development environment, you might install the tool globally or locally:
Bash

# Example command using npm (Node Package Manager)
npm install -g mcp-inspector

If you are using a Python SDK, the tool might be included, or you might install a separate package:
Bash

# Example command using Python's pip
pip install mcp-tools

B. Launching the Inspector​

Once installed, you execute the inspector command. This usually starts a local web server (the Inspector application itself) and opens it in your default web browser.
Bash

# Common launch command
mcp-inspector start

  • Output: The terminal will display the local URL where the Inspector is running, typically: MCP Inspector running at: http://localhost:8080 (or similar port).
  • Action: Open your browser and navigate to the displayed URL.

2. To Connect MCP Inspector with Your MCP Server You Will Have to Do This...​

Once the Inspector is open in your browser, you need to configure it to point to your specific MCP Server. The connection method depends on how you built your server—either as a long-running HTTP service or as a simple command-line executable using STDIO.

A. Configuration for STDIO (Recommended for Local Testing)​

This method is used when your MCP Server is compiled into an executable file (e.g., written in Go, Rust, or a Python script) that communicates via Standard Input/Output.
  1. Open the Inspector: Go to the URL (e.g., http://localhost:8080).
  2. Select Connection Type: Choose the "STDIO" or "Executable" connection mode in the Inspector's interface.
  3. Specify Server Path:Enter the full file path to your compiled MCP Server executable.
    • Example: /home/user/my-mcp-server/bin/server-go-executable
  4. Connect: Click the "Connect" button.
  • Process: The Inspector will execute your file, open the STDIN/STDOUT pipes, and send the initial initialize request.
  • Verification: If successful, the Inspector will display a list of all the Tools (methods) that your server exposed in its initialization response.

B. Configuration for HTTP Service​

This method is used when your MCP Server is running as a persistent web service (daemon) and exposes an HTTP endpoint.
  1. Open the Inspector: Go to the URL.
  2. Select Connection Type: Choose the "HTTP" or "Remote Server" connection mode.
  3. Specify Server URL:Enter the full URL of your running server's API endpoint.
  4. Connect: Click the "Connect" button.
  • Process: The Inspector will send the initial JSON-RPC initialize request via HTTP POST to your specified URL.
  • Verification: If the connection is successful and the server responds with its metadata, the Inspector will populate the list of available tools.
Once connected, you can then interact with your server by selecting a tool, providing parameters, and sending a manual request to ensure your server handles the JSON-RPC calls and returns the correct context data.
Would you like me to walk you through a specific example of sending a test request using the Inspector's interface?
 

hatzisn

Expert
Licensed User
Longtime User
And here is the answer to an other crucial add up question "Can you please specifically also tell me how to connect an LLM to the MCP Inspector to try it?"

That is a very insightful question. It highlights a common point of confusion: The MCP Inspector is designed to test the Server, not the LLM Client.1


You generally do not connect the LLM (Large Language Model) directly to the MCP Inspector. Instead, you use the Inspector to simulate the LLM's behavior.
Here is the breakdown of why and how you would simulate the connection, followed by the specific steps.

🛑 Why the LLM Doesn't Connect to the Inspector​

The MCP ecosystem is a three-part chain:2


  1. The LLM/Host (Client): The model (e.g., Anthropic's Claude or a custom client built around a model). This entity decides when to call a tool.
  2. The MCP Server: Your custom application (written in Go, Rust, Python, etc.) that executes the tool's actual function (e.g., reading a database).
  3. The MCP Inspector (Debugger/Simulator): A separate tool used by developers to verify that the Server is working correctly.3
The Inspector's job is to act as a substitute for the LLM/Host. It pretends to be the LLM client so you can debug your server without needing to integrate the actual LLM yet.

📝 How to Simulate the LLM Client Interaction​

Once you have successfully connected your MCP Server executable to the Inspector (as detailed in the previous response), you simulate the interaction using the Inspector's user interface.

Step 1: Initialization Verification​

After clicking "Connect" (STDIO or HTTP), the Inspector automatically performs the first critical step that an LLM client would do:
  • It sends the initialize request.
  • It checks the server's response for the initializationResult, which contains the full metadata and schemas of all the tools your server exposes (e.g., get_user_data, send_email).
If this is successful, the Inspector will display a list of all your server's tools.

Step 2: Selecting and Preparing a Tool Call​

This step simulates the LLM deciding which tool to call and with what parameters.
  1. Select the Tool: In the Inspector's interface (often a sidebar or dropdown), click on the specific Tool Name (method) you want to test (e.g., get_current_weather).
  2. Input Parameters: The Inspector interface will then display input fields corresponding to the parameters defined in your tool's schema (e.g., city: string, unit: string).
  3. Fill the Parameters:Enter the values that the LLM would logically generate based on a user prompt.
    • Example: If testing a weather tool: set city to "London" and unit to "celsius".

Step 3: Sending the Simulated Request​

This step simulates the actual JSON-RPC request the LLM client would send to your server.
  1. Generate Request: The Inspector automatically formats your inputs into a valid JSON-RPC 2.0 Request object (including a unique id, the method name, and the parameters).
  2. Send Request: Click the "Send Request" or "Execute" button on the Inspector interface.
  3. Monitor Communication:The Inspector displays the live communication log:
    • Outgoing: The exact JSON-RPC Request sent to your server.
    • Incoming: The expected JSON-RPC Response (or Error) received from your server.

Step 4: Verification of the Context (Result)​

This step verifies that your MCP Server executed the function correctly and returned the result in the proper format.
  • Check Result: Review the Responsesection. It should contain a valid JSON-RPC Success object with the computed result in the result field.
    • Example: The result field should contain the weather data structure (e.g., {"temperature": 15, "description": "Cloudy"}).
  • Debug Errors: If the server returns a JSON-RPC Error object (e.g., -32602 Invalid params), the Inspector makes it easy to diagnose whether the error is in your server logic or if the parameters sent were incorrect.4
By successfully simulating all these steps in the MCP Inspector, you gain confidence that when a real LLM client calls your server, the communication will be correct and the tools will execute reliably.
 
Top