1919import io .modelcontextprotocol .spec .McpSchema .ResourceTemplate ;
2020import io .modelcontextprotocol .spec .McpServerTransportProvider ;
2121import io .modelcontextprotocol .util .Assert ;
22+ import io .modelcontextprotocol .util .DeafaultMcpUriTemplateManagerFactory ;
23+ import io .modelcontextprotocol .util .McpUriTemplateManagerFactory ;
2224import reactor .core .publisher .Mono ;
2325
2426/**
@@ -156,6 +158,8 @@ class AsyncSpecification {
156158
157159 private final McpServerTransportProvider transportProvider ;
158160
161+ private McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory ();
162+
159163 private ObjectMapper objectMapper ;
160164
161165 private McpSchema .Implementation serverInfo = DEFAULT_SERVER_INFO ;
@@ -204,6 +208,19 @@ private AsyncSpecification(McpServerTransportProvider transportProvider) {
204208 this .transportProvider = transportProvider ;
205209 }
206210
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+
207224 /**
208225 * Sets the duration to wait for server responses before timing out requests. This
209226 * timeout applies to all requests made through the client, including tool calls,
@@ -617,7 +634,8 @@ public McpAsyncServer build() {
617634 this .resources , this .resourceTemplates , this .prompts , this .completions , this .rootsChangeHandlers ,
618635 this .instructions );
619636 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 );
621639 }
622640
623641 }
@@ -630,6 +648,8 @@ class SyncSpecification {
630648 private static final McpSchema .Implementation DEFAULT_SERVER_INFO = new McpSchema .Implementation ("mcp-server" ,
631649 "1.0.0" );
632650
651+ private McpUriTemplateManagerFactory uriTemplateManagerFactory = new DeafaultMcpUriTemplateManagerFactory ();
652+
633653 private final McpServerTransportProvider transportProvider ;
634654
635655 private ObjectMapper objectMapper ;
@@ -680,6 +700,19 @@ private SyncSpecification(McpServerTransportProvider transportProvider) {
680700 this .transportProvider = transportProvider ;
681701 }
682702
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+
683716 /**
684717 * Sets the duration to wait for server responses before timing out requests. This
685718 * timeout applies to all requests made through the client, including tool calls,
@@ -1094,7 +1127,8 @@ public McpSyncServer build() {
10941127 this .rootsChangeHandlers , this .instructions );
10951128 McpServerFeatures .Async asyncFeatures = McpServerFeatures .Async .fromSync (syncFeatures );
10961129 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 );
10981132
10991133 return new McpSyncServer (asyncServer );
11001134 }
0 commit comments