In this video, you will see the power of Sampling in action. You will run an MCP tool that analyzes a complex database error by using the Client’s connection to Claude.
Step 1: Start the Sampling Server
First, open a terminal window and start your server. This server has the “Brawn” (file writing) but needs the “Brain”.
uv run --with mcp sampling_server.py
Wait for the server to initialize on port 8000.
Step 2: Configure the Client Environment
Open a second terminal window. Before you run the client, you need to ensure it has the anthropic library installed and the API key configured.
Install the library:
uv add anthropic
Now, set your API key.
If you are on Windows (PowerShell), use this command:
$env:ANTHROPIC_API_KEY = "sk-ant-..."
If you are on Linux or macOS, use this command:
export ANTHROPIC_API_KEY="sk-ant-..."
Step 3: Run the Sampling Client
Now that your environment is ready, run the client script.
uv run --with mcp --with anthropic sampling_client.py
Watch the output closely.
First, the client calls the tool process_log_entry with a complex deadlock error. Next, you see [Client] Server requested LLM generation. The server has paused and is asking for help. The client forwards this request to Claude. Claude responds with a clear explanation: “Two database processes (821 and 999) are stuck in a circular dependency…” Finally, the server receives this explanation, saves it to incident_report.txt, and returns a success message.
You have just successfully used MCP Sampling to inject cloud-based intelligence into a local file-system operation.