eyaltoledano/claude-task-master · error

MCP provider requires session object

Error message

MCP provider requires session object

What it means

createMCP builds an AI SDK provider around an MCP session; it throws if options.session is absent because every later call (sampling via MCPLanguageModel) needs the session. It validates eagerly so misconfiguration surfaces at provider creation, not at first generation.

Source

Thrown at mcp-server/src/custom-sdk/index.js:19

/**
 * src/ai-providers/custom-sdk/mcp/index.js
 *
 * AI SDK factory function for MCP provider.
 * Creates MCP language model instances with session-based AI operations.
 */

import { MCPLanguageModel } from './language-model.js';

/**
 * Create MCP provider factory function following AI SDK patterns
 * @param {object} options - Provider options
 * @param {object} options.session - MCP session object
 * @param {object} options.defaultSettings - Default settings for the provider
 * @returns {Function} Provider factory function
 */
export function createMCP(options = {}) {
	if (!options.session) {
		throw new Error('MCP provider requires session object');
	}

	// Return the provider factory function that AI SDK expects
	const provider = function (modelId, settings = {}) {
		if (new.target) {
			throw new Error(
				'The MCP model function cannot be called with the new keyword.'
			);
		}

		return new MCPLanguageModel({
			session: options.session,
			modelId: modelId || 'claude-3-5-sonnet-20241022',
			settings: {
				temperature: settings.temperature,
				maxTokens: settings.maxTokens,
				...options.defaultSettings,
				...settings

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Create and connect the MCP session first, then pass it: createMCP({ session: mcpSession })
  2. Ensure getClient obtains the session (await connection establishment) before calling createMCP
  3. Log options at the call site to confirm the session object is actually present

Example fix

// before
const provider = createMCP({ defaultSettings });
// after
const provider = createMCP({ session: mcpClient, defaultSettings });
Defensive patterns

Strategy: validation

Validate before calling

function canCreateMCP(options) {
  return !!options && !!options.session && typeof options.session === 'object';
}

Type guard

function hasSession(options) {
  return typeof options === 'object' && options !== null &&
    'session' in options && options.session != null &&
    typeof options.session === 'object';
}

Try / catch

try { const provider = createMCP({ session }); } catch (e) {
  if (e.message === 'MCP provider requires session object') {
    // connect the MCP client first, then retry
  } else throw e;
}

Prevention

When it happens

Trigger: Calling createMCP() with no options, with an options object that omits session, or with session explicitly set to undefined/null; e.g. getClient wiring a provider without an established MCP session.

Common situations: MCP client not connected before provider creation; destructuring options incorrectly; passing settings where session is expected.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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