Skip to content

Commit 1705f98

Browse files
ochafikclaude
andcommitted
refactor: re-export more schemas (Task, Pagination, Logging, EmptyResult)
Continue progressive re-export from generated schemas: - TaskSchema, TaskStatusNotificationParamsSchema - PaginatedRequestParamsSchema - GetPromptRequestParamsSchema - LoggingMessageNotificationParamsSchema - EmptyResultSchema (with .strict() transform in generate-schemas.ts) Types.ts reduced from ~1358 to ~1299 lines (~4% further reduction). Total reduction from original ~2600 lines: ~50%. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8ff45ca commit 1705f98

File tree

4 files changed

+43
-101
lines changed

4 files changed

+43
-101
lines changed

scripts/generate-schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const STRICT_SCHEMAS = [
9797
'JSONRPCNotificationSchema',
9898
'JSONRPCResultResponseSchema',
9999
'JSONRPCErrorResponseSchema',
100+
'EmptyResultSchema',
100101
];
101102

102103
// =============================================================================

src/generated/sdk.schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export const JSONRPCResponseSchema = z.union([JSONRPCResultResponseSchema, JSONR
171171
*
172172
* @category Common Types
173173
*/
174-
export const EmptyResultSchema = ResultSchema;
174+
export const EmptyResultSchema = ResultSchema.strict();
175175

176176
/* Cancellation */
177177
/**

src/generated/sdk.schemas.zod.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export type ProgressTokenSchemaInferredType = z.infer<typeof generated.ProgressT
1515

1616
export type CursorSchemaInferredType = z.infer<typeof generated.CursorSchema>;
1717

18-
export type RequestParamsSchemaInferredType = z.infer<typeof generated.RequestParamsSchema>;
19-
2018
export type TaskMetadataSchemaInferredType = z.infer<typeof generated.TaskMetadataSchema>;
2119

22-
export type RequestSchemaInferredType = z.infer<typeof generated.RequestSchema>;
20+
export type RelatedTaskMetadataSchemaInferredType = z.infer<typeof generated.RelatedTaskMetadataSchema>;
21+
22+
export type RequestParamsSchemaInferredType = z.infer<typeof generated.RequestParamsSchema>;
2323

2424
export type NotificationParamsSchemaInferredType = z.infer<typeof generated.NotificationParamsSchema>;
2525

@@ -31,7 +31,7 @@ export type ErrorSchemaInferredType = z.infer<typeof generated.ErrorSchema>;
3131

3232
export type RequestIdSchemaInferredType = z.infer<typeof generated.RequestIdSchema>;
3333

34-
export type JSONRPCRequestSchemaInferredType = z.infer<typeof generated.JSONRPCRequestSchema>;
34+
export type RequestSchemaInferredType = z.infer<typeof generated.RequestSchema>;
3535

3636
export type JSONRPCNotificationSchemaInferredType = z.infer<typeof generated.JSONRPCNotificationSchema>;
3737

@@ -133,8 +133,6 @@ export type ToolSchemaInferredType = z.infer<typeof generated.ToolSchema>;
133133

134134
export type TaskStatusSchemaInferredType = z.infer<typeof generated.TaskStatusSchema>;
135135

136-
export type RelatedTaskMetadataSchemaInferredType = z.infer<typeof generated.RelatedTaskMetadataSchema>;
137-
138136
export type TaskSchemaInferredType = z.infer<typeof generated.TaskSchema>;
139137

140138
export type CreateTaskResultSchemaInferredType = z.infer<typeof generated.CreateTaskResultSchema>;
@@ -241,7 +239,7 @@ export type ReadResourceResultSchemaInferredType = z.infer<typeof generated.Read
241239

242240
export type ListToolsResultSchemaInferredType = z.infer<typeof generated.ListToolsResultSchema>;
243241

244-
export type JSONRPCMessageSchemaInferredType = z.infer<typeof generated.JSONRPCMessageSchema>;
242+
export type JSONRPCRequestSchemaInferredType = z.infer<typeof generated.JSONRPCRequestSchema>;
245243

246244
export type URLElicitationRequiredErrorSchemaInferredType = z.infer<typeof generated.URLElicitationRequiredErrorSchema>;
247245

@@ -281,6 +279,8 @@ export type ListResourcesResultSchemaInferredType = z.infer<typeof generated.Lis
281279

282280
export type CallToolResultSchemaInferredType = z.infer<typeof generated.CallToolResultSchema>;
283281

282+
export type JSONRPCMessageSchemaInferredType = z.infer<typeof generated.JSONRPCMessageSchema>;
283+
284284
export type PromptMessageSchemaInferredType = z.infer<typeof generated.PromptMessageSchema>;
285285

286286
export type SamplingMessageContentBlockSchemaInferredType = z.infer<typeof generated.SamplingMessageContentBlockSchema>;
@@ -305,12 +305,12 @@ expectType<spec.ProgressToken>({} as ProgressTokenSchemaInferredType);
305305
expectType<ProgressTokenSchemaInferredType>({} as spec.ProgressToken);
306306
expectType<spec.Cursor>({} as CursorSchemaInferredType);
307307
expectType<CursorSchemaInferredType>({} as spec.Cursor);
308-
expectType<spec.RequestParams>({} as RequestParamsSchemaInferredType);
309-
expectType<RequestParamsSchemaInferredType>({} as spec.RequestParams);
310308
expectType<spec.TaskMetadata>({} as TaskMetadataSchemaInferredType);
311309
expectType<TaskMetadataSchemaInferredType>({} as spec.TaskMetadata);
312-
expectType<spec.Request>({} as RequestSchemaInferredType);
313-
expectType<RequestSchemaInferredType>({} as spec.Request);
310+
expectType<spec.RelatedTaskMetadata>({} as RelatedTaskMetadataSchemaInferredType);
311+
expectType<RelatedTaskMetadataSchemaInferredType>({} as spec.RelatedTaskMetadata);
312+
expectType<spec.RequestParams>({} as RequestParamsSchemaInferredType);
313+
expectType<RequestParamsSchemaInferredType>({} as spec.RequestParams);
314314
expectType<spec.NotificationParams>({} as NotificationParamsSchemaInferredType);
315315
expectType<NotificationParamsSchemaInferredType>({} as spec.NotificationParams);
316316
expectType<spec.Notification>({} as NotificationSchemaInferredType);
@@ -321,8 +321,8 @@ expectType<spec.Error>({} as ErrorSchemaInferredType);
321321
expectType<ErrorSchemaInferredType>({} as spec.Error);
322322
expectType<spec.RequestId>({} as RequestIdSchemaInferredType);
323323
expectType<RequestIdSchemaInferredType>({} as spec.RequestId);
324-
expectType<spec.JSONRPCRequest>({} as JSONRPCRequestSchemaInferredType);
325-
expectType<JSONRPCRequestSchemaInferredType>({} as spec.JSONRPCRequest);
324+
expectType<spec.Request>({} as RequestSchemaInferredType);
325+
expectType<RequestSchemaInferredType>({} as spec.Request);
326326
expectType<spec.JSONRPCNotification>({} as JSONRPCNotificationSchemaInferredType);
327327
expectType<JSONRPCNotificationSchemaInferredType>({} as spec.JSONRPCNotification);
328328
expectType<spec.JSONRPCResultResponse>({} as JSONRPCResultResponseSchemaInferredType);
@@ -423,8 +423,6 @@ expectType<spec.Tool>({} as ToolSchemaInferredType);
423423
expectType<ToolSchemaInferredType>({} as spec.Tool);
424424
expectType<spec.TaskStatus>({} as TaskStatusSchemaInferredType);
425425
expectType<TaskStatusSchemaInferredType>({} as spec.TaskStatus);
426-
expectType<spec.RelatedTaskMetadata>({} as RelatedTaskMetadataSchemaInferredType);
427-
expectType<RelatedTaskMetadataSchemaInferredType>({} as spec.RelatedTaskMetadata);
428426
expectType<spec.Task>({} as TaskSchemaInferredType);
429427
expectType<TaskSchemaInferredType>({} as spec.Task);
430428
expectType<spec.CreateTaskResult>({} as CreateTaskResultSchemaInferredType);
@@ -531,8 +529,8 @@ expectType<spec.ReadResourceResult>({} as ReadResourceResultSchemaInferredType);
531529
expectType<ReadResourceResultSchemaInferredType>({} as spec.ReadResourceResult);
532530
expectType<spec.ListToolsResult>({} as ListToolsResultSchemaInferredType);
533531
expectType<ListToolsResultSchemaInferredType>({} as spec.ListToolsResult);
534-
expectType<spec.JSONRPCMessage>({} as JSONRPCMessageSchemaInferredType);
535-
expectType<JSONRPCMessageSchemaInferredType>({} as spec.JSONRPCMessage);
532+
expectType<spec.JSONRPCRequest>({} as JSONRPCRequestSchemaInferredType);
533+
expectType<JSONRPCRequestSchemaInferredType>({} as spec.JSONRPCRequest);
536534
expectType<spec.URLElicitationRequiredError>({} as URLElicitationRequiredErrorSchemaInferredType);
537535
expectType<URLElicitationRequiredErrorSchemaInferredType>({} as spec.URLElicitationRequiredError);
538536
expectType<spec.InitializeRequestParams>({} as InitializeRequestParamsSchemaInferredType);
@@ -571,6 +569,8 @@ expectType<spec.ListResourcesResult>({} as ListResourcesResultSchemaInferredType
571569
expectType<ListResourcesResultSchemaInferredType>({} as spec.ListResourcesResult);
572570
expectType<spec.CallToolResult>({} as CallToolResultSchemaInferredType);
573571
expectType<CallToolResultSchemaInferredType>({} as spec.CallToolResult);
572+
expectType<spec.JSONRPCMessage>({} as JSONRPCMessageSchemaInferredType);
573+
expectType<JSONRPCMessageSchemaInferredType>({} as spec.JSONRPCMessage);
574574
expectType<spec.PromptMessage>({} as PromptMessageSchemaInferredType);
575575
expectType<PromptMessageSchemaInferredType>({} as spec.PromptMessage);
576576
expectType<spec.SamplingMessageContentBlock>({} as SamplingMessageContentBlockSchemaInferredType);

src/types.ts

Lines changed: 24 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ import {
176176
ToolResultContentSchema,
177177
// String schema
178178
StringSchemaSchema,
179+
// Task schemas
180+
TaskSchema,
181+
TaskStatusNotificationParamsSchema,
182+
// Request/Notification params schemas
183+
PaginatedRequestParamsSchema,
184+
GetPromptRequestParamsSchema,
185+
LoggingMessageNotificationParamsSchema,
186+
// EmptyResult (with .strict())
187+
EmptyResultSchema,
179188
} from './generated/sdk.schemas.js';
180189

181190
// Alias RequestParamsSchema to BaseRequestParamsSchema for internal use
@@ -308,6 +317,12 @@ export {
308317
ToolUseContentSchema,
309318
ToolResultContentSchema,
310319
StringSchemaSchema,
320+
TaskSchema,
321+
TaskStatusNotificationParamsSchema,
322+
PaginatedRequestParamsSchema,
323+
GetPromptRequestParamsSchema,
324+
LoggingMessageNotificationParamsSchema,
325+
EmptyResultSchema,
311326
};
312327

313328
export const LATEST_PROTOCOL_VERSION = '2025-11-25';
@@ -405,13 +420,7 @@ export const JSONRPCMessageSchema = z.union([
405420
]);
406421
export const JSONRPCResponseSchema = z.union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
407422

408-
/* Empty result */
409-
/**
410-
* A response that indicates success but carries no data.
411-
*/
412-
export const EmptyResultSchema = ResultSchema.strict();
413-
414-
// Note: CancelledNotificationParamsSchema is re-exported from generated.
423+
// Note: EmptyResultSchema (with .strict()), CancelledNotificationParamsSchema are re-exported from generated.
415424

416425
/* Cancellation */
417426
/**
@@ -655,51 +664,14 @@ export const ProgressNotificationParamsSchema = z.object({
655664
});
656665
// Note: ProgressNotificationSchema is re-exported from generated.
657666

658-
export const PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
659-
/**
660-
* An opaque token representing the current pagination position.
661-
* If provided, the server should return results starting after this cursor.
662-
*/
663-
cursor: CursorSchema.optional()
664-
});
665-
666667
/* Pagination */
667-
// Note: PaginatedRequestSchema and PaginatedResultSchema are re-exported from generated.
668+
// Note: PaginatedRequestParamsSchema, PaginatedRequestSchema, PaginatedResultSchema
669+
// are re-exported from generated.
668670

