Sub topic 3
Configuring an MCP Host and Using Servers
This chapter assumes you understand MCP roles, JSON, transports, and basic tool calling. A host is the AI application that manages one or more MCP clients. Each client connects to a server and exposes that server’s features to the host.
Configuring a Host
A host usually needs a server name, command, and arguments. For a local stdio server, configuration may look like this:
{
"mcpServers": {
"demo": {
"command": "python",
"args": ["server.py"]
}
}
}The exact file name and location depend on the host. The host starts the command, connects its input and output streams to the MCP client, and performs the initialization handshake. Use absolute paths when the host’s working directory is uncertain. Keep secrets in environment variables or the host’s secret store, not in this file.
Testing with MCP Inspector
MCP Inspector provides an interactive way to launch a server, inspect its capabilities, and call tools without involving a full host. A typical command is:
npx @modelcontextprotocol/inspector python server.pyCheck the server’s advertised tools, resource templates, and prompts. Call read-only tools first. If a server fails to start, inspect its command, arguments, environment variables, and stderr output.
Features Offered by Clients
Servers can request client features during normal protocol operations:
- Sampling lets a server ask the client’s model to generate a completion. The client should apply its own model and consent policy.
- Roots tell a server which filesystem locations the client considers available. A root is permission context, not automatic authorization.
- Elicitation lets a server ask the user for additional information through the client.
These features increase capability, so clients should show clear prompts and enforce limits.
Utilities and Operational Messages
MCP utilities support reliable long-running sessions:
- List-changed notifications tell the client to refresh available tools, resources, or prompts.
- Progress notifications report work on a long operation.
- Cancellation requests let a client stop work that is no longer needed.
- Logging messages help diagnose behavior without exposing secrets.
Security and Consent
Treat every server as privileged code. Review its source, dependencies, commands, filesystem access, network access, and environment variables. Require confirmation before destructive tool calls. Validate tool arguments on the server, restrict roots, redact logs, and use separate credentials with minimum permissions.
Exercise
Why should a client treat an MCP root as a boundary rather than as permission to read every file beneath it?
Show answer
A root describes the locations available to the server, but the client or user must still enforce authorization, consent, and tool-specific access rules.