sampling-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@sampling-mcpsummarize the article on quantum computing"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Sampling in MCP — Demo
A minimal FastMCP example that demonstrates sampling: the mechanism by which an MCP server asks the client to run an LLM completion on its behalf, instead of calling an LLM itself.
The server exposes a summarize_document tool. When called, the tool doesn't talk to any LLM
directly — it requests a completion from the client, which runs the model (GPT-4o via LiteLLM) and
returns the text.
Sampling
The request direction is inverted from a normal tool call:
The server holds no API keys and no model SDK. It just declares what it wants generated.
The client owns the credentials, the model choice, and the LLM SDK. It decides how the generation actually happens (and can apply its own policy, fallbacks, cost controls, etc.).
This keeps secrets on the client side and lets a single server work with whatever model the client is willing to provide.
Related MCP server: Basic MCP Server
Flow
sequenceDiagram
autonumber
participant Main as client.py (main)
participant Client as FastMCP Client
participant Handler as sampling_handler
participant LLM as GPT-4o (LiteLLM → OpenAI)
participant Server as server.py (subprocess)
Note over Main,Server: stdio transport — Client spawns server.py as a child process
Main->>Client: async with client (start + handshake)
Client->>Server: launch server.py, open stdio pipes
Main->>Client: call_tool("summarize_document", {document_text})
Client->>Server: tools/call request
Server->>Server: summarize_document() runs
Server-->>Client: ctx.sample(messages, system_prompt,<br/>temperature, max_tokens, model_preferences)
Note right of Server: Server requests generation —<br/>it does NOT call the LLM itself
Client->>Handler: invoke sampling_handler(messages, params, ctx)
Handler->>Handler: build chat messages,<br/>read OPENAI_API_KEY from .env
Handler->>LLM: acompletion(model, messages, temperature, max_tokens)
LLM-->>Handler: generated summary text
Handler-->>Server: return text (sampling result)
Server->>Server: format "Summary:\n..."
Server-->>Client: tool result
Client-->>Main: CallToolResult
Main->>Client: exit async with → connection closedComponents
flowchart LR
subgraph ClientProc["Client process (holds the secrets)"]
Main["main()<br/>reads sample.txt,<br/>calls the tool"]
Client["FastMCP Client<br/>stdio transport"]
Handler["sampling_handler<br/>OPENAI_API_KEY + LiteLLM"]
end
subgraph ServerProc["Server subprocess (no keys, no LLM SDK)"]
Tool["summarize_document tool<br/>ctx.sample(...)"]
end
LLM[("OpenAI GPT-4o")]
Main --> Client
Client -- "tools/call (stdio)" --> Tool
Tool -- "ctx.sample request (stdio)" --> Handler
Handler -- "HTTPS" --> LLM
LLM -- "completion" --> Handler
Handler -- "result" --> ToolImportant parts of the code
Where | What to notice |
| |
| |
| |
| |
|
Setup
This project uses uv.
# 1. Install dependencies (creates .venv)
uv sync
# 2. Add your key — copy the template and fill it in
cp .env.example .env
# then set OPENAI_API_KEY="sk-..." in .env
# 3. Run — the client launches the server automatically
uv run client.pyopen-me.ipynb contains a guided, step-by-step walkthrough of the same setup.
Expected output
[..] INFO Starting MCP server 'Document Assistant' with transport 'stdio'
gpt-4o # \
0.7 # } printed by sampling_handler (model / temperature / max_tokens)
300 # /
CallToolResult(content=[TextContent(... text="Summary:\n...")], is_error=False)
Connected?: False # connection closed when the `async with` block exits — expectedProject layout
server.py # FastMCP server — exposes summarize_document, uses ctx.sample()
client.py # FastMCP client — runs the sampling_handler (the actual LLM call)
sample.txt # input document fed to the tool
open-me.ipynb # guided walkthrough notebook
.env.example # template for OPENAI_API_KEY (copy to .env)
pyproject.toml # uv project + dependencies (fastmcp, litellm, python-dotenv)Available Tools
1 toolsummarize_documentB
Generate a summary of the given document text.
| Name | Required | Description | Default |
|---|---|---|---|
| document_text | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It merely says 'generate a summary' without mentioning output format, length limits, input size constraints, or any processing nuances. It doesn't describe what the summary looks like or any side effects.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, clear sentence that is front-loaded with the action and object. Every word earns its place, with no redundancy or unnecessary detail.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The tool is simple with one parameter and an output schema, so the description doesn't need to explain return values. However, it lacks guidance on how the summary is generated (e.g., length, style, or handling of long inputs), leaving some behavioral gaps. It is minimally adequate but not rich.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must compensate. The phrase 'the given document text' essentially repeats the parameter name without adding meaningful detail about the expected format, encoding, or constraints. The parameter name itself is self-explanatory, but the description adds no extra semantic value.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool generates a summary of the provided document text. The verb 'generate' and the resource 'summary of the given document text' precisely convey the tool's function. Since there are no sibling tools, differentiation is not needed.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no context about when to use this tool versus alternatives, nor any exclusions or prerequisites. It is a simple one-liner that leaves usage entirely implied.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
1 tool update
v0.1.0- First observed
summarize_document
TDQS
With only one tool, there is no possibility of confusion between tools. The tool name and description clearly indicate its purpose.
The single tool uses a clear snake_case verb_noun format. With no other tools, there are no inconsistencies.
A single tool feels too thin for a server named 'sampling-mcp', which implies a broader set of sampling-related operations. The summarization tool seems out of place given the server name.
The server name suggests a sampling domain, but only document summarization is provided. There are no sampling tools at all, leaving severe gaps in the apparent intended functionality.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
A simple MCP server built with FastMCP and python
Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.
MCP server for progressive tool usage at any scale (see https://klavis.ai)
Related MCP Servers
- AlicenseBqualityDmaintenanceAn educational implementation of a Model Context Protocol server that demonstrates how to build a functional MCP server integrating with various LLM clients.2MIT
- AlicenseNot gradedqualityDmaintenanceA minimal demonstration server showcasing MCP protocol capabilities including tools, resources, and prompts with basic examples like hello world functionality.2MIT
- FlicenseNot gradedqualityDmaintenanceDemonstrates how to implement sampling in MCP servers, allowing tools to request LLM content generation from the client without requiring external API integrations or credentials.1-
- FlicenseNot gradedqualityDmaintenanceA foundational implementation of a Model Context Protocol (MCP) server designed for educational purposes. It demonstrates the complete interaction between an LLM, an inference engine, and a client during an agentic call.-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/srod0010/sampling-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server