669671
/* Tasks */
670-
/**
671-
* A pollable state object associated with a request.
672-
*/
673-
export const TaskSchema = z.object({
674-
taskId: z.string(),
675-
status: TaskStatusSchema,
676-
/**
677-
* Time in milliseconds to keep task results available after completion.
678-
* If null, the task has unlimited lifetime until manually cleaned up.
679-
*/
680-
ttl: z.union([z.number(), z.null()]),
681-
/**
682-
* ISO 8601 timestamp when the task was created.
683-
*/
684-
createdAt: z.string(),
685-
/**
686-
* ISO 8601 timestamp when the task was last updated.
687-
*/
688-
lastUpdatedAt: z.string(),
689-
pollInterval: z.optional(z.number()),
690-
/**
691-
* Optional diagnostic message for failed tasks or other status information.
692-
*/
693-
statusMessage: z.optional(z.string())
694-
});
695-
696-
// Note: CreateTaskResultSchema, TaskStatusNotificationSchema, GetTaskResultSchema,
697-
// GetTaskPayloadResultSchema, ListTasksResultSchema, CancelTaskResultSchema are re-exported from generated.
698-
699-
/**
700-
* Parameters for task status notification.
701-
*/
702-
export const TaskStatusNotificationParamsSchema = NotificationsParamsSchema.merge(TaskSchema);
672+
// Note: TaskSchema, TaskStatusNotificationParamsSchema, CreateTaskResultSchema,
673+
// TaskStatusNotificationSchema, GetTaskResultSchema, GetTaskPayloadResultSchema,
674+
// ListTasksResultSchema, CancelTaskResultSchema are re-exported from generated.
703675

