arcade-mcp/examples/mcp_servers
Eric Gustin 3204201360
fix: TypedDict total=False output breaks validation (#816)
When a tool’s output TypedDict uses total=False, MCP clients reject the
response with:
```
MCP error -32602: Structured content does not match the tool's output schema
```
Note that the bug also exists for the Engine transport
(/worker/tools/execute), but since the engine doesn't validate the
output schema, the bug never surfaced. This PR addresses the problem
holistically (MCP and Engine) in preparation for a future where the
Engine transport validates output schemas.

Two bugs combined to cause this:
1. Schema: The outputSchema had no required array and declared all
fields as strict types (e.g. "type": "string"), making every field look
mandatory and non-null.
2. Serialization: model_dump() on TypedDict-derived Pydantic models
emitted None for absent optional fields. A tool returning {"name":
"hello"} produced {"name": "hello", "optional_field": null} which is a
value the schema forbids.


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Adjusts core schema generation and MCP JSON Schema conversion for
TypedDicts, affecting how tool input/output contracts are emitted and
validated across clients; mistakes could break compatibility or
validation behavior.
> 
> **Overview**
> Fixes MCP/engine validation failures for `TypedDict(total=False)`
outputs by ensuring absent optional keys are **omitted from serialized
output** and that emitted schemas correctly describe **required vs
optional** keys.
> 
> `arcade-core` now tracks `required_keys`/`inner_required_keys` and
per-field `nullable` in `ValueSchema`, derives required sets from
TypedDict `__required_keys__`, and unwraps `Optional[T]` to support
optional nested TypedDicts; TypedDict-derived Pydantic models now
`model_dump(exclude_unset=True)` to avoid leaking missing fields as
`null`.
> 
> `arcade-mcp-server` JSON Schema conversion now emits `required` arrays
(including for arrays of objects), supports `nullable` by generating
`type: [<type>, "null"]` (and `enum` including `None`), and treats
nullable top-level objects as valid unwrapped output schemas. Adds
focused unit/end-to-end tests plus an expanded example server
demonstrating total-false, mixed required/optional, nullable, and
optional-nested TypedDict outputs, and bumps package
versions/dependencies accordingly.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
53fe8365f613053599130520b75f30b614b465ca. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2026-04-09 17:47:57 -07:00
..
authorization Improve .env discovery (#737) 2026-02-25 23:20:28 -08:00
custom_server_with_prebuilt_tools Fix changed files gha (#662) 2025-10-30 13:45:41 -07:00
echo Add Tool Metadata (#766) 2026-02-17 14:31:45 -08:00
local_filesystem Fix MCP capabilities, examples, tests, and more (#657) 2025-10-30 11:59:00 -07:00
logging Rename example servers (#675) 2025-11-12 10:21:25 -08:00
progress_reporting Fix MCP capabilities, examples, tests, and more (#657) 2025-10-30 11:59:00 -07:00
resources Add full support for MCP Resources (#803) 2026-03-27 15:27:57 -07:00
sampling Fix MCP capabilities, examples, tests, and more (#657) 2025-10-30 11:59:00 -07:00
server_with_evaluations Rename example servers (#675) 2025-11-12 10:21:25 -08:00
simple Improve .env discovery (#737) 2026-02-25 23:20:28 -08:00
telemetry_passback feat: Add TelemetryPassbackMiddleware for serverExecutionTelemetry capability (#797) 2026-03-25 15:57:50 -07:00
tool_chaining Improve .env discovery (#737) 2026-02-25 23:20:28 -08:00
tool_metadata Add Tool Metadata (#766) 2026-02-17 14:31:45 -08:00
tools_with_output_schema fix: TypedDict total=False output breaks validation (#816) 2026-04-09 17:47:57 -07:00
user_elicitation Fix MCP capabilities, examples, tests, and more (#657) 2025-10-30 11:59:00 -07:00