Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
limitNo
scopeNo

Implementation Reference

  • 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),
          },
        ],
      };
    });
  • 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(),
    });
  • 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);
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description discloses that search is semantic, results are branch-stamped from MemPalace, and it excludes docs/config. With no annotations, it carries the transparency burden but omits details like how the 'scope' parameter affects behavior, potential rate limits, or authentication needs. It provides minimal but useful behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences deliver the core purpose, scope, and a constraint with no wasted words. Information is front-loaded, making it easy for an agent to quickly understand the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers the main purpose and a key exclusion. It lacks explanation of the return format, the meaning of 'scope', and how results are structured. Since there is no output schema, more detail on return values would improve completeness. It is adequate but not thorough.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has no descriptions (0% coverage). The description only implicitly covers the 'query' parameter via the search verb but does not explain the 'limit' or 'scope' parameters. This leaves the agent lacking guidance on how to use these parameters effectively.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Semantic search over the current branch's code,' specifying the verb, resource, and scope. It distinguishes from siblings by targeting code only and explicitly excluding docs and config, setting it apart from other tools on the server like those for tracks or changes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides context that search is over current branch code and never searches docs or config, implying when to use. However, it does not explicitly state when to avoid using this tool or suggest alternatives, leaving some ambiguity about comparative usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/2loch-ness6/mempalace-mcp-dev'

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