Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion goldens/public-api/core/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ export function provideCheckNoChangesConfig(options: {
export function provideEnvironmentInitializer(initializerFn: () => void): EnvironmentProviders;

// @public
export function provideExperimentalWebMcpTools<const InputSchema extends JsonSchemaForInference>(tools: WebMcpToolDescriptor<InputSchema>[]): EnvironmentProviders;
export function provideExperimentalWebMcpTools<const InputSchemas extends readonly JsonSchemaForInference[]>(tools: { [K in keyof InputSchemas]: WebMcpToolDescriptor<InputSchemas[K]>; }): EnvironmentProviders;

// @public
export function provideIdleServiceWith(useExisting: AbstractType<IdleService> | InjectionToken<IdleService>): EnvironmentProviders;
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/webmcp/provide_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import type {ToolDescriptor} from './types';
* or route providers.
* @experimental
*/
export function provideExperimentalWebMcpTools<const InputSchema extends JsonSchemaForInference>(
tools: ToolDescriptor<InputSchema>[],
export function provideExperimentalWebMcpTools<
const InputSchemas extends readonly JsonSchemaForInference[],
>(
tools: {[K in keyof InputSchemas]: ToolDescriptor<InputSchemas[K]>},
): EnvironmentProviders {
return makeEnvironmentProviders([
provideEnvironmentInitializer(() => {
Expand Down
54 changes: 54 additions & 0 deletions packages/core/test/strict_types/mcp_tools_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import {provideExperimentalWebMcpTools} from '../../src/webmcp/provide_tools';

describe('provideExperimentalWebMcpTools', () => {
// Regression test for https://github.com/angular/angular/issues/70125
//
// Each tool passed to `provideExperimentalWebMcpTools` must infer its own
// argument types from its own `inputSchema`. Previously the function inferred
// a single shared `InputSchema` for the whole array, so heterogeneous tools
// lost their `execute` argument types (each `args` was widened to
// `Record<string, unknown>`), making the `arg1`/`arg2` accesses below type
// errors. This file intentionally fails to compile on the unfixed signature.
it('should preserve per-tool argument types for heterogeneous input schemas', () => {
provideExperimentalWebMcpTools([
{
name: 'tool1',
description: 'Tool #1',
inputSchema: {
type: 'object',
properties: {
arg1: {type: 'number'},
},
required: ['arg1'],
},
execute: (args) => {
const arg1 = args.arg1; // must be inferred as `number`
return `arg1 number value is ${arg1.toFixed()}`;
},
},
{
name: 'tool2',
description: 'Tool #2',
inputSchema: {
type: 'object',
properties: {
arg2: {type: 'string'},
},
required: ['arg2'],
},
execute: (args) => {
const arg2 = args.arg2; // must be inferred as `string`
return `arg2 string value is ${arg2.trim()}`;
},
},
]);
});
});