MCPcopy Create free account
hub / github.com/bytebase/dbhub / createSearchDatabaseObjectsToolHandler

Function createSearchDatabaseObjectsToolHandler

src/tools/search-objects.ts:619–739  ·  view source on GitHub ↗
(sourceId?: string)

Source from the content-addressed store, hash-verified

617 * Create a search_database_objects tool handler
618 */
619export 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

Callers 2

Calls 14

getEffectiveSourceIdFunction · 0.85
createToolErrorResponseFunction · 0.85
searchSchemasFunction · 0.85
searchTablesFunction · 0.85
searchViewsFunction · 0.85
searchColumnsFunction · 0.85
searchProceduresFunction · 0.85
searchIndexesFunction · 0.85
trackToolRequestFunction · 0.85
ensureConnectedMethod · 0.80

Tested by

no test coverage detected