Skip to content

fix(gti): accept explicit null for parameters that default to None - #323

Merged
dandye merged 2 commits into
google:mainfrom
vishalhabib99:fix/gti-null-defaults
Nov 1, 2026
Merged

dandye merged 2 commits into
google:mainfrom
vishalhabib99:fix/gti-null-defaults

Conversation

@vishalhabib99

Copy link
Copy Markdown
Contributor

Summary

Seven GTI tool parameters default to None but are annotated with a non-Optional type (e.g. collection_type: str = None in search_threats). FastMCP builds the input schema from the annotation, so it advertises {"type": "string", "default": null}. A client that sends the advertised default explicitly (some agent frameworks fill every optional field with null) is rejected at argument validation:

Error executing tool search_threats: 1 validation error for search_threatsArguments
collection_type
  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]

…even though None is the intended default. Reproduced on mcp 1.23.0 and 1.30.0 with an in-memory client; the rejection happens before the tool body runs.

Change

Annotate these as typing.Optional[...] so the schema becomes anyOf: [{type: X}, {type: null}]. No behavior change for callers that omit the argument.

  • search_threats: collection_type
  • update_collection_attributes: attributes
  • get_collection_rules: rule_types
  • search_digital_threat_monitoring: since, until, page, truncate

Tests

  • test_none_default_params_accept_null: fails if any tool advertises "default": null on a type that excludes null.
  • test_search_threats_accepts_null_collection_type: end-to-end call with collection_type=None through the existing mock VT fixture.

Both fail on main and pass with this change; server/gti suite: 55 → 57 passed.

The same pattern exists in server/scc (6 tools) and server/secops (4 tools); I kept this PR to GTI and can send those separately if you'd like.

Found with mcp-doctor (https://github.com/vishalhabib99/mcp-doctor); happy to run a no-install scan on your other servers if useful.

🤖 Generated with Claude Code

Seven tool parameters default to None but were annotated with a
non-Optional type (e.g. `collection_type: str = None` in search_threats).
FastMCP derives the input schema from the annotation, so it advertised
`{"type": "string", "default": null}`. A client that sends the advertised
default explicitly (some agent frameworks fill every optional field with
null) gets a pydantic validation error instead of the default behavior.

Annotate them as Optional so the schema becomes
`anyOf: [{type: X}, {type: null}]`:

- search_threats: collection_type
- update_collection_attributes: attributes
- get_collection_rules: rule_types
- search_digital_threat_monitoring: since, until, page, truncate

Add a regression test that checks every tool's advertised schema allows
null wherever the default is null, plus an end-to-end call of
search_threats with collection_type=null.
@vishalhabib99
vishalhabib99 requested a review from a team October 9, 2026 23:47
@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Hi @dandye, just checking this one is still on your radar. It's still mergeable and includes a regression test for the seven parameters. Happy to change anything.

@dandye

dandye commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks for catching the schema/type mismatch and adding the test_none_default_params_accept_null regression check, @vishalhabib99.

Before we merge, could we adjust a couple of things in how these parameters are handled?

1. Make attributes in update_collection_attributes a required parameter (remove = None)

In server/gti/gti_mcp/tools/collections.py:

@server.tool()
async def update_collection_attributes(
    id: str,
    ctx: Context,
    attributes: typing.Dict[str, typing.Any],
) -> typing.Dict[str, typing.Any]:

attributes is the entire payload sent to PATCH /collections/{id} ({"data": {"attributes": attributes, "type": "collection"}}). It only had = None originally by mistake after ctx: Context (similar to update_iocs_in_collection right below it, required args can follow ctx: Context without defaults). Making it Optional keeps it out of required and allows null, which will fail against the VT API. Removing = None makes it required in the schema and still satisfies test_none_default_params_accept_null.

2. Guard against empty strings in search_digital_threat_monitoring

In server/gti/gti_mcp/tools/files.py (line 403), query parameters are currently filtered with:

params = {k: v for k, v in params.items() if v is not None}

Since since, until, page, and truncate are optional string filters, could we change that filter to if v is not None and v != "" (or if v since size and sanitize are always non-empty)? That way, whether an agent passes None or "" for unused string parameters, we don't append empty query parameters (&since=&until=) to /dtm/docs/search.

…pty DTM query params

attributes is the whole PATCH payload, so it should be required rather
than optional. search_digital_threat_monitoring now skips "" as well as
None so unused filters don't add empty query parameters.
@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Thanks @dandye, both done in dbcd2cc:

  1. attributes in update_collection_attributes is now required (no = None), so it lands in required and test_none_default_params_accept_null still passes.
  2. search_digital_threat_monitoring now filters with v is not None and v != "". I added test_search_digital_threat_monitoring_drops_empty_params, which sends since="", until=None, page="" and checks the path is /dtm/docs/search?size=10&sanitize=true.

All 58 GTI tests pass locally.

@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Hi @dandye, when you have a moment, could you take another look? Both changes you asked for are in dbcd2cc: attributes is now required, and search_digital_threat_monitoring drops empty strings as well as None, with a test for that. The branch is still mergeable.

@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.

LGTM! Thank you for the follow-up changes and test coverage, @vishalhabib99, and thank you for your first contribution to google/mcp-security!

@dandye
dandye merged commit 2d1aaa8 into google:main Nov 1, 2026
6 checks passed
@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Thanks @dandye for the careful review, especially for catching that attributes should be required and that empty strings needed filtering too, and for merging.

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