Skip to content

Commit 86e367f

Browse files
committed
* In elicitation.test.ts
- Replace @ts-expect-error erroneously removed for "pattern" types * In types.ts - follow the pattern of the other primitive types - name the zod schemas with SchemaSchema at the end - export types inferred from enum schemas with just Schema at the end * In spec.types.test.ts - add tests for enum types
1 parent 7b83590 commit 86e367f

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed

src/server/elicitation.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo
159159
age: { type: 'integer', minimum: 0, maximum: 150 },
160160
street: { type: 'string' },
161161
city: { type: 'string' },
162+
// @ts-expect-error - pattern is not a valid property by MCP spec, however it is making use of the Ajv validator
162163
zipCode: { type: 'string', pattern: '^[0-9]{5}$' },
163164
newsletter: { type: 'boolean' },
164165
notifications: { type: 'boolean' }
@@ -273,6 +274,7 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo
273274
requestedSchema: {
274275
type: 'object',
275276
properties: {
277+
// @ts-expect-error - pattern is not a valid property by MCP spec, however it is making use of the Ajv validator
276278
zipCode: { type: 'string', pattern: '^[0-9]{5}$' }
277279
},
278280
required: ['zipCode']

src/spec.types.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,34 @@ const sdkTypeChecks = {
464464
sdk = spec;
465465
spec = sdk;
466466
},
467+
UntitledSingleSelectEnumSchema: (sdk: SDKTypes.UntitledSingleSelectEnumSchema, spec: SpecTypes.UntitledSingleSelectEnumSchema) => {
468+
sdk = spec;
469+
spec = sdk;
470+
},
471+
TitledSingleSelectEnumSchema: (sdk: SDKTypes.TitledSingleSelectEnumSchema, spec: SpecTypes.TitledSingleSelectEnumSchema) => {
472+
sdk = spec;
473+
spec = sdk;
474+
},
475+
SingleSelectEnumSchema: (sdk: SDKTypes.SingleSelectEnumSchema, spec: SpecTypes.SingleSelectEnumSchema) => {
476+
sdk = spec;
477+
spec = sdk;
478+
},
479+
UntitledMultiSelectEnumSchema: (sdk: SDKTypes.UntitledMultiSelectEnumSchema, spec: SpecTypes.UntitledMultiSelectEnumSchema) => {
480+
sdk = spec;
481+
spec = sdk;
482+
},
483+
TitledMultiSelectEnumSchema: (sdk: SDKTypes.TitledMultiSelectEnumSchema, spec: SpecTypes.TitledMultiSelectEnumSchema) => {
484+
sdk = spec;
485+
spec = sdk;
486+
},
487+
MultiSelectEnumSchema: (sdk: SDKTypes.MultiSelectEnumSchema, spec: SpecTypes.MultiSelectEnumSchema) => {
488+
sdk = spec;
489+
spec = sdk;
490+
},
491+
LegacyTitledEnumSchema: (sdk: SDKTypes.LegacyTitledEnumSchema, spec: SpecTypes.LegacyTitledEnumSchema) => {
492+
sdk = spec;
493+
spec = sdk;
494+
},
467495
PrimitiveSchemaDefinition: (sdk: SDKTypes.PrimitiveSchemaDefinition, spec: SpecTypes.PrimitiveSchemaDefinition) => {
468496
sdk = spec;
469497
spec = sdk;
@@ -565,7 +593,7 @@ describe('Spec Types', () => {
565593
it('should define some expected types', () => {
566594
expect(specTypes).toContain('JSONRPCNotification');
567595
expect(specTypes).toContain('ElicitResult');
568-
expect(specTypes).toHaveLength(112);
596+
expect(specTypes).toHaveLength(119);
569597
});
570598

571599
it('should have up to date list of missing sdk types', () => {

src/types.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,21 +1229,18 @@ export const NumberSchemaSchema = z.object({
12291229
/**
12301230
* Schema for single-selection enumeration without display titles for options.
12311231
*/
1232-
export const UntitledSingleSelectEnumSchema = z
1233-
.object({
1234-
type: z.literal('string'),
1235-
title: z.optional(z.string()),
1236-
description: z.optional(z.string()),
1237-
enum: z.array(z.string()),
1238-
default: z.string().optional()
1239-
})
1240-
.passthrough();
1241-
1232+
export const UntitledSingleSelectEnumSchemaSchema = z.object({
1233+
type: z.literal('string'),
1234+
title: z.string().optional(),
1235+
description: z.string().optional(),
1236+
enum: z.array(z.string()),
1237+
default: z.string().optional()
1238+
});
12421239

12431240
/**
12441241
* Schema for single-selection enumeration with display titles for each option.
12451242
*/
1246-
export const TitledSingleSelectEnumSchema = z.object({
1243+
export const TitledSingleSelectEnumSchemaSchema = z.object({
12471244
type: z.literal('string'),
12481245
title: z.string().optional(),
12491246
description: z.string().optional(),
@@ -1260,7 +1257,7 @@ export const TitledSingleSelectEnumSchema = z.object({
12601257
* Use TitledSingleSelectEnumSchema instead.
12611258
* This interface will be removed in a future version.
12621259
*/
1263-
export const LegacyTitledEnumSchema = z.object({
1260+
export const LegacyTitledEnumSchemaSchema = z.object({
12641261
type: z.literal('string'),
12651262
title: z.string().optional(),
12661263
description: z.string().optional(),
@@ -1270,12 +1267,16 @@ export const LegacyTitledEnumSchema = z.object({
12701267
});
12711268

12721269
// Combined single selection enumeration
1273-
export const SingleSelectEnumSchema = z.union([UntitledSingleSelectEnumSchema, TitledSingleSelectEnumSchema, LegacyTitledEnumSchema]);
1270+
export const SingleSelectEnumSchemaSchema = z.union([
1271+
UntitledSingleSelectEnumSchemaSchema,
1272+
TitledSingleSelectEnumSchemaSchema,
1273+
LegacyTitledEnumSchemaSchema
1274+
]);
12741275

12751276
/**
12761277
* Schema for multiple-selection enumeration without display titles for options.
12771278
*/
1278-
export const UntitledMultiSelectEnumSchema = z.object({
1279+
export const UntitledMultiSelectEnumSchemaSchema = z.object({
12791280
type: z.literal('array'),
12801281
title: z.string().optional(),
12811282
description: z.string().optional(),
@@ -1291,7 +1292,7 @@ export const UntitledMultiSelectEnumSchema = z.object({
12911292
/**
12921293
* Schema for multiple-selection enumeration with display titles for each option.
12931294
*/
1294-
export const TitledMultiSelectEnumSchema = z.object({
1295+
export const TitledMultiSelectEnumSchemaSchema = z.object({
12951296
type: z.literal('array'),
12961297
title: z.string().optional(),
12971298
description: z.string().optional(),
@@ -1311,12 +1312,12 @@ export const TitledMultiSelectEnumSchema = z.object({
13111312
/**
13121313
* Combined schema for multiple-selection enumeration
13131314
*/
1314-
export const MultiSelectEnumSchema = z.union([UntitledMultiSelectEnumSchema, TitledMultiSelectEnumSchema]);
1315+
export const MultiSelectEnumSchemaSchema = z.union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
13151316

13161317
/**
13171318
* Primitive schema definition for enum fields.
13181319
*/
1319-
export const EnumSchemaSchema = z.union([SingleSelectEnumSchema, MultiSelectEnumSchema]);
1320+
export const EnumSchemaSchema = z.union([SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
13201321

13211322
/**
13221323
* Union of all primitive schema definitions.
@@ -1735,7 +1736,16 @@ export type CreateMessageResult = Infer<typeof CreateMessageResultSchema>;
17351736
export type BooleanSchema = Infer<typeof BooleanSchemaSchema>;
17361737
export type StringSchema = Infer<typeof StringSchemaSchema>;
17371738
export type NumberSchema = Infer<typeof NumberSchemaSchema>;
1739+
17381740
export type EnumSchema = Infer<typeof EnumSchemaSchema>;
1741+
export type UntitledSingleSelectEnumSchema = Infer<typeof UntitledSingleSelectEnumSchemaSchema>;
1742+
export type TitledSingleSelectEnumSchema = Infer<typeof TitledSingleSelectEnumSchemaSchema>;
1743+
export type LegacyTitledEnumSchema = Infer<typeof LegacyTitledEnumSchemaSchema>;
1744+
export type UntitledMultiSelectEnumSchema = Infer<typeof UntitledMultiSelectEnumSchemaSchema>;
1745+
export type TitledMultiSelectEnumSchema = Infer<typeof TitledMultiSelectEnumSchemaSchema>;
1746+
export type SingleSelectEnumSchema = Infer<typeof SingleSelectEnumSchemaSchema>;
1747+
export type MultiSelectEnumSchema = Infer<typeof MultiSelectEnumSchemaSchema>;
1748+
17391749
export type PrimitiveSchemaDefinition = Infer<typeof PrimitiveSchemaDefinitionSchema>;
17401750
export type ElicitRequestParams = Infer<typeof ElicitRequestParamsSchema>;
17411751
export type ElicitRequest = Infer<typeof ElicitRequestSchema>;

0 commit comments

Comments
 (0)