Skip to main content
Glama

search_context

Find information across all project documentation files by searching for keywords in local markdown files organized by project and layer.

Instructions

Search for a keyword across all context files in all projects

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query

Implementation Reference

  • Main handler function that searches for the query across all projects in the context directory by listing projects and recursively searching each one.
    async function searchContext(query: string): Promise<any[]> { const projects = await listProjects(); const results: any[] = []; for (const project of projects) { const matches = await searchInProject(project, "", query); if (matches.length > 0) { results.push({ project, matches, }); } } return results; }
  • Recursive helper function that traverses project directories, reads .md files, and finds lines matching the query (case-insensitive).
    async function searchInProject( projectName: string, subPath: string, query: string ): Promise<any[]> { const fullPath = path.join(CONTEXT_DIR, projectName, subPath); const entries = await fs.readdir(fullPath, { withFileTypes: true }); const matches: any[] = []; for (const entry of entries) { const entryPath = path.join(subPath, entry.name); if (entry.isDirectory()) { const subMatches = await searchInProject(projectName, entryPath, query); matches.push(...subMatches); } else if (entry.name.endsWith(".md")) { const content = await readContext(projectName, entryPath); const lines = content.split("\n"); const queryLower = query.toLowerCase(); lines.forEach((line, index) => { if (line.toLowerCase().includes(queryLower)) { matches.push({ file: entryPath, line: index + 1, content: line.trim(), }); } }); } } return matches; }
  • Tool schema definition including name, description, and input schema (requires 'query' string). Used in ListTools response.
    { name: "search_context", description: "Search for a keyword across all context files in all projects", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query", }, }, required: ["query"], }, },
  • src/index.ts:287-313 (registration)
    Registration in the CallToolRequest handler switch: validates input, calls searchContext, and formats response as JSON with total results.
    case "search_context": { const query = args.query as string; if (!query) { throw new Error("query is required"); } const results = await searchContext(query); return { content: [ { type: "text", text: JSON.stringify( { query, total_results: results.reduce( (sum, r) => sum + r.matches.length, 0 ), results, }, null, 2 ), }, ], }; }

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/doko89/mcp-mycontext'

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