3636import io .modelcontextprotocol .json .McpJsonMapper ;
3737import io .modelcontextprotocol .spec .McpSchema ;
3838import java .util .List ;
39+ import org .junit .After ;
3940import org .junit .Rule ;
4041import org .junit .Test ;
4142import org .junit .runner .RunWith ;
@@ -52,6 +53,11 @@ public class McpToolsetTest {
5253 @ Mock private McpSyncClient mockMcpSyncClient ;
5354 @ Mock private ReadonlyContext mockReadonlyContext ;
5455
56+ @ After
57+ public void restoreConfigStdioDefault () {
58+ McpToolset .setAllowConfigStdioServers (true );
59+ }
60+
5561 private static final McpJsonMapper jsonMapper = McpJsonDefaults .getMapper ();
5662
5763 private static final ImmutableMap <String , Object > STDIO_SERVER_PARAMS =
@@ -211,6 +217,69 @@ public void testFromConfig_validStdioConnectionParams_createsToolset()
211217 assertThat (toolset ).isNotNull ();
212218 }
213219
220+ @ Test
221+ public void testFromConfig_stdioServerParams_rejectedWhenDisallowed () {
222+ McpToolset .setAllowConfigStdioServers (false );
223+ BaseTool .ToolArgsConfig args = new BaseTool .ToolArgsConfig ();
224+ args .put ("stdioServerParams" , STDIO_SERVER_PARAMS );
225+
226+ BaseTool .ToolConfig config = new BaseTool .ToolConfig ("mcp_toolset" , args );
227+ String configPath = "/path/to/config.yaml" ;
228+
229+ ConfigurationException exception =
230+ assertThrows (ConfigurationException .class , () -> McpToolset .fromConfig (config , configPath ));
231+
232+ assertThat (exception )
233+ .hasMessageThat ()
234+ .contains ("Refusing to start a local MCP server declared in an agent config" );
235+ }
236+
237+ @ Test
238+ public void testFromConfig_stdioConnectionParams_rejectedWhenDisallowed () {
239+ McpToolset .setAllowConfigStdioServers (false );
240+ BaseTool .ToolArgsConfig args = new BaseTool .ToolArgsConfig ();
241+ args .put (
242+ "stdioConnectionParams" ,
243+ ImmutableMap .of ("timeout" , 10f , "serverParams" , STDIO_SERVER_PARAMS ));
244+
245+ BaseTool .ToolConfig config = new BaseTool .ToolConfig ("mcp_toolset" , args );
246+ String configPath = "/path/to/config.yaml" ;
247+
248+ ConfigurationException exception =
249+ assertThrows (ConfigurationException .class , () -> McpToolset .fromConfig (config , configPath ));
250+
251+ assertThat (exception )
252+ .hasMessageThat ()
253+ .contains ("Refusing to start a local MCP server declared in an agent config" );
254+ }
255+
256+ @ Test
257+ public void testFromConfig_stdioServerParams_allowedByDefault () throws ConfigurationException {
258+ BaseTool .ToolArgsConfig args = new BaseTool .ToolArgsConfig ();
259+ args .put ("stdioServerParams" , STDIO_SERVER_PARAMS );
260+
261+ BaseTool .ToolConfig config = new BaseTool .ToolConfig ("mcp_toolset" , args );
262+ String configPath = "/path/to/config.yaml" ;
263+
264+ McpToolset toolset = McpToolset .fromConfig (config , configPath );
265+
266+ assertThat (toolset ).isNotNull ();
267+ }
268+
269+ @ Test
270+ public void testFromConfig_sseParams_unaffectedByStdioRejection () throws ConfigurationException {
271+ McpToolset .setAllowConfigStdioServers (false );
272+ BaseTool .ToolArgsConfig args = new BaseTool .ToolArgsConfig ();
273+ args .put ("sseServerParams" , ImmutableMap .of ("url" , "http://localhost:8080" ));
274+
275+ BaseTool .ToolConfig config = new BaseTool .ToolConfig ("mcp_toolset" , args );
276+ String configPath = "/path/to/config.yaml" ;
277+
278+ McpToolset toolset = McpToolset .fromConfig (config , configPath );
279+
280+ assertThat (toolset ).isNotNull ();
281+ }
282+
214283 @ Test
215284 public void testFromConfig_onlySseParams_doesNotUseStdioBranch () throws ConfigurationException {
216285 // This test ensures that when only SSE params are provided, the SSE branch is taken
0 commit comments