Skip to content

Bug: FOLDERS search ignores limit parameter and defaults to 10000, exceeding API maximum #152

@pkarpiel-appliscale

Description

@pkarpiel-appliscale

Summary

The search tool has a bug where FOLDERS searches ignore the limit parameter and default to 10000 when a searchTerm is provided, which exceeds the Monday.com API's maximum limit of 100 for folders queries. This causes all FOLDERS searches with a search term to fail with a MaxQueryLimitExceededException.

Note: This bug does NOT affect BOARD and DOCUMENTS searches because those APIs accept higher limits (up to 10000), so the same buggy behavior doesn't cause failures for those search types.

Environment

  • Tool: search (MCP tool)
  • Search Type: FOLDERS
  • Affected Parameter: limit
  • MCP Package: @mondaydotcomorg/monday-api-mcp

Steps to Reproduce

  1. Call the search tool with:

    • searchType: "FOLDERS"
    • searchTerm: "demo" (or any non-empty string)
    • limit: 100 (or any value ≤ 100)
  2. Observe the request sent to the GraphQL API

Expected Behavior:

  • The GraphQL query should use limit: 100 (or the provided limit value)

Actual Behavior:

  • The GraphQL query uses limit: 10000 regardless of the provided limit value
  • The API returns an error: "The maximum limit for this query is 100"

Error Details

{
  "errors": [{
    "message": "The maximum limit for this query is 100",
    "extensions": {
      "code": "MaxQueryLimitExceededException",
      "error_data": {
        "requested_limit": 10000,
        "max_limit": 100
      }
    }
  }]
}

Root Cause

The bug is in getPagingParamsForSearch() method in search-tool.ts. When a searchTerm is provided, the code uses LOAD_INTO_MEMORY_LIMIT (10000) for client-side filtering, but it doesn't account for the fact that the FOLDERS API has a maximum limit of 100, unlike BOARD and DOCUMENTS APIs which accept up to 10000.

Current Code (buggy):

private getPagingParamsForSearch(input: ToolInputType<SearchToolInput>): { page: number, limit: number } {
  return {
    page: input.searchTerm ? 1 : (input.page ?? 1),
    limit: input.searchTerm ? LOAD_INTO_MEMORY_LIMIT : (input.limit ?? SEARCH_LIMIT),
  };
}

Problem:

  • When searchTerm is truthy → uses LOAD_INTO_MEMORY_LIMIT (10000) for ALL search types
  • When searchTerm is falsy → uses input.limit ?? SEARCH_LIMIT (100)
  • This works for BOARD and DOCUMENTS (they accept 10000), but fails for FOLDERS (max 100)

File Location:
mcp/packages/agent-toolkit/src/core/tools/platform-api-tools/search-tool/search-tool.ts (line ~135-140)

Impact

  • Severity: High - FOLDERS searches with search terms are completely broken
  • Affected Users: Anyone using the search tool with searchType: "FOLDERS" and a searchTerm
  • Workaround: Users must avoid providing searchTerm for FOLDERS searches and filter client-side, or wait for the fix

Why BOARD and DOCUMENTS Work Fine

The same buggy code path exists for all three search types, but:

  • BOARD API: Accepts limit up to 10000 ✅
  • DOCUMENTS API: Accepts limit up to 10000 ✅
  • FOLDERS API: Maximum limit is 100 ❌

So the bug exists for all three, but only FOLDERS fails because it hits the API's lower limit restriction.

Proposed Solution

The getPagingParamsForSearch() method should be aware of the search type and cap the limit accordingly:

private getPagingParamsForSearch(input: ToolInputType<SearchToolInput>, searchType: GlobalSearchType): { page: number, limit: number } {
  // For folders, the API has a maximum limit of 100, so we cap it even when doing client-side filtering
  const maxLimitForType = searchType === GlobalSearchType.FOLDERS ? SEARCH_LIMIT : LOAD_INTO_MEMORY_LIMIT;
  
  let limit: number;
  if (input.searchTerm) {
    // When searching, load items into memory for client-side filtering
    limit = maxLimitForType;
  } else {
    // When not searching, use the provided limit or default
    limit = input.limit ?? SEARCH_LIMIT;
  }
  
  // Ensure limit doesn't exceed the maximum for this search type
  limit = Math.min(limit, maxLimitForType);
  
  return {
    page: input.searchTerm ? 1 : (input.page ?? 1),
    limit,
  };
}

Changes needed:

  1. Add searchType parameter to getPagingParamsForSearch()
  2. Set maxLimitForType based on search type (100 for FOLDERS, 10000 for others)
  3. Update all three search methods (searchFoldersAsync, searchDocsAsync, searchBoardsAsync) to pass the search type

Additional Context

  • Constants involved:

    • SEARCH_LIMIT = 100 (maximum for folders)
    • LOAD_INTO_MEMORY_LIMIT = 10_000 (used for client-side filtering)
  • Related files:

    • mcp/packages/agent-toolkit/src/core/tools/platform-api-tools/search-tool/search-tool.ts
    • mcp/packages/agent-toolkit/src/core/tools/platform-api-tools/search-tool/search-tool.consts.ts

Test Case

// This should work but currently fails
const result = await client.callTool({
  name: 'search',
  arguments: {
    searchType: 'FOLDERS',
    searchTerm: 'demo',
    limit: 100
  }
});

// Expected: GraphQL query with limit: 100
// Actual: GraphQL query with limit: 10000 → API error

Related

This issue was discovered when implementing a wrapper around the MCP tool. The workaround involves not sending searchTerm for FOLDERS searches and filtering client-side instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions