Skip to content

fix(samples): accept explicit null for optional MCP params, keep logs off stdout - #335

Open
vishalhabib99 wants to merge 1 commit into
strands-agents:mainfrom
vishalhabib99:fix/sample-mcp-servers-null-and-stdout
Open

vishalhabib99 wants to merge 1 commit into
strands-agents:mainfrom
vishalhabib99:fix/sample-mcp-servers-null-and-stdout

Conversation

@vishalhabib99

Copy link
Copy Markdown

What breaks

Two sample MCP servers have params that default to None but are typed str:

  • 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": null on a field typed string. Some agent frameworks send that default explicitly, and the call fails before the tool runs. This is the real email_history_server.py on main, called in memory with {"limit": 2, "subject_contains": null} (mcp 1.25):

isError=True  Error executing tool get_emails: 1 validation error for get_emailsArguments
subject_contains
  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]

With this change, the same call returns isError=False with {"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_chart prints the chart path on every call.
  • triage-agent/.../strands/strands_agent.py: real_estate_expert prints "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 existing typing imports) and file=sys.stderr on the two prints. No behaviour change otherwise.

Checked

  • The real get_emails call above fails on main and passes on this branch.
  • python -m py_compile passes on all 4 files.
  • A static scan (mcp-doctor) of both sample folders reports these 4 issues before the change and none after.
  • I did not run the finance or triage samples end to end, since they need AWS Bedrock credentials.

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

1 participant