Skip to content

Commit 0a2f13a

Browse files
authored
style: fmt the project (modelcontextprotocol#54)
add rustfmt.toml Signed-off-by: jokemanfire <[email protected]>
1 parent 59bfb6e commit 0a2f13a

36 files changed

+158
-132
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ jobs:
4141
steps:
4242
- uses: actions/checkout@v3
4343

44-
- name: Install Rust
45-
uses: dtolnay/rust-toolchain@stable
44+
- name: Install Rust fmt
45+
run: rustup toolchain install nightly --component rustfmt
4646

4747
- name: Check formatting
48-
run: cargo fmt --all -- --check
48+
run: cargo +nightly fmt --all -- --check
4949

5050
clippy:
5151
name: Lint with Clippy

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["edition2024"]
2+
13
[workspace]
24
members = ["crates/rmcp", "crates/rmcp-macros", "examples/*"]
35
resolver = "2"
@@ -12,7 +14,7 @@ version = "0.1.5"
1214
authors = ["4t145 <[email protected]>"]
1315
license = "MIT/Apache-2.0"
1416
repository = "https://github.com/modelcontextprotocol/rust-sdk/"
15-
description = "Rust SDK for the Model Context Protocol"
17+
description = "Rust SDK for Model Context Protocol"
1618
keywords = ["mcp", "sdk", "tokio", "modelcontextprotocol"]
1719
homepage = "https://github.com/modelcontextprotocol/rust-sdk"
1820
categories = [

crates/rmcp-macros/Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
cargo-features = ["edition2024"]
2+
13
[package]
24
name = "rmcp-macros"
3-
license.workspace = true
4-
version.workspace = true
5-
edition.workspace = true
6-
repository.workspace = true
7-
homepage.workspace = true
8-
readme.workspace = true
5+
license = { workspace = true }
6+
version = { workspace = true }
7+
edition = { workspace = true }
8+
repository = { workspace = true }
9+
homepage = { workspace = true }
10+
readme = { workspace = true }
911
description = "Rust SDK for Model Context Protocol macros library"
1012
documentation = "https://docs.rs/rmcp-macros"
1113

crates/rmcp/Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
cargo-features = ["edition2024"]
2+
13
[package]
24
name = "rmcp"
3-
license.workspace = true
4-
version.workspace = true
5-
edition.workspace = true
6-
repository.workspace = true
7-
homepage.workspace = true
8-
readme.workspace = true
5+
license = { workspace = true }
6+
version = { workspace = true }
7+
edition = { workspace = true }
8+
repository = { workspace = true }
9+
homepage = { workspace = true }
10+
readme = { workspace = true }
911
description = "Rust SDK for Model Context Protocol"
1012
documentation = "https://docs.rs/rmcp"
1113

crates/rmcp/src/handler/client.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use crate::error::Error as McpError;
2-
use crate::model::*;
3-
use crate::service::{Peer, RequestContext, RoleClient, Service, ServiceRole};
1+
use crate::{
2+
error::Error as McpError,
3+
model::*,
4+
service::{Peer, RequestContext, RoleClient, Service, ServiceRole},
5+
};
46

57
impl<H: ClientHandler> Service<RoleClient> for H {
68
async fn handle_request(

crates/rmcp/src/handler/server.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use crate::error::Error as McpError;
2-
use crate::model::*;
3-
use crate::service::{Peer, RequestContext, RoleServer, Service, ServiceRole};
1+
use crate::{
2+
error::Error as McpError,
3+
model::*,
4+
service::{Peer, RequestContext, RoleServer, Service, ServiceRole},
5+
};
46

57
mod resource;
68
pub mod tool;

crates/rmcp/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,26 @@ pub use error::Error;
66
pub mod model;
77
#[cfg(any(feature = "client", feature = "server"))]
88
pub mod service;
9+
#[cfg(feature = "client")]
10+
pub use handler::client::ClientHandler;
11+
#[cfg(feature = "server")]
12+
pub use handler::server::ServerHandler;
913
#[cfg(any(feature = "client", feature = "server"))]
1014
pub use service::{Peer, Service, ServiceError, ServiceExt};
1115
#[cfg(feature = "client")]
1216
pub use service::{RoleClient, serve_client};
1317
#[cfg(feature = "server")]
1418
pub use service::{RoleServer, serve_server};
1519

16-
#[cfg(feature = "client")]
17-
pub use handler::client::ClientHandler;
18-
#[cfg(feature = "server")]
19-
pub use handler::server::ServerHandler;
20-
2120
pub mod handler;
2221
pub mod transport;
2322

24-
#[cfg(all(feature = "macros", feature = "server"))]
25-
pub use rmcp_macros::tool;
26-
2723
// re-export
2824
#[cfg(all(feature = "macros", feature = "server"))]
2925
pub use paste::paste;
3026
#[cfg(all(feature = "macros", feature = "server"))]
27+
pub use rmcp_macros::tool;
28+
#[cfg(all(feature = "macros", feature = "server"))]
3129
pub use schemars;
3230
#[cfg(feature = "macros")]
3331
pub use serde;

crates/rmcp/src/model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub use capabilities::*;
1111
pub use content::*;
1212
pub use prompt::*;
1313
pub use resource::*;
14-
1514
use serde::{Deserialize, Serialize};
1615
use serde_json::Value;
1716
pub use tool::*;
@@ -964,9 +963,10 @@ impl From<CancelledNotification> for ClientNotification {
964963

965964
#[cfg(test)]
966965
mod tests {
967-
use super::*;
968966
use serde_json::json;
969967

968+
use super::*;
969+
970970
#[test]
971971
fn test_notification_serde() {
972972
let raw = json!( {

crates/rmcp/src/model/annotated.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::ops::{Deref, DerefMut};
22

3+
use chrono::{DateTime, Utc};
4+
use serde::{Deserialize, Serialize};
5+
36
use super::{
47
RawContent, RawEmbeddedResource, RawImageContent, RawResource, RawResourceTemplate,
58
RawTextContent, Role,
69
};
7-
use chrono::{DateTime, Utc};
8-
use serde::{Deserialize, Serialize};
910

1011
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
1112
#[serde(rename_all = "camelCase")]

crates/rmcp/src/model/capabilities.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use super::JsonObject;
1+
use std::{collections::BTreeMap, marker::PhantomData};
2+
23
use paste::paste;
34
use serde::{Deserialize, Serialize};
4-
use std::collections::BTreeMap;
5-
use std::marker::PhantomData;
5+
6+
use super::JsonObject;
67
pub type ExperimentalCapabilities = BTreeMap<String, JsonObject>;
78

89
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]

crates/rmcp/src/model/content.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Content sent around agents, extensions, and LLMs
22
//! The various content types can be display to humans but also understood by models
33
//! They include optional annotations used to help inform agent usage
4-
use super::resource::ResourceContents;
5-
use super::{AnnotateAble, Annotated};
64
use serde::{Deserialize, Serialize};
75
use serde_json::json;
86

7+
use super::{AnnotateAble, Annotated, resource::ResourceContents};
8+
99
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1010
#[serde(rename_all = "camelCase")]
1111
pub struct RawTextContent {

crates/rmcp/src/model/prompt.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
use super::content::{EmbeddedResource, ImageContent};
2-
use super::resource::ResourceContents;
3-
use super::{AnnotateAble, Annotations, RawEmbeddedResource, RawImageContent};
41
use base64::engine::{Engine, general_purpose::STANDARD as BASE64_STANDARD};
52
use serde::{Deserialize, Serialize};
63

4+
use super::{
5+
AnnotateAble, Annotations, RawEmbeddedResource, RawImageContent,
6+
content::{EmbeddedResource, ImageContent},
7+
resource::ResourceContents,
8+
};
9+
710
/// A prompt that can be used to generate text from a model
811
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
912
#[serde(rename_all = "camelCase")]

crates/rmcp/src/service.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
use crate::error::Error as McpError;
2-
use crate::model::{
3-
CancelledNotification, CancelledNotificationParam, JsonRpcMessage, Message, RequestId,
4-
};
5-
use crate::transport::IntoTransport;
61
use futures::future::BoxFuture;
72
use thiserror::Error;
3+
4+
use crate::{
5+
error::Error as McpError,
6+
model::{
7+
CancelledNotification, CancelledNotificationParam, JsonRpcMessage, Message, RequestId,
8+
},
9+
transport::IntoTransport,
10+
};
811
#[cfg(feature = "client")]
912
mod client;
1013
#[cfg(feature = "client")]
@@ -15,10 +18,9 @@ mod server;
1518
pub use server::*;
1619
#[cfg(feature = "tower")]
1720
mod tower;
21+
use tokio_util::sync::CancellationToken;
1822
#[cfg(feature = "tower")]
1923
pub use tower::*;
20-
21-
use tokio_util::sync::CancellationToken;
2224
use tracing::instrument;
2325
#[derive(Error, Debug)]
2426
#[non_exhaustive]
@@ -189,11 +191,12 @@ impl<R: ServiceRole, S: Service<R>> DynService<R> for S {
189191
}
190192
}
191193

192-
use std::collections::HashMap;
193-
use std::ops::Deref;
194-
use std::sync::Arc;
195-
use std::sync::atomic::AtomicU32;
196-
use std::time::Duration;
194+
use std::{
195+
collections::HashMap,
196+
ops::Deref,
197+
sync::{Arc, atomic::AtomicU32},
198+
time::Duration,
199+
};
197200

198201
use tokio::sync::mpsc;
199202

crates/rmcp/src/service/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use futures::{SinkExt, StreamExt};
2+
3+
use super::*;
14
use crate::model::{
25
CallToolRequest, CallToolRequestParam, CallToolResult, CancelledNotification,
36
CancelledNotificationParam, ClientInfo, ClientMessage, ClientNotification, ClientRequest,
@@ -12,9 +15,6 @@ use crate::model::{
1215
UnsubscribeRequest, UnsubscribeRequestParam,
1316
};
1417

15-
use super::*;
16-
use futures::{SinkExt, StreamExt};
17-
1818
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1919
pub struct RoleClient;
2020

crates/rmcp/src/service/server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use futures::{SinkExt, StreamExt};
2+
3+
use super::*;
14
use crate::model::{
25
CancelledNotification, CancelledNotificationParam, ClientInfo, ClientNotification,
36
ClientRequest, ClientResult, CreateMessageRequest, CreateMessageRequestParam,
@@ -8,9 +11,6 @@ use crate::model::{
811
ServerResult, ToolListChangedNotification,
912
};
1013

11-
use super::*;
12-
use futures::{SinkExt, StreamExt};
13-
1414
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
1515
pub struct RoleServer;
1616

crates/rmcp/src/transport/child_process.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use tokio::{
44
process::{ChildStdin, ChildStdout},
55
};
66

7-
use crate::service::{RxJsonRpcMessage, ServiceRole, TxJsonRpcMessage};
8-
97
use super::IntoTransport;
8+
use crate::service::{RxJsonRpcMessage, ServiceRole, TxJsonRpcMessage};
109

1110
pub(crate) fn child_process(
1211
mut child: tokio::process::Child,

crates/rmcp/src/transport/io.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ use std::marker::PhantomData;
44
use futures::{Sink, SinkExt, Stream, StreamExt};
55
use serde::{Serialize, de::DeserializeOwned};
66
use thiserror::Error;
7-
87
use tokio::io::{AsyncRead, AsyncWrite};
98
use tokio_util::{
109
bytes::{Buf, BufMut, BytesMut},
1110
codec::{Decoder, Encoder, FramedRead, FramedWrite},
1211
};
1312

14-
use crate::service::{RxJsonRpcMessage, ServiceRole, TxJsonRpcMessage};
15-
1613
use super::IntoTransport;
14+
use crate::service::{RxJsonRpcMessage, ServiceRole, TxJsonRpcMessage};
1715

1816
#[cfg(feature = "transport-io")]
1917
/// # StdIO Transport

crates/rmcp/src/transport/sse.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//! reference: https://html.spec.whatwg.org/multipage/server-sent-events.html
2-
use crate::model::{ClientJsonRpcMessage, ServerJsonRpcMessage};
2+
use std::{collections::VecDeque, sync::Arc, time::Duration};
3+
34
use futures::{FutureExt, Sink, Stream, StreamExt, future::BoxFuture, stream::BoxStream};
45
use reqwest::{
56
Client as HttpClient, IntoUrl, Url,
67
header::{ACCEPT, HeaderValue},
78
};
89
use sse_stream::{Error as SseError, Sse, SseStream};
9-
use std::{collections::VecDeque, sync::Arc, time::Duration};
1010
use thiserror::Error;
11+
12+
use crate::model::{ClientJsonRpcMessage, ServerJsonRpcMessage};
1113
const MIME_TYPE: &str = "text/event-stream";
1214
const HEADER_LAST_EVENT_ID: &str = "Last-Event-ID";
1315

crates/rmcp/src/transport/sse_server.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
use crate::{
2-
RoleServer, Service,
3-
model::ClientJsonRpcMessage,
4-
service::{RxJsonRpcMessage, TxJsonRpcMessage},
5-
};
1+
use std::{collections::HashMap, net::SocketAddr, sync::Arc};
2+
63
use axum::{
74
Json, Router,
85
extract::{Query, State},
@@ -14,13 +11,16 @@ use axum::{
1411
routing::{get, post},
1512
};
1613
use futures::{Sink, SinkExt, Stream, StreamExt};
17-
use std::{collections::HashMap, net::SocketAddr};
14+
use tokio::io;
1815
use tokio_stream::wrappers::ReceiverStream;
1916
use tokio_util::sync::{CancellationToken, PollSender};
2017
use tracing::Instrument;
2118

22-
use std::sync::Arc;
23-
use tokio::io;
19+
use crate::{
20+
RoleServer, Service,
21+
model::ClientJsonRpcMessage,
22+
service::{RxJsonRpcMessage, TxJsonRpcMessage},
23+
};
2424
type SessionId = Arc<str>;
2525
type TxStore =
2626
Arc<tokio::sync::RwLock<HashMap<SessionId, tokio::sync::mpsc::Sender<ClientJsonRpcMessage>>>>;

crates/rmcp/tests/test_tool_macros.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rmcp::{ServerHandler, handler::server::tool::ToolCallContext, tool};
22
use schemars::JsonSchema;
3-
43
use serde::{Deserialize, Serialize};
54

65
#[derive(Serialize, Deserialize, JsonSchema)]

examples/clients/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["edition2024"]
2+
13
[package]
24
name = "mcp-client-examples"
35
version = "0.1.5"

examples/clients/src/collection.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use std::collections::HashMap;
22

33
use anyhow::Result;
4-
use rmcp::service::ServiceExt;
5-
use rmcp::{model::CallToolRequestParam, transport::TokioChildProcess};
6-
4+
use rmcp::{model::CallToolRequestParam, service::ServiceExt, transport::TokioChildProcess};
75
use tokio::process::Command;
8-
use tracing_subscriber::layer::SubscriberExt;
9-
use tracing_subscriber::util::SubscriberInitExt;
6+
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
107

118
#[tokio::main]
129
async fn main() -> Result<()> {

0 commit comments

Comments
 (0)