(sourceId?: string)
| 617 | * Create a search_database_objects tool handler |
| 618 | */ |
| 619 | export function createSearchDatabaseObjectsToolHandler(sourceId?: string) { |
| 620 | return async (args: any, extra: any) => { |
| 621 | const { |
| 622 | object_type, |
| 623 | pattern = "%", |
| 624 | schema, |
| 625 | table, |
| 626 | detail_level = "names", |
| 627 | limit = 100, |
| 628 | } = args as { |
| 629 | object_type: DatabaseObjectType; |
| 630 | pattern?: string; |
| 631 | schema?: string; |
| 632 | table?: string; |
| 633 | detail_level: DetailLevel; |
| 634 | limit: number; |
| 635 | }; |
| 636 | |
| 637 | const startTime = Date.now(); |
| 638 | const effectiveSourceId = getEffectiveSourceId(sourceId); |
| 639 | let success = true; |
| 640 | let errorMessage: string | undefined; |
| 641 | |
| 642 | try { |
| 643 | // Ensure source is connected (handles lazy connections) |
| 644 | await ConnectorManager.ensureConnected(sourceId); |
| 645 | |
| 646 | const connector = ConnectorManager.getCurrentConnector(sourceId); |
| 647 | |
| 648 | // Tool is already registered, so it's enabled (no need to check) |
| 649 | |
| 650 | // Validate table parameter |
| 651 | if (table) { |
| 652 | if (!schema) { |
| 653 | success = false; |
| 654 | errorMessage = "The 'table' parameter requires 'schema' to be specified"; |
| 655 | return createToolErrorResponse(errorMessage, "SCHEMA_REQUIRED"); |
| 656 | } |
| 657 | if (!["column", "index"].includes(object_type)) { |
| 658 | success = false; |
| 659 | errorMessage = `The 'table' parameter only applies to object_type 'column' or 'index', not '${object_type}'`; |
| 660 | return createToolErrorResponse(errorMessage, "INVALID_TABLE_FILTER"); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | // Validate schema if provided |
| 665 | if (schema) { |
| 666 | const schemas = await connector.getSchemas(); |
| 667 | if (!schemas.includes(schema)) { |
| 668 | success = false; |
| 669 | errorMessage = `Schema '${schema}' does not exist. Available schemas: ${schemas.join(", ")}`; |
| 670 | return createToolErrorResponse(errorMessage, "SCHEMA_NOT_FOUND"); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | let results: any[] = []; |
| 675 | |
| 676 | // Route to appropriate search function |
no test coverage detected