Skip to main content
Glama

find_related

Find other files that share tags with a given file, ranked by shared tag count. Navigate related content based on tag associations.

Instructions

Find other files sharing tags with the given file, ranked by shared_tag_count descending. Read-only; no side effects, auth, or rate limits. Returns annotated file rows with shared_tag_count and shared_tags. Empty result means the file has no tags or no other file shares them — try search/regex_search for content-based discovery, or suggest_tags to bootstrap labels first. Default limit 10.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_idYesID of the file to find relations for
limitNoMaximum number of related files to return (default 10)

Implementation Reference

  • MCP tool handler for 'find_related'. Registers the tool with Zod schema (file_id required, limit optional), calls core findRelated(), annotates results with tokens, and returns JSON.
    server.tool(
      "find_related",
      "Find other files sharing tags with the given file, ranked by `shared_tag_count` descending. Read-only; no side effects, auth, or rate limits. Returns annotated file rows with `shared_tag_count` and `shared_tags`. Empty result means the file has no tags or no other file shares them — try `search`/`regex_search` for content-based discovery, or `suggest_tags` to bootstrap labels first. Default limit 10.",
      {
        file_id: z.number().describe("ID of the file to find relations for"),
        limit: z.number().optional().describe("Maximum number of related files to return (default 10)"),
      },
      async ({ file_id, limit }) => {
        const related = findRelated(file_id, limit ?? 10);
        const annotated = related.map((r) => ({ ...annotateTokens(r), shared_tag_count: r.shared_tag_count, shared_tags: r.shared_tags }));
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({ file_id, related: annotated }, null, 2),
            },
          ],
        };
      }
    );
  • Zod schema for find_related tool parameters: file_id (number) required, limit (number) optional.
    {
      file_id: z.number().describe("ID of the file to find relations for"),
      limit: z.number().optional().describe("Maximum number of related files to return (default 10)"),
    },
  • Core implementation of findRelated(). Executes SQL query joining file_tags to find files sharing tags, ordered by shared_tag_count descending.
    export function findRelated(fileId: number, limit: number = 10): RelatedFileRecord[] {
      const db = getDatabase();
      const rows = db
        .prepare(
          `
          SELECT
            f.*,
            COUNT(ft2.tag_id) AS shared_tag_count,
            GROUP_CONCAT(t.name) AS shared_tags_csv
          FROM file_tags ft1
          JOIN file_tags ft2 ON ft1.tag_id = ft2.tag_id
          JOIN files f ON f.id = ft2.file_id
          JOIN tags t ON t.id = ft2.tag_id
          WHERE ft1.file_id = ?
            AND ft2.file_id != ?
          GROUP BY f.id
          ORDER BY shared_tag_count DESC, f.updated_at DESC
          LIMIT ?
          `
        )
        .all(fileId, fileId, limit) as Array<FileRecord & { shared_tag_count: number; shared_tags_csv: string }>;
    
      return rows.map(({ shared_tags_csv, ...rest }) => ({
        ...rest,
        shared_tags: shared_tags_csv ? shared_tags_csv.split(",") : [],
      }));
    }
  • RelatedFileRecord interface extending FileRecord with shared_tag_count and shared_tags.
    export interface RelatedFileRecord extends FileRecord {
      shared_tag_count: number;
      shared_tags: string[];
    }
  • Export of findRelated and RelatedFileRecord from core package.
      findRelated, getTagsForFiles, type RelatedFileRecord,
    } from "./metadata/index.js";
Behavior5/5

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

Discloses read-only nature, no side effects, auth, or rate limits, which is critical since annotations are absent. Also specifies return fields (shared_tag_count, shared_tags) and default limit.

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?

Three sentences, all essential information front-loaded. No filler or redundancy. Highly efficient.

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

Completeness5/5

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

Despite no output schema, description fully covers purpose, behavior, parameters, edge cases (empty results), and alternatives. Complete for a simple two-parameter tool.

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

Parameters3/5

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

Schema already provides 100% coverage for both parameters. Description adds minimal extra value: mentions default limit of 10. Baseline score of 3 is appropriate.

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?

Description clearly states the tool finds other files sharing tags with a given file, ranked by shared_tag_count descending. It distinguishes from sibling tools like search/regex_search and suggest_tags.

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

Usage Guidelines5/5

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

Explicitly advises when results are empty and suggests alternatives: search/regex_search for content-based discovery, suggest_tags to bootstrap labels. Provides clear context for when to use this tool vs alternatives.

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/safiyu/ctxnest'

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