Repository navigation
fix(samples): accept explicit null for optional MCP params, keep logs off stdout - #335
Open
vishalhabib99 wants to merge 1 commit into
Open
vishalhabib99 wants to merge 1 commit into
vishalhabib99 wants to merge 1 commit into
Conversation
… off stdout - knowledge_base_list(region_name) and get_emails(subject_contains) default to None but were typed str, so an explicit null failed validation. Type them Optional[str]. - create_comparison_chart and real_estate_expert printed to stdout, which is the JSON-RPC channel on stdio. Print to stderr.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What breaks
Two sample MCP servers have params that default to
Nonebut are typedstr:finance/genai-powered-financial-advisor-tools/application/mcp_server_kb.py:knowledge_base_list(region_name)07-ux-demos/triage-agent/backend/mcp_servers/email_history/email_history_server.py:get_emails(subject_contains)The generated schema advertises
"default": nullon a field typedstring. Some agent frameworks send that default explicitly, and the call fails before the tool runs. This is the realemail_history_server.pyonmain, called in memory with{"limit": 2, "subject_contains": null}(mcp 1.25):With this change, the same call returns
isError=Falsewith{"result": []}.Two other tools in these samples
print()to stdout, which is the JSON-RPC channel on the stdio transport:mcp_server_stock.py:create_comparison_chartprints the chart path on every call.triage-agent/.../strands/strands_agent.py:real_estate_expertprints "Routed to Real Estate Expert" on every call.A client reading stdout gets a non-JSON line (
Invalid JSON: expected value at line 1 column 1). Both now print to stderr.Change
7 lines across 4 files:
Optional[str]for the two params (matching the existingtypingimports) andfile=sys.stderron the two prints. No behaviour change otherwise.Checked
get_emailscall above fails onmainand passes on this branch.python -m py_compilepasses on all 4 files.