Skip to main content
Welcome. This lesson is a concise, hands-on demonstration of an MCP server and how an MCP Inspector client interacts with it. The Inspector connects to a single server process — in this demo the server is named shipment-tracker. We walk through: starting the server, what you see in the Inspector, the data model (fixtures), and the full server implementation.

Running the server

Start the demo server from the project root:
When the server begins it prints a ready message to stderr, for example:
This indicates the process is running and ready to accept Inspector connections over stdio.

Connecting with MCP Inspector

  • The Inspector connects to one server process (here, shipment-tracker) and displays protocol and client/server metadata.
  • This demo uses the modern MCP protocol era (2026.07.28). The Inspector shows:
    • protocol era (modern vs legacy),
    • supported transports (e.g., stdio),
    • server capabilities (tools/resources/prompts),
    • client capabilities (roots, sampling, elicitation, etc.).
  • In the modern era the Inspector sends a single request containing a _meta object with client metadata. (Legacy-era MCP used a multi-step handshake.)
Example of a typical tool response when invoking get_shipment_status for shipment PL-4417:
Inspector’s protocol log contains both the client-to-server request (including _meta) and the server response (also including _meta). A key takeaway: the modern protocol embeds metadata in _meta on both requests and responses so client and server can exchange runtime capabilities and diagnostics.

Response fields (quick reference)

Console logs

When running over stdio, print human-readable logs to stderr so protocol messages on stdout remain uncorrupted. Example stderr output from the running server:
When using the stdio transport, log statements should be printed to stderr (not stdout). This prevents logs from being mixed with the protocol messages that travel over stdout.

Fixtures: shipment model and demo data

This demo uses a small fixtures module (mcpa_demo) that:
  • defines a Pydantic model representing a shipment, and
  • provides an in-memory dataset of example shipments.
The model ensures the JSON structure returned by the tool is typed and validated. See Pydantic documentation for details: https://docs.pydantic.dev/latest/
Note: find_shipment normalizes the supplied reference by stripping whitespace and uppercasing, then looks up the value in SHIPMENTS. It returns either a Shipment instance or None when not found.

Server implementation

The server is an asyncio-based MCP server that exposes a single tool: get_shipment_status. The tool accepts a ref argument with validation, logs the lookup to stderr, queries the fixture helper find_shipment, and returns the Shipment model or raises ToolError when no matching shipment exists.
Key implementation notes:
  • The @server.tool(...) decorator exposes this function as an MCP tool.
  • The ref parameter is typed as Annotated[str, Field(...)] so the generated tool schema includes validation (regex) and a description that clients (Inspector) can present to users.
  • Lookups are logged to stderr; if a shipment is not found the function raises ToolError. The MCP framework will propagate this as a tool execution error to the client.
Caveat about case sensitivity:
  • The Field description mentions “Case-insensitive”, but the regex ^PL-\d{4}$ is case-sensitive. Pydantic will validate the raw input against that pattern, so lowercased input like pl-4417 will fail validation before find_shipment runs.
  • Options to make it truly case-insensitive include:
    • use a case-insensitive pattern (for example (?i)^PL-\d{4}$), or
    • normalize input (e.g., uppercase) before validation/lookup.
If a tool raises a ToolError, the client will receive a proper tool-execution error. Use ToolError to signal user-facing failures instead of returning partial or malformed data.

mcp.json — registering the server

The local MCP configuration instructs the Inspector how to start the server process. For this demo, the configuration looks like:
This tells the Inspector to launch shipment-tracker by running the virtualenv’s Python interpreter with server.py, and that the server speaks the modern protocol over stdio.

Files & responsibilities

When including examples or configuration snippets in tables, keep any JSON or object literals quoted or in code blocks to avoid MDX/JS parsing issues.

Summary

  • The MCP Inspector acts as a client that connects to a single server process (here, shipment-tracker).
  • Servers expose tools (for example get_shipment_status) with typed, validated arguments and structured return values (Pydantic models).
  • In the modern MCP era a single request payload is used and both client and server embed runtime metadata in the _meta object.
  • When using stdio transport, print logs to stderr so stdout remains reserved for protocol traffic.
This lesson covered how to run and inspect an MCP server, how request/response metadata flows are handled with _meta, and the structure of a minimal server plus fixtures for a demo implementation.
  • Pydantic documentation: https://docs.pydantic.dev/latest/
  • (For MCP specifics, consult your project’s MCP protocol documentation or internal reference materials.)

Watch Video