Skip to content

Commit 7cda785

Browse files
committed
Making Stricter
1 parent 9b09723 commit 7cda785

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/utils/toolProperties.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { McpToolProperty, ToolProps } from '../../types/mcpTool';
4+
import { Args, McpToolProperty } from '../../types/mcpTool';
55

66
/**
77
* Fluent API builder for creating MCP Tool properties
@@ -192,8 +192,8 @@ export const arg = {
192192
* @param toolProps - Object with property names as keys and ToolProperty as values
193193
* @returns Array of McpToolProperty objects with propertyName set correctly
194194
*/
195-
export function convertToolProperties(toolProps: ToolProps): McpToolProperty[] {
196-
return Object.entries(toolProps).map(([propertyName, property]) => ({
195+
export function convertToolProperties(args: Args): McpToolProperty[] {
196+
return Object.entries(args).map(([propertyName, property]) => ({
197197
propertyName,
198198
propertyType: property.propertyType,
199199
description: property.description || '', // Default to empty string if not provided
@@ -205,7 +205,7 @@ export function convertToolProperties(toolProps: ToolProps): McpToolProperty[] {
205205
/**
206206
* Type guard to check if properties are in toolProp format
207207
*/
208-
export function isToolProperties(properties: unknown): properties is ToolProps {
208+
export function isToolProperties(properties: unknown): properties is Args {
209209
return (
210210
typeof properties === 'object' &&
211211
properties !== null &&
@@ -243,7 +243,7 @@ function validateToolProperty(property: McpToolProperty, propertyName?: string):
243243
* Supports both legacy array format and new toolProp object format
244244
*/
245245
export function normalizeToolProperties(
246-
properties: McpToolProperty[] | ToolProps | undefined
246+
properties: McpToolProperty[] | Args | undefined
247247
): McpToolProperty[] | undefined {
248248
if (!properties) {
249249
return undefined;

test/converters/toMcpToolTriggerOptionsToRpc.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'mocha';
55
import { expect } from 'chai';
66
import { converToMcpToolTriggerOptionsToRpc } from '../../src/converters/toMcpToolTriggerOptionsToRpc';
77
import { arg } from '../../src/utils/toolProperties';
8-
import { McpToolProperty, McpToolTriggerOptions, ToolProps } from '../../types/mcpTool';
8+
import { Args, McpToolProperty, McpToolTriggerOptions } from '../../types/mcpTool';
99

1010
describe('converToMcpToolTriggerOptionsToRpc', () => {
1111
describe('basic conversion', () => {
@@ -89,7 +89,7 @@ describe('converToMcpToolTriggerOptionsToRpc', () => {
8989

9090
describe('toolProps object format', () => {
9191
it('should handle toolProps object format', () => {
92-
const toolProperties: ToolProps = {
92+
const toolProperties: Args = {
9393
name: arg.string().describe('The name of the item'),
9494
age: arg.number().describe('The age of the person').optional(),
9595
};
@@ -115,7 +115,7 @@ describe('converToMcpToolTriggerOptionsToRpc', () => {
115115
});
116116

117117
it('should handle all supported property types', () => {
118-
const toolProperties: ToolProps = {
118+
const toolProperties: Args = {
119119
stringProp: arg.string().describe('A string property'),
120120
numberProp: arg.number().describe('A number property').optional(),
121121
booleanProp: arg.boolean().describe('A boolean property'),
@@ -139,7 +139,7 @@ describe('converToMcpToolTriggerOptionsToRpc', () => {
139139
});
140140

141141
it('should handle array properties correctly', () => {
142-
const toolProperties: ToolProps = {
142+
const toolProperties: Args = {
143143
stringArray: arg.string().describe('A string array').asArray().optional(),
144144
numberArray: arg.number().describe('A number array').asArray(),
145145
};
@@ -311,7 +311,7 @@ describe('converToMcpToolTriggerOptionsToRpc', () => {
311311

312312
describe('JSON serialization', () => {
313313
it('should produce valid JSON in toolProperties', () => {
314-
const toolProperties: ToolProps = {
314+
const toolProperties: Args = {
315315
test: arg.string().describe('Test property'),
316316
};
317317

@@ -351,7 +351,7 @@ describe('converToMcpToolTriggerOptionsToRpc', () => {
351351

352352
describe('edge cases', () => {
353353
it('should handle properties with special characters', () => {
354-
const toolProperties: ToolProps = {
354+
const toolProperties: Args = {
355355
'special-field_with$symbols': arg.string().describe('A property with special characters in name'),
356356
};
357357

@@ -371,7 +371,7 @@ describe('converToMcpToolTriggerOptionsToRpc', () => {
371371
});
372372

373373
it('should handle properties with non-empty descriptions', () => {
374-
const toolProperties: ToolProps = {
374+
const toolProperties: Args = {
375375
validDesc: arg.string().describe('A valid description'),
376376
};
377377

@@ -390,7 +390,7 @@ describe('converToMcpToolTriggerOptionsToRpc', () => {
390390
expect(parsedProperties).to.have.length(1);
391391
});
392392
it('should handle whitespace in names and descriptions', () => {
393-
const toolProperties: ToolProps = {
393+
const toolProperties: Args = {
394394
' spaced name ': arg.string().describe(' spaced description ').optional(),
395395
};
396396

types/mcpTool.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export interface McpToolTriggerOptions {
4848

4949
/**
5050
* Additional properties or metadata for the tool.
51-
* Can be provided as an array (legacy format) or as a toolProp object format.
51+
* Can be provided as an array or as a Args object format.
5252
*/
53-
toolProperties?: McpToolProperty[] | ToolProps | any;
53+
toolProperties?: McpToolProperty[] | Args;
5454
}
5555

5656
/**
@@ -114,9 +114,9 @@ export interface McpToolProperty {
114114
/**
115115
* Represents a tool property definition (same as McpToolProperty but without propertyName)
116116
*/
117-
export type ToolProperty = Omit<McpToolProperty, 'propertyName'>;
117+
export type Arg = Omit<McpToolProperty, 'propertyName'>;
118118

119119
/**
120120
* Tool properties format - an object mapping property names to their definitions
121121
*/
122-
export type ToolProps = Record<string, ToolProperty>;
122+
export type Args = Record<string, Arg>;

0 commit comments

Comments
 (0)