11use anyhow:: Error ;
22use rmcp:: { ServiceExt , transport:: TokioChildProcess } ;
3- use serde_json:: json ;
3+ use serde_json:: Value ;
44use std:: { env, process:: Command } ;
55use trustify_test_context:: subset:: ContainsSubset ;
66
7- #[ test]
8- fn tools_list_mcp_inspector ( ) {
9- let inspector_commmand = format ! (
10- "npx @modelcontextprotocol/inspector --cli {} --method tools/list" ,
11- env!( "CARGO_BIN_EXE_stdio" )
12- ) ;
13- log:: debug!( "inspector command: {}" , inspector_commmand) ;
14- let output = Command :: new ( "sh" )
15- . arg ( "-c" )
16- . arg ( inspector_commmand)
17- . env ( "API_URL" , "" )
18- . env ( "OPENID_ISSUER_URL" , "" )
19- . env ( "OPENID_CLIENT_ID" , "" )
20- . env ( "OPENID_CLIENT_SECRET" , "" )
21- . output ( )
22- . expect ( "failed to execute process" ) ;
23-
24- let result = serde_json:: from_str ( str:: from_utf8 ( & output. stdout ) . unwrap_or_default ( ) )
25- . unwrap_or_default ( ) ;
26- log:: debug!( "{:#?}" , result) ;
27- log:: debug!( "{:#?}" , str :: from_utf8( & output. stderr) . unwrap_or_default( ) ) ;
28- let expected_result = json ! ( {
7+ const EXPECTED_TOOLS_LIST_RESPONSE : & str = r#"{
298 "tools": [
309 {
3110 "name": "trustify_vulnerabilities_list",
@@ -261,10 +240,47 @@ fn tools_list_mcp_inspector() {
261240 }
262241 }
263242 ]
264- } ) ;
243+ }"# ;
244+
245+ #[ test]
246+ fn tools_list_mcp_inspector_stdio ( ) {
247+ let inspector_commmand = format ! (
248+ "npx @modelcontextprotocol/inspector --cli {} --method tools/list" ,
249+ env!( "CARGO_BIN_EXE_stdio" )
250+ ) ;
251+ log:: debug!( "inspector command: {}" , inspector_commmand) ;
252+ let output = Command :: new ( "sh" )
253+ . arg ( "-c" )
254+ . arg ( inspector_commmand)
255+ . env ( "API_URL" , "" )
256+ . env ( "OPENID_ISSUER_URL" , "" )
257+ . env ( "OPENID_CLIENT_ID" , "" )
258+ . env ( "OPENID_CLIENT_SECRET" , "" )
259+ . output ( )
260+ . expect ( "failed to execute process" ) ;
261+
262+ let result = serde_json:: from_str ( str:: from_utf8 ( & output. stdout ) . unwrap_or_default ( ) )
263+ . unwrap_or_default ( ) ;
264+ log:: debug!( "{:#?}" , result) ;
265+ log:: debug!( "{:#?}" , str :: from_utf8( & output. stderr) . unwrap_or_default( ) ) ;
266+ let expected_result: Value =
267+ serde_json:: from_str ( EXPECTED_TOOLS_LIST_RESPONSE ) . unwrap_or_default ( ) ;
265268 assert ! ( expected_result. contains_subset( result) ) ;
266269}
267270
271+ #[ test]
272+ fn tools_list_mcp_inspector_sse ( ) -> Result < ( ) , Error > {
273+ run_server_test ( env ! ( "CARGO_BIN_EXE_sse" ) , "http://localhost:8081/sse" )
274+ }
275+
276+ #[ test]
277+ fn tools_list_mcp_inspector_streamable_http ( ) -> Result < ( ) , Error > {
278+ run_server_test (
279+ env ! ( "CARGO_BIN_EXE_streamable" ) ,
280+ "http://localhost:8000/mcp --transport http" ,
281+ )
282+ }
283+
268284#[ tokio:: test]
269285async fn tools_list_mcp_client ( ) -> Result < ( ) , Error > {
270286 let mut command = tokio:: process:: Command :: new ( env ! ( "CARGO_BIN_EXE_stdio" ) ) ;
@@ -288,3 +304,33 @@ async fn tools_list_mcp_client() -> Result<(), Error> {
288304
289305 Ok ( ( ) )
290306}
307+
308+ fn run_server_test ( server_command : & str , inspector_cli_parameter : & str ) -> Result < ( ) , Error > {
309+ let mut server = Command :: new ( "sh" )
310+ . arg ( "-c" )
311+ . arg ( server_command)
312+ . env ( "API_URL" , "" )
313+ . env ( "OPENID_ISSUER_URL" , "" )
314+ . env ( "OPENID_CLIENT_ID" , "" )
315+ . env ( "OPENID_CLIENT_SECRET" , "" )
316+ . spawn ( ) ?;
317+
318+ let inspector_commmand = format ! (
319+ "npx @modelcontextprotocol/inspector --cli {} --method tools/list" ,
320+ inspector_cli_parameter
321+ ) ;
322+ log:: debug!( "inspector command: {}" , inspector_commmand) ;
323+ let output = Command :: new ( "sh" )
324+ . arg ( "-c" )
325+ . arg ( inspector_commmand)
326+ . output ( ) ?;
327+
328+ let result: Value = serde_json:: from_str ( str:: from_utf8 ( & output. stdout ) ?) ?;
329+ log:: debug!( "{:#?}" , result) ;
330+
331+ let expected_result: Value = serde_json:: from_str ( EXPECTED_TOOLS_LIST_RESPONSE ) ?;
332+ assert ! ( expected_result. contains_subset( result) ) ;
333+
334+ server. kill ( ) ?;
335+ Ok ( ( ) )
336+ }
0 commit comments