Skip to content

Commit 8ff45ca

Browse files
ochafikclaude
andcommitted
refactor: re-export more schemas from generated (Prompt, Tool, Sampling, Elicitation)
Re-export additional schemas from generated, further reducing types.ts: - PromptArgumentSchema, PromptSchema, PromptMessageSchema - ToolUseContentSchema, ToolSchema, ToolResultContentSchema - StringSchemaSchema Reduces types.ts from ~1574 to ~1358 lines (~14% additional reduction). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b6b7584 commit 8ff45ca

File tree

1 file changed

+33
-249
lines changed

1 file changed

+33
-249
lines changed

src/types.ts

Lines changed: 33 additions & 249 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ import {
163163
// ReadResource schemas
164164
ReadResourceRequestSchema,
165165
ReadResourceResultSchema,
166+
// Prompt schemas
167+
PromptMessageSchema,
168+
PromptSchema,
169+
PromptArgumentSchema,
170+
// Resource schemas
171+
ResourceSchema,
172+
ResourceTemplateSchema,
173+
// Tool schemas
174+
ToolSchema,
175+
ToolUseContentSchema,
176+
ToolResultContentSchema,
177+
// String schema
178+
StringSchemaSchema,
166179
} from './generated/sdk.schemas.js';
167180

168181
// Alias RequestParamsSchema to BaseRequestParamsSchema for internal use
@@ -286,6 +299,15 @@ export {
286299
ResourceTemplateReferenceSchema,
287300
ReadResourceRequestSchema,
288301
ReadResourceResultSchema,
302+
PromptMessageSchema,
303+
PromptSchema,
304+
PromptArgumentSchema,
305+
ResourceSchema,
306+
ResourceTemplateSchema,
307+
ToolSchema,
308+
ToolUseContentSchema,
309+
ToolResultContentSchema,
310+
StringSchemaSchema,
289311
};
290312

291313
export const LATEST_PROTOCOL_VERSION = '2025-11-25';
@@ -683,75 +705,7 @@ export const TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merg
683705
// Note: ResourceContentsSchema, TextResourceContentsSchema, BlobResourceContentsSchema
684706
// are re-exported from generated with Base64 validation.
685707

686-
/**
687-
* A known resource that the server is capable of reading.
688-
*/
689-
export const ResourceSchema = z.object({
690-
...BaseMetadataSchema.shape,
691-
...IconsSchema.shape,
692-
/**
693-
* The URI of this resource.
694-
*/
695-
uri: z.string(),
696-
697-
/**
698-
* A description of what this resource represents.
699-
*
700-
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
701-
*/
702-
description: z.optional(z.string()),
703-
704-
/**
705-
* The MIME type of this resource, if known.
706-
*/
707-
mimeType: z.optional(z.string()),
708-
709-
/**
710-
* Optional annotations for the client.
711-
*/
712-
annotations: AnnotationsSchema.optional(),
713-
714-
/**
715-
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
716-
* for notes on _meta usage.
717-
*/
718-
_meta: z.optional(z.looseObject({}))
719-
});
720-
721-
/**
722-
* A template description for resources available on the server.
723-
*/
724-
export const ResourceTemplateSchema = z.object({
725-
...BaseMetadataSchema.shape,
726-
...IconsSchema.shape,
727-
/**
728-
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
729-
*/
730-
uriTemplate: z.string(),
731-
732-
/**
733-
* A description of what this template is for.
734-
*
735-
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
736-
*/
737-
description: z.optional(z.string()),
738-
739-
/**
740-
* The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type.
741-
*/
742-
mimeType: z.optional(z.string()),
743-
744-
/**
745-
* Optional annotations for the client.
746-
*/
747-
annotations: AnnotationsSchema.optional(),
748-
749-
/**
750-
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
751-
* for notes on _meta usage.
752-
*/
753-
_meta: z.optional(z.looseObject({}))
754-
});
708+
// Note: ResourceSchema, ResourceTemplateSchema are re-exported from generated.
755709

756710
// Note: ListResourcesRequestSchema, ListResourceTemplatesRequestSchema, SubscribeRequestSchema,
757711
// UnsubscribeRequestSchema are re-exported from generated.
@@ -791,46 +745,8 @@ export const ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema
791745
// Note: ResourceUpdatedNotificationSchema is re-exported from generated.
792746

