{"record":{"id":"df20ed380ad0f987","repo":"eyaltoledano/claude-task-master","slug":"mcp-session-must-have-client-sampling-capabilities","errorCode":null,"errorMessage":"MCP session must have client sampling capabilities","messagePattern":"MCP session must have client sampling capabilities","errorType":"exception","errorClass":"MCPError","httpStatus":null,"severity":"error","filePath":"mcp-server/src/custom-sdk/language-model.js","lineNumber":44,"sourceCode":"\tsupportsStructuredOutputs = true;\n\n\tconstructor(options) {\n\t\tthis.session = options.session; // MCP session object\n\t\tthis.modelId = options.modelId;\n\t\tthis.settings = options.settings || {};\n\t\tthis.provider = 'mcp-ai-sdk';\n\t\tthis.maxTokens = this.settings.maxTokens;\n\t\tthis.temperature = this.settings.temperature;\n\n\t\tthis.validateSession();\n\t}\n\n\t/**\n\t * Validate that the MCP session has required capabilities\n\t */\n\tvalidateSession() {\n\t\tif (!this.session?.clientCapabilities?.sampling) {\n\t\t\tthrow new MCPError('MCP session must have client sampling capabilities');\n\t\t}\n\t}\n\n\t/**\n\t * Generate text using MCP session sampling\n\t * @param {object} options - Generation options\n\t * @param {Array} options.prompt - AI SDK prompt format\n\t * @param {AbortSignal} options.abortSignal - Abort signal\n\t * @returns {Promise<object>} Generation result in AI SDK format\n\t */\n\tasync doGenerate(options) {\n\t\ttry {\n\t\t\t// Convert AI SDK prompt to MCP format\n\t\t\tconst { messages, systemPrompt } = convertToMCPFormat(options.prompt);\n\n\t\t\t// Use MCP session.requestSampling (same as MCPRemoteProvider)\n\t\t\tconst response = await this.session.requestSampling(\n\t\t\t\t{","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/custom-sdk/language-model.js#L26-L62","documentation":"MCPLanguageModel.validateSession requires the MCP session to expose clientCapabilities.sampling, because generation is implemented via MCP server->client sampling requests. If the connected client did not declare the sampling capability, the server cannot fulfill generation requests and the model throws MCPError at construction time.","triggerScenarios":"Constructing MCPLanguageModel (directly or via createMCP) with a session whose clientCapabilities lack the sampling object — e.g. client connected without requesting/enabling sampling capability.","commonSituations":"MCP host/client (IDE, CLI harness) launched without sampling support; capability negotiation omitted in client options; connecting a bare Client without capabilities.","solutions":["Enable sampling in the MCP client capabilities when creating the session (e.g. capabilities: { sampling: {} })","Verify the client's declared capabilities via session.getClientCapabilities() before constructing the model","Use a client/host that supports MCP sampling, or switch to a non-MCP model provider for generation"],"exampleFix":"// before\nconst client = new Client({ name: 'app', version: '1.0' });\n// after\nconst client = new Client({ name: 'app', version: '1.0' }, { capabilities: { sampling: {} } });","handlingStrategy":"type-guard","validationCode":"const caps = session?.getClientCapabilities?.();\nif (!caps?.sampling) throw new Error('Client must declare sampling capability before creating MCP model');","typeGuard":"function supportsSampling(session) {\n  return !!session?.clientCapabilities?.sampling;\n}","tryCatchPattern":"try { const model = createMCP({ session })('model'); } catch (e) {\n  if (e.message.includes('client sampling capabilities')) {\n    // recreate client with sampling capability enabled\n  } else throw e;\n}","preventionTips":["Always pass capabilities: { sampling: {} } when constructing the MCP Client","Check getClientCapabilities() after connecting and before model creation","Verify the host application supports MCP sampling before relying on it"],"tags":["mcp","sampling","capabilities","ai-sdk"],"backgroundTag":"mcp-capability-missing","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}