{"record":{"id":"b1100997e0badb0e","repo":"eyaltoledano/claude-task-master","slug":"the-mcp-model-function-cannot-be-called-with-the-n","errorCode":null,"errorMessage":"The MCP model function cannot be called with the new keyword.","messagePattern":"The MCP model function cannot be called with the new keyword\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp-server/src/custom-sdk/index.js","lineNumber":25,"sourceCode":"\nimport { MCPLanguageModel } from './language-model.js';\n\n/**\n * Create MCP provider factory function following AI SDK patterns\n * @param {object} options - Provider options\n * @param {object} options.session - MCP session object\n * @param {object} options.defaultSettings - Default settings for the provider\n * @returns {Function} Provider factory function\n */\nexport function createMCP(options = {}) {\n\tif (!options.session) {\n\t\tthrow new Error('MCP provider requires session object');\n\t}\n\n\t// Return the provider factory function that AI SDK expects\n\tconst provider = function (modelId, settings = {}) {\n\t\tif (new.target) {\n\t\t\tthrow new Error(\n\t\t\t\t'The MCP model function cannot be called with the new keyword.'\n\t\t\t);\n\t\t}\n\n\t\treturn new MCPLanguageModel({\n\t\t\tsession: options.session,\n\t\t\tmodelId: modelId || 'claude-3-5-sonnet-20241022',\n\t\t\tsettings: {\n\t\t\t\ttemperature: settings.temperature,\n\t\t\t\tmaxTokens: settings.maxTokens,\n\t\t\t\t...options.defaultSettings,\n\t\t\t\t...settings\n\t\t\t}\n\t\t});\n\t};\n\n\t// Add required methods for AI SDK compatibility\n\tprovider.languageModel = (modelId, settings) => provider(modelId, settings);","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/custom-sdk/index.js#L7-L43","documentation":"The object returned by createMCP is a plain provider function implementing the AI SDK provider-callable convention; calling it with `new` is unsupported. The library explicitly rejects new.target so users get a clear message instead of subtle failures from skipping MCPLanguageModel construction. Call the provider as a normal function: provider('model-id', settings).","triggerScenarios":"Writing `new provider(modelId)` or `new createMCP({session})(modelId)` — treating the provider factory as a class constructor.","commonSituations":"Refactoring from class-based providers to AI SDK function-style providers; copy-pasting old instantiation code.","solutions":["Remove the `new` keyword and call the provider directly: ai.generateText({ model: provider('model-id') })","Use the languageModel property or template literal form (e.g. mcp('model-id')) per AI SDK v1 provider convention"],"exampleFix":"// before\nconst model = new mcpProvider('my-model', {});\n// after\nconst model = mcpProvider('my-model');","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call the provider as a plain function: provider(modelId, settings) — never with `new`","Use AI SDK helpers (generateText/generateObject with `model: mcp('id')`) instead of manual instantiation","Add an ESLint rule or code-review note against `new` on provider functions"],"tags":["mcp","ai-sdk","javascript","api-misuse"],"backgroundTag":"invalid-constructor-call","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}