mcp_search_comprehensive
Search SQL Server database objects by name and definition using configurable criteria to find tables, views, procedures, and other database elements.
Instructions
Search across database objects by name and definition with configurable criteria
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | Search pattern or text to find | |
| object_types | No | Types of objects to search in | |
| search_in_names | No | Whether to search in object names | |
| search_in_definitions | No | Whether to search in object definitions/source code |
Implementation Reference
- src/tools/objectSearch.ts:272-329 (handler)Main handler function that implements mcp_search_comprehensive. Orchestrates parallel searches in object names and definitions based on input parameters and 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 }; } };
- src/tools.ts:139-170 (schema)Defines the tool name, description, and input schema for mcp_search_comprehensive in the MCP tools registry.{ 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"] } },
- src/server.ts:64-66 (registration)Registers the MCP tools list (MCP_MSQL_TOOLS containing mcp_search_comprehensive) for ListTools requests.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: MCP_MSQL_TOOLS }));
- src/tools/index.ts:36-44 (registration)Re-exports the mcp_search_comprehensive handler from objectSearch.ts for use in tool handlers map.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';
- src/tools/objectSearch.ts:39-95 (helper)Helper function called by handler to search database objects by name pattern.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 }; } };