Skip to content

Commit cb69865

Browse files
committed
Changed naming to adhere to official Rust API guidelines.
1 parent 9cda30c commit cb69865

File tree

32 files changed

+238
-240
lines changed

32 files changed

+238
-240
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: 6 additions & 6 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

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

Lines changed: 3 additions & 3 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()));

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, JsonrpcErrorError> {
73+
async fn handle_list_tools_request(&self, request: ListToolsRequest, runtime: &dyn McpServer) -> Result<ListToolsResult, JsonrpcErrorError> {
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::JsonrpcErrorError;
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
JsonrpcErrorError(#[from] JsonrpcErrorError),
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
}

crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rust_mcp_schema::{
77
};
88
use serde_json::Value;
99

10-
use crate::mcp_traits::mcp_client::MCPClient;
10+
use crate::mcp_traits::mcp_client::McpClient;
1111

1212
/// Defines the `ClientHandler` trait for handling Model Context Protocol (MCP) operations on a client.
1313
/// This trait provides default implementations for request and notification handlers in an MCP client,
@@ -21,15 +21,15 @@ pub trait ClientHandler: Send + Sync + 'static {
2121
async fn handle_ping_request(
2222
&self,
2323
request: PingRequest,
24-
runtime: &dyn MCPClient,
24+
runtime: &dyn McpClient,
2525
) -> std::result::Result<Result, JsonrpcErrorError> {
2626
Ok(Result::default())
2727
}
2828

2929
async fn handle_create_message_request(
3030
&self,
3131
request: CreateMessageRequest,
32-
runtime: &dyn MCPClient,
32+
runtime: &dyn McpClient,
3333
) -> std::result::Result<CreateMessageResult, JsonrpcErrorError> {
3434
runtime.assert_client_request_capabilities(request.method())?;
3535
Err(JsonrpcErrorError::method_not_found().with_message(format!(
@@ -41,7 +41,7 @@ pub trait ClientHandler: Send + Sync + 'static {
4141
async fn handle_list_roots_request(
4242
&self,
4343
request: ListRootsRequest,
44-
runtime: &dyn MCPClient,
44+
runtime: &dyn McpClient,
4545
) -> std::result::Result<ListRootsResult, JsonrpcErrorError> {
4646
runtime.assert_client_request_capabilities(request.method())?;
4747
Err(JsonrpcErrorError::method_not_found().with_message(format!(
@@ -53,7 +53,7 @@ pub trait ClientHandler: Send + Sync + 'static {
5353
async fn handle_custom_request(
5454
&self,
5555
request: Value,
56-
runtime: &dyn MCPClient,
56+
runtime: &dyn McpClient,
5757
) -> std::result::Result<ListRootsResult, JsonrpcErrorError> {
5858
Err(JsonrpcErrorError::method_not_found()
5959
.with_message("No handler is implemented for custom requests.".to_string()))
@@ -66,63 +66,63 @@ pub trait ClientHandler: Send + Sync + 'static {
6666
async fn handle_cancelled_notification(
6767
&self,
6868
notification: CancelledNotification,
69-
runtime: &dyn MCPClient,
69+
runtime: &dyn McpClient,
7070
) -> std::result::Result<(), JsonrpcErrorError> {
7171
Ok(())
7272
}
7373

7474
async fn handle_progress_notification(
7575
&self,
7676
notification: ProgressNotification,
77-
runtime: &dyn MCPClient,
77+
runtime: &dyn McpClient,
7878
) -> std::result::Result<(), JsonrpcErrorError> {
7979
Ok(())
8080
}
8181

8282
async fn handle_resource_list_changed_notification(
8383
&self,
8484
notification: ResourceListChangedNotification,
85-
runtime: &dyn MCPClient,
85+
runtime: &dyn McpClient,
8686
) -> std::result::Result<(), JsonrpcErrorError> {
8787
Ok(())
8888
}
8989

9090
async fn handle_resource_updated_notification(
9191
&self,
9292
notification: ResourceUpdatedNotification,
93-
runtime: &dyn MCPClient,
93+
runtime: &dyn McpClient,
9494
) -> std::result::Result<(), JsonrpcErrorError> {
9595
Ok(())
9696
}
9797

9898
async fn handle_prompt_list_changed_notification(
9999
&self,
100100
notification: PromptListChangedNotification,
101-
runtime: &dyn MCPClient,
101+
runtime: &dyn McpClient,
102102
) -> std::result::Result<(), JsonrpcErrorError> {
103103
Ok(())
104104
}
105105

106106
async fn handle_tool_list_changed_notification(
107107
&self,
108108
notification: ToolListChangedNotification,
109-
runtime: &dyn MCPClient,
109+
runtime: &dyn McpClient,
110110
) -> std::result::Result<(), JsonrpcErrorError> {
111111
Ok(())
112112
}
113113

114114
async fn handle_logging_message_notification(
115115
&self,
116116
notification: LoggingMessageNotification,
117-
runtime: &dyn MCPClient,
117+
runtime: &dyn McpClient,
118118
) -> std::result::Result<(), JsonrpcErrorError> {
119119
Ok(())
120120
}
121121

122122
async fn handle_custom_notification(
123123
&self,
124124
notification: Value,
125-
runtime: &dyn MCPClient,
125+
runtime: &dyn McpClient,
126126
) -> std::result::Result<(), JsonrpcErrorError> {
127127
Ok(())
128128
}
@@ -133,15 +133,15 @@ pub trait ClientHandler: Send + Sync + 'static {
133133
async fn handle_error(
134134
&self,
135135
error: JsonrpcErrorError,
136-
runtime: &dyn MCPClient,
136+
runtime: &dyn McpClient,
137137
) -> std::result::Result<(), JsonrpcErrorError> {
138138
Ok(())
139139
}
140140

141141
async fn handle_process_error(
142142
&self,
143143
error_message: String,
144-
runtime: &dyn MCPClient,
144+
runtime: &dyn McpClient,
145145
) -> std::result::Result<(), JsonrpcErrorError> {
146146
if !runtime.is_shut_down().await {
147147
eprintln!("Process error: {}", error_message);

crates/rust-mcp-sdk/src/mcp_handlers/mcp_client_handler_core.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use async_trait::async_trait;
22
use rust_mcp_schema::schema_utils::*;
33
use rust_mcp_schema::*;
44

5-
use crate::mcp_traits::mcp_client::MCPClient;
5+
use crate::mcp_traits::mcp_client::McpClient;
66

77
/// Defines the `ClientHandlerCore` trait for handling Model Context Protocol (MCP) client operations.
88
/// Unlike `ClientHandler`, this trait offers no default implementations, providing full control over MCP message handling
@@ -19,7 +19,7 @@ pub trait ClientHandlerCore: Send + Sync + 'static {
1919
async fn handle_request(
2020
&self,
2121
request: RequestFromServer,
22-
runtime: &dyn MCPClient,
22+
runtime: &dyn McpClient,
2323
) -> std::result::Result<ResultFromClient, JsonrpcErrorError>;
2424

2525
/// Asynchronously handles an incoming notification from the server.
@@ -29,7 +29,7 @@ pub trait ClientHandlerCore: Send + Sync + 'static {
2929
async fn handle_notification(
3030
&self,
3131
notification: NotificationFromServer,
32-
runtime: &dyn MCPClient,
32+
runtime: &dyn McpClient,
3333
) -> std::result::Result<(), JsonrpcErrorError>;
3434

3535
/// Asynchronously handles an error received from the server.
@@ -39,13 +39,13 @@ pub trait ClientHandlerCore: Send + Sync + 'static {
3939
async fn handle_error(
4040
&self,
4141
error: JsonrpcErrorError,
42-
runtime: &dyn MCPClient,
42+
runtime: &dyn McpClient,
4343
) -> std::result::Result<(), JsonrpcErrorError>;
4444

4545
async fn handle_process_error(
4646
&self,
4747
error_message: String,
48-
runtime: &dyn MCPClient,
48+
runtime: &dyn McpClient,
4949
) -> std::result::Result<(), JsonrpcErrorError> {
5050
if !runtime.is_shut_down().await {
5151
eprintln!("Process error: {}", error_message);

0 commit comments

Comments
 (0)