Skip to content

Commit a63aeeb

Browse files
ochafikclaude
andcommitted
Add missing type definitions from spec.types.ts
- Add Annotations schema and type export - Add annotations field to TextContent, ImageContent, AudioContent schemas - Add annotations field to Resource and ResourceTemplate schemas - Add size field to Resource schema - Add annotations field to EmbeddedResource schema - Add ModelHint schema and type export - Update ModelPreferences schema to include hints array and detailed documentation - Uncomment spec type tests These changes align types.ts with the latest spec definitions to ensure full compatibility. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a19175a commit a63aeeb

File tree

2 files changed

+123
-24
lines changed

2 files changed

+123
-24
lines changed

src/spec.types.test.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -659,32 +659,29 @@ function checkServerNotification(
659659
spec = sdk;
660660
}
661661

662-
// TODO(bug): missing type in SDK. This dead code is checked by the test suite below.
663-
// function checkModelHint(
664-
// RemovePassthrough< sdk: SDKTypes.ModelHint>,
665-
// spec: SpecTypes.ModelHint
666-
// ) {
667-
// sdk = spec;
668-
// spec = sdk;
669-
// }
662+
function checkModelHint(
663+
sdk: RemovePassthrough<SDKTypes.ModelHint>,
664+
spec: SpecTypes.ModelHint
665+
) {
666+
sdk = spec;
667+
spec = sdk;
668+
}
670669

671-
// TODO(bug): missing type in SDK. This dead code is checked by the test suite below.
672-
// function checkModelPreferences(
673-
// RemovePassthrough< sdk: SDKTypes.ModelPreferences>,
674-
// spec: SpecTypes.ModelPreferences
675-
// ) {
676-
// sdk = spec;
677-
// spec = sdk;
678-
// }
670+
function checkModelPreferences(
671+
sdk: RemovePassthrough<SDKTypes.ModelPreferences>,
672+
spec: SpecTypes.ModelPreferences
673+
) {
674+
sdk = spec;
675+
spec = sdk;
676+
}
679677

680-
// TODO(bug): missing type in SDK. This dead code is checked by the test suite below.
681-
// function checkAnnotations(
682-
// RemovePassthrough< sdk: SDKTypes.Annotations>,
683-
// spec: SpecTypes.Annotations
684-
// ) {
685-
// sdk = spec;
686-
// spec = sdk;
687-
// }
678+
function checkAnnotations(
679+
sdk: RemovePassthrough<SDKTypes.Annotations>,
680+
spec: SpecTypes.Annotations
681+
) {
682+
sdk = spec;
683+
spec = sdk;
684+
}
688685

689686
// This file is .gitignore'd, and fetched by `npm run fetch:spec-types` (called by `npm run test`)
690687
const SPEC_TYPES_FILE = 'src/spec.types.ts';

src/types.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,40 @@ export const PaginatedResultSchema = ResultSchema.extend({
429429
nextCursor: z.optional(CursorSchema),
430430
});
431431

432+
/* Annotations */
433+
/**
434+
* Optional annotations for the client. The client can use annotations to inform how objects are used or displayed
435+
*/
436+
export const AnnotationsSchema = z
437+
.object({
438+
/**
439+
* Describes who the intended customer of this object or data is.
440+
*
441+
* It can include multiple entries to indicate content useful for multiple audiences (e.g., `["user", "assistant"]`).
442+
*/
443+
audience: z.optional(z.array(z.enum(["user", "assistant"]))),
444+
445+
/**
446+
* Describes how important this data is for operating the server.
447+
*
448+
* A value of 1 means "most important," and indicates that the data is
449+
* effectively required, while 0 means "least important," and indicates that
450+
* the data is entirely optional.
451+
*/
452+
priority: z.optional(z.number().min(0).max(1)),
453+
454+
/**
455+
* The moment the resource was last modified, as an ISO 8601 formatted string.
456+
*
457+
* Should be an ISO 8601 formatted string (e.g., "2025-01-12T15:00:58Z").
458+
*
459+
* Examples: last activity timestamp in an open file, timestamp when the resource
460+
* was attached, etc.
461+
*/
462+
lastModified: z.optional(z.string()),
463+
})
464+
.passthrough();
465+
432466
/* Resources */
433467
/**
434468
* The contents of a specific resource or sub-resource.
@@ -486,6 +520,18 @@ export const ResourceSchema = BaseMetadataSchema.extend({
486520
*/
487521
mimeType: z.optional(z.string()),
488522

523+
/**
524+
* Optional annotations for the client.
525+
*/
526+
annotations: z.optional(AnnotationsSchema),
527+
528+
/**
529+
* The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
530+
*
531+
* This can be used by Hosts to display file sizes and estimate context window usage.
532+
*/
533+
size: z.optional(z.number()),
534+
489535
/**
490536
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
491537
* for notes on _meta usage.
@@ -514,6 +560,11 @@ export const ResourceTemplateSchema = BaseMetadataSchema.extend({
514560
*/
515561
mimeType: z.optional(z.string()),
516562

