Skip to content

Commit a910311

Browse files
feat(specTypeSchema): include ResourceTemplate in SPEC_SCHEMA_KEYS
ResourceTemplate is a first-class spec type with a public type export (ResourceTemplateType). It was excluded under the assumption that the name collides with the server package's ResourceTemplate class, but isSpecType.ResourceTemplate is a record property, not a top-level export, so no collision occurs. Including it makes the migration docs' 'every named type in the MCP spec' claim accurate. Corrected the allowlist comment (ResourceTemplate is not an internal helper) and added type-level and runtime tests.
1 parent 11b0ba3 commit a910311

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

packages/core/src/types/specTypeSchema.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ import * as schemas from './schemas.js';
2121
*
2222
* This intentionally excludes internal helper schemas exported from `schemas.ts` that have no
2323
* matching public type (e.g. `ListChangedOptionsBaseSchema`, `BaseRequestParamsSchema`,
24-
* `NotificationsParamsSchema`, `ClientTasksCapabilitySchema`, `ServerTasksCapabilitySchema`,
25-
* `ResourceTemplateSchema` whose public type was renamed to `ResourceTemplateType`). Keeping the
26-
* list explicit means new public spec types must be added here deliberately, and internals never
27-
* leak into `SpecTypeName`.
24+
* `NotificationsParamsSchema`, `ClientTasksCapabilitySchema`, `ServerTasksCapabilitySchema`).
25+
* Keeping the list explicit means new public spec types must be added here deliberately, and
26+
* internals never leak into `SpecTypeName`.
27+
*
28+
* `ResourceTemplateSchema` is included; its public type is exported as `ResourceTemplateType`
29+
* (the bare name collides with the server package's `ResourceTemplate` class), so
30+
* `SpecTypes['ResourceTemplate']` is structurally equal to `ResourceTemplateType` rather than to
31+
* a type literally named `ResourceTemplate`.
2832
*/
2933
const SPEC_SCHEMA_KEYS = [
3034
'AnnotationsSchema',
@@ -135,6 +139,7 @@ const SPEC_SCHEMA_KEYS = [
135139
'ResourceLinkSchema',
136140
'ResourceListChangedNotificationSchema',
137141
'ResourceRequestParamsSchema',
142+
'ResourceTemplateSchema',
138143
'ResourceTemplateReferenceSchema',
139144
'ResourceUpdatedNotificationSchema',
140145
'ResourceUpdatedNotificationParamsSchema',

packages/core/test/types/specTypeSchema.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import { describe, expect, expectTypeOf, it } from 'vitest';
33
import type { OAuthMetadata, OAuthTokens } from '../../src/shared/auth.js';
44
import type { SpecTypeName, SpecTypes } from '../../src/types/specTypeSchema.js';
55
import { isSpecType, specTypeSchemas } from '../../src/types/specTypeSchema.js';
6-
import type { CallToolResult, ContentBlock, Implementation, JSONRPCRequest, Tool } from '../../src/types/types.js';
6+
import type {
7+
CallToolResult,
8+
ContentBlock,
9+
Implementation,
10+
JSONRPCRequest,
11+
ResourceTemplateType,
12+
Tool,
13+
} from '../../src/types/types.js';
714

815
describe('specTypeSchemas', () => {
916
it('returns a StandardSchemaV1 validator that accepts valid values', () => {
@@ -103,6 +110,7 @@ describe('SpecTypeName / SpecTypes (type-level)', () => {
103110
expectTypeOf<'JSONRPCRequest'>().toMatchTypeOf<SpecTypeName>();
104111
expectTypeOf<'OAuthTokens'>().toMatchTypeOf<SpecTypeName>();
105112
expectTypeOf<'OAuthMetadata'>().toMatchTypeOf<SpecTypeName>();
113+
expectTypeOf<'ResourceTemplate'>().toMatchTypeOf<SpecTypeName>();
106114
});
107115

108116
it('SpecTypes[K] matches the named export type', () => {
@@ -113,5 +121,14 @@ describe('SpecTypeName / SpecTypes (type-level)', () => {
113121
expectTypeOf<SpecTypes['JSONRPCRequest']>().toEqualTypeOf<JSONRPCRequest>();
114122
expectTypeOf<SpecTypes['OAuthTokens']>().toEqualTypeOf<OAuthTokens>();
115123
expectTypeOf<SpecTypes['OAuthMetadata']>().toEqualTypeOf<OAuthMetadata>();
124+
// The public type is exported as ResourceTemplateType (the bare name collides with the
125+
// server package's ResourceTemplate class), so this is the one entry where the key and
126+
// the public type name differ.
127+
expectTypeOf<SpecTypes['ResourceTemplate']>().toEqualTypeOf<ResourceTemplateType>();
128+
});
129+
130+
it('isSpecType.ResourceTemplate validates a resource template', () => {
131+
expect(isSpecType.ResourceTemplate({ name: 'r', uriTemplate: 'file:///{path}' })).toBe(true);
132+
expect(isSpecType.ResourceTemplate({ name: 'r' })).toBe(false);
116133
});
117134
});

0 commit comments

Comments
 (0)