2525import io .modelcontextprotocol .util .Assert ;
2626import io .modelcontextprotocol .util .DefaultMcpUriTemplateManagerFactory ;
2727import io .modelcontextprotocol .util .McpUriTemplateManagerFactory ;
28+ import io .modelcontextprotocol .util .ToolInputValidator ;
2829import io .modelcontextprotocol .util .ToolNameValidator ;
2930import reactor .core .publisher .Mono ;
3031
@@ -243,7 +244,7 @@ public McpAsyncServer build() {
243244 : McpJsonDefaults .getSchemaValidator ();
244245
245246 return new McpAsyncServer (transportProvider , jsonMapper == null ? McpJsonDefaults .getMapper () : jsonMapper ,
246- features , requestTimeout , uriTemplateManagerFactory , jsonSchemaValidator );
247+ features , requestTimeout , uriTemplateManagerFactory , jsonSchemaValidator , validateToolInputs );
247248 }
248249
249250 }
@@ -269,7 +270,7 @@ public McpAsyncServer build() {
269270 var jsonSchemaValidator = this .jsonSchemaValidator != null ? this .jsonSchemaValidator
270271 : McpJsonDefaults .getSchemaValidator ();
271272 return new McpAsyncServer (transportProvider , jsonMapper == null ? McpJsonDefaults .getMapper () : jsonMapper ,
272- features , requestTimeout , uriTemplateManagerFactory , jsonSchemaValidator );
273+ features , requestTimeout , uriTemplateManagerFactory , jsonSchemaValidator , validateToolInputs );
273274 }
274275
275276 }
@@ -293,6 +294,8 @@ abstract class AsyncSpecification<S extends AsyncSpecification<S>> {
293294
294295 boolean strictToolNameValidation = ToolNameValidator .isStrictByDefault ();
295296
297+ boolean validateToolInputs = ToolInputValidator .isEnabledByDefault ();
298+
296299 /**
297300 * The Model Context Protocol (MCP) allows servers to expose tools that can be
298301 * invoked by language models. Tools enable models to interact with external
@@ -421,6 +424,18 @@ public AsyncSpecification<S> strictToolNameValidation(boolean strict) {
421424 return this ;
422425 }
423426
427+ /**
428+ * Sets whether to validate tool inputs against the tool's input schema. When set,
429+ * this takes priority over the system property
430+ * {@code io.modelcontextprotocol.validateToolInputs}.
431+ * @param validate true to validate inputs and return error on validation failure
432+ * @return This builder instance for method chaining
433+ */
434+ public AsyncSpecification <S > validateToolInputs (boolean validate ) {
435+ this .validateToolInputs = validate ;
436+ return this ;
437+ }
438+
424439 /**
425440 * Sets the server capabilities that will be advertised to clients during
426441 * connection initialization. Capabilities define what features the server
@@ -818,7 +833,8 @@ public McpSyncServer build() {
818833 var asyncServer = new McpAsyncServer (transportProvider ,
819834 jsonMapper == null ? McpJsonDefaults .getMapper () : jsonMapper , asyncFeatures , requestTimeout ,
820835 uriTemplateManagerFactory ,
821- jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults .getSchemaValidator ());
836+ jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults .getSchemaValidator (),
837+ validateToolInputs );
822838 return new McpSyncServer (asyncServer , this .immediateExecution );
823839 }
824840
@@ -849,7 +865,7 @@ public McpSyncServer build() {
849865 : McpJsonDefaults .getSchemaValidator ();
850866 var asyncServer = new McpAsyncServer (transportProvider ,
851867 jsonMapper == null ? McpJsonDefaults .getMapper () : jsonMapper , asyncFeatures , this .requestTimeout ,
852- this .uriTemplateManagerFactory , jsonSchemaValidator );
868+ this .uriTemplateManagerFactory , jsonSchemaValidator , validateToolInputs );
853869 return new McpSyncServer (asyncServer , this .immediateExecution );
854870 }
855871
@@ -872,6 +888,8 @@ abstract class SyncSpecification<S extends SyncSpecification<S>> {
872888
873889 boolean strictToolNameValidation = ToolNameValidator .isStrictByDefault ();
874890
891+ boolean validateToolInputs = ToolInputValidator .isEnabledByDefault ();
892+
875893 /**
876894 * The Model Context Protocol (MCP) allows servers to expose tools that can be
877895 * invoked by language models. Tools enable models to interact with external
@@ -1004,6 +1022,18 @@ public SyncSpecification<S> strictToolNameValidation(boolean strict) {
10041022 return this ;
10051023 }
10061024
1025+ /**
1026+ * Sets whether to validate tool inputs against the tool's input schema. When set,
1027+ * this takes priority over the system property
1028+ * {@code io.modelcontextprotocol.validateToolInputs}.
1029+ * @param validate true to validate inputs and return error on validation failure
1030+ * @return This builder instance for method chaining
1031+ */
1032+ public SyncSpecification <S > validateToolInputs (boolean validate ) {
1033+ this .validateToolInputs = validate ;
1034+ return this ;
1035+ }
1036+
10071037 /**
10081038 * Sets the server capabilities that will be advertised to clients during
10091039 * connection initialization. Capabilities define what features the server
@@ -1401,6 +1431,8 @@ class StatelessAsyncSpecification {
14011431
14021432 boolean strictToolNameValidation = ToolNameValidator .isStrictByDefault ();
14031433
1434+ boolean validateToolInputs = ToolInputValidator .isEnabledByDefault ();
1435+
14041436 /**
14051437 * The Model Context Protocol (MCP) allows servers to expose tools that can be
14061438 * invoked by language models. Tools enable models to interact with external
@@ -1530,6 +1562,18 @@ public StatelessAsyncSpecification strictToolNameValidation(boolean strict) {
15301562 return this ;
15311563 }
15321564
1565+ /**
1566+ * Sets whether to validate tool inputs against the tool's input schema. When set,
1567+ * this takes priority over the system property
1568+ * {@code io.modelcontextprotocol.validateToolInputs}.
1569+ * @param validate true to validate inputs and return error on validation failure
1570+ * @return This builder instance for method chaining
1571+ */
1572+ public StatelessAsyncSpecification validateToolInputs (boolean validate ) {
1573+ this .validateToolInputs = validate ;
1574+ return this ;
1575+ }
1576+
15331577 /**
15341578 * Sets the server capabilities that will be advertised to clients during
15351579 * connection initialization. Capabilities define what features the server
@@ -1859,7 +1903,8 @@ public McpStatelessAsyncServer build() {
18591903 this .resources , this .resourceTemplates , this .prompts , this .completions , this .instructions );
18601904 return new McpStatelessAsyncServer (transport , jsonMapper == null ? McpJsonDefaults .getMapper () : jsonMapper ,
18611905 features , requestTimeout , uriTemplateManagerFactory ,
1862- jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults .getSchemaValidator ());
1906+ jsonSchemaValidator != null ? jsonSchemaValidator : McpJsonDefaults .getSchemaValidator (),
1907+ validateToolInputs );
18631908 }
18641909
18651910 }
@@ -1884,6 +1929,8 @@ class StatelessSyncSpecification {
18841929
18851930 boolean strictToolNameValidation = ToolNameValidator .isStrictByDefault ();
18861931
1932+ boolean validateToolInputs = ToolInputValidator .isEnabledByDefault ();
1933+
18871934 /**
18881935 * The Model Context Protocol (MCP) allows servers to expose tools that can be
18891936 * invoked by language models. Tools enable models to interact with external
@@ -2013,6 +2060,18 @@ public StatelessSyncSpecification strictToolNameValidation(boolean strict) {
20132060 return this ;
20142061 }
20152062
2063+ /**
2064+ * Sets whether to validate tool inputs against the tool's input schema. When set,
2065+ * this takes priority over the system property
2066+ * {@code io.modelcontextprotocol.validateToolInputs}.
2067+ * @param validate true to validate inputs and return error on validation failure
2068+ * @return This builder instance for method chaining
2069+ */
2070+ public StatelessSyncSpecification validateToolInputs (boolean validate ) {
2071+ this .validateToolInputs = validate ;
2072+ return this ;
2073+ }
2074+
20162075 /**
20172076 * Sets the server capabilities that will be advertised to clients during
20182077 * connection initialization. Capabilities define what features the server
@@ -2360,7 +2419,8 @@ public McpStatelessSyncServer build() {
23602419 var asyncServer = new McpStatelessAsyncServer (transport ,
23612420 jsonMapper == null ? McpJsonDefaults .getMapper () : jsonMapper , asyncFeatures , requestTimeout ,
23622421 uriTemplateManagerFactory ,
2363- this .jsonSchemaValidator != null ? this .jsonSchemaValidator : McpJsonDefaults .getSchemaValidator ());
2422+ this .jsonSchemaValidator != null ? this .jsonSchemaValidator : McpJsonDefaults .getSchemaValidator (),
2423+ validateToolInputs );
23642424 return new McpStatelessSyncServer (asyncServer , this .immediateExecution );
23652425 }
23662426
0 commit comments