|
1 | 1 | import { ConnectorManager } from '../connectors/manager.js'; |
2 | 2 | import { ConnectorRegistry } from '../connectors/interface.js'; |
3 | 3 | import { createToolSuccessResponse } from '../utils/response-formatter.js'; |
| 4 | +import { isDemoMode } from '../config/env.js'; |
4 | 5 |
|
5 | 6 | /** |
6 | 7 | * list_connectors tool handler |
7 | 8 | * Lists all available database connectors and their sample DSNs |
| 9 | + * Indicates which connector is active based on current DSN |
8 | 10 | */ |
9 | 11 | export async function listConnectorsToolHandler(_args: {}, _extra: any) { |
10 | 12 | const connectors = ConnectorManager.getAvailableConnectors(); |
11 | 13 | const samples = ConnectorRegistry.getAllSampleDSNs(); |
12 | 14 |
|
| 15 | + // Get active connector if possible |
| 16 | + let activeConnectorId: string | null = null; |
| 17 | + try { |
| 18 | + // Check if we have an active connection using static method |
| 19 | + const activeConnector = ConnectorManager.getCurrentConnector(); |
| 20 | + activeConnectorId = activeConnector.id; |
| 21 | + } catch (error) { |
| 22 | + // No active connector yet or not connected |
| 23 | + } |
| 24 | + |
| 25 | + // If we're in demo mode, SQLite should be active |
| 26 | + const isDemo = isDemoMode(); |
| 27 | + if (isDemo && !activeConnectorId) { |
| 28 | + activeConnectorId = 'sqlite'; |
| 29 | + } |
| 30 | + |
13 | 31 | // Convert to a more structured format |
14 | 32 | const sampleObjects = Object.entries(samples).map(([id, dsn]) => ({ |
15 | 33 | id, |
16 | | - dsn |
| 34 | + dsn, |
| 35 | + active: id === activeConnectorId |
17 | 36 | })); |
18 | 37 |
|
19 | 38 | // Prepare response data |
20 | 39 | const responseData = { |
21 | 40 | connectors: sampleObjects, |
22 | | - count: sampleObjects.length |
| 41 | + count: sampleObjects.length, |
| 42 | + activeConnector: activeConnectorId, |
| 43 | + demoMode: isDemo |
23 | 44 | }; |
24 | 45 |
|
25 | 46 | // Use the utility to create a standardized response |
|
0 commit comments