append_insight
Add business insights and analysis notes to database memos with optional tags and connection associations for better data documentation.
Instructions
Add a business insight or analysis note to the memo
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection | No | Optional connection ID to associate with this insight | |
| insight | Yes | The business insight or analysis note to store | |
| tags | No | Optional tags to categorize the insight |
Implementation Reference
- src/index.ts:962-988 (handler)The main handler function for the 'append_insight' tool. Validates the input insight, creates a new BusinessInsight object with timestamp, optional connection and tags, appends it to the in-memory insights array, saves to a JSON file in tmp dir, and returns a success response with the new insight ID.private async handleAppendInsight(args: { insight: string; connection?: string; tags?: string[] }) { if (!args.insight || args.insight.trim().length === 0) { throw new McpError(ErrorCode.InvalidParams, 'Insight text is required'); } const newInsight: BusinessInsight = { id: Date.now(), insight: args.insight.trim(), created_at: new Date().toISOString(), connection: args.connection, tags: args.tags || [] }; this.insights.push(newInsight); this.saveInsights(); return { content: [{ type: 'text' as const, text: JSON.stringify({ success: true, message: 'Insight added successfully', id: newInsight.id }, null, 2), }], }; }
- src/index.ts:429-449 (schema)Tool schema definition including name, description, and inputSchema with properties for insight (required string), optional connection string, and optional tags array.name: 'append_insight', description: 'Add a business insight or analysis note to the memo', inputSchema: { type: 'object', properties: { insight: { type: 'string', description: 'The business insight or analysis note to store', }, connection: { type: 'string', description: 'Optional connection ID to associate with this insight', }, tags: { type: 'array', items: { type: 'string' }, description: 'Optional tags to categorize the insight', }, }, required: ['insight'], },
- src/index.ts:548-553 (registration)Registration in the tool dispatcher switch statement within CallToolRequestSchema handler, which routes calls to the handleAppendInsight method.case 'append_insight': return await this.handleAppendInsight(args as { insight: string; connection?: string; tags?: string[] });
- src/index.ts:96-102 (helper)Helper method called by handleAppendInsight to persist the insights array to a JSON file in the system's tmp directory.private saveInsights() { try { fs.writeFileSync(this.insightsFile, JSON.stringify(this.insights, null, 2)); } catch (error) { this.log(`Failed to save insights: ${error}`, 'error'); } }
- src/index.ts:84-94 (helper)Helper method to load existing insights from the JSON file on server startup, used to initialize the insights array before handling append_insight calls.private loadInsights() { try { if (fs.existsSync(this.insightsFile)) { const data = fs.readFileSync(this.insightsFile, 'utf-8'); this.insights = JSON.parse(data); } } catch (error) { this.log(`Failed to load insights: ${error}`, 'debug'); this.insights = []; } }