2828//! -H 'content-type: application/json' \
2929//! -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_agent_weather_city","arguments":{"city":"Istanbul"}}}'
3030
31+ #[ cfg( not( any( feature = "protocol-mcp" , feature = "mcp" ) ) ) ]
32+ fn main ( ) {
33+ eprintln ! (
34+ "Run this example with MCP support enabled:\n cargo run -p rustapi-rs --example mcp_tools --features protocol-mcp"
35+ ) ;
36+ }
37+
38+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
3139use rustapi_rs:: prelude:: * ;
40+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
3241use rustapi_rs:: protocol:: mcp:: {
3342 run_rustapi_and_mcp_with_shutdown, InvocationMode , McpConfig , McpServer ,
3443} ;
44+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
3545use serde:: { Deserialize , Serialize } ;
3646
47+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
3748#[ derive( Serialize , Schema ) ]
3849struct Weather {
3950 city : String ,
4051 temperature : i32 ,
4152 unit : & ' static str ,
4253}
4354
55+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
4456#[ derive( Deserialize , Serialize , Schema ) ]
4557struct SumRequest {
4658 a : i32 ,
4759 b : i32 ,
4860}
4961
62+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
5063#[ derive( Serialize , Schema ) ]
5164struct SumResponse {
5265 sum : i32 ,
5366}
5467
5568/// This route will be exposed as an MCP tool because of the "agent" tag.
69+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
5670#[ rustapi_rs:: get( "/agent/weather/{city}" ) ]
5771#[ rustapi_rs:: tag( "agent" ) ]
5872#[ rustapi_rs:: summary( "Get weather information for a city" ) ]
@@ -65,6 +79,7 @@ async fn get_weather(Path(city): Path<String>) -> Json<Weather> {
6579}
6680
6781/// Another exposed tool (POST with JSON body).
82+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
6883#[ rustapi_rs:: post( "/agent/sum" ) ]
6984#[ rustapi_rs:: tag( "agent" ) ]
7085#[ rustapi_rs:: summary( "Add two integers and return the result" ) ]
@@ -73,11 +88,13 @@ async fn sum(Json(req): Json<SumRequest>) -> Json<SumResponse> {
7388}
7489
7590/// This route is deliberately NOT tagged — it will NOT appear in MCP discovery.
91+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
7692#[ rustapi_rs:: get( "/admin/internal-config" ) ]
7793async fn internal_only ( ) -> & ' static str {
7894 "this-should-never-be-visible-to-agents"
7995}
8096
97+ #[ cfg( any( feature = "protocol-mcp" , feature = "mcp" ) ) ]
8198#[ tokio:: main]
8299async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error + Send + Sync > > {
83100 let app = RustApi :: auto ( ) ;
0 commit comments