Sub topic 3
Testing and Sharing an MCP Server
Assume you know Python, JSON, terminals, and basic LLM tool calling. This chapter tests a local MCP server, connects it to a host, and prepares it for team use.
Test with the MCP Inspector
The MCP Inspector is an interactive tool for checking a server before a real host uses it. It can list tools, display their input schemas, and call them with test arguments.
Install the SDK and start the Inspector with your server:
pip install "mcp[cli]"
npx @modelcontextprotocol/inspector python server.pyUse the Inspector to verify that:
- The server starts without errors.
- Tool names and descriptions are clear.
- Required and optional arguments have the expected types.
- Valid calls return useful results.
- Invalid calls return understandable errors.
- The server stays running after a tool error.
For a stdio server, write logs to standard error. Standard output carries MCP protocol messages.
import logging
import sys
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
logger = logging.getLogger("team-tools")Connect a Host Application
A host application launches an MCP client, which starts or connects to your server. A local host commonly starts a stdio server as a subprocess.
A host configuration may look like this:
{
"mcpServers": {
"team-tools": {
"command": "python",
"args": ["/absolute/path/to/server.py"]
}
}
}The exact file location and configuration keys depend on the host. Restart the host after changing its configuration, then confirm that it discovers the expected tools.
Secure Tools That Touch Real Systems
Treat tool arguments as untrusted input. Validate identifiers, use allowlists, and give the server only the permissions it needs. Separate read-only tools from actions that change data. Require explicit confirmation in the host for destructive operations.
Never place credentials in source code or tool output. Store them in the host environment or a secret manager. Record useful audit events without logging tokens or sensitive payloads.
Share and Deploy the Server
Use stdio for a developer's local tools. Use Streamable HTTP when several users need one managed service. HTTP deployment requires authentication, authorization, HTTPS, monitoring, and controlled upgrades.
| Deployment choice | Best fit | Main concern |
|---|---|---|
| Stdio subprocess | One developer or workstation | Local configuration |
| Streamable HTTP | Shared team service | Identity and network security |
Package the server with pinned dependencies, document its configuration, and test each release with the Inspector before publishing it.
Exercise
Which transport is usually appropriate for a server shared by several authenticated team members?
Show answer
Streamable HTTP, with HTTPS, authentication, authorization, and monitoring.