19
19
import io .modelcontextprotocol .spec .McpSchema .ResourceTemplate ;
20
20
import io .modelcontextprotocol .spec .McpServerTransportProvider ;
21
21
import io .modelcontextprotocol .util .Assert ;
22
+ import io .modelcontextprotocol .util .DeafaultMcpUriTemplateManagerFactory ;
23
+ import io .modelcontextprotocol .util .McpUriTemplateManagerFactory ;
22
24
import reactor .core .publisher .Mono ;
23
25
24
26
/**
@@ -156,6 +158,8 @@ class AsyncSpecification {
156
158
157
159
private final McpServerTransportProvider transportProvider ;
158
160
161
+ private McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory ();
162
+
159
163
private ObjectMapper objectMapper ;
160
164
161
165
private McpSchema .Implementation serverInfo = DEFAULT_SERVER_INFO ;
@@ -204,6 +208,19 @@ private AsyncSpecification(McpServerTransportProvider transportProvider) {
204
208
this .transportProvider = transportProvider ;
205
209
}
206
210
211
+ /**
212
+ * Sets the URI template manager factory to use for creating URI templates. This
213
+ * allows for custom URI template parsing and variable extraction.
214
+ * @param uriTemplateManagerFactory The factory to use. Must not be null.
215
+ * @return This builder instance for method chaining
216
+ * @throws IllegalArgumentException if uriTemplateManagerFactory is null
217
+ */
218
+ public AsyncSpecification uriTemplateManagerFactory (McpUriTemplateManagerFactory uriTemplateManagerFactory ) {
219
+ Assert .notNull (uriTemplateManagerFactory , "URI template manager factory must not be null" );
220
+ this .uriTemplateManagerFactory = uriTemplateManagerFactory ;
221
+ return this ;
222
+ }
223
+
207
224
/**
208
225
* Sets the duration to wait for server responses before timing out requests. This
209
226
* timeout applies to all requests made through the client, including tool calls,
@@ -617,7 +634,8 @@ public McpAsyncServer build() {
617
634
this .resources , this .resourceTemplates , this .prompts , this .completions , this .rootsChangeHandlers ,
618
635
this .instructions );
619
636
var mapper = this .objectMapper != null ? this .objectMapper : new ObjectMapper ();
620
- return new McpAsyncServer (this .transportProvider , mapper , features , this .requestTimeout );
637
+ return new McpAsyncServer (this .transportProvider , mapper , features , this .requestTimeout ,
638
+ this .uriTemplateManagerFactory );
621
639
}
622
640
623
641
}
@@ -630,6 +648,8 @@ class SyncSpecification {
630
648
private static final McpSchema .Implementation DEFAULT_SERVER_INFO = new McpSchema .Implementation ("mcp-server" ,
631
649
"1.0.0" );
632
650
651
+ private McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory ();
652
+
633
653
private final McpServerTransportProvider transportProvider ;
634
654
635
655
private ObjectMapper objectMapper ;
@@ -680,6 +700,19 @@ private SyncSpecification(McpServerTransportProvider transportProvider) {
680
700
this .transportProvider = transportProvider ;
681
701
}
682
702
703
+ /**
704
+ * Sets the URI template manager factory to use for creating URI templates. This
705
+ * allows for custom URI template parsing and variable extraction.
706
+ * @param uriTemplateManagerFactory The factory to use. Must not be null.
707
+ * @return This builder instance for method chaining
708
+ * @throws IllegalArgumentException if uriTemplateManagerFactory is null
709
+ */
710
+ public SyncSpecification uriTemplateManagerFactory (McpUriTemplateManagerFactory uriTemplateManagerFactory ) {
711
+ Assert .notNull (uriTemplateManagerFactory , "URI template manager factory must not be null" );
712
+ this .uriTemplateManagerFactory = uriTemplateManagerFactory ;
713
+ return this ;
714
+ }
715
+
683
716
/**
684
717
* Sets the duration to wait for server responses before timing out requests. This
685
718
* timeout applies to all requests made through the client, including tool calls,
@@ -1094,7 +1127,8 @@ public McpSyncServer build() {
1094
1127
this .rootsChangeHandlers , this .instructions );
1095
1128
McpServerFeatures .Async asyncFeatures = McpServerFeatures .Async .fromSync (syncFeatures );
1096
1129
var mapper = this .objectMapper != null ? this .objectMapper : new ObjectMapper ();
1097
- var asyncServer = new McpAsyncServer (this .transportProvider , mapper , asyncFeatures , this .requestTimeout );
1130
+ var asyncServer = new McpAsyncServer (this .transportProvider , mapper , asyncFeatures , this .requestTimeout ,
1131
+ this .uriTemplateManagerFactory );
1098
1132
1099
1133
return new McpSyncServer (asyncServer );
1100
1134
}
0 commit comments