Skip to content

fix: let optional params accept an explicit null - #75

Merged
adarshdigievo merged 2 commits into
serpapi:mainfrom
vishalhabib99:fix/optional-params-accept-null
Oct 27, 2026
Merged

adarshdigievo merged 2 commits into
serpapi:mainfrom
vishalhabib99:fix/optional-params-accept-null

Conversation

@vishalhabib99

Copy link
Copy Markdown
Contributor

Summary

Annotate params on the search_table and search_dashboard MCP App tools as dict[str, Any] | None = None (it was dict[str, Any] = None), matching the search tool.

Why

The generated input schema advertises "default": null on a field whose type (object) rejects null. Some agent frameworks fill every optional argument with its advertised default, so they send "params": null and the call fails validation before the tool runs. The function body already handles None (fetch_search_data uses params or {}), so only the annotation was wrong.

Testing

  • Added test_app_tools_accept_explicit_null_params (parametrized over both tools): it checks that the schema allows null and that calling with {"params": null} through a FastMCP Client succeeds. It fails on both tools without the fix and passes with it.
  • uv run pytest -q: 241 passed, 1 skipped (live contract test, needs SERPAPI_KEY).
  • uv format --check: clean.

Reproduction

In-memory FastMCP client, serpapi.search stubbed (no network):

Before:

search_table schema params: {"additionalProperties": true, "default": null, "type": "object"}
search_table {'params': None} -> ToolError: 1 validation error for call[search_table]
params
  Input should be a valid dictionary [type=dict_type, input_value=None, input_type=NoneType]

(same for search_dashboard)

After:

search_table schema params: {"anyOf": [{"additionalProperties": true, "type": "object"}, {"type": "null"}], "default": null}
search_table {'params': None} -> OK
search_dashboard {'params': None} -> OK

Additional Notes

Found with mcp-doctor's none_default_type check, then reproduced as above. If useful, it can scan the rest of the server with no install: open a scan request.

@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Hi @adarshdigievo, just checking this one is still on your radar. It's still mergeable, and the new test fails on both tools without the fix and passes with it. Happy to change anything.

@adarshdigievo adarshdigievo self-assigned this Oct 27, 2026
@adarshdigievo
adarshdigievo self-requested a review October 27, 2026 09:38
@adarshdigievo

Copy link
Copy Markdown
Member

Thanks for the fix, @vishalhabib99!

I reproduced this with CrewAI’s URL-based HTTP MCP integration. It sends null when params is omitted, causing validation to fail for the MCP App tools.

Merging now. The fix will be included in the next release.

@adarshdigievo
adarshdigievo merged commit d61758f into serpapi:main Oct 27, 2026
2 checks passed
@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Thanks @adarshdigievo, and for confirming it with CrewAI's HTTP integration. Good to know which client was sending the null in practice.

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