fix(core): preserve per-tool argument type inference in provideExperimentalWebMcpTools - #70159
Open
SnowingFox wants to merge 1 commit into
Open
fix(core): preserve per-tool argument type inference in provideExperimentalWebMcpTools#70159SnowingFox wants to merge 1 commit into
SnowingFox wants to merge 1 commit into
Conversation
…mentalWebMcpTools Fixes angular#70125
|
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. |
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.
PR Checklist
Please check if your PR fulfills the following requirements:
Fixes #70125
What is the current behavior?
provideExperimentalWebMcpToolsdeclares a single genericInputSchemafor the wholeToolDescriptor<InputSchema>[]array. Because the entire array shares oneInputSchema, TypeScript unifies theinputSchematypes when multiple tools with heterogeneous inputs are provided, and theexecutecallback arguments degrade tounknown/Record<string, unknown>(the reporter observednumber | { [x: string]: unknown }), breaking type safety insideexecute.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
InputSchemafrom its owninputSchemaproperty. The parameter type is a tuple-mapped type ({ [K in keyof InputSchemas]: ToolDescriptor<InputSchemas[K]> }overconst InputSchemas extends readonly JsonSchemaForInference[]) so everyexecutecallback receives precisely-typed arguments:args.arg1isnumberfor a{ type: 'number' }schema,args.arg2isstring, etc. The function body is unchanged (it only iterates the tools), and the existing call shapeprovideExperimentalWebMcpTools([...])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-typedToolDescriptor<JsonSchemaForInference>[]arrays, and theprovideExperimentalWebMcpTools<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?
Verification
packages/core/test/strict_types/mcp_tools_spec.ts(the repo's strict-types test target, which compiles understrict: true). With the old signature the spec fails to compile (arg1/arg2resolve tounknown); with the fix it compiles and the jasmine test passes.pnpm bazel test //packages/core/test/strict_types:strict_typespasses with the fix applied.Notes
angular/angular.pnpm public-api:updateproduces it deterministically.