eyaltoledano/claude-task-master · error · MCPError

MCP session must have client sampling capabilities

Error message

MCP session must have client sampling capabilities

What it means

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.

Source

Thrown at mcp-server/src/custom-sdk/language-model.js:44

	supportsStructuredOutputs = true;

	constructor(options) {
		this.session = options.session; // MCP session object
		this.modelId = options.modelId;
		this.settings = options.settings || {};
		this.provider = 'mcp-ai-sdk';
		this.maxTokens = this.settings.maxTokens;
		this.temperature = this.settings.temperature;

		this.validateSession();
	}

	/**
	 * Validate that the MCP session has required capabilities
	 */
	validateSession() {
		if (!this.session?.clientCapabilities?.sampling) {
			throw new MCPError('MCP session must have client sampling capabilities');
		}
	}

	/**
	 * Generate text using MCP session sampling
	 * @param {object} options - Generation options
	 * @param {Array} options.prompt - AI SDK prompt format
	 * @param {AbortSignal} options.abortSignal - Abort signal
	 * @returns {Promise<object>} Generation result in AI SDK format
	 */
	async doGenerate(options) {
		try {
			// Convert AI SDK prompt to MCP format
			const { messages, systemPrompt } = convertToMCPFormat(options.prompt);

			// Use MCP session.requestSampling (same as MCPRemoteProvider)
			const response = await this.session.requestSampling(
				{

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Enable sampling in the MCP client capabilities when creating the session (e.g. capabilities: { sampling: {} })
  2. Verify the client's declared capabilities via session.getClientCapabilities() before constructing the model
  3. Use a client/host that supports MCP sampling, or switch to a non-MCP model provider for generation

Example fix

// before
const client = new Client({ name: 'app', version: '1.0' });
// after
const client = new Client({ name: 'app', version: '1.0' }, { capabilities: { sampling: {} } });
Defensive patterns

Strategy: type-guard

Validate before calling

const caps = session?.getClientCapabilities?.();
if (!caps?.sampling) throw new Error('Client must declare sampling capability before creating MCP model');

Type guard

function supportsSampling(session) {
  return !!session?.clientCapabilities?.sampling;
}

Try / catch

try { const model = createMCP({ session })('model'); } catch (e) {
  if (e.message.includes('client sampling capabilities')) {
    // recreate client with sampling capability enabled
  } else throw e;
}

Prevention

When it happens

Trigger: Constructing MCPLanguageModel (directly or via createMCP) with a session whose clientCapabilities lack the sampling object — e.g. client connected without requesting/enabling sampling capability.

Common situations: MCP host/client (IDE, CLI harness) launched without sampling support; capability negotiation omitted in client options; connecting a bare Client without capabilities.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/df20ed380ad0f987. Report an issue: GitHub.