Skip to content

Commit 1bb118d

Browse files
authored
Updating to rmcp 0.3 (#31)
1 parent 3fa6f32 commit 1bb118d

File tree

6 files changed

+116
-35
lines changed

6 files changed

+116
-35
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- pull_request
66

77
env:
8-
CARGO_PKG_VERSION: "0.1.${{ github.run_number }}"
8+
CARGO_PKG_VERSION: "0.2.${{ github.run_number }}"
99

1010
permissions:
1111
contents: write

Cargo.lock

Lines changed: 73 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66
license = "MIT"
77

88
[dependencies]
9-
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", rev = "db03f63e76b5b32f65d34a1bd08ae56dab595f60", features = ["server", "transport-io"] }
9+
rmcp = { version = "0.3", features = ["server", "transport-io"] }
1010
tokio = { version = "1", features = ["full"] }
1111
serde = { version = "1.0", features = ["derive"] }
1212
serde_json = "1.0"

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use librojo::cli;
33
fn main() {
44
let out_dir = std::env::var_os("OUT_DIR").unwrap();
55
let dest_path = std::path::PathBuf::from(&out_dir).join("MCPStudioPlugin.rbxm");
6-
eprintln!("Rebuilding plugin: {:?}", dest_path);
6+
eprintln!("Rebuilding plugin: {dest_path:?}");
77
let options = cli::Options {
88
global: cli::GlobalOptions {
99
verbosity: 1,

src/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async fn install_internal() -> Result<String> {
151151

152152
println!();
153153
let msg = get_message(successes.join("\n"));
154-
println!("{}", msg);
154+
println!("{msg}");
155155
Ok(msg)
156156
}
157157

@@ -171,7 +171,7 @@ pub async fn install() -> Result<()> {
171171
let alert_builder = match install_internal().await {
172172
Err(e) => DialogBuilder::message()
173173
.set_level(MessageLevel::Error)
174-
.set_text(format!("Errors occurred: {:#}", e)),
174+
.set_text(format!("Errors occurred: {e:#}")),
175175
Ok(msg) => DialogBuilder::message()
176176
.set_level(MessageLevel::Info)
177177
.set_text(msg),

src/rbx_studio_server.rs

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ use axum::http::StatusCode;
33
use axum::response::IntoResponse;
44
use axum::{extract::State, Json};
55
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,
912
};
10-
use rmcp::tool;
11-
use rmcp::{Error as McpError, ServerHandler};
1213
use serde::{Deserialize, Serialize};
1314
use std::collections::{HashMap, VecDeque};
15+
use std::future::Future;
1416
use std::sync::Arc;
1517
use tokio::sync::oneshot::Receiver;
1618
use tokio::sync::{mpsc, watch, Mutex};
@@ -70,9 +72,10 @@ impl ToolArguments {
7072
#[derive(Clone)]
7173
pub struct RBXStudioServer {
7274
state: PackedState,
75+
tool_router: rmcp::handler::server::tool::ToolRouter<Self>,
7376
}
7477

75-
#[tool(tool_box)]
78+
#[tool_handler]
7679
impl ServerHandler for RBXStudioServer {
7780
fn get_info(&self) -> ServerInfo {
7881
ServerInfo {
@@ -87,27 +90,39 @@ impl ServerHandler for RBXStudioServer {
8790
}
8891
}
8992

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)]
91105
enum ToolArgumentValues {
92-
RunCode { command: String },
93-
InsertModel { query: String },
106+
RunCode(RunCode),
107+
InsertModel(InsertModel),
94108
}
95-
#[tool(tool_box)]
109+
#[tool_router]
96110
impl RBXStudioServer {
97111
pub fn new(state: PackedState) -> Self {
98-
Self { state }
112+
Self {
113+
state,
114+
tool_router: Self::tool_router(),
115+
}
99116
}
100117

101118
#[tool(
102119
description = "Runs a command in Roblox Studio and returns the printed output. Can be used to both make changes and retrieve information"
103120
)]
104121
async fn run_code(
105122
&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))
111126
.await
112127
}
113128

@@ -116,15 +131,16 @@ impl RBXStudioServer {
116131
)]
117132
async fn insert_model(
118133
&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))
124137
.await
125138
}
126139

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> {
128144
let (command, id) = ToolArguments::new(args);
129145
tracing::debug!("Running command: {:?}", command);
130146
let (tx, mut rx) = mpsc::unbounded_channel::<Result<String>>();

0 commit comments

Comments
 (0)