Skip to main content
Glama
bazylhorsey
by bazylhorsey

dataview_query

Execute Dataview-style queries to filter, sort, and analyze notes from your Obsidian vault based on metadata, tags, and content criteria.

Instructions

Execute a Dataview-style query on notes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromNoSource filter (folder path or #tag)
groupByNoField to group by
limitNoMaximum results
selectNoFields to select
sortNoSort order
vaultYesVault name
whereNoFilter conditions

Implementation Reference

  • Core handler function that executes the full Dataview query logic: loads notes, applies FROM/WHERE/SORT/GROUP/SELECT/LIMIT filters, and returns results.
    async executeQuery(query: DataviewQuery): Promise<QueryExecutionResult> {
      let results = this.notes.map(note => this.noteToDataviewResult(note));
    
      // Apply FROM clause (source filtering)
      if (query.from) {
        results = this.applyFromFilter(results, query.from);
      }
    
      // Apply WHERE clause (filters)
      if (query.where && query.where.length > 0) {
        results = this.applyFilters(results, query.where);
      }
    
      // Apply SORT
      if (query.sort && query.sort.length > 0) {
        results = this.applySorting(results, query.sort);
      }
    
      // Apply field selection
      if (query.select && query.select.length > 0) {
        results = this.applyFieldSelection(results, query.select);
      }
    
      const totalCount = results.length;
    
      // Apply GROUP BY
      if (query.groupBy) {
        const grouped = this.applyGrouping(results, query.groupBy);
        return {
          results: grouped,
          totalCount,
          grouped: true
        };
      }
    
      // Apply LIMIT
      if (query.limit && query.limit > 0) {
        results = results.slice(0, query.limit);
      }
    
      return {
        results,
        totalCount,
        grouped: false
      };
    }
  • MCP tool dispatch handler for 'dataview_query': fetches notes from vault connector, updates DataviewService, constructs query from arguments, calls executeQuery, and formats response.
    case 'dataview_query': {
      const connector = this.connectors.get(args?.vault as string);
      if (!connector) {
        throw new Error(`Vault "${args?.vault}" not found`);
      }
    
      const notesResult = await connector.getAllNotes();
      if (!notesResult.success || !notesResult.data) {
        throw new Error('Failed to get notes');
      }
    
      this.dataviewService.updateNotes(notesResult.data);
    
      const query: any = {};
      if (args?.from) query.from = args.from;
      if (args?.where) query.where = args.where;
      if (args?.sort) query.sort = args.sort;
      if (args?.groupBy) query.groupBy = args.groupBy;
      if (args?.select) query.select = args.select;
      if (args?.limit) query.limit = args.limit;
    
      const result = await this.dataviewService.executeQuery(query);
    
      return {
        content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
      };
    }
  • TypeScript interface defining the structure of DataviewQuery used by the handler, matching the tool's inputSchema.
    export interface DataviewQuery {
      // Source selection
      from?: string | string[]; // Folder, tag, or file paths
    
      // Filters
      where?: QueryFilter[];
    
      // Sorting
      sort?: QuerySort[];
    
      // Limiting
      limit?: number;
    
      // Grouping
      groupBy?: string;
    
      // Fields to select
      select?: string[];
    }
  • src/index.ts:290-326 (registration)
    Tool registration in ListToolsRequestHandler, defining name, description, and inputSchema for 'dataview_query'.
      name: 'dataview_query',
      description: 'Execute a Dataview-style query on notes',
      inputSchema: {
        type: 'object',
        properties: {
          vault: { type: 'string', description: 'Vault name' },
          from: { type: 'string', description: 'Source filter (folder path or #tag)' },
          where: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                field: { type: 'string' },
                operator: { type: 'string', enum: ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'contains', 'startsWith', 'endsWith', 'exists'] },
                value: { type: 'string' }
              }
            },
            description: 'Filter conditions'
          },
          sort: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                field: { type: 'string' },
                direction: { type: 'string', enum: ['asc', 'desc'] }
              }
            },
            description: 'Sort order'
          },
          groupBy: { type: 'string', description: 'Field to group by' },
          select: { type: 'array', items: { type: 'string' }, description: 'Fields to select' },
          limit: { type: 'number', description: 'Maximum results' }
        },
        required: ['vault'],
      },
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden but only states the action without disclosing behavioral traits. It doesn't mention whether this is read-only, if it requires specific permissions, potential rate limits, or what the output looks like, which is insufficient for a query tool.

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 a single, efficient sentence that directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, making it easy to grasp quickly.

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

Completeness2/5

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

Given the complexity of 7 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavior, output format, and usage context, which are crucial for a query tool in a note-taking environment with many siblings.

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 description coverage is 100%, so the schema fully documents all 7 parameters. The description adds no additional meaning beyond the schema, such as query syntax examples or Dataview-specific nuances, meeting the baseline for high schema coverage.

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 the action ('Execute') and target ('Dataview-style query on notes'), making the purpose understandable. It doesn't distinguish from siblings like 'search_notes' or 'get_related_notes', which might have overlapping functionality, so it misses full differentiation.

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 is provided on when to use this tool versus alternatives like 'search_notes' or 'get_related_notes'. The description implies a query-based approach but doesn't specify contexts, prerequisites, or exclusions, leaving usage ambiguous.

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/bazylhorsey/obsidian-mcp-server'

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