Skip to content

Commit 2aa469b

Browse files
authored
refactor!: naming & less constrained dependencies (#8)
* Changed naming to adhere to official Rust API guidelines. * Re-renamed handle_get_prompt_request(), see #8.
1 parent e00913a commit 2aa469b

File tree

32 files changed

+250
-252
lines changed

32 files changed

+250
-252
lines changed

crates/rust-mcp-macros/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A procedural macro, part of the [rust-mcp-sdk](https://github.com/rust-mcp-stack
55
The `mcp_tool` macro generates an implementation for the annotated struct that includes:
66

77
- A `tool_name()` method returning the tool's name as a string.
8-
- A `get_tool()` method returning a `rust_mcp_schema::Tool` instance with the tool's name,
8+
- A `tool()` method returning a `rust_mcp_schema::Tool` instance with the tool's name,
99
description, and input schema derived from the struct's fields.
1010

1111
## Attributes
@@ -32,7 +32,7 @@ fn main() {
3232

3333
assert_eq!(WriteFileTool::tool_name(), "write_file");
3434

35-
let tool: rust_mcp_schema::Tool = WriteFileTool::get_tool();
35+
let tool: rust_mcp_schema::Tool = WriteFileTool::tool();
3636
assert_eq!(tool.name, "write_file");
3737
assert_eq!( tool.description.unwrap(),"Create a new file or completely overwrite an existing file with new content.");
3838

crates/rust-mcp-macros/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use utils::{is_option, renamed_field, type_to_json_schema};
1919
/// * `name` - An optional string representing the tool's name.
2020
/// * `description` - An optional string describing the tool.
2121
///
22-
struct MCPToolMacroAttributes {
22+
struct McpToolMacroAttributes {
2323
name: Option<String>,
2424
description: Option<String>,
2525
}
2626

27-
impl Parse for MCPToolMacroAttributes {
27+
impl Parse for McpToolMacroAttributes {
2828
/// Parses the macro attributes from a `ParseStream`.
2929
///
3030
/// This implementation extracts `name` and `description` from the attribute input,
@@ -96,7 +96,7 @@ impl Parse for MCPToolMacroAttributes {
9696
///
9797
/// The `mcp_tool` macro generates an implementation for the annotated struct that includes:
9898
/// - A `tool_name()` method returning the tool's name as a string.
99-
/// - A `get_tool()` method returning a `rust_mcp_schema::Tool` instance with the tool's name,
99+
/// - A `tool()` method returning a `rust_mcp_schema::Tool` instance with the tool's name,
100100
/// description, and input schema derived from the struct's fields.
101101
///
102102
/// # Attributes
@@ -116,7 +116,7 @@ impl Parse for MCPToolMacroAttributes {
116116
/// }
117117
///
118118
/// assert_eq!(ExampleTool::tool_name() , "example_tool");
119-
/// let tool : rust_mcp_schema::Tool = ExampleTool::get_tool();
119+
/// let tool : rust_mcp_schema::Tool = ExampleTool::tool();
120120
/// assert_eq!(tool.name , "example_tool");
121121
/// assert_eq!(tool.description.unwrap() , "An example tool");
122122
///
@@ -131,7 +131,7 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {
131131
let input = parse_macro_input!(input as DeriveInput); // Parse the input as a function
132132
let input_ident = &input.ident;
133133

134-
let macro_attributes = parse_macro_input!(attributes as MCPToolMacroAttributes);
134+
let macro_attributes = parse_macro_input!(attributes as McpToolMacroAttributes);
135135

136136
let tool_name = macro_attributes.name.unwrap_or_default();
137137
let tool_description = macro_attributes.description.unwrap_or_default();
@@ -147,7 +147,7 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {
147147
///
148148
/// The tool includes the name, description, and input schema derived from
149149
/// the struct's attributes.
150-
pub fn get_tool()-> rust_mcp_schema::Tool
150+
pub fn tool()-> rust_mcp_schema::Tool
151151
{
152152
let json_schema = &#input_ident::json_schema();
153153

@@ -304,7 +304,7 @@ mod tests {
304304
#[test]
305305
fn test_valid_macro_attributes() {
306306
let input = r#"name = "test_tool", description = "A test tool.""#;
307-
let parsed: MCPToolMacroAttributes = parse_str(input).unwrap();
307+
let parsed: McpToolMacroAttributes = parse_str(input).unwrap();
308308

309309
assert_eq!(parsed.name.unwrap(), "test_tool");
310310
assert_eq!(parsed.description.unwrap(), "A test tool.");
@@ -313,7 +313,7 @@ mod tests {
313313
#[test]
314314
fn test_missing_name() {
315315
let input = r#"description = "Only description""#;
316-
let result: Result<MCPToolMacroAttributes, Error> = parse_str(input);
316+
let result: Result<McpToolMacroAttributes, Error> = parse_str(input);
317317
assert!(result.is_err());
318318
assert_eq!(
319319
result.err().unwrap().to_string(),
@@ -324,7 +324,7 @@ mod tests {
324324
#[test]
325325
fn test_missing_description() {
326326
let input = r#"name = "OnlyName""#;
327-
let result: Result<MCPToolMacroAttributes, Error> = parse_str(input);
327+
let result: Result<McpToolMacroAttributes, Error> = parse_str(input);
328328
assert!(result.is_err());
329329
assert_eq!(
330330
result.err().unwrap().to_string(),
@@ -335,7 +335,7 @@ mod tests {
335335
#[test]
336336
fn test_empty_name_field() {
337337
let input = r#"name = "", description = "something""#;
338-
let result: Result<MCPToolMacroAttributes, Error> = parse_str(input);
338+
let result: Result<McpToolMacroAttributes, Error> = parse_str(input);
339339
assert!(result.is_err());
340340
assert_eq!(
341341
result.err().unwrap().to_string(),
@@ -345,7 +345,7 @@ mod tests {
345345
#[test]
346346
fn test_empty_description_field() {
347347
let input = r#"name = "my-tool", description = """#;
348-
let result: Result<MCPToolMacroAttributes, Error> = parse_str(input);
348+
let result: Result<McpToolMacroAttributes, Error> = parse_str(input);
349349
assert!(result.is_err());
350350
assert_eq!(
351351
result.err().unwrap().to_string(),

crates/rust-mcp-macros/src/utils.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn is_vec(ty: &Type) -> bool {
2828

2929
// Extract the inner type from Vec<T> or Option<T>
3030
#[allow(unused)]
31-
pub fn get_inner_type(ty: &Type) -> Option<&Type> {
31+
pub fn inner_type(ty: &Type) -> Option<&Type> {
3232
if let Type::Path(type_path) = ty {
3333
if type_path.path.segments.len() == 1 {
3434
let segment = &type_path.path.segments[0];
@@ -46,7 +46,7 @@ pub fn get_inner_type(ty: &Type) -> Option<&Type> {
4646
None
4747
}
4848

49-
fn get_doc_comment(attrs: &[Attribute]) -> Option<String> {
49+
fn doc_comment(attrs: &[Attribute]) -> Option<String> {
5050
let mut docs = Vec::new();
5151
for attr in attrs {
5252
if attr.path().is_ident("doc") {
@@ -86,7 +86,7 @@ pub fn type_to_json_schema(ty: &Type, attrs: &[Attribute]) -> proc_macro2::Token
8686
let number_types = [
8787
"i8", "i16", "i32", "i64", "i128", "u8", "u16", "u32", "u64", "u128", "f32", "f64",
8888
];
89-
let doc_comment = get_doc_comment(attrs);
89+
let doc_comment = doc_comment(attrs);
9090
let description = doc_comment.as_ref().map(|desc| {
9191
quote! {
9292
map.insert("description".to_string(), serde_json::Value::String(#desc.to_string()));
@@ -266,21 +266,21 @@ mod tests {
266266
}
267267

268268
#[test]
269-
fn test_get_inner_type() {
269+
fn test_inner_type() {
270270
let ty: Type = parse_quote!(Option<String>);
271-
let inner = get_inner_type(&ty);
271+
let inner = inner_type(&ty);
272272
assert!(inner.is_some());
273273
let inner = inner.unwrap();
274274
assert_eq!(quote!(#inner).to_string(), quote!(String).to_string());
275275

276276
let ty: Type = parse_quote!(Vec<i32>);
277-
let inner = get_inner_type(&ty);
277+
let inner = inner_type(&ty);
278278
assert!(inner.is_some());
279279
let inner = inner.unwrap();
280280
assert_eq!(quote!(#inner).to_string(), quote!(i32).to_string());
281281

282282
let ty: Type = parse_quote!(i32);
283-
assert!(get_inner_type(&ty).is_none());
283+
assert!(inner_type(&ty).is_none());
284284
}
285285

286286
#[test]
@@ -338,7 +338,7 @@ mod tests {
338338
#[test]
339339
fn test_get_doc_comment_single_line() {
340340
let attrs: Vec<Attribute> = vec![parse_quote!(#[doc = "This is a test comment."])];
341-
let result = super::get_doc_comment(&attrs);
341+
let result = super::doc_comment(&attrs);
342342
assert_eq!(result, Some("This is a test comment.".to_string()));
343343
}
344344

@@ -349,7 +349,7 @@ mod tests {
349349
parse_quote!(#[doc = "Line two."]),
350350
parse_quote!(#[doc = "Line three."]),
351351
];
352-
let result = super::get_doc_comment(&attrs);
352+
let result = super::doc_comment(&attrs);
353353
assert_eq!(
354354
result,
355355
Some("Line one.\nLine two.\nLine three.".to_string())
@@ -359,14 +359,14 @@ mod tests {
359359
#[test]
360360
fn test_get_doc_comment_no_doc() {
361361
let attrs: Vec<Attribute> = vec![parse_quote!(#[allow(dead_code)])];
362-
let result = super::get_doc_comment(&attrs);
362+
let result = super::doc_comment(&attrs);
363363
assert_eq!(result, None);
364364
}
365365

366366
#[test]
367367
fn test_get_doc_comment_trim_whitespace() {
368368
let attrs: Vec<Attribute> = vec![parse_quote!(#[doc = " Trimmed line. "])];
369-
let result = super::get_doc_comment(&attrs);
369+
let result = super::doc_comment(&attrs);
370370
assert_eq!(result, Some("Trimmed line.".to_string()));
371371
}
372372

crates/rust-mcp-sdk/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
# Rust MCP SDK
66

7-
A high-performance, asynchronous toolkit for building MCP servers and clients.
7+
A high-performance, asynchronous toolkit for building MCP servers and clients.
88
Focus on your app's logic while **rust-mcp-sdk** takes care of the rest!
99

10-
**rust-mcp-sdk** provides the necessary components for developing both servers and clients in the MCP ecosystem.
10+
**rust-mcp-sdk** provides the necessary components for developing both servers and clients in the MCP ecosystem.
1111
Leveraging the [rust-mcp-schema](https://github.com/rust-mcp-stack/rust-mcp-schema) crate for type safe MCP schema objects and MCP type utilities simplifies the process of building robust and reliable MCP servers and clients, ensuring consistency and minimizing errors in data handling and message processing.
1212

1313
**⚠️WARNING**: This project only supports Standard Input/Output (stdio) transport at this time, with support for SSE (Server-Sent Events) transport still in progress and not yet available. Project is currently under development and should be used at your own risk.
@@ -70,18 +70,18 @@ pub struct MyServerHandler;
7070
#[async_trait]
7171
impl ServerHandler for MyServerHandler {
7272
// Handle ListToolsRequest, return list of available tools as ListToolsResult
73-
async fn handle_list_tools_request(&self, request: ListToolsRequest, runtime: &dyn MCPServer) -> Result<ListToolsResult, RpcError> {
73+
async fn handle_list_tools_request(&self, request: ListToolsRequest, runtime: &dyn McpServer) -> Result<ListToolsResult, RpcError> {
7474

7575
Ok(ListToolsResult {
76-
tools: vec![SayHelloTool::get_tool()],
76+
tools: vec![SayHelloTool::tool()],
7777
meta: None,
7878
next_cursor: None,
7979
})
8080

8181
}
8282

8383
/// Handles requests to call a specific tool.
84-
async fn handle_call_tool_request( &self, request: CallToolRequest, runtime: &dyn MCPServer, ) -> Result<CallToolResult, CallToolError> {
84+
async fn handle_call_tool_request( &self, request: CallToolRequest, runtime: &dyn McpServer, ) -> Result<CallToolResult, CallToolError> {
8585

8686
if request.tool_name() == SayHelloTool::tool_name() {
8787
Ok(CallToolResult::text_content(
@@ -153,7 +153,7 @@ async fn main() -> SdkResult<()> {
153153
// STEP 7: use client methods to communicate with the MCP Server as you wish
154154

155155
// Retrieve and display the list of tools available on the server
156-
let server_version = client.get_server_version().unwrap();
156+
let server_version = client.server_version().unwrap();
157157
let tools = client.list_tools(None).await?.tools;
158158

159159
println!("List of tools for {}@{}", server_version.name, server_version.version);
@@ -195,10 +195,10 @@ If you are looking for a step-by-step tutorial on how to get started with `rust-
195195

196196
[rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of handler traits that you can chose from:
197197

198-
- **mcp_server_handler**: This is the recommended trait for your MCP project, offering a default implementation for all types of MCP messages. It includes predefined implementations within the trait, such as handling initialization or responding to ping requests, so you only need to override and customize the handler functions relevant to your specific needs.
198+
- **mcp_server_handler**: This is the recommended trait for your MCP project, offering a default implementation for all types of MCP messages. It includes predefined implementations within the trait, such as handling initialization or responding to ping requests, so you only need to override and customize the handler functions relevant to your specific needs.
199199
Refer to [examples/hello-world-mcp-server/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server/src/handler.rs) for an example.
200200

201-
- **mcp_server_handler_core**: If you need more control over MCP messages, consider using `mcp_server_handler_core`. It offers three primary methods to manage the three MCP message types: `request`, `notification`, and `error`. While still providing type-safe objects in these methods, it allows you to determine how to handle each message based on its type and parameters.
201+
- **mcp_server_handler_core**: If you need more control over MCP messages, consider using `mcp_server_handler_core`. It offers three primary methods to manage the three MCP message types: `request`, `notification`, and `error`. While still providing type-safe objects in these methods, it allows you to determine how to handle each message based on its type and parameters.
202202
Refer to [examples/hello-world-mcp-server-core/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-core/src/handler.rs) for an example.
203203

204204
---
@@ -209,8 +209,8 @@ If you are looking for a step-by-step tutorial on how to get started with `rust-
209209

210210
### Choosing Between `mcp_client_handler` and `mcp_client_handler_core`
211211

212-
The same principles outlined above apply to the client-side handlers, `mcp_client_handler` and `mcp_client_handler_core`.
213-
Use `client_runtime::create_client()` or `client_runtime_core::create_client()` , respectively.
212+
The same principles outlined above apply to the client-side handlers, `mcp_client_handler` and `mcp_client_handler_core`.
213+
Use `client_runtime::create_client()` or `client_runtime_core::create_client()` , respectively.
214214
Check out the corresponding examples at: [examples/simple-mcp-client](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client) and [examples/simple-mcp-client-core](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client-core).
215215

216216
## License

crates/rust-mcp-sdk/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use rust_mcp_schema::RpcError;
22
use rust_mcp_transport::error::TransportError;
33
use thiserror::Error;
44

5-
pub type SdkResult<T> = core::result::Result<T, MCPSdkError>;
5+
pub type SdkResult<T> = core::result::Result<T, McpSdkError>;
66

77
#[derive(Debug, Error)]
8-
pub enum MCPSdkError {
8+
pub enum McpSdkError {
99
#[error("{0}")]
1010
RpcError(#[from] RpcError),
1111
#[error("{0}")]
@@ -15,7 +15,7 @@ pub enum MCPSdkError {
1515
#[error("{0}")]
1616
AnyErrorStatic(Box<(dyn std::error::Error + Send + Sync + 'static)>),
1717
#[error("{0}")]
18-
AnyError(Box<(dyn std::error::Error + Send + Sync + 'static)>),
18+
AnyError(Box<(dyn std::error::Error + Send + Sync)>),
1919
#[error("{0}")]
2020
SdkError(#[from] rust_mcp_schema::schema_utils::SdkError),
2121
}

0 commit comments

Comments
 (0)