Composition + Sampling Lab
Explore how MCP tools, resources, and prompts can be composed into a workflow and how the MCP client can provide Sampling.
What happens when MCP results are combined and then used to request Sampling?
Deterministic replay · No network
Resource → Sampling workflow from the recorded trace.
Workflow ready. Replay to observe the recorded execution.
Protocol trace11 events
Recorded MCP exchange — observable protocol events only. No chain-of-thought.
1. initialize
{ "interactionId": "initialize", "method": "initialize", "clientInfo": { "name": "dataaihub-cookbook-mcp-client", "version": "0.1.0" }, "samplingCallbackRegistered": true, "samplingMode": "mock" }2. initialize
{ "interactionId": "initialize", "method": "initialize", "protocolVersion": "2025-11-25", "serverInfo": { "name": "dataaihub-cookbook-composition", "version": "" }, "capabilities": { "experimental": {}, "prompts": { "list_changed": false }, "resources": { "subscribe": false, "list_changed": false }, "tools": { "list_changed": false } } }3. resources/list
{ "interactionId": "resources/list", "method": "resources/list" }4. resources/list
{ "interactionId": "resources/list", "method": "resources/list", "resources": [ { "uri": "acme://docs/knowledge-platform", "name": "knowledge-platform", "description": "Service documentation for the Knowledge Platform.", "mimeType": "text/markdown" }, { "uri": "acme://docs/billing-portal", "name": "billing-portal", "description": "Service documentation for the Billing Portal.", "mimeType": "text/markdown" }, { "uri": "acme://status/services", "name": "service-status", "description": "Service statuses for the Acme AI environment.", "mimeType": "application/json" } ], "resourceCount": 3 }5. resources/read
{ "interactionId": "resources/read:acme://docs/knowledge-platform", "method": "resources/read", "uri": "acme://docs/knowledge-platform" }6. resources/read
{ "interactionId": "resources/read:acme://docs/knowledge-platform", "method": "resources/read", "uri": "acme://docs/knowledge-platform", "isError": false, "contents": [ { "uri": "acme://docs/knowledge-platform", "text": "# Knowledge Platform\n\nService documentation for the Knowledge Platform.\n\nThe Knowledge Platform indexes internal documents and serves retrieval\nqueries for Acme applications. Clients read this resource for current\nservice facts; they do not invent the catalog locally.\n\n## Services\n\n- knowledge-platform\n- billing-api\n- identity-api\n\n## Capabilities\n\n- Document ingest and chunking\n- Keyword and vector retrieval\n- Citation-preserving answer assembly\n\n## Operational notes\n\nStatus and incident details live in `acme://status/services`.\nBilling product surfaces live in `acme://docs/billing-portal`.\n", "mimeType": "text/markdown" } ] }7. tools/call
{ "interactionId": "tools/call:compose_resource_brief:2", "method": "tools/call", "name": "compose_resource_brief", "arguments": { "uri": "acme://docs/knowledge-platform", "content": "# Knowledge Platform\n\nService documentation for the Knowledge Platform.\n\nThe Knowledge Platform indexes internal documents and serves retrieval\nqueries for Acme applications. Clients read this resource for current\nservice facts; they do not invent the catalog locally.\n\n## Services\n\n- knowledge-platform\n- billing-api\n- identity-api\n\n## Capabilities\n\n- Document ingest and chunking\n- Keyword and vector retrieval\n- Citation-preserving answer assembly\n\n## Operational notes\n\nStatus and incident details live in `acme://status/services`.\nBilling product surfaces live in `acme://docs/billing-portal`.\n", "mime_type": "text/markdown", "name": "knowledge-platform" } }8. sampling/createMessage
{ "interactionId": "sampling/createMessage:1", "method": "sampling/createMessage", "params": { "meta": {}, "messages": [ { "role": "user", "content": { "type": "text", "text": "Resource URI: acme://docs/knowledge-platform\nName: knowledge-platform\nMIME type: text/markdown\nContent:\n# Knowledge Platform\n\nService documentation for the Knowledge Platform.\n\nThe Knowledge Platform indexes internal documents and serves retrieval\nqueries for Acme applications. Clients read this resource for current\nservice facts; they do not invent the catalog locally.\n\n## Services\n\n- knowledge-platform\n- billing-api\n- identity-api\n\n## Capabilities\n\n- Document ingest and chunking\n- Keyword and vector retrieval\n- Citation-preserving answer assembly\n\n## Operational notes\n\nStatus and incident details live in `acme://status/services`.\nBilling product surfaces live in `acme://docs/billing-portal`.\n\n\nWrite a two-sentence operational brief using only this resource." } } ], "system_prompt": "Use only the supplied MCP resource content. Do not invent facts.", "max_tokens": 200 }, "boundary": "mcp-client-sampling-callback" }9. sampling/createMessage
{ "interactionId": "sampling/createMessage:1", "method": "sampling/createMessage", "isError": false, "result": { "role": "assistant", "content": { "type": "text", "text": "[mock] Client sampling callback completed this request.\nGrounded context (1 message(s)):\nResource URI: acme://docs/knowledge-platform\nName: knowledge-platform\nMIME type: text/markdown\nContent:\n# Knowledge Platform\n\nService documentation for the Knowledge Platform.\n\nThe Knowledge Platform indexes internal documents and serves retrieval\nqueries for Acme applications. Clients read this resource for current\nservice facts; they do not invent the catalog locally.\n\n## Services\n\n- knowledge-platform\n- billing-api\n- identity-api\n\n## Capabilities\n\n- Document ingest and chunking\n- Keyword and vector retrieval\n- Citation-preserving answer assembly\n\n## Operational notes\n\nStatus and incident details live in `acme://status/services`.\nBilling product surfaces live in `acme://docs/billing-portal`.\n\n\nWrite a two-sentence operational brief using only this resource." }, "model": "mock" }, "boundary": "mcp-client-sampling-callback" }10. tools/call
{ "interactionId": "tools/call:compose_resource_brief:2", "method": "tools/call", "name": "compose_resource_brief", "arguments": { "uri": "acme://docs/knowledge-platform", "content": "# Knowledge Platform\n\nService documentation for the Knowledge Platform.\n\nThe Knowledge Platform indexes internal documents and serves retrieval\nqueries for Acme applications. Clients read this resource for current\nservice facts; they do not invent the catalog locally.\n\n## Services\n\n- knowledge-platform\n- billing-api\n- identity-api\n\n## Capabilities\n\n- Document ingest and chunking\n- Keyword and vector retrieval\n- Citation-preserving answer assembly\n\n## Operational notes\n\nStatus and incident details live in `acme://status/services`.\nBilling product surfaces live in `acme://docs/billing-portal`.\n", "mime_type": "text/markdown", "name": "knowledge-platform" }, "isError": false, "result": { "isError": false, "content": [ { "type": "text", "text": "{\n \"ok\": true,\n \"workflow\": \"resource_to_sampling\",\n \"resourceUri\": \"acme://docs/knowledge-platform\",\n \"resourceName\": \"knowledge-platform\",\n \"mimeType\": \"text/markdown\",\n \"sampling\": {\n \"model\": \"mock\",\n \"role\": \"assistant\",\n \"text\": \"[mock] Client sampling callback completed this request.\\nGrounded context (1 message(s)):\\nResource URI: acme://docs/knowledge-platform\\nName: knowledge-platform\\nMIME type: text/markdown\\nContent:\\n# Knowledge Platform\\n\\nService documentation for the Knowledge Platform.\\n\\nThe Knowledge Platform indexes internal documents and serves retrieval\\nqueries for Acme applications. Clients read this resource for current\\nservice facts; they do not invent the catalog locally.\\n\\n## Services\\n\\n- knowledge-platform\\n- billing-api\\n- identity-api\\n\\n## Capabilities\\n\\n- Document ingest and chunking\\n- Keyword and vector retrieval\\n- Citation-preserving answer assembly\\n\\n## Operational notes\\n\\nStatus and incident details live in `acme://status/services`.\\nBilling product surfaces live in `acme://docs/billing-portal`.\\n\\n\\nWrite a two-sentence operational brief using only this resource.\"\n }\n}" } ], "structuredContent": { "ok": true, "workflow": "resource_to_sampling", "resourceUri": "acme://docs/knowledge-platform", "resourceName": "knowledge-platform", "mimeType": "text/markdown", "sampling": { "model": "mock", "role": "assistant", "text": "[mock] Client sampling callback completed this request.\nGrounded context (1 message(s)):\nResource URI: acme://docs/knowledge-platform\nName: knowledge-platform\nMIME type: text/markdown\nContent:\n# Knowledge Platform\n\nService documentation for the Knowledge Platform.\n\nThe Knowledge Platform indexes internal documents and serves retrieval\nqueries for Acme applications. Clients read this resource for current\nservice facts; they do not invent the catalog locally.\n\n## Services\n\n- knowledge-platform\n- billing-api\n- identity-api\n\n## Capabilities\n\n- Document ingest and chunking\n- Keyword and vector retrieval\n- Citation-preserving answer assembly\n\n## Operational notes\n\nStatus and incident details live in `acme://status/services`.\nBilling product surfaces live in `acme://docs/billing-portal`.\n\n\nWrite a two-sentence operational brief using only this resource." } } } }11. termination
{ "reason": "session_closed" }
How it works
The server requests Sampling through MCP. The client controls how the model interaction is handled.
Run MCP #4 locally
The Lab replays measured traces. Use the Cookbook to run the same cases with the official MCP Python SDK. The default Lab never requires OPENAI_API_KEY.
cd examples/mcp/04-composition uv sync --extra dev uv run python main.py --case resource-to-sampling --show-sequence
Previous Lab
MCP #3 covers prompt discovery and retrieval. This Lab composes those primitives and requests Sampling.
Continue Learning
Guides that explain MCP as a client/server protocol for tools, resources, prompts, and Sampling.
Related Rankings
See how this stack compares in DataAIHub rankings.
Lab ID mcp-composition · guided / precomputed mock