563+
/**
564+
* Optional annotations for the client.
565+
*/
566+
annotations: z.optional(AnnotationsSchema),
567+
517568
/**
518569
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
519570
* for notes on _meta usage.
@@ -701,6 +752,11 @@ export const TextContentSchema = z
701752
*/
702753
text: z.string(),
703754

755+
/**
756+
* Optional annotations for the client.
757+
*/
758+
annotations: z.optional(AnnotationsSchema),
759+
704760
/**
705761
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
706762
* for notes on _meta usage.
@@ -724,6 +780,11 @@ export const ImageContentSchema = z
724780
*/
725781
mimeType: z.string(),
726782

783+
/**
784+
* Optional annotations for the client.
785+
*/
786+
annotations: z.optional(AnnotationsSchema),
787+
727788
/**
728789
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
729790
* for notes on _meta usage.
@@ -747,6 +808,11 @@ export const AudioContentSchema = z
747808
*/
748809
mimeType: z.string(),
749810

811+
/**
812+
* Optional annotations for the client.
813+
*/
814+
annotations: z.optional(AnnotationsSchema),
815+
750816
/**
751817
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
752818
* for notes on _meta usage.
@@ -762,6 +828,10 @@ export const EmbeddedResourceSchema = z
762828
.object({
763829
type: z.literal("resource"),
764830
resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
831+
/**
832+
* Optional annotations for the client.
833+
*/
834+
annotations: z.optional(AnnotationsSchema),
765835
/**
766836
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
767837
* for notes on _meta usage.
@@ -1046,23 +1116,50 @@ export const LoggingMessageNotificationSchema = NotificationSchema.extend({
10461116
/* Sampling */
10471117
/**
10481118
* Hints to use for model selection.
1119+
*
1120+
* Keys not declared here are currently left unspecified by the spec and are up
1121+
* to the client to interpret.
10491122
*/
10501123
export const ModelHintSchema = z
10511124
.object({
10521125
/**
10531126
* A hint for a model name.
1127+
*
1128+
* The client SHOULD treat this as a substring of a model name; for example:
1129+
* - `claude-3-5-sonnet` should match `claude-3-5-sonnet-20241022`
1130+
* - `sonnet` should match `claude-3-5-sonnet-20241022`, `claude-3-sonnet-20240229`, etc.
1131+
* - `claude` should match any Claude model
1132+
*
1133+
* The client MAY also map the string to a different provider's model name or a different model family, as long as it fills a similar niche; for example:
1134+
* - `gemini-1.5-flash` could match `claude-3-haiku-20240307`
10541135
*/
10551136
name: z.string().optional(),
10561137
})
10571138
.passthrough();
10581139

10591140
/**
10601141
* The server's preferences for model selection, requested of the client during sampling.
1142+
*
1143+
* Because LLMs can vary along multiple dimensions, choosing the "best" model is
1144+
* rarely straightforward. Different models excel in different areas—some are
1145+
* faster but less capable, others are more capable but more expensive, and so
1146+
* on. This interface allows servers to express their priorities across multiple
1147+
* dimensions to help clients make an appropriate selection for their use case.
1148+
*
1149+
* These preferences are always advisory. The client MAY ignore them. It is also
1150+
* up to the client to decide how to interpret these preferences and how to
1151+
* balance them against other considerations.
10611152
*/
10621153
export const ModelPreferencesSchema = z
10631154
.object({
10641155
/**
10651156
* Optional hints to use for model selection.
1157+
*
1158+
* If multiple hints are specified, the client MUST evaluate them in order
1159+
* (such that the first match is taken).
1160+
*
1161+
* The client SHOULD prioritize these hints over the numeric priorities, but
1162+
* MAY still use the priorities to select from ambiguous matches.
10661163
*/
10671164
hints: z.optional(z.array(ModelHintSchema)),
10681165
/**
@@ -1569,6 +1666,9 @@ export type PromptMessage = Infer<typeof PromptMessageSchema>;
15691666
export type GetPromptResult = Infer<typeof GetPromptResultSchema>;
15701667
export type PromptListChangedNotification = Infer<typeof PromptListChangedNotificationSchema>;
15711668

1669+
/* Annotations */
1670+
export type Annotations = Infer<typeof AnnotationsSchema>;
1671+
15721672
/* Tools */
15731673
export type ToolAnnotations = Infer<typeof ToolAnnotationsSchema>;
15741674
export type Tool = Infer<typeof ToolSchema>;
@@ -1585,6 +1685,8 @@ export type SetLevelRequest = Infer<typeof SetLevelRequestSchema>;
15851685
export type LoggingMessageNotification = Infer<typeof LoggingMessageNotificationSchema>;
15861686

15871687
/* Sampling */
1688+
export type ModelHint = Infer<typeof ModelHintSchema>;
1689+
export type ModelPreferences = Infer<typeof ModelPreferencesSchema>;
15881690
export type SamplingMessage = Infer<typeof SamplingMessageSchema>;
15891691
export type CreateMessageRequest = Infer<typeof CreateMessageRequestSchema>;
15901692
export type CreateMessageResult = Infer<typeof CreateMessageResultSchema>;

0 commit comments

Comments
 (0)