Skip to content

[BUG] Resource URIs with query parameters fail - "Unknown operation: search?limit=2" #4

@ivnvxd

Description

@ivnvxd

Resource URI Parsing Bug

Bug Description

Resource operations that include query parameters are failing with "Unknown operation" errors. This affects 2 out of 5 resource operations, making search and browse resources unusable through the MCP protocol.

Current Behavior

When accessing resources with query parameters:

  • odoo://res.partner/search?limit=2 → Error: "Unknown operation: search?limit=2"
  • odoo://res.partner/browse?ids=10,11 → Error: "Unknown operation: browse?ids=10,11"

Expected Behavior

  • odoo://res.partner/search?limit=2 should return 2 partner records
  • odoo://res.partner/browse?ids=10,11 should return partner records with IDs 10 and 11
  • All query parameters should be properly parsed and passed to the handler

Root Cause Analysis

The URI regex pattern in uri_schema.py correctly captures the query string:

URI_PATTERN = re.compile(r"^odoo://([^/]+)/([^/?]+)(?:/(\d+))?(?:\?(.*))?$")

However, the resource handler doesn't properly separate the operation from the query parameters before processing.

Steps to Reproduce

  1. Start the MCP server
  2. Use an MCP client to access: odoo://res.partner/search?limit=2
  3. Observe the error: "Unknown operation: search?limit=2"

Before Implementation

⚠️ CRITICAL: Thoroughly analyze the current implementation before making changes

  1. Examine Current Code

    • Review uri_schema.py - check if URI parsing is actually the issue
    • Check resource handler registration in resources.py
    • Verify FastMCP decorator behavior
    • Test actual resource calls vs MCP client calls
  2. Validate Root Cause

    • Confirm this is a parsing issue, not a FastMCP limitation
    • Check if query parameters are being captured correctly
    • Verify error messages match expected pattern
  3. Test Current Behavior

    • Test direct resource handler calls
    • Test through MCP client protocol
    • Compare working vs failing operations

Proposed Investigation & Fix

Step 1: Investigate Current Implementation

# PSEUDOCODE - Check actual implementation first!
# Look for where URI parsing happens and how operations are extracted

Step 2: Potential Fix Locations

# PSEUDOCODE - Verify actual code structure first!
# If operation parsing is the issue:
if "?" in operation_string:
    clean_operation = operation_string.split("?")[0]
    query_params = parse_query_parameters(operation_string)

Affected Components

  • mcp_server_odoo/uri_schema.py - URI parsing logic
  • Resource handler that processes the parsed URI
  • Integration tests that should catch this issue

Test Cases

After fix, verify:

  • odoo://res.partner/search?limit=2 returns exactly 2 records
  • odoo://res.partner/search?domain=[["is_company","=",true]] filters correctly
  • odoo://res.partner/search?fields=name,email&limit=5 returns 5 records with only name and email
  • odoo://res.partner/browse?ids=10,11,12 returns 3 specific records
  • odoo://res.partner/count?domain=[["customer_rank",">",0]] counts filtered records
  • Error handling works for invalid query parameters

Impact

  • Severity: High - 40% of resource operations are broken
  • Users Affected: All users trying to use resource URIs with parameters
  • Workaround: Use tools instead of resources (e.g., search_records tool)

Additional Context

  • Working resources: record/{id}, count, fields (no query parameters)
  • Failing resources: search, browse (require query parameters)
  • All functionality works correctly through tools, only resources are affected

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions