{"record":{"id":"6ea1ffd1813409a8","repo":"eyaltoledano/claude-task-master","slug":"mcp-provider-requires-active-mcp-session","errorCode":null,"errorMessage":"MCP Provider requires active MCP session","messagePattern":"MCP Provider requires active MCP session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp-server/src/providers/mcp-provider.js","lineNumber":34,"sourceCode":"\t\tthis.session = null; // MCP server session object\n\t}\n\n\tgetRequiredApiKeyName() {\n\t\treturn 'MCP_API_KEY';\n\t}\n\n\tisRequiredApiKey() {\n\t\treturn false;\n\t}\n\n\t/**\n\t * Override validateAuth to validate MCP session instead of API key\n\t * @param {object} params - Parameters to validate\n\t */\n\tvalidateAuth(params) {\n\t\t// Validate MCP session instead of API key\n\t\tif (!this.session) {\n\t\t\tthrow new Error('MCP Provider requires active MCP session');\n\t\t}\n\n\t\tif (!this.session.clientCapabilities?.sampling) {\n\t\t\tthrow new Error('MCP session must have client sampling capabilities');\n\t\t}\n\t}\n\n\t/**\n\t * Creates and returns an MCP AI SDK client instance.\n\t * @param {object} params - Parameters for client initialization\n\t * @returns {Function} MCP AI SDK client function\n\t * @throws {Error} If initialization fails\n\t */\n\tgetClient(params) {\n\t\ttry {\n\t\t\t// Pass MCP session to AI SDK implementation\n\t\t\treturn createMCP({\n\t\t\t\tsession: this.session,","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/providers/mcp-provider.js#L16-L52","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst provider = new McpProvider();\nconst result = await provider.generate(params); // throws: requires active MCP session\n// after\nconst provider = new McpProvider();\nprovider.session = await establishMcpSession(client); // set session first\nconst result = await provider.generate(params);","handlingStrategy":"validation","validationCode":"if (!provider.session) throw new Error('Call establishMcpSession() before using the MCP provider');","typeGuard":"function hasMcpSession(p) { return !!p.session; }","tryCatchPattern":"try { await provider.generate(params); } catch (e) { if (e.message.includes('requires active MCP session')) { await reconnectAndInitSession(); } else { throw e; } }","preventionTips":["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"],"tags":["mcp","session","authentication"],"backgroundTag":"missing-session","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}