{"record":{"id":"45f6e9e455117e58","repo":"FlowiseAI/Flowise","slug":"database-not-available","errorCode":null,"errorMessage":"Database not available","messagePattern":"Database not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/tools/MCP/CustomMcpServerTool/CustomMcpServerTool.ts","lineNumber":127,"sourceCode":"                mcpActions = typeof _mcpActions === 'string' ? JSON.parse(_mcpActions) : _mcpActions\n            } catch (error) {\n                console.error('Error parsing mcp actions:', error)\n            }\n        }\n\n        return tools.filter((tool: any) => mcpActions.includes(tool.name))\n    }\n\n    async getTools(nodeData: INodeData, options: ICommonObject): Promise<Tool[]> {\n        const serverId = nodeData.inputs?.mcpServerId as string\n        if (!serverId) {\n            throw new Error('MCP Server is required')\n        }\n\n        const appDataSource = options.appDataSource as DataSource\n        const databaseEntities = options.databaseEntities as IDatabaseEntity\n        if (!appDataSource || !databaseEntities?.['CustomMcpServer']) {\n            throw new Error('Database not available')\n        }\n\n        const workspaceId =\n            (options.workspaceId as string | undefined) ??\n            ((options.searchOptions as ICommonObject | undefined)?.workspaceId as string | undefined)\n        if (!workspaceId) {\n            throw new Error('Workspace context is required to load MCP server')\n        }\n\n        const serverRecord = await appDataSource.getRepository(databaseEntities['CustomMcpServer']).findOneBy({ id: serverId, workspaceId })\n        if (!serverRecord) {\n            throw new Error(`MCP server ${serverId} not found`)\n        }\n        if (serverRecord.status !== 'AUTHORIZED') {\n            throw new Error(`MCP server \"${serverRecord.name}\" is not authorized. Please authorize it in the Tools page first.`)\n        }\n\n        // Build headers from encrypted authConfig — only when authType explicitly requires them","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/tools/MCP/CustomMcpServerTool/CustomMcpServerTool.ts#L109-L145","documentation":"Thrown by CustomMcpServerTool.getTools when options.appDataSource or options.databaseEntities['CustomMcpServer'] is missing. This is an infrastructure precondition — the Flowise runtime must inject the TypeORM DataSource and the registered entity for managed MCP servers. Hitting it means getTools was called outside the normal flow-execution context (where options are populated) or the CustomMcpServer entity is not registered in this build.","triggerScenarios":"Invoking the tool from a test harness or script that constructs options manually without appDataSource/databaseEntities; running on a Flowise build where the CustomMcpServer migration/entity is disabled; a race where getTools runs before the DataSource is initialized.","commonSituations":"Unit tests that bypass Flowise DI; a stripped-down Flowise fork that omitted the MCP server entity; an upgrade where the entity name changed but the code wasn't rebuilt.","solutions":["Ensure the tool is invoked through the Flowise runtime, which injects appDataSource and databaseEntities into options.","If calling programmatically, populate options.appDataSource and options.databaseEntities.CustomMcpServer with the real TypeORM DataSource and entity.","Confirm the CustomMcpServer entity is registered (DB migration ran); re-run migrations if missing.","Rebuild/restart Flowise after an entity-name change."],"exampleFix":"// before (in a test)\nawait tool.getTools(nodeData, {})\n// after\nawait tool.getTools(nodeData, { appDataSource, databaseEntities: { CustomMcpServer: Entity }, workspaceId: 'ws1' })","handlingStrategy":"type-guard","validationCode":"function assertRuntimeReady(options: ICommonObject) {\n  if (!options.appDataSource) throw new Error('appDataSource not injected — call via the Flowise runtime')\n  if (!options.databaseEntities?.['CustomMcpServer']) throw new Error('CustomMcpServer entity not registered — run migrations')\n}","typeGuard":"function hasDataSource(o: unknown): o is { appDataSource: DataSource; databaseEntities: IDatabaseEntity } {\n  return !!o && typeof (o as any).appDataSource?.getRepository === 'function' && !!(o as any).databaseEntities?.['CustomMcpServer']\n}","tryCatchPattern":null,"preventionTips":["Invoke through the Flowise runtime which injects DataSource + entities.","In tests, populate options.appDataSource and options.databaseEntities manually.","Run DB migrations so the CustomMcpServer entity is registered.","Rebuild after any entity-name change."],"tags":["mcp","infrastructure","database","typeorm","di"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}