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: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
_metaobject with client metadata. (Legacy-era MCP used a multi-step handshake.)
get_shipment_status for shipment PL-4417:
_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.
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.
- The
@server.tool(...)decorator exposes this function as an MCP tool. - The
refparameter is typed asAnnotated[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.
- 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 likepl-4417will fail validation beforefind_shipmentruns. - 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.
- use a case-insensitive pattern (for example
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: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
_metaobject. - When using stdio transport, print logs to stderr so stdout remains reserved for protocol traffic.
_meta, and the structure of a minimal server plus fixtures for a demo implementation.
Links and references
- Pydantic documentation: https://docs.pydantic.dev/latest/
- (For MCP specifics, consult your project’s MCP protocol documentation or internal reference materials.)