Skip to main content
Glama

mcp_search_comprehensive

Search database objects by name and definition using configurable criteria. Specify object types, search patterns, and focus on names or source code for precise results.

Instructions

Search across database objects by name and definition with configurable criteria

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
object_typesNoTypes of objects to search in
patternYesSearch pattern or text to find
search_in_definitionsNoWhether to search in object definitions/source code
search_in_namesNoWhether to search in object names

Implementation Reference

  • Main handler function that executes comprehensive search by calling helper functions for name matching and definition searching, then combines results.
    export const mcp_search_comprehensive = async (args: { pattern: string; search_in_names?: boolean; search_in_definitions?: boolean; object_types?: string[] }): Promise<ToolResult<{ name_matches: any[]; definition_matches: any[]; total_matches: number; }>> => { const { pattern, search_in_names = true, search_in_definitions = true, object_types } = args; console.log('Executing mcp_search_comprehensive with:', args); try { const promises = []; // Search in object names if (search_in_names) { promises.push(mcp_search_objects_by_name({ pattern, object_types })); } else { // Return empty result with the expected structure promises.push(Promise.resolve({ success: true as const, data: [] })); } // Search in object definitions if (search_in_definitions) { promises.push(mcp_search_in_definitions({ pattern, object_types })); } else { // Return empty result with the expected structure promises.push(Promise.resolve({ success: true as const, data: [] })); } const [nameResults, definitionResults] = await Promise.all(promises); if (!nameResults.success) return nameResults; if (!definitionResults.success) return definitionResults; const nameMatches = nameResults.data; const definitionMatches = definitionResults.data; return { success: true, data: { name_matches: nameMatches, definition_matches: definitionMatches, total_matches: nameMatches.length + definitionMatches.length } }; } catch (error: any) { console.error(`Error in mcp_search_comprehensive: ${error.message}`); return { success: false, error: error.message }; } };
  • Input schema defining parameters for the tool: pattern (required), object_types, search_in_names, search_in_definitions.
    { name: "mcp_search_comprehensive", description: "Search across database objects by name and definition with configurable criteria", inputSchema: { type: "object", properties: { pattern: { type: "string", description: "Search pattern or text to find" }, object_types: { type: "array", items: { type: "string", enum: ["TABLE", "VIEW", "PROCEDURE", "FUNCTION", "TRIGGER", "DEFAULT", "CHECK", "RULE"] }, description: "Types of objects to search in" }, search_in_names: { type: "boolean", description: "Whether to search in object names", default: true }, search_in_definitions: { type: "boolean", description: "Whether to search in object definitions/source code", default: true } }, required: ["pattern"] } },
  • Exports the mcp_search_comprehensive handler (imported from objectSearch.js) for use in toolHandlers mapping.
    export { mcp_search_comprehensive, // Comprehensive search mcp_get_dependencies, // Object dependencies // Funciones adicionales para compatibilidad con server.ts mcp_search_objects_by_name, mcp_search_in_definitions, mcp_search_objects_by_type, mcp_get_object_dependencies } from './objectSearch.js';
  • Helper function to search database objects by name pattern using sys.objects, supports object type filtering.
    export const mcp_search_objects_by_name = async (args: { pattern: string; object_types?: string[] }): Promise<ToolResult<any[]>> => { const { pattern, object_types } = args; console.log('Executing mcp_search_objects_by_name with:', args); try { const pool = getPool(); let typeFilter = ''; if (object_types && object_types.length > 0) { const validTypes = object_types.map(type => { switch(type.toLowerCase()) { case 'table': return "'U'"; case 'view': return "'V'"; case 'procedure': return "'P'"; case 'function': return "'FN', 'IF', 'TF'"; case 'trigger': return "'TR'"; default: return null; } }).filter(Boolean); if (validTypes.length > 0) { typeFilter = `AND o.type IN (${validTypes.join(', ')})`; } } const query = ` SELECT s.name AS schema_name, o.name AS object_name, o.type_desc AS object_type, SCHEMA_NAME(o.schema_id) + '.' + o.name AS full_name, o.create_date, o.modify_date FROM sys.objects o JOIN sys.schemas s ON o.schema_id = s.schema_id WHERE o.name LIKE @pattern ${typeFilter} ORDER BY s.name, o.name; `; const result = await pool.request() .input('pattern', `%${pattern}%`) .query(query); return { success: true, data: result.recordset }; } catch (error: any) { console.error(`Error in mcp_search_objects_by_name: ${error.message}`); return { success: false, error: error.message }; } };
  • Helper function to search within object definitions/source code using sys.sql_modules, supports type filtering.
    /** * Search in object definitions */ export const mcp_search_in_definitions = async (args: { pattern: string; object_types?: string[] }): Promise<ToolResult<any[]>> => { const { pattern, object_types } = args; console.log('Executing mcp_search_in_definitions with:', args); try { const pool = getPool(); let typeFilter = ''; if (object_types && object_types.length > 0) { const validTypes = object_types.map(type => { switch(type.toLowerCase()) { case 'procedure': return "'P'"; case 'function': return "'FN', 'IF', 'TF'"; case 'view': return "'V'"; case 'trigger': return "'TR'"; default: return null; } }).filter(Boolean); if (validTypes.length > 0) { typeFilter = `AND o.type IN (${validTypes.join(', ')})`; } } const query = ` SELECT SCHEMA_NAME(o.schema_id) AS schema_name, o.name AS object_name, o.type_desc AS object_type, SCHEMA_NAME(o.schema_id) + '.' + o.name AS full_name, o.create_date, o.modify_date FROM sys.sql_modules m JOIN sys.objects o ON m.object_id = o.object_id WHERE m.definition LIKE @pattern ${typeFilter} ORDER BY schema_name, object_name; `; const result = await pool.request() .input('pattern', `%${pattern}%`) .query(query); return { success: true, data: result.recordset }; } catch (error: any) { console.error(`Error in mcp_search_in_definitions: ${error.message}`); return { success: false, error: error.message }; } };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hendrickcastro/MCPQL'

If you have feedback or need assistance with the MCP directory API, please join our Discord server