Sampling TransportMode http does not show sampling popup
Inspector Version
- 0.16.7
Describe the bug The inspector does not show the sampling approval popup with transport mode "http" instead of transport mode "stdio".
To Reproduce
- start an mcp server with transport streaming-http and a tool (see below) with mcpServer.server.createMessage
- run the inspector and connect via transport type streaming-http
- Run the tool
- See timeout error and no popup to approve the sampling request.
Expected behavior There should be a sampling request like with transport mode "stdio" resulting in no timeout in mcpServer.server.createMessage.
Environment
- OS: windows
- Browser chrome
Additional context
mcpServer.registerTool(
"create-random-user",
{
title: "Create Random User Tool",
description: "Create a random user with fake data",
annotations: {
readOnlyHint: false,
destructiveHint: false,
idempotentHint: false,
openWorldHint: true
}
},
async () => {
try {
const caps = mcpServer.server.getClientCapabilities() ?? {};
console.error("Client capabilities", caps);
if (!caps.sampling) {
return {
isError: true,
content: [{ type: "text", text: "Client does not support MCP sampling." }]
};
}
const response = await mcpServer.server.createMessage({
messages: [
{
role: "user",
content: {
type: "text",
text: `Generate fake user data. The user should have a realistic name and email.
Return this data as a json object with name and email fields only. No other text so it can be used with JSON.parse.`,
},
},
],
maxTokens: 1024,
});
console.error("createMessage response", response);
//create user etc. and return content object.
Probably the same issue as mentioned in elicitation timeout. Stateless server is most likely the issue.
Update: Confirmed - Sampling works with a stateful server with transport http-streamable and the best, this change also solved the issue that createMessage / logging was not working as well in the inspector. I think the documentation should be maybe extended for streamable stateless vs stateful (which features are working).
Added the documentation label in case this needs to be clarified in docs.
What is the limitation that prevents stateless servers from leveraging sampling? I just ran into this as well.