omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(mcp): get_conversations silently drops an unparseable date filter and returns the unfiltered list

Open goldnbones opened this issue 2 months ago • 0 comments

Symptom

In the standalone MCP server (mcp/), the get_conversations tool silently ignores a start_date / end_date it cannot parse. A model that asks for "conversations since 01/01/2026" (or yesterday, or any non-YYYY-MM-DD value) gets back the entire unfiltered conversation list with no error, so it reasons over the wrong data and has no signal that its filter was dropped. The sibling search_conversations tool forwards the raw strings and turns the backend's 400 into an opaque Omi API request failed (HTTP 400) with no hint about which argument was wrong.

Evidence

  • mcp/src/mcp_server_omi/server.py get_conversations (lines 235-245): datetime.strptime(start_date, "%Y-%m-%d") inside try/except ValueError whose only handler is logger.warning(...); params["start_date"] is never set and the request proceeds with {"limit", "offset"} only. Same for end_date.
  • search_conversations (lines 274-278): params["start_date"] = start_date with no validation; the backend's /v1/mcp/conversations/search rejects it with 400 (backend/routers/mcp.py lines 463-471), which _response_json re-raises as HTTPError("Omi API request failed (HTTP 400)") — the detail is deliberately dropped.
  • The MCP tool descriptions promise yyyy-mm-dd but nothing enforces it, and the tool's own log line (Could not parse start date) goes to the server log the model never sees.
  • Reproduced hermetically: with requests.get patched, get_conversations(logger, key, start_date="01/01/2026") returns the mocked unfiltered list and the call's params contain no date bound.

Proposed Fix

Add a _parse_date_only(value, field) helper and use it in both tools so a malformed date raises ValueError("Invalid start_date '01/01/2026'. Expected YYYY-MM-DD.") before any request is made. The server's tool handler already surfaces exceptions to the client (the same path its query is required error and the HTTP errors from #13049 take), so the model receives an actionable error instead of wrong data. Valid dates keep their existing start-of-day / end-of-day semantics.

While here, in separate commits: remove mcp/tests/test_server.py, which calls signatures that do not exist (get_memories(uid), MemoryCategory.personal, include_discarded=) and needs a uid fixture nothing provides, so every run has ended with two collection errors; and add a small path-filtered workflow that runs mcp/tests on pull requests, because no CI lane executes them today (the check manifest is stdlib-only and no workflow references mcp/).

Tests

mcp/tests/test_date_filters.py: helper-level rejection for both tools and both fields with requests.get asserted never called; unchanged request params for valid dates; and an in-memory MCP session (create_server() + ClientSession) asserting the client receives the error naming the field. The malformed-date cases fail on main and pass with the fix; the full suite is 65 passed under the locked mcp==2.0.0.


Proposed Bounty Reward: $50.00 USD Bounty Payout Destination (PayPal): will be provided by email to [email protected] on payout

cc @josancamon19 @kodjima33

goldnbones avatar Sep 14 '26 21:09 goldnbones