@@ -3,14 +3,16 @@ use axum::http::StatusCode;
3
3
use axum:: response:: IntoResponse ;
4
4
use axum:: { extract:: State , Json } ;
5
5
use color_eyre:: eyre:: { Error , OptionExt } ;
6
- use rmcp:: model:: {
7
- CallToolResult , Content , ErrorData , Implementation , ProtocolVersion , ServerCapabilities ,
8
- ServerInfo ,
6
+ use rmcp:: {
7
+ handler:: server:: tool:: Parameters ,
8
+ model:: {
9
+ CallToolResult , Content , Implementation , ProtocolVersion , ServerCapabilities , ServerInfo ,
10
+ } ,
11
+ schemars, tool, tool_handler, tool_router, ErrorData , ServerHandler ,
9
12
} ;
10
- use rmcp:: tool;
11
- use rmcp:: { Error as McpError , ServerHandler } ;
12
13
use serde:: { Deserialize , Serialize } ;
13
14
use std:: collections:: { HashMap , VecDeque } ;
15
+ use std:: future:: Future ;
14
16
use std:: sync:: Arc ;
15
17
use tokio:: sync:: oneshot:: Receiver ;
16
18
use tokio:: sync:: { mpsc, watch, Mutex } ;
@@ -70,9 +72,10 @@ impl ToolArguments {
70
72
#[ derive( Clone ) ]
71
73
pub struct RBXStudioServer {
72
74
state : PackedState ,
75
+ tool_router : rmcp:: handler:: server:: tool:: ToolRouter < Self > ,
73
76
}
74
77
75
- #[ tool ( tool_box ) ]
78
+ #[ tool_handler ]
76
79
impl ServerHandler for RBXStudioServer {
77
80
fn get_info ( & self ) -> ServerInfo {
78
81
ServerInfo {
@@ -87,27 +90,39 @@ impl ServerHandler for RBXStudioServer {
87
90
}
88
91
}
89
92
90
- #[ derive( Deserialize , Serialize , Clone , Debug ) ]
93
+ #[ derive( Debug , Deserialize , Serialize , schemars:: JsonSchema , Clone ) ]
94
+ struct RunCode {
95
+ #[ schemars( description = "Code to run" ) ]
96
+ command : String ,
97
+ }
98
+ #[ derive( Debug , Deserialize , Serialize , schemars:: JsonSchema , Clone ) ]
99
+ struct InsertModel {
100
+ #[ schemars( description = "Query to search for the model" ) ]
101
+ query : String ,
102
+ }
103
+
104
+ #[ derive( Debug , Deserialize , Serialize , schemars:: JsonSchema , Clone ) ]
91
105
enum ToolArgumentValues {
92
- RunCode { command : String } ,
93
- InsertModel { query : String } ,
106
+ RunCode ( RunCode ) ,
107
+ InsertModel ( InsertModel ) ,
94
108
}
95
- #[ tool ( tool_box ) ]
109
+ #[ tool_router ]
96
110
impl RBXStudioServer {
97
111
pub fn new ( state : PackedState ) -> Self {
98
- Self { state }
112
+ Self {
113
+ state,
114
+ tool_router : Self :: tool_router ( ) ,
115
+ }
99
116
}
100
117
101
118
#[ tool(
102
119
description = "Runs a command in Roblox Studio and returns the printed output. Can be used to both make changes and retrieve information"
103
120
) ]
104
121
async fn run_code (
105
122
& self ,
106
- #[ tool( param) ]
107
- #[ schemars( description = "code to run" ) ]
108
- command : String ,
109
- ) -> Result < CallToolResult , McpError > {
110
- self . generic_tool_run ( ToolArgumentValues :: RunCode { command } )
123
+ Parameters ( args) : Parameters < RunCode > ,
124
+ ) -> Result < CallToolResult , ErrorData > {
125
+ self . generic_tool_run ( ToolArgumentValues :: RunCode ( args) )
111
126
. await
112
127
}
113
128
@@ -116,15 +131,16 @@ impl RBXStudioServer {
116
131
) ]
117
132
async fn insert_model (
118
133
& self ,
119
- #[ tool( param) ]
120
- #[ schemars( description = "Query to search for the model." ) ]
121
- query : String ,
122
- ) -> Result < CallToolResult , McpError > {
123
- self . generic_tool_run ( ToolArgumentValues :: InsertModel { query } )
134
+ Parameters ( args) : Parameters < InsertModel > ,
135
+ ) -> Result < CallToolResult , ErrorData > {
136
+ self . generic_tool_run ( ToolArgumentValues :: InsertModel ( args) )
124
137
. await
125
138
}
126
139
127
- async fn generic_tool_run ( & self , args : ToolArgumentValues ) -> Result < CallToolResult , McpError > {
140
+ async fn generic_tool_run (
141
+ & self ,
142
+ args : ToolArgumentValues ,
143
+ ) -> Result < CallToolResult , ErrorData > {
128
144
let ( command, id) = ToolArguments :: new ( args) ;
129
145
tracing:: debug!( "Running command: {:?}" , command) ;
130
146
let ( tx, mut rx) = mpsc:: unbounded_channel :: < Result < String > > ( ) ;
0 commit comments