Skip to content

fix(gti-mcp): return API errors from create and update collection tools - #345

Merged
dandye merged 2 commits into
google:mainfrom
VISHNU0906:fix/gti-collection-write-errors
Nov 11, 2026
Merged

dandye merged 2 commits into
google:mainfrom
VISHNU0906:fix/gti-collection-write-errors

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

create_collection and update_collection_attributes return data["data"] from the GTI response without checking it. When the API sends back an error instead (403 for an account that can't create collections, 404 for an unknown collection id), the tool fails with

Error executing tool create_collection: 'data'

and the API's message never reaches the client.

This PR returns {"error": "API Error: <message>"} in that case, using the same data guard that get_collections_commonalities got in #335. The success path doesn't change.

Testing: new tests call both tools through the MCP client session against the pytest-httpserver mock, with a 403/404 error body, an error body without a message, and {"data": null}. All five cases fail on main with the 'data' error above. The full server/gti suite passes (77 tests).

@dandye could you take a look when you have a moment?

create_collection and update_collection_attributes read data["data"]
straight from the GTI response. When the API answers with an error
payload (403 for an account without collection access, 404 for an unknown
collection id), the tool fails with "Error executing tool ...: 'data'" and
the API's message is lost. Return an error dict with that message instead,
using the same data guard as get_collections_commonalities.

Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>
@VISHNU0906
VISHNU0906 requested a review from a team November 10, 2026 03:25
Use PEP 585 dict[str, str] return annotation on _api_error, fall back to error_info['code'] when message is absent, and switch mock server expectations to expect_oneshot_request.

@dandye dandye left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching and fixing this, @VISHNU0906!

Nice work checking isinstance(data.get("data"), dict) rather than restricting to status == 200 so 201 Created collection responses keep working, keeping _api_error private to the module, and testing the full MCP client session round-trips against pytest-httpserver for 403/404 responses, non-dict error bodies, and {"data": null}.

I pushed a small follow-up commit to align with #347 before merging:

  • Updated _api_error's return annotation from typing.Dict[str, str] to dict[str, str] (UP006).
  • Added a fallback to error_info.get("code") in _api_error when message is absent, with a matching test case.
  • Switched the new pytest-httpserver expectations to expect_oneshot_request so parameterized cases sharing a status code do not collide on the session-scoped server.

Thanks again for all of your recent gti-mcp fixes!

@dandye
dandye merged commit bc045e2 into google:main Nov 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants