eyaltoledano/claude-task-master · error
MCP Provider requires active MCP session
Error message
MCP Provider requires active MCP session
What it means
The MCP provider validates authentication by checking for an active MCP session instead of an API key. This error is thrown when the provider's `this.session` is null/undefined at validation time, meaning the provider was used before an MCP session was established. It guards against calling AI sampling features outside a live MCP client connection.
Source
Thrown at mcp-server/src/providers/mcp-provider.js:34
this.session = null; // MCP server session object
}
getRequiredApiKeyName() {
return 'MCP_API_KEY';
}
isRequiredApiKey() {
return false;
}
/**
* Override validateAuth to validate MCP session instead of API key
* @param {object} params - Parameters to validate
*/
validateAuth(params) {
// Validate MCP session instead of API key
if (!this.session) {
throw new Error('MCP Provider requires active MCP session');
}
if (!this.session.clientCapabilities?.sampling) {
throw new Error('MCP session must have client sampling capabilities');
}
}
/**
* Creates and returns an MCP AI SDK client instance.
* @param {object} params - Parameters for client initialization
* @returns {Function} MCP AI SDK client function
* @throws {Error} If initialization fails
*/
getClient(params) {
try {
// Pass MCP session to AI SDK implementation
return createMCP({
session: this.session,View on GitHub (pinned to c0c98d367c)
Solutions
- Ensure the MCP session is initialized and assigned to the provider before any request (complete the MCP client handshake).
- Verify the code path that sets `provider.session` actually runs before validateAuth is invoked.
- If running outside MCP (tests/CLI), use a provider that authenticates via API key instead of the MCP provider.
- Check that the client did not disconnect mid-request, which can clear the session.
Example fix
// before const provider = new McpProvider(); const result = await provider.generate(params); // throws: requires active MCP session // after const provider = new McpProvider(); provider.session = await establishMcpSession(client); // set session first const result = await provider.generate(params);
Defensive patterns
Strategy: validation
Validate before calling
if (!provider.session) throw new Error('Call establishMcpSession() before using the MCP provider'); Type guard
function hasMcpSession(p) { return !!p.session; } Try / catch
try { await provider.generate(params); } catch (e) { if (e.message.includes('requires active MCP session')) { await reconnectAndInitSession(); } else { throw e; } } Prevention
- Always run the MCP handshake before issuing provider requests
- Write an integration smoke test that connects a session first
- Fail fast at startup if session setup is skipped
When it happens
Trigger: Calling any provider operation (e.g. generateText/doGenerate) when `this.session` was never set via session initialization, or after the provider was constructed standalone without wiring in an MCP session.
Common situations: Instantiating McpProvider directly in tests or scripts without an MCP server handshake; using the provider after the MCP client disconnected and session was cleared; misconfigured server bootstrap that skips session setup.
Related errors
- MCP session must have client sampling capabilities
- AUTHENTICATION_ERROR
- SESSION_ERROR
- AUTH_REQUIRED
- Please run: task-master auth login
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/6ea1ffd1813409a8.
Report an issue: GitHub.