Skip to main content
Glama

search_code

Search indexed codebases using semantic queries to find relevant code snippets and project files. Filter results by specific project paths for targeted retrieval.

Instructions

Recherche sémantique dans le code indexé avec options RAG

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesRequête de recherche sémantique
project_filterNoFiltrer par chemin de projet spécifique

Implementation Reference

  • Main handler function executing the search_code tool logic: validates query, loads RAG configuration, sets embedding provider, performs semantic search, and formats output.
    export const searchCodeHandler = async (args) => { if (!args.query || typeof args.query !== 'string') { throw new Error("The 'query' parameter is required and must be a string"); } // Charger la configuration const configManager = getRagConfigManager(); const defaults = configManager.getDefaults(); const searchDefaults = configManager.getSearchDefaults(); // Utiliser uniquement les valeurs par défaut de la configuration const embedding_provider = defaults.embedding_provider; const embedding_model = defaults.embedding_model; const limit = configManager.applyLimits('search_limit', searchDefaults.limit); const threshold = configManager.applyLimits('search_threshold', searchDefaults.threshold); const format_output = searchDefaults.format; // Configurer le fournisseur d'embeddings setEmbeddingProvider(embedding_provider, embedding_model); const options = { projectFilter: args.project_filter, limit: limit, threshold: threshold }; try { const searchResult = await searchCode(args.query, options); // Formater la sortie si demandé if (format_output !== false) { const formatted = `Recherche RAG: "${args.query}"\n` + `Configuration: provider=${embedding_provider}, model=${embedding_model}\n` + `Résultats: ${searchResult.totalResults}\n` + `Temps d'exécution: ${searchResult.stats?.executionTime || 0}ms\n` + `Projets scannés: ${searchResult.stats?.projectsScanned || 0}\n` + `Limite: ${limit}, Seuil: ${threshold}\n\n` + searchResult.results.map((r, i) => `${i + 1}. ${r.filePath} (score: ${(r.score * 100).toFixed(2)}%)\n` + ` Projet: ${r.metadata.projectPath}\n` + ` Contenu: ${r.content.substring(0, 100)}...`).join('\n\n'); return { content: [{ type: "text", text: formatted }] }; } return { content: [{ type: "text", text: JSON.stringify({ ...searchResult, config_used: { embedding_provider, embedding_model, limit, threshold, format_output } }, null, 2) }] }; } catch (error) { console.error("Error in search_code tool:", error); throw error; } };
  • Tool definition including name, description, and input schema for search_code.
    export const searchCodeTool = { name: "search_code", description: "Recherche sémantique dans le code indexé avec options RAG", inputSchema: { type: "object", properties: { query: { type: "string", description: "Requête de recherche sémantique" }, project_filter: { type: "string", description: "Filtrer par chemin de projet spécifique" } }, required: ["query"] }, };
  • getExpectedTools function lists 'search_code' among expected auto-registered RAG tools.
    export function getExpectedTools() { return [ // Outils Graph (9 outils) 'create_entities', 'create_relations', 'add_observations', 'delete_entities', 'delete_observations', 'delete_relations', 'read_graph', 'search_nodes', 'open_nodes', // Outils RAG (5 outils - avec injection_rag comme outil principal) 'injection_rag', // Nouvel outil principal 'index_project', // Alias déprécié (rétrocompatibilité) 'search_code', 'manage_projects', 'update_project' ];
  • Core helper function searchCode that performs the semantic search via vector store and structures the results with stats.
    export async function searchCode(query, options = {}) { const startTime = Date.now(); try { const results = await semanticSearch(query, options); const endTime = Date.now(); // Compter les projets uniques dans les résultats const uniqueProjects = new Set(results.map(r => r.metadata.projectPath)); return { query, results, totalResults: results.length, stats: { executionTime: endTime - startTime, projectsScanned: uniqueProjects.size, }, }; } catch (error) { console.error("Error in searchCode:", error); throw error; } }

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/ali-48/rag-mcp-server'

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