Skip to content

fix(core): preserve per-tool argument type inference in provideExperimentalWebMcpTools - #70159

Open
SnowingFox wants to merge 1 commit into
angular:mainfrom
SnowingFox:fix/70125-webmcp-tools-inference
Open

fix(core): preserve per-tool argument type inference in provideExperimentalWebMcpTools#70159
SnowingFox wants to merge 1 commit into
angular:mainfrom
SnowingFox:fix/70125-webmcp-tools-inference

Conversation

@SnowingFox

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Fixes #70125

What is the current behavior?

provideExperimentalWebMcpTools declares a single generic InputSchema for the whole ToolDescriptor<InputSchema>[] array. Because the entire array shares one InputSchema, TypeScript unifies the inputSchema types when multiple tools with heterogeneous inputs are provided, and the execute callback arguments degrade to unknown / Record<string, unknown> (the reporter observed number | { [x: string]: unknown }), breaking type safety inside execute.

This is the well-known TS limitation from microsoft/TypeScript#14466: a single generic cannot be inferred independently per array element.

What is the new behavior?

Each tool now infers its own InputSchema from its own inputSchema property. The parameter type is a tuple-mapped type ({ [K in keyof InputSchemas]: ToolDescriptor<InputSchemas[K]> } over const InputSchemas extends readonly JsonSchemaForInference[]) so every execute callback receives precisely-typed arguments: args.arg1 is number for a { type: 'number' } schema, args.arg2 is string, etc. The function body is unchanged (it only iterates the tools), and the existing call shape provideExperimentalWebMcpTools([...]) is preserved.

Existing call sites remain backward compatible. Verified against the patterns used in the current runtime spec (packages/core/test/webmcp/provide_tools_spec.ts), pre-typed ToolDescriptor<JsonSchemaForInference>[] arrays, and the provideExperimentalWebMcpTools<any>(...) workaround from the issue.

The public API golden (goldens/public-api/core/index.api.md) was updated to the new signature.

Does this PR introduce a breaking change?

  • Yes
  • No (type-level change only; all existing homogeneous call sites compile unchanged)

Verification

  • Added a compile-time regression spec at packages/core/test/strict_types/mcp_tools_spec.ts (the repo's strict-types test target, which compiles under strict: true). With the old signature the spec fails to compile (arg1 / arg2 resolve to unknown); with the fix it compiles and the jasmine test passes.
  • pnpm bazel test //packages/core/test/strict_types:strict_types passes with the fix applied.

Notes

  • This is a type-level fix with no runtime behavior change; WebMCP remains experimental.
  • There are no other open pull requests from this author in angular/angular.
  • If the API golden needs regenerating, pnpm public-api:update produces it deterministically.

@google-cla

google-cla Bot commented Aug 12, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@pullapprove
pullapprove Bot requested a review from kirjs August 12, 2026 03:53
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Aug 12, 2026
@ngbot ngbot Bot added this to the Backlog milestone Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues related to the framework runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

provideExperimentalWebMcpTools signature prevents type safety with heterogeneous tool inputs

1 participant