@@ -47,6 +47,24 @@ import { UriTemplate, Variables } from "../shared/uriTemplate.js";
47
47
import { RequestHandlerExtra } from "../shared/protocol.js" ;
48
48
import { Transport } from "../shared/transport.js" ;
49
49
50
+ /**
51
+ * Simple interface for tool registration that avoids TypeScript "Type instantiation is excessively deep"
52
+ * errors when registering large numbers of tools with complex schemas.
53
+ *
54
+ * Uses unknown types to prevent TypeScript from attempting deep type inference on complex schemas.
55
+ */
56
+ export interface ToolRegistration {
57
+ name : string ;
58
+ config : {
59
+ title ?: string ;
60
+ description ?: string ;
61
+ inputSchema ?: unknown ;
62
+ outputSchema ?: unknown ;
63
+ annotations ?: ToolAnnotations ;
64
+ } ;
65
+ callback : ( args : unknown , extra : RequestHandlerExtra < ServerRequest , ServerNotification > ) => CallToolResult | Promise < CallToolResult > ;
66
+ }
67
+
50
68
/**
51
69
* High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
52
70
* For advanced usage (like sending notifications or setting custom request handlers), use the underlying
@@ -671,12 +689,12 @@ export class McpServer {
671
689
* This is more efficient than calling registerResource() multiple times,
672
690
* especially when registering many resources, as it sends only one list_changed notification.
673
691
*/
674
- registerResources < T extends Array < {
692
+ registerResources ( resources : Array < {
675
693
name : string ;
676
694
uriOrTemplate : string | ResourceTemplate ;
677
695
config : ResourceMetadata ;
678
696
callback : ReadResourceCallback | ReadResourceTemplateCallback ;
679
- } > > ( resources : T ) : ( RegisteredResource | RegisteredResourceTemplate ) [ ] {
697
+ } > ) : ( RegisteredResource | RegisteredResourceTemplate ) [ ] {
680
698
if ( resources . length === 0 ) {
681
699
return [ ] ;
682
700
}
@@ -731,15 +749,15 @@ export class McpServer {
731
749
* This is more efficient than calling registerPrompt() multiple times when registering many prompts,
732
750
* especially when registering many prompts, as it sends only one list_changed notification.
733
751
*/
734
- registerPrompts < T extends Array < {
752
+ registerPrompts ( prompts : Array < {
735
753
name : string ;
736
754
config : {
737
755
title ?: string ;
738
756
description ?: string ;
739
757
argsSchema ?: PromptArgsRawShape ;
740
758
} ;
741
759
callback : PromptCallback < PromptArgsRawShape | undefined > ;
742
- } > > ( prompts : T ) : RegisteredPrompt [ ] {
760
+ } > ) : RegisteredPrompt [ ] {
743
761
if ( prompts . length === 0 ) {
744
762
return [ ] ;
745
763
}
@@ -1066,18 +1084,10 @@ export class McpServer {
1066
1084
* Registers multiple tools at once with a single notification.
1067
1085
* This is more efficient than calling registerTool() multiple times,
1068
1086
* especially when registering many tools, as it sends only one list_changed notification.
1087
+ *
1088
+ * Uses simplified types to avoid TypeScript compilation issues with large numbers of complex tools.
1069
1089
*/
1070
- registerTools < T extends Array < {
1071
- name : string ;
1072
- config : {
1073
- title ?: string ;
1074
- description ?: string ;
1075
- inputSchema ?: ZodRawShape ;
1076
- outputSchema ?: ZodRawShape ;
1077
- annotations ?: ToolAnnotations ;
1078
- } ;
1079
- callback : ToolCallback < ZodRawShape | undefined > ;
1080
- } > > ( tools : T ) : RegisteredTool [ ] {
1090
+ registerTools ( tools : ToolRegistration [ ] ) : RegisteredTool [ ] {
1081
1091
if ( tools . length === 0 ) {
1082
1092
return [ ] ;
1083
1093
}
@@ -1099,8 +1109,8 @@ export class McpServer {
1099
1109
name ,
1100
1110
title ,
1101
1111
description ,
1102
- inputSchema ,
1103
- outputSchema ,
1112
+ inputSchema as ZodRawShape | undefined ,
1113
+ outputSchema as ZodRawShape | undefined ,
1104
1114
annotations ,
1105
1115
callback as ToolCallback < ZodRawShape | undefined >
1106
1116
) ;
0 commit comments