Skip to main content
Glama

doc_find

Search for documents matching a query string. Use the q parameter to specify the search, and optionally set top or limit to control the number of results returned.

Instructions

Alias of doc.find

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYes
topNo
limitNo

Implementation Reference

  • The core handler function that searches the local document index (MiniSearch). Loads/builds the index, searches with prefix/fuzzy matching, and returns scored snippets.
    export async function docFind(q: string, top = 5) {
      let idx = loadIndex();
      if (!idx) { await indexBuild(CONFIG.sandboxDir); idx = loadIndex(); }
      if (!idx) return [];
      const res = idx.mini.search(q, { prefix: true, fuzzy: 0.2, boost: { title: 2 } }).slice(0, top);
      return res.map((r: any) => {
        const doc = idx.docs.find(d => d.id === r.id)!;
        const text = doc.text || '';
        const i = text.toLowerCase().indexOf(q.toLowerCase());
        const start = Math.max(0, i - 80);
        const end = Math.min(text.length, i + 80);
        const snippet = text.slice(start, end).replace(/\s+/g, ' ');
        return { path: doc.path, score: r.score, snippet };
      });
    }
  • Zod schema defining inputs for doc_find: 'q' (string, required), 'top' (optional int), 'limit' (optional int).
    const docFindShape = {
      q: z.string(),
      top: z.number().int().optional(),
      limit: z.number().int().optional()
    };
  • src/server.ts:116-122 (registration)
    Registration of the 'doc_find' tool alias, delegating to the docFind handler with the same docFindShape schema.
    server.tool('doc_find', 'Alias of doc.find',
      docFindShape, OPEN,
      async ({ q, top, limit }) => {
        const res = await docFind(q, top ?? limit ?? 5);
        return { content: [{ type: 'text', text: JSON.stringify(res) }] };
      }
    );
  • indexBuild helper that collects files from the sandbox directory, converts them to text (with PDF/HTML support), and builds a MiniSearch index saved to .cache/index.json.
    export async function indexBuild(root?: string) {
      const base = root ? path.resolve(root) : CONFIG.sandboxDir;
      const files = await collectFiles(base);
      const docs: DocRecord[] = [];
      for (const p of files) {
        const { title, text } = await fileToText(p);
        docs.push({ id: p, path: p, title, text });
      }
      const mini = new MiniSearch({
        fields: ['title','text'],
        storeFields: ['path','title'],
        searchOptions: { boost: { title: 2 } }
      });
      mini.addAll(docs);
      const payload = { docs, index: mini.toJSON() };
      await fs.mkdir(path.dirname(INDEX_PATH), { recursive: true }).catch(()=>{});
      await fs.writeFile(INDEX_PATH, JSON.stringify(payload));
      return { ok: true, indexed: docs.length };
    }
  • loadIndex helper that loads the cached MiniSearch index from disk, used by docFind.
    function loadIndex() {
      if (!fssync.existsSync(INDEX_PATH)) return null;
      const payload = JSON.parse(fssync.readFileSync(INDEX_PATH, 'utf-8'));
      const mini = MiniSearch.loadJSON(payload.index, { fields: ['title','text'], storeFields: ['path','title'] });
      return { mini, docs: payload.docs as DocRecord[] };
    }
Behavior1/5

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

No behavioral details disclosed; annotation openWorldHint provides minimal context, but description adds nothing.

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

Conciseness2/5

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

Very short but lacks substantive content; under-specification is not good conciseness.

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

Completeness1/5

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

Inadequate for a tool with 3 parameters and no output schema; fails to provide needed context.

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

Parameters1/5

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

No parameter descriptions; schema coverage is 0% and description does not explain any parameters.

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

Purpose2/5

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

States it is an alias of doc.find, but does not describe what doc.find does, leaving purpose unclear.

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

Usage Guidelines2/5

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

No guidance on when to use this tool vs alternatives; merely indicates it is an alias.

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/khanhs-234/tool4lm'

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