704676
/* Resources */
705677
// Note: ResourceContentsSchema, TextResourceContentsSchema, BlobResourceContentsSchema
@@ -748,21 +720,7 @@ export const ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema
748720
// Note: PromptArgumentSchema, PromptSchema, ListPromptsRequestSchema, GetPromptRequestSchema
749721
// are re-exported from generated.
750722

751-
// Note: ListPromptsResultSchema is re-exported from generated.
752-
753-
/**
754-
* Parameters for a `prompts/get` request.
755-
*/
756-
export const GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
757-
/**
758-
* The name of the prompt or prompt template.
759-
*/
760-
name: z.string(),
761-
/**
762-
* Arguments to use for templating the prompt.
763-
*/
764-
arguments: z.record(z.string(), z.string()).optional()
765-
});
723+
// Note: ListPromptsResultSchema, GetPromptRequestParamsSchema are re-exported from generated.
766724

767725
// Note: TextContentSchema, ImageContentSchema, AudioContentSchema are re-exported
768726
// from generated with Base64 validation for data fields.
@@ -874,25 +832,8 @@ export const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
874832
*/
875833
level: LoggingLevelSchema
876834
});
877-
// Note: SetLevelRequestSchema, LoggingMessageNotificationSchema are re-exported from generated.
878-
879-
/**
880-
* Parameters for a `notifications/message` notification.
881-
*/
882-
export const LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
883-
/**
884-
* The severity of this log message.
885-
*/
886-
level: LoggingLevelSchema,
887-
/**
888-
* An optional name of the logger issuing this message.
889-
*/
890-
logger: z.string().optional(),
891-
/**
892-
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
893-
*/
894-
data: z.unknown()
895-
});
835+
// Note: SetLevelRequestSchema, LoggingMessageNotificationSchema, LoggingMessageNotificationParamsSchema
836+
// are re-exported from generated.
896837

897838
/* Sampling */
898839
// Note: ToolResultContentSchema is re-exported from generated.

0 commit comments

Comments
 (0)