Skip to main content
Glama
bezata

kObsidian MCP

Search Notes By Tag

tags.search
Read-onlyIdempotent

Search the entire vault for notes containing a given tag, from frontmatter or inline #tag. Returns file path and distinguishes frontmatter from inline locations. Read-only. For a single note, use tags.analyze instead.

Instructions

Find every note in the vault that contains a given tag, either in frontmatter tags or as an inline #tag in the body. Leading # on the query is stripped. For each hit, the result carries {file, absolutePath, tagLocations: {frontmatter, inline}} so callers can distinguish where the tag came from. Read-only. For analyzing tags of ONE specific note (not a vault-wide search), use tags.analyze instead.

Operates on the session-active vault (see vault.current — selectable via vault.select) unless an explicit vaultPath argument is passed, which always wins.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tagYesTag to find. Leading `#` is stripped.
vaultPathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
tagYesThe normalized tag that was searched (leading `#` stripped).
totalYes
itemsYes

Implementation Reference

  • The core domain function that walks all markdown files in the vault, searches for the given tag in frontmatter and inline content, and returns matching notes with location details.
    export async function searchByTag(
      context: DomainContext,
      args: { tag: string; vaultPath?: string },
    ) {
      const vaultRoot = requireVaultPath(context, args.vaultPath);
      const searchTag = args.tag.replace(/^#/, "");
      const items: Array<{
        file: string;
        absolutePath: string;
        tagLocations: { frontmatter: boolean; inline: boolean };
      }> = [];
    
      for (const absolutePath of await walkMarkdownFiles(vaultRoot)) {
        const content = await readUtf8(absolutePath);
        const tags = extractAllTags(content);
        const frontmatter = tags.frontmatterTags.includes(searchTag);
        const inline = tags.inlineTags.includes(searchTag);
        if (!frontmatter && !inline) {
          continue;
        }
        items.push({
          file: toVaultRelativePath(vaultRoot, absolutePath),
          absolutePath,
          tagLocations: { frontmatter, inline },
        });
      }
    
      return {
        tag: searchTag,
        items,
        total: items.length,
      };
    }
  • Zod schema defining the input arguments for tags.search: requires a tag string, optionally accepts vaultPath.
    export const tagsSearchArgsSchema = z
      .object({
        tag: tagSchema.describe("Tag to find. Leading `#` is stripped."),
        vaultPath: z.string().optional(),
      })
      .strict()
      .describe("Arguments for `tags.search`.");
    export type TagsSearchArgs = z.input<typeof tagsSearchArgsSchema>;
  • Zod schema defining the output shape: normalized tag, total count, and array of items with file paths and tag location booleans.
    export const tagsSearchOutputSchema = z
      .object({
        tag: z.string().describe("The normalized tag that was searched (leading `#` stripped)."),
        total: z.number().int().nonnegative(),
        items: z.array(
          z
            .object({
              file: z.string(),
              absolutePath: z.string(),
              tagLocations: z.object({
                frontmatter: z
                  .boolean()
                  .describe("True if the tag appears in the note's frontmatter `tags` list."),
                inline: z
                  .boolean()
                  .describe("True if the tag appears as an inline `#tag` in the body."),
              }),
            })
            .passthrough(),
        ),
      })
      .passthrough();
  • Tool registration in the tagTools array: defines the tool name, description, input/output schemas, and the handler that delegates to searchByTag.
    {
      name: "tags.search",
      title: "Search Notes By Tag",
      description:
        "Find every note in the vault that contains a given tag, either in frontmatter `tags` or as an inline `#tag` in the body. Leading `#` on the query is stripped. For each hit, the result carries `{file, absolutePath, tagLocations: {frontmatter, inline}}` so callers can distinguish where the tag came from. Read-only. For analyzing tags of ONE specific note (not a vault-wide search), use `tags.analyze` instead.",
      inputSchema: tagsSearchArgsSchema,
      outputSchema: tagsSearchOutputSchema,
      annotations: READ_ONLY,
      handler: async (context, rawArgs) => {
        const args = tagsSearchArgsSchema.parse(rawArgs) as TagsSearchArgs;
        return searchByTag(context, args);
      },
    },
Behavior5/5

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

Discloses that the tool strips leading `#` from queries, that it is read-only (consistent with annotations), and describes the result structure including `tagLocations` to distinguish frontmatter from inline. Annotations already indicate read-only, so this adds valuable behavioral nuance.

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 short, focused paragraphs. The first covers core functionality and result shape; the second addresses vault context. Every sentence adds value, no fluff.

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?

Covers all essential aspects: what it does, how it works, result format, when to use alternatives, vault context, and safety (read-only). With annotations already providing safety info, the description is fully complete.

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

Parameters5/5

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

Despite 50% schema coverage (only tag has schema description), the description enriches both parameters: it explains the `#` stripping for `tag` and the vault resolution logic for `vaultPath`, which is not described in the schema.

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 finds every note containing a given tag, specifying both frontmatter and inline occurrences. It distinguishes itself from the sibling tool `tags.analyze` by noting the different scope (vault-wide vs. per-note).

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 tells when to use this tool (vault-wide search) and when not to (for analyzing one specific note, use `tags.analyze`). Also clarifies vault selection behavior and the override via `vaultPath`.

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/bezata/kObsidian'

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