793747
/* Prompts */
794-
/**
795-
* Describes an argument that a prompt can accept.
796-
*/
797-
export const PromptArgumentSchema = z.object({
798-
/**
799-
* The name of the argument.
800-
*/
801-
name: z.string(),
802-
/**
803-
* A human-readable description of the argument.
804-
*/
805-
description: z.optional(z.string()),
806-
/**
807-
* Whether this argument must be provided.
808-
*/
809-
required: z.optional(z.boolean())
810-
});
811-
812-
/**
813-
* A prompt or prompt template that the server offers.
814-
*/
815-
export const PromptSchema = z.object({
816-
...BaseMetadataSchema.shape,
817-
...IconsSchema.shape,
818-
/**
819-
* An optional description of what this prompt provides
820-
*/
821-
description: z.optional(z.string()),
822-
/**
823-
* A list of arguments to use for templating the prompt.
824-
*/
825-
arguments: z.optional(z.array(PromptArgumentSchema)),
826-
/**
827-
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
828-
* for notes on _meta usage.
829-
*/
830-
_meta: z.optional(z.looseObject({}))
831-
});
832-
833-
// Note: ListPromptsRequestSchema, GetPromptRequestSchema are re-exported from generated.
748+
// Note: PromptArgumentSchema, PromptSchema, ListPromptsRequestSchema, GetPromptRequestSchema
749+
// are re-exported from generated.
834750

835751
// Note: ListPromptsResultSchema is re-exported from generated.
836752

@@ -851,113 +767,12 @@ export const GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
851767
// Note: TextContentSchema, ImageContentSchema, AudioContentSchema are re-exported
852768
// from generated with Base64 validation for data fields.
853769

854-
/**
855-
* A tool call request from an assistant (LLM).
856-
* Represents the assistant's request to use a tool.
857-
*/
858-
export const ToolUseContentSchema = z.object({
859-
type: z.literal('tool_use'),
860-
/**
861-
* The name of the tool to invoke.
862-
* Must match a tool name from the request's tools array.
863-
*/
864-
name: z.string(),
865-
/**
866-
* Unique identifier for this tool call.
867-
* Used to correlate with ToolResultContent in subsequent messages.
868-
*/
869-
id: z.string(),
870-
/**
871-
* Arguments to pass to the tool.
872-
* Must conform to the tool's inputSchema.
873-
*/
874-
input: z.record(z.string(), z.unknown()),
875-
/**
876-
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
877-
* for notes on _meta usage.
878-
*/
879-
_meta: z.record(z.string(), z.unknown()).optional()
880-
});
881-
882-
// Note: EmbeddedResourceSchema, ResourceLinkSchema, ContentBlockSchema are re-exported from generated.
883-
884-
/**
885-
* Describes a message returned as part of a prompt.
886-
*/
887-
export const PromptMessageSchema = z.object({
888-
role: RoleSchema,
889-
content: ContentBlockSchema
890-
});
891-
892-
// Note: GetPromptResultSchema, PromptListChangedNotificationSchema are re-exported from generated.
770+
// Note: ToolUseContentSchema, EmbeddedResourceSchema, ResourceLinkSchema, ContentBlockSchema,
771+
// PromptMessageSchema, GetPromptResultSchema, PromptListChangedNotificationSchema are re-exported from generated.
893772

894773
/* Tools */
895-
/**
896-
* Additional properties describing a Tool to clients.
897-
*
898-
* NOTE: all properties in ToolAnnotations are **hints**.
899-
* They are not guaranteed to provide a faithful description of
900-
* tool behavior (including descriptive properties like `title`).
901-
*
902-
* Clients should never make tool use decisions based on ToolAnnotations
903-
* received from untrusted servers.
904-
*
905-
* Note: ToolAnnotationsSchema and ToolExecutionSchema are re-exported from generated schemas.
906-
*/
907-
908-
/**
909-
* Definition for a tool the client can call.
910-
*/
911-
export const ToolSchema = z.object({
912-
...BaseMetadataSchema.shape,
913-
...IconsSchema.shape,
914-
/**
915-
* A human-readable description of the tool.
916-
*/
917-
description: z.string().optional(),
918-
/**
919-
* A JSON Schema 2020-12 object defining the expected parameters for the tool.
920-
* Must have type: 'object' at the root level per MCP spec.
921-
*/
922-
inputSchema: z
923-
.object({
924-
type: z.literal('object'),
925-
properties: z.record(z.string(), AssertObjectSchema).optional(),
926-
required: z.array(z.string()).optional()
927-
})
928-
.catchall(z.unknown()),
929-
/**
930-
* An optional JSON Schema 2020-12 object defining the structure of the tool's output
931-
* returned in the structuredContent field of a CallToolResult.
932-
* Must have type: 'object' at the root level per MCP spec.
933-
*/
934-
outputSchema: z
935-
.object({
936-
type: z.literal('object'),
937-
properties: z.record(z.string(), AssertObjectSchema).optional(),
938-
required: z.array(z.string()).optional()
939-
})
940-
.catchall(z.unknown())
941-
.optional(),
942-
/**
943-
* Optional additional tool information.
944-
*/
945-
annotations: ToolAnnotationsSchema.optional(),
946-
/**
947-
* Execution-related properties for this tool.
948-
*/
949-
execution: ToolExecutionSchema.optional(),
950-
951-
/**
952-
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
953-
* for notes on _meta usage.
954-
*/
955-
_meta: z.record(z.string(), z.unknown()).optional()
956-
});
957-
958-
// Note: ListToolsRequestSchema is re-exported from generated.
959-
960-
// Note: ListToolsResultSchema, CallToolResultSchema, CallToolRequestParamsSchema,
774+
// Note: ToolAnnotationsSchema, ToolExecutionSchema, ToolSchema, ListToolsRequestSchema,
775+
// ListToolsResultSchema, CallToolResultSchema, CallToolRequestParamsSchema,
961776
// CallToolRequestSchema, ToolListChangedNotificationSchema are re-exported from generated.
962777

963778
/**
@@ -1080,23 +895,7 @@ export const LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.
1080895
});
1081896

1082897
/* Sampling */
1083-
/**
1084-
* The result of a tool execution, provided by the user (server).
1085-
* Represents the outcome of invoking a tool requested via ToolUseContent.
1086-
*/
1087-
export const ToolResultContentSchema = z.object({
1088-
type: z.literal('tool_result'),
1089-
toolUseId: z.string().describe('The unique identifier for the corresponding tool call.'),
1090-
content: z.array(ContentBlockSchema).default([]),
1091-
structuredContent: z.object({}).loose().optional(),
1092-
isError: z.boolean().optional(),
1093-
1094-
/**
1095-
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1096-
* for notes on _meta usage.
1097-
*/
1098-
_meta: z.record(z.string(), z.unknown()).optional()
1099-
});
898+
// Note: ToolResultContentSchema is re-exported from generated.
1100899

1101900
/**
1102901
* Basic content types for sampling responses (without tool use).
@@ -1148,26 +947,11 @@ export const CreateMessageResultWithToolsSchema = ResultSchema.extend({
1148947
});
1149948

1150949
/* Elicitation */
1151-
// Note: BooleanSchemaSchema and NumberSchemaSchema are re-exported from generated schemas.
1152-
// StringSchemaSchema differs slightly (enum vs union for format) so kept here.
1153-
1154-
/**
1155-
* Primitive schema definition for string fields.
1156-
*/
1157-
export const StringSchemaSchema = z.object({
1158-
type: z.literal('string'),
1159-
title: z.string().optional(),
1160-
description: z.string().optional(),
1161-
minLength: z.number().optional(),
1162-
maxLength: z.number().optional(),
1163-
format: z.enum(['email', 'uri', 'date', 'date-time']).optional(),
1164-
default: z.string().optional()
1165-
});
1166-
1167-
// Note: Enum schemas (UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema,
950+
// Note: BooleanSchemaSchema, NumberSchemaSchema, StringSchemaSchema,
951+
// UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema,
1168952
// LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, UntitledMultiSelectEnumSchemaSchema,
1169953
// TitledMultiSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema, EnumSchemaSchema,
1170-
// PrimitiveSchemaDefinitionSchema) are re-exported from generated.
954+
// PrimitiveSchemaDefinitionSchema are re-exported from generated.
1171955

1172956
// Note: ElicitRequestFormParamsSchema, ElicitRequestURLParamsSchema, ElicitRequestParamsSchema,
1173957
// ElicitRequestSchema, ElicitResultSchema, ElicitationCompleteNotificationSchema are re-exported from generated.

0 commit comments

Comments
 (0)