Skip to main content
Glama

find_orphans

Identifies notes lacking incoming wikilinks. Optionally filter by a scope path, returns root, scope, and array of orphan relative paths.

Instructions

Finds notes with no incoming wikilinks. Optional { scope } path prefix. Returns { root, scope, orphans[] } (array of relative paths).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • makeFindOrphansTool: tool handler that parses the schema, delegates to services.links.findOrphans(), and returns { root, scope, orphans }.
    function makeFindOrphansTool(container: ServiceContainer): ToolHandler {
      return {
        name: "find_orphans",
        description:
          "Finds notes with no incoming wikilinks. Optional `{ scope }` path prefix. Returns `{ root, scope, orphans[] }` (array of relative paths).",
        inputSchema: FindOrphansSchema,
        async handler(args): Promise<ToolResponse> {
          try {
            const services = requireServices(container);
            const { scope } = FindOrphansSchema.parse(args);
            log.info({ scope }, "find_orphans called");
            const orphans = await services.links.findOrphans(scope);
            log.info({ scope, count: orphans.length }, "find_orphans complete");
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify({ root: getRoot(container), scope: scope ?? null, orphans }),
                },
              ],
            };
          } catch (err) {
            log.error({ err }, "find_orphans failed");
            return {
              content: [{ type: "text", text: JSON.stringify({
                root: getRoot(container),
                error: err instanceof Error ? err.message : String(err),
                possibleSolutions: ["Check the scope path is root-relative", "Omit scope to scan the entire directory"],
              }) }],
              isError: true,
            };
          }
        },
  • FindOrphansSchema: Zod schema defining the optional 'scope' string parameter for the find_orphans tool.
    const FindOrphansSchema = z.object({
      scope: z.string().optional(),
    });
  • findOrphans() service method: collects files, builds in-degree map from wikilinks, returns files with zero incoming links.
    async findOrphans(scope?: string): Promise<string[]> {
      log.info({ scope }, "findOrphans");
    
      const files = await this.collectFiles(scope);
    
      // Build in-degree map
      const inDegree = new Map<string, number>();
      for (const f of files) {
        inDegree.set(f, 0);
      }
    
      // Map each stem to the file paths that share it (for O(1) lookup)
      const stemToFiles = new Map<string, string[]>();
      for (const f of files) {
        const stem = getStem(f);
        const existing = stemToFiles.get(stem);
        if (existing) {
          existing.push(f);
        } else {
          stemToFiles.set(stem, [f]);
        }
      }
    
      for (const filePath of files) {
        const links = await this.getLinksForFile(filePath);
    
        for (const link of links) {
          const stem = this.stemFromTarget(link.target);
          const targets = stemToFiles.get(stem);
          if (!targets) continue;
    
          for (const f of targets) {
            inDegree.set(f, (inDegree.get(f) ?? 0) + 1);
          }
        }
      }
    
      const orphans = files.filter((f) => (inDegree.get(f) ?? 0) === 0);
      log.info({ scope, orphanCount: orphans.length }, "findOrphans complete");
      return orphans;
    }
  • registerLinkTools() registers makeFindOrphansTool into the tool registry map.
    export function registerLinkTools(
      registry: Map<string, ToolHandler>,
      container: ServiceContainer,
    ): void {
      const tools = [
        makeGetBacklinksTool(container),
        makeFindUnlinkedMentionsTool(container),
        makeFindBrokenLinksTool(container),
        makeFindOrphansTool(container),
        makeFindBidirectionalMentionsTool(container),
      ];
    
      for (const tool of tools) {
        registry.set(tool.name, tool);
  • LITE_TOOL_NAMES: 'find_orphans' is allowlisted in lite mode.
    export const LITE_TOOL_NAMES: ReadonlySet<string> = new Set([
      // Schema / lint
      "lint_note",
      "validate_folder",
      "validate_area",
      "validate_all",
      "list_schemas",
      // Link graph
      "find_broken_links",
      "find_orphans",
      "find_unlinked_mentions",
      "find_bidirectional_mentions",
      "get_backlinks",
      // Meta
      "switch_directory",
      "get_stats",
    ]);
  • Interface declaration: findOrphans(scope?: string): Promise<string[]> on the LinkEngine interface.
    /** Find notes with no incoming links in scope */
    findOrphans(scope?: string): Promise<string[]>;
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses the return format {root, scope, orphans[]} and the operation is read-only by nature, but it does not explicitly state safety, permissions, or side effects. Basic behavior is clear but could be more transparent.

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?

The description is extremely concise: two sentences covering purpose, optional parameter, and return structure. Every word adds value, and the information is front-loaded. No wasted words.

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

Completeness4/5

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

For a simple tool with one optional parameter and no output schema, the description provides the core purpose, the scope parameter, and the return format. It could mention that the operation is read-only, but overall it is sufficiently complete for effective use.

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

Parameters4/5

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

Schema coverage is 100% with one optional string parameter 'scope'. The description adds 'path prefix' which provides contextual meaning beyond the schema type, helping the agent understand its purpose. This extra information merits a 4.

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

Purpose4/5

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

The description clearly states it finds notes with no incoming wikilinks, which is a specific verb+resource. It distinguishes the tool's function from siblings like find_broken_links and find_unlinked_mentions implicitly, but does not explicitly differentiate, so score is 4.

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

Usage Guidelines3/5

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

The description implies usage for identifying orphan notes without inbound links. However, it provides no guidance on when not to use this tool or alternatives like find_broken_links. The optional scope parameter is mentioned, but no exclusions or context for sibling tools is given.

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/Erodenn/markscribe'

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