Skip to main content
Glama

List Attachments

list_attachments
Read-onlyIdempotent

List all non-markdown attachments by extension, returning sorted relative paths and per-extension counts for auditing assets or finding duplicates.

Instructions

Enumerate every non-markdown file in the vault — images, PDFs, audio/video clips, anything pasted in beyond notes/canvases/Bases. Returns a sorted list of relative paths plus a per-extension count summary. Use to audit assets, find duplicates by name, or pick targets for find_unused_attachments.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
extensionNoRestrict to one extension (e.g., 'png' or '.png'). Omit for every attachment.
limitNoMaximum number of attachment paths to return (1-10000, default: 200). Total counts are still reported.

Implementation Reference

  • Tool 'list_attachments' is registered on the McpServer via registerTool() with Zod input schema (optional 'extension' filter and 'limit' with default 200).
    export function registerAttachmentTools(server: McpServer, vaultPath: string): void {
      server.registerTool(
        "list_attachments",
        {
          title: "List Attachments",
          description:
            "Enumerate every non-markdown file in the vault — images, PDFs, audio/video clips, anything pasted in beyond notes/canvases/Bases. Returns a sorted list of relative paths plus a per-extension count summary. Use to audit assets, find duplicates by name, or pick targets for find_unused_attachments.",
          annotations: {
            readOnlyHint: true,
            idempotentHint: true,
            openWorldHint: false,
          },
          inputSchema: {
            extension: z
              .string()
              .optional()
              .describe("Restrict to one extension (e.g., 'png' or '.png'). Omit for every attachment."),
            limit: z
              .number()
              .int()
              .min(1)
              .max(10000)
              .optional()
              .default(200)
              .describe("Maximum number of attachment paths to return (1-10000, default: 200). Total counts are still reported."),
          },
        },
        async ({ extension, limit }) => {
          try {
            const all = await listAttachments(vaultPath);
            const filtered = extension
              ? all.filter((p) => {
                  const ext = (extension.startsWith(".") ? extension : `.${extension}`).toLowerCase();
                  return p.toLowerCase().endsWith(ext);
                })
              : all;
            if (filtered.length === 0) {
              return textResult(
                extension
                  ? `No attachments with extension "${extension}".`
                  : "No attachments in this vault.",
              );
            }
            const truncated = filtered.slice(0, limit);
            const lines: string[] = [
              `${filtered.length} attachment(s)${extension ? ` (.${extension.replace(/^\./, "")})` : ""}${filtered.length > limit ? ` (showing first ${limit})` : ""}:`,
              "",
            ];
            const summary = summarizeByExtension(filtered);
            if (summary.size > 1) {
              lines.push("By extension:");
              const entries = Array.from(summary.entries()).sort((a, b) => b[1] - a[1]);
              for (const [ext, n] of entries) lines.push(`  ${ext}  ${n}`);
              lines.push("");
            }
            for (const p of truncated) lines.push(`- ${p}`);
            return textResult(lines.join("\n"));
          } catch (err) {
            log.error("list_attachments failed", { tool: "list_attachments", err: err as Error });
            return errorResult(`Error listing attachments: ${sanitizeError(err)}`);
          }
        },
      );
  • Input schema defines 'extension' (optional string) and 'limit' (optional int, 1-10000, default 200) inputs.
      inputSchema: {
        extension: z
          .string()
          .optional()
          .describe("Restrict to one extension (e.g., 'png' or '.png'). Omit for every attachment."),
        limit: z
          .number()
          .int()
          .min(1)
          .max(10000)
          .optional()
          .default(200)
          .describe("Maximum number of attachment paths to return (1-10000, default: 200). Total counts are still reported."),
      },
    },
  • Handler function: calls listAttachments() from vault lib, optionally filters by extension, truncates to limit, groups by extension for a summary, and returns text result.
    async ({ extension, limit }) => {
      try {
        const all = await listAttachments(vaultPath);
        const filtered = extension
          ? all.filter((p) => {
              const ext = (extension.startsWith(".") ? extension : `.${extension}`).toLowerCase();
              return p.toLowerCase().endsWith(ext);
            })
          : all;
        if (filtered.length === 0) {
          return textResult(
            extension
              ? `No attachments with extension "${extension}".`
              : "No attachments in this vault.",
          );
        }
        const truncated = filtered.slice(0, limit);
        const lines: string[] = [
          `${filtered.length} attachment(s)${extension ? ` (.${extension.replace(/^\./, "")})` : ""}${filtered.length > limit ? ` (showing first ${limit})` : ""}:`,
          "",
        ];
        const summary = summarizeByExtension(filtered);
        if (summary.size > 1) {
          lines.push("By extension:");
          const entries = Array.from(summary.entries()).sort((a, b) => b[1] - a[1]);
          for (const [ext, n] of entries) lines.push(`  ${ext}  ${n}`);
          lines.push("");
        }
        for (const p of truncated) lines.push(`- ${p}`);
        return textResult(lines.join("\n"));
      } catch (err) {
        log.error("list_attachments failed", { tool: "list_attachments", err: err as Error });
        return errorResult(`Error listing attachments: ${sanitizeError(err)}`);
      }
    },
  • Core helper that walks the vault directory tree excluding .md, .canvas, .base files and hidden/excluded directories, returning all attachment paths sorted.
    export async function listAttachments(
      vaultPath: string,
    ): Promise<string[]> {
      const entries = await walkVaultExcluding(
        await getRealVaultRoot(vaultPath),
        [".md", ".canvas", ".base"],
      );
      const out: string[] = [];
      for (const rel of entries) {
        if (isExcluded(rel)) continue;
        out.push(rel);
      }
      return out.sort();
    }
Behavior4/5

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

Annotations already declare readOnlyHint and idempotentHint. The description adds value by specifying the return format (sorted list of relative paths + per-extension count summary) and clarifying that even with a limit, total counts are still reported. No contradictions with annotations.

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, front-loaded with purpose and scope, no filler. Every sentence adds value: first defines what the tool does, second gives usage guidance.

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?

The description fully explains the tool's output (sorted paths + count summary), behavior with parameters (limit, extension), and use cases. No output schema exists, but the description covers return values adequately. With strong annotations, it's complete.

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 coverage is 100%, so parameters are well-documented. The description adds context by noting 'Total counts are still reported' for the limit parameter and hinting at the extension parameter by saying 'pick targets.' Baseline acceptable.

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 it enumerates every non-markdown file (images, PDFs, audio/video clips) beyond notes/canvases/Bases, returning sorted paths and extension counts. It distinguishes from siblings like list_notes and list_canvases by specifying 'non-markdown' and 'attachments'.

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 gives explicit use cases: 'audit assets, find duplicates by name, or pick targets for find_unused_attachments.' It mentions a sibling tool (find_unused_attachments) as a next step but does not explicitly state when not to use this tool.

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/rps321321/obsidian-mcp-pro'

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