The Hook
When an LLM hallucinates two mutually exclusive filter arguments in a single MCP tools/call, letting those arguments pass through to your GraphQL executor turns a deterministic client-side bad_request into an opaque server-side execution fault—corrupting your AI observability SLOs and depriving the agent of actionable self-correction feedback.
The Deep Dive
Autonomous AI agents frequently explore tool schemas by combining filter parameters. When I added the reviewer_wildcard_id filter (NONE or ANY) to list_merge_requests in MR !270521 (feat(mcp): add merge request read fields and reviewer filter), I had to account for how GitLab's underlying GraphQL MergeRequestsResolver handles conflicting reviewer filters. At the GraphQL resolver layer, passing reviewerWildcardId simultaneously with reviewerUsername—or alongside scope: "review_requested"—is a domain invariant violation that aborts query execution and returns a top-level GraphQL errors array.
However, in an MCP server architecture, where a validation failure is caught determines how it is classified in production telemetry (mcp.log) and how the LLM reacts. If Mcp::Tools::MergeRequests::ListMergeRequestsService blindly forwards conflicting parameters into GitlabSchema.execute, the resulting GraphQL error is logged by the MCP handler as tool_status: error—indistinguishable from an unhandled backend exception or database timeout. Instead, in MR !270521, I implemented explicit pre-query mutual-exclusion validation inside ListMergeRequestsService before constructing the GraphQL variables hash. Whenever reviewer_wildcard_id is paired with reviewer_username or scope: review_requested, the service short-circuits immediately with Mcp::Tools::Response.error, recording tool_status: bad_request in mcp.log and returning a crisp, self-correcting error message to the agent.
At the same time, every new parameter exposed on an enterprise MCP tool must be audited against GitLab's AI tool governance rules (ee/spec/lib/ai/tool_rules/governable_tools_container_spec.rb), which enforce tenant and resource-container scoping (such as project_id or group_id) across governable AI tools. In MR !270521 (building on the MCP spec hygiene standards I helped enforce in MR !268752), I classified reviewer_wildcard_id under not_a_container in governable_tools_container_spec.rb, ensuring that the suffix _id on reviewer_wildcard_id wasn't misidentified by policy analyzers as an unscoped resource container identifier.
The GitLab Hero Angle
GitLab's Duo Agent Platform and MCP governance framework (MR !270521) combine static container-rule verification (governable_tools_container_spec.rb) with pre-query domain validation, ensuring AI tool invocations maintain clean bad_request vs. error telemetry boundaries and strict multi-tenant policy enforcement.
The Takeaway
Intercept mutually exclusive AI tool parameters at the service boundary before invoking GraphQL so client hallucinations are logged as bad_request with deterministic self-correction hints rather than polluting 5xx-equivalent server error budgets.
Top comments (0)