search_code
Search code in the current branch using semantic queries. Returns branch-stamped results from MemPalace, focusing solely on code files, not docs or configuration. Provides precise, context-aware code matches.
Instructions
Semantic search over the current branch's code. Returns branch-stamped results from MemPalace. Never searches docs or config.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| limit | No | ||
| scope | No |
Implementation Reference
- src/tools/code-search.tool.ts:14-35 (handler)The MCP tool handler for 'search_code' — takes query, limit, scope args and calls manager.search() returning branch-stamped results.
server.tool('search_code', 'Semantic search over the current branch\'s code. Returns branch-stamped results from MemPalace. Never searches docs or config.', SearchCodeSchema.shape, async (args) => { const result = await manager.search({ query: args.query, limit: args.limit, scope: args.scope }); return { content: [ { type: 'text' as const, text: JSON.stringify({ branch: result.branch, sha: result.sha, totalFound: result.totalFound, results: result.results.map((r) => ({ source: r.source, score: r.score, room: r.room, branchStamp: r.branchStamp, content: r.content, })), }, null, 2), }, ], }; }); - src/tools/code-search.tool.ts:5-9 (schema)Zod schema defining the input parameters for search_code: query (string, min 1), limit (int 1-50, default 10), scope (optional string).
export const SearchCodeSchema = z.object({ query: z.string().min(1), limit: z.number().int().min(1).max(50).optional().default(10), scope: z.string().optional(), }); - src/tools/code-search.tool.ts:13-48 (registration)Registration function registerCodeSearchTools that calls server.tool('search_code', ...) to register the tool on the MCP server.
export function registerCodeSearchTools(server: McpServer, manager: CodeSearchManager, repoDir: string): void { server.tool('search_code', 'Semantic search over the current branch\'s code. Returns branch-stamped results from MemPalace. Never searches docs or config.', SearchCodeSchema.shape, async (args) => { const result = await manager.search({ query: args.query, limit: args.limit, scope: args.scope }); return { content: [ { type: 'text' as const, text: JSON.stringify({ branch: result.branch, sha: result.sha, totalFound: result.totalFound, results: result.results.map((r) => ({ source: r.source, score: r.score, room: r.room, branchStamp: r.branchStamp, content: r.content, })), }, null, 2), }, ], }; }); server.tool('mine_changed_files', 'Re-index files changed since last commit into MemPalace. Call after making code changes to keep the search index current.', MineChangedFilesSchema.shape, async () => { const result = await manager.mineChangedFiles(repoDir); return { content: [ { type: 'text' as const, text: JSON.stringify({ mined: result.mined, skipped: result.skipped }), }, ], }; }); } - src/index.ts:14-14 (registration)Import of registerCodeSearchTools from the tool file into the main server entry point.
import { registerCodeSearchTools } from './tools/code-search.tool.js'; - src/index.ts:49-49 (registration)Invocation of registerCodeSearchTools to register the tool on the MCP server with the CodeSearchManager.
registerCodeSearchTools(server, codeSearchManager, REPO_DIR);