Skip to main content
Glama

list_docs

Retrieve documents from Dart AI by folder, title, or text content. Filter results and paginate with limit and offset parameters.

Instructions

List documents with optional filtering by folder, title_contains, text_contains. Supports pagination.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
folderNoFilter by folder (dart_id or name)
title_containsNoFilter by title substring (case-insensitive)
text_containsNoFilter by text content substring (case-insensitive)
limitNoMax docs to return (default: 50, max: 500)
offsetNoPagination offset (default: 0)

Implementation Reference

  • Main handler function for list_docs tool. Validates input (limit, offset, folder), resolves folder name to ID, calls DartClient.listDocs(), calculates pagination metadata, and returns ListDocsOutput.
    export async function handleListDocs(input?: ListDocsInput): Promise<ListDocsOutput> {
      const DART_TOKEN = process.env.DART_TOKEN;
    
      if (!DART_TOKEN) {
        throw new DartAPIError(
          'DART_TOKEN environment variable is required. Get your token from: https://app.dartai.com/?settings=account',
          401
        );
      }
    
      // ============================================================================
      // Step 1: Defensive input handling and validation
      // ============================================================================
      const safeInput = input || {};
    
      // Validate limit (default 50, max 500)
      let limit = safeInput.limit !== undefined ? safeInput.limit : 50;
      if (typeof limit !== 'number' || limit < 1 || limit > 500) {
        throw new ValidationError(
          `limit must be a number between 1 and 500 (received: ${limit})`,
          'limit'
        );
      }
    
      // Validate offset (default 0, non-negative)
      let offset = safeInput.offset !== undefined ? safeInput.offset : 0;
      if (typeof offset !== 'number' || offset < 0) {
        throw new ValidationError(
          `offset must be a non-negative number (received: ${offset})`,
          'offset'
        );
      }
    
      // ============================================================================
      // Step 2: Validate folder reference (if provided)
      // ============================================================================
      let resolvedFolder: string | undefined;
    
      if (safeInput.folder) {
        // Get config to validate folder reference
        let config: DartConfig;
        try {
          config = await handleGetConfig({ cache_bust: false });
        } catch (error) {
          if (error instanceof DartAPIError) {
            throw new DartAPIError(
              `Failed to retrieve workspace config for folder validation: ${error.message}`,
              error.statusCode,
              error.response
            );
          }
          throw error;
        }
    
        // Check if folder exists (by dart_id or name)
        if (!config.folders || config.folders.length === 0) {
          throw new ValidationError(
            'No folders found in workspace configuration. Create a folder first in Dart AI.',
            'folder'
          );
        }
    
        const folder = findFolder(config.folders, safeInput.folder);
    
        if (!folder) {
          const folderNames = getFolderNames(config.folders);
          const availableFolders = folderNames.join(', ');
          throw new ValidationError(
            `Invalid folder: "${safeInput.folder}" not found in workspace. Available folders: ${availableFolders}`,
            'folder',
            folderNames
          );
        }
    
        resolvedFolder = folder.dart_id;
      }
    
      // ============================================================================
      // Step 3: Call DartClient.listDocs()
      // ============================================================================
      const client = new DartClient({ token: DART_TOKEN });
    
      const apiInput: {
        folder?: string;
        title_contains?: string;
        text_contains?: string;
        limit: number;
        offset: number;
      } = {
        limit,
        offset,
      };
    
      if (resolvedFolder) {
        apiInput.folder = resolvedFolder;
      }
    
      // Validate title_contains is non-empty string if provided
      if (safeInput.title_contains !== undefined) {
        if (typeof safeInput.title_contains !== 'string') {
          throw new ValidationError(
            'title_contains must be a string',
            'title_contains'
          );
        }
        if (safeInput.title_contains.trim() !== '') {
          apiInput.title_contains = safeInput.title_contains;
        }
        // Silently ignore empty/whitespace-only strings
      }
    
      // Validate text_contains is non-empty string if provided
      if (safeInput.text_contains !== undefined) {
        if (typeof safeInput.text_contains !== 'string') {
          throw new ValidationError(
            'text_contains must be a string',
            'text_contains'
          );
        }
        if (safeInput.text_contains.trim() !== '') {
          apiInput.text_contains = safeInput.text_contains;
        }
        // Silently ignore empty/whitespace-only strings
      }
    
      let apiResponse: { docs: DartAPIDoc[]; total: number };
      try {
        apiResponse = await client.listDocs(apiInput);
      } catch (error) {
        if (error instanceof DartAPIError) {
          throw new DartAPIError(
            `Failed to list documents: ${error.message}`,
            error.statusCode,
            error.response
          );
        }
        throw error;
      }
    
      // ============================================================================
      // Step 4: Calculate pagination metadata
      // ============================================================================
      const returnedCount = apiResponse.docs.length;
      const totalCount = apiResponse.total;
      const hasMore = (offset + returnedCount) < totalCount;
      const nextOffset = hasMore ? offset + returnedCount : null;
    
      // ============================================================================
      // Step 5: Build filters_applied object for transparency
      // ============================================================================
      const filtersApplied: Record<string, unknown> = {
        limit,
        offset,
      };
    
      if (resolvedFolder) {
        filtersApplied.folder = resolvedFolder;
      }
    
      if (safeInput.title_contains) {
        filtersApplied.title_contains = safeInput.title_contains;
      }
    
      if (safeInput.text_contains) {
        filtersApplied.text_contains = safeInput.text_contains;
      }
    
      // ============================================================================
      // Step 6: Return output
      // ============================================================================
      return {
        docs: apiResponse.docs,
        total_count: totalCount,
        returned_count: returnedCount,
        has_more: hasMore,
        next_offset: nextOffset,
        filters_applied: filtersApplied,
      };
    }
    
    // Import DartDoc type from types (avoiding circular dependency)
    import type { DartDoc as DartAPIDoc } from '../types/index.js';
  • ListDocsInput interface defining optional input params: folder, title_contains, text_contains, limit, offset.
    export interface ListDocsInput {
      folder?: string;
      title_contains?: string;
      text_contains?: string;
      limit?: number;
      offset?: number;
    }
  • ListDocsOutput interface defining return shape: docs array, total_count, returned_count, has_more, next_offset, filters_applied.
    export interface ListDocsOutput {
      docs: DartDoc[];
      total_count: number;
      returned_count: number;
      has_more: boolean;
      next_offset: number | null;
      filters_applied: Record<string, unknown>;
    }
  • src/index.ts:664-692 (registration)
    Tool registration in src/index.ts: json schema defining list_docs name, description, and inputSchema with folder, title_contains, text_contains, limit, offset.
    {
      name: 'list_docs',
      description: 'List documents with optional filtering by folder, title_contains, text_contains. Supports pagination.',
      inputSchema: {
        type: 'object',
        properties: {
          folder: {
            type: 'string',
            description: 'Filter by folder (dart_id or name)',
          },
          title_contains: {
            type: 'string',
            description: 'Filter by title substring (case-insensitive)',
          },
          text_contains: {
            type: 'string',
            description: 'Filter by text content substring (case-insensitive)',
          },
          limit: {
            type: 'integer',
            description: 'Max docs to return (default: 50, max: 500)',
          },
          offset: {
            type: 'integer',
            description: 'Pagination offset (default: 0)',
          },
        },
      },
    },
  • DartClient.listDocs() API method that builds query params and sends GET request to /docs/list endpoint, returning docs array and total count.
    async listDocs(input?: {
      folder?: string;
      title_contains?: string;
      text_contains?: string;
      limit?: number;
      offset?: number;
    }): Promise<{ docs: DartDoc[]; total: number }> {
      const queryParams = new URLSearchParams();
    
      if (input) {
        // Config returns folder names (strings), not IDs — use name-based param
        if (input.folder) queryParams.append('folder', input.folder);
        // API uses "title" and "text" (not "title_contains" / "text_contains")
        if (input.title_contains) queryParams.append('title', input.title_contains);
        if (input.text_contains) queryParams.append('text', input.text_contains);
        if (input.limit !== undefined) queryParams.append('limit', input.limit.toString());
        if (input.offset !== undefined) queryParams.append('offset', input.offset.toString());
      }
    
      const query = queryParams.toString();
      const endpoint = query ? `/docs/list?${query}` : '/docs/list';
    
      const response = await this.request<{ count: number; results: any[] }>('GET', endpoint);
      return {
        docs: response.results || [],
        total: response.count || 0,
      };
    }
Behavior3/5

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

No annotations provided, so description bears full burden. It mentions pagination and filters but does not disclose read-only nature, output format, sorting, or rate limits. Adequate but not thorough.

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?

Single sentence that captures key functionality with no superfluous information. Front-loaded with verb and resource.

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

Completeness3/5

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

Given 5 parameters, no output schema, and no annotations, the description is functional but lacks details like return structure, default ordering, or handling of empty results. Moderately 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% with clear parameter descriptions. The description restates filter purpose and pagination without adding meaningful new semantics beyond 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?

Description clearly states 'List documents' and enumerates filtering options (folder, title_contains, text_contains) and pagination. It effectively distinguishes from siblings like get_doc (single doc) and search_tasks (different resource).

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?

Description implies usage for listing documents with filters, but does not explicitly state when not to use or direct to alternatives. It is clear enough for typical list scenarios.

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/standardbeagle/dart-query'

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