Skip to content

Commit 3075dc9

Browse files
authored
fix(model): deprecate ServerInfo and ClientInfo aliases (#1156)
* fix(model): deprecate ServerInfo and ClientInfo aliases Those names collide with the protocol's serverInfo/clientInfo fields, which are only Implementation identity. Prefer InitializeResult and InitializeRequestParams. Handler trait signatures, the tool_handler macro output, tests, examples and docs now use the canonical types; the aliases remain as deprecated shims for the rest of 3.x. Fixes #1082 * fix(model): keep public signatures on the deprecated aliases The public API check compares rendered signatures, and rustdoc records a type alias by the name it was written with. Respelling `ServerHandler::get_info`, `ClientHandler::get_info`, `DiscoverResult::from_server_info` and `impl ClientHandler for ClientInfo` onto `InitializeResult`/`InitializeRequestParams` therefore reads as changed public items even though the aliases resolve to those exact types and nothing downstream breaks. Put those four signatures back on the aliases so the published API is byte-identical, and note why at the alias definitions. The deprecation still steers new code, and the macro output, tests, examples and docs keep using the canonical names. * fix(model): migrate leftover ClientInfo test sites Two tests landed on main after the alias deprecation and still named ClientInfo. Clippy -D warnings and the no-local feature test job both failed on them.
1 parent a5d1169 commit 3075dc9

63 files changed

Lines changed: 323 additions & 286 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ Use [`ClientServiceExt::serve_with_lifecycle`](crates/rmcp/src/service/client.rs
9999
select another lifecycle explicitly:
100100

101101
```rust, ignore
102-
use rmcp::{ClientInfo, ClientLifecycleMode, ClientServiceExt, ProtocolVersion};
102+
use rmcp::{ClientLifecycleMode, ClientServiceExt, InitializeRequestParams, ProtocolVersion};
103103
104104
// Start directly with server/discover and include client metadata on every request.
105-
let client = ClientInfo::default()
105+
let client = InitializeRequestParams::default()
106106
.serve_with_lifecycle(
107107
transport,
108108
ClientLifecycleMode::Discover {
@@ -113,7 +113,7 @@ let client = ClientInfo::default()
113113
114114
// Or probe the discover lifecycle and fall back when a legacy server reports
115115
// that server/discover is not implemented or does not respond within 10 seconds.
116-
let client = ClientInfo::default()
116+
let client = InitializeRequestParams::default()
117117
.serve_with_lifecycle(
118118
transport,
119119
ClientLifecycleMode::Auto {
@@ -369,8 +369,8 @@ use serde_json::json;
369369
struct MyServer;
370370

371371
impl ServerHandler for MyServer {
372-
fn get_info(&self) -> ServerInfo {
373-
ServerInfo::new(
372+
fn get_info(&self) -> InitializeResult {
373+
InitializeResult::new(
374374
ServerCapabilities::builder()
375375
.enable_resources()
376376
.build(),
@@ -582,8 +582,8 @@ impl MyServer {
582582

583583
#[prompt_handler]
584584
impl ServerHandler for MyServer {
585-
fn get_info(&self) -> ServerInfo {
586-
ServerInfo::new(ServerCapabilities::builder().enable_prompts().build())
585+
fn get_info(&self) -> InitializeResult {
586+
InitializeResult::new(ServerCapabilities::builder().enable_prompts().build())
587587
}
588588
}
589589
```
@@ -934,8 +934,8 @@ Enable the logging capability, handle level changes from the client, and send lo
934934
use rmcp::{ServerHandler, model::*, service::RequestContext};
935935

936936
impl ServerHandler for MyServer {
937-
fn get_info(&self) -> ServerInfo {
938-
ServerInfo::new(
937+
fn get_info(&self) -> InitializeResult {
938+
InitializeResult::new(
939939
ServerCapabilities::builder()
940940
.enable_logging()
941941
.build(),
@@ -1007,8 +1007,8 @@ Enable the completions capability and implement the `complete()` handler. Use `r
10071007
use rmcp::{ErrorData as McpError, ServerHandler, model::*, service::RequestContext, RoleServer};
10081008

10091009
impl ServerHandler for MyServer {
1010-
fn get_info(&self) -> ServerInfo {
1011-
ServerInfo::new(
1010+
fn get_info(&self) -> InitializeResult {
1011+
InitializeResult::new(
10121012
ServerCapabilities::builder()
10131013
.enable_completions()
10141014
.enable_prompts()
@@ -1253,8 +1253,8 @@ use rmcp::{
12531253
};
12541254

12551255
impl ServerHandler for MyServer {
1256-
fn get_info(&self) -> ServerInfo {
1257-
ServerInfo::new(
1256+
fn get_info(&self) -> InitializeResult {
1257+
InitializeResult::new(
12581258
ServerCapabilities::builder()
12591259
.enable_tools()
12601260
.enable_tool_list_changed()
@@ -1584,7 +1584,7 @@ use rmcp::transport::StreamableHttpClientTransport;
15841584
15851585
// Defaults are stateless-friendly.
15861586
let transport = StreamableHttpClientTransport::from_uri("http://localhost:8000/mcp");
1587-
let client = ClientInfo::default().serve(transport).await?;
1587+
let client = InitializeRequestParams::default().serve(transport).await?;
15881588
```
15891589

15901590
**Example:** [`examples/servers/src/counter_streamhttp.rs`](examples/servers/src/counter_streamhttp.rs) (server), [`examples/clients/src/streamable_http.rs`](examples/clients/src/streamable_http.rs) (client)
@@ -1638,7 +1638,7 @@ server example). The client transport connects with a single URI:
16381638
use rmcp::transport::StreamableHttpClientTransport;
16391639
16401640
let transport = StreamableHttpClientTransport::from_uri("http://localhost:8000/mcp");
1641-
let client = ClientInfo::default().serve(transport).await?;
1641+
let client = InitializeRequestParams::default().serve(transport).await?;
16421642
```
16431643

16441644
The client allows up to 16 ordinary http POSTs at once. Configure this with
@@ -1742,10 +1742,10 @@ knows what the other supports. Declare yours with the `ServerCapabilities`
17421742
builder in `get_info()`:
17431743

17441744
```rust,ignore
1745-
use rmcp::model::{ServerCapabilities, ServerInfo};
1745+
use rmcp::model::{InitializeResult, ServerCapabilities};
17461746
1747-
fn get_info(&self) -> ServerInfo {
1748-
ServerInfo::new(
1747+
fn get_info(&self) -> InitializeResult {
1748+
InitializeResult::new(
17491749
ServerCapabilities::builder()
17501750
.enable_tools()
17511751
.enable_prompts()

‎conformance/src/bin/client.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ impl ClientHandler for BasicClientHandler {}
7474
struct ElicitationDefaultsClientHandler;
7575

7676
impl ClientHandler for ElicitationDefaultsClientHandler {
77-
fn get_info(&self) -> ClientInfo {
78-
let mut info = ClientInfo::default();
77+
fn get_info(&self) -> InitializeRequestParams {
78+
let mut info = InitializeRequestParams::default();
7979
info.capabilities.elicitation = Some(
8080
ElicitationCapability::new()
8181
.with_form(FormElicitationCapability::new().with_schema_validation(true)),
@@ -163,8 +163,8 @@ impl ClientHandler for ElicitationDefaultsClientHandler {
163163
struct FullClientHandler;
164164

165165
impl ClientHandler for FullClientHandler {
166-
fn get_info(&self) -> ClientInfo {
167-
let mut info = ClientInfo::default();
166+
fn get_info(&self) -> InitializeRequestParams {
167+
let mut info = InitializeRequestParams::default();
168168
info.capabilities.elicitation = Some(
169169
ElicitationCapability::new()
170170
.with_form(FormElicitationCapability::new().with_schema_validation(true)),

‎conformance/src/bin/server.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ impl ServerHandler for ConformanceServer {
704704
(name == "test_custom_header").then(custom_header_tool)
705705
}
706706

707-
fn get_info(&self) -> ServerInfo {
708-
ServerInfo::new(
707+
fn get_info(&self) -> InitializeResult {
708+
InitializeResult::new(
709709
ServerCapabilities::builder()
710710
.enable_prompts()
711711
.enable_prompts_list_changed()

‎crates/rmcp-macros/src/lib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ pub fn tool_router(attr: TokenStream, input: TokenStream) -> TokenStream {
217217
/// ```rust,ignore
218218
/// #[tool_handler]
219219
/// impl ServerHandler for MyToolHandler {
220-
/// fn get_info(&self) -> ServerInfo {
221-
/// ServerInfo::new(ServerCapabilities::builder().enable_tools().build())
220+
/// fn get_info(&self) -> InitializeResult {
221+
/// InitializeResult::new(ServerCapabilities::builder().enable_tools().build())
222222
/// }
223223
/// }
224224
/// ```

‎crates/rmcp-macros/src/tool_handler.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub(crate) enum CallerCapability {
116116
Prompts,
117117
}
118118

119-
/// Build a `get_info()` method that returns `ServerInfo` with the appropriate capabilities.
119+
/// Build a `get_info()` method that returns `InitializeResult` with the appropriate capabilities.
120120
///
121121
/// The caller declares its own capability via `caller`. Sibling handler attributes
122122
/// (`prompt_handler`, `tool_handler`) are detected automatically
@@ -157,8 +157,8 @@ pub(crate) fn build_get_info(
157157
}
158158

159159
syn::parse2::<ImplItem>(quote! {
160-
fn get_info(&self) -> rmcp::model::ServerInfo {
161-
rmcp::model::ServerInfo::new(
160+
fn get_info(&self) -> rmcp::model::InitializeResult {
161+
rmcp::model::InitializeResult::new(
162162
rmcp::model::ServerCapabilities::builder()
163163
#(#capability_calls)*
164164
.build()

‎crates/rmcp/src/handler/client.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ macro_rules! client_handler_methods {
275275
}
276276

277277
fn get_info(&self) -> ClientInfo {
278-
ClientInfo::default()
278+
InitializeRequestParams::default()
279279
}
280280
};
281281
}

‎crates/rmcp/src/handler/server.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ macro_rules! server_handler_methods {
601601
}
602602

603603
fn get_info(&self) -> ServerInfo {
604-
ServerInfo::default()
604+
InitializeResult::default()
605605
}
606606

607607
/// SEP-2663 `tasks/get`: return the current [`DetailedTask`] state.

‎crates/rmcp/src/model.rs‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,26 @@ impl InitializeResult {
11191119
}
11201120
}
11211121

1122+
/// Full server initialize payload (`InitializeResult`).
1123+
///
1124+
/// Prefer [`InitializeResult`]. The name collides with the protocol's
1125+
/// `serverInfo` field, which is only the [`Implementation`] identity (#1082).
1126+
//
1127+
// The signatures this crate publishes (`ServerHandler::get_info`,
1128+
// `DiscoverResult::from_server_info`, and the `ClientInfo` equivalents below)
1129+
// keep spelling the alias. It resolves to the same type, so the spelling makes
1130+
// no difference to callers, but rustdoc records the name as written and the
1131+
// public API check treats a respelling as a changed item. Moving those
1132+
// signatures onto the canonical names is a documented API change and belongs in
1133+
// the next major release.
1134+
#[deprecated(note = "use `InitializeResult` instead")]
11221135
pub type ServerInfo = InitializeResult;
1136+
1137+
/// Full client initialize params (`InitializeRequestParams`).
1138+
///
1139+
/// Prefer [`InitializeRequestParams`]. The name collides with the protocol's
1140+
/// `clientInfo` field, which is only the [`Implementation`] identity (#1082).
1141+
#[deprecated(note = "use `InitializeRequestParams` instead")]
11231142
pub type ClientInfo = InitializeRequestParams;
11241143

11251144
/// Information negotiated about a server peer.
@@ -1284,7 +1303,7 @@ impl DiscoverResult {
12841303
supported_versions: Vec<ProtocolVersion>,
12851304
server_info: ServerInfo,
12861305
) -> Self {
1287-
let ServerInfo {
1306+
let InitializeResult {
12881307
capabilities,
12891308
server_info,
12901309
instructions,
@@ -1332,9 +1351,9 @@ impl ServerPeerInfo {
13321351
}
13331352

13341353
#[allow(clippy::derivable_impls)]
1335-
impl Default for ServerInfo {
1354+
impl Default for InitializeResult {
13361355
fn default() -> Self {
1337-
ServerInfo {
1356+
InitializeResult {
13381357
protocol_version: ProtocolVersion::default(),
13391358
capabilities: ServerCapabilities::default(),
13401359
server_info: Implementation::from_build_env(),
@@ -1345,9 +1364,9 @@ impl Default for ServerInfo {
13451364
}
13461365

13471366
#[allow(clippy::derivable_impls)]
1348-
impl Default for ClientInfo {
1367+
impl Default for InitializeRequestParams {
13491368
fn default() -> Self {
1350-
ClientInfo {
1369+
InitializeRequestParams {
13511370
meta: None,
13521371
protocol_version: ProtocolVersion::default(),
13531372
capabilities: ClientCapabilities::default(),

‎crates/rmcp/src/service/client.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use crate::{
1313
model::{
1414
ArgumentInfo, CacheScope, CallToolRequest, CallToolRequestParams, CallToolResponse,
1515
CallToolResult, CancelTaskParams, CancelTaskRequest, CancelledNotification,
16-
CancelledNotificationParam, ClientInfo, ClientJsonRpcMessage, ClientNotification,
17-
ClientRequest, ClientResult, CompleteRequest, CompleteRequestParams, CompleteResult,
18-
CompletionContext, CompletionInfo, DEFAULT_MRTR_MAX_ROUNDS, DiscoverRequest,
19-
DiscoverRequestParams, DiscoverResult, ErrorData, GetExtensions, GetMeta, GetPromptRequest,
16+
CancelledNotificationParam, ClientJsonRpcMessage, ClientNotification, ClientRequest,
17+
ClientResult, CompleteRequest, CompleteRequestParams, CompleteResult, CompletionContext,
18+
CompletionInfo, DEFAULT_MRTR_MAX_ROUNDS, DiscoverRequest, DiscoverRequestParams,
19+
DiscoverResult, ErrorData, GetExtensions, GetMeta, GetPromptRequest,
2020
GetPromptRequestParams, GetPromptResponse, GetPromptResult, GetTaskParams, GetTaskRequest,
21-
GetTaskResult, InitializeRequest, InitializedNotification, InputRequest,
22-
InputRequiredResult, InputResponses, JsonRpcResponse, ListPromptsRequest,
21+
GetTaskResult, InitializeRequest, InitializeRequestParams, InitializedNotification,
22+
InputRequest, InputRequiredResult, InputResponses, JsonRpcResponse, ListPromptsRequest,
2323
ListPromptsResult, ListResourceTemplatesRequest, ListResourceTemplatesResult,
2424
ListResourcesRequest, ListResourcesResult, ListToolsRequest, ListToolsResult,
2525
NumberOrString, PaginatedRequestParams, ProgressNotification, ProgressNotificationParam,
@@ -266,7 +266,7 @@ impl ServiceRole for RoleClient {
266266
type PeerReq = ServerRequest;
267267
type PeerResp = ServerResult;
268268
type PeerNot = ServerNotification;
269-
type Info = ClientInfo;
269+
type Info = InitializeRequestParams;
270270
type PeerInfo = ServerPeerInfo;
271271
type InitializeError = ClientInitializeError;
272272
const IS_CLIENT: bool = true;
@@ -870,7 +870,7 @@ async fn legacy_startup<S, T>(
870870
transport: &mut T,
871871
id_provider: &Arc<AtomicU32RequestIdProvider>,
872872
peer: &Peer<RoleClient>,
873-
client_info: ClientInfo,
873+
client_info: InitializeRequestParams,
874874
) -> Result<(), ClientInitializeError>
875875
where
876876
S: Service<RoleClient>,
@@ -919,7 +919,7 @@ async fn discover_startup<S, T>(
919919
transport: &mut T,
920920
id_provider: &Arc<AtomicU32RequestIdProvider>,
921921
peer: &Peer<RoleClient>,
922-
client_info: &ClientInfo,
922+
client_info: &InitializeRequestParams,
923923
preferred_versions: Vec<ProtocolVersion>,
924924
) -> Result<DiscoverOutcome, ClientInitializeError>
925925
where

‎crates/rmcp/src/service/server.rs‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ use super::*;
1313
use crate::model::{ElicitRequest, ElicitRequestParams, ElicitResult, ElicitationAction};
1414
use crate::{
1515
model::{
16-
CancelledNotification, CancelledNotificationParam, ClientInfo, ClientJsonRpcMessage,
16+
CancelledNotification, CancelledNotificationParam, ClientJsonRpcMessage,
1717
ClientNotification, ClientRequest, ClientResult, CreateMessageRequest,
18-
CreateMessageRequestParams, CreateMessageResult, EmptyResult, ErrorData, ListRootsRequest,
19-
ListRootsResult, LoggingMessageNotification, LoggingMessageNotificationParam,
20-
ProgressNotification, ProgressNotificationParam, PromptListChangedNotification,
21-
ProtocolVersion, ResourceListChangedNotification, ResourceUpdatedNotification,
22-
ResourceUpdatedNotificationParam, ServerInfo, ServerNotification, ServerRequest,
23-
ServerResult, SubscriptionFilter, SubscriptionsAcknowledgedNotification,
18+
CreateMessageRequestParams, CreateMessageResult, EmptyResult, ErrorData,
19+
InitializeRequestParams, InitializeResult, ListRootsRequest, ListRootsResult,
20+
LoggingMessageNotification, LoggingMessageNotificationParam, ProgressNotification,
21+
ProgressNotificationParam, PromptListChangedNotification, ProtocolVersion,
22+
ResourceListChangedNotification, ResourceUpdatedNotification,
23+
ResourceUpdatedNotificationParam, ServerNotification, ServerRequest, ServerResult,
24+
SubscriptionFilter, SubscriptionsAcknowledgedNotification,
2425
SubscriptionsAcknowledgedNotificationParams, ToolListChangedNotification,
2526
},
2627
transport::DynamicTransportError,
@@ -37,8 +38,8 @@ impl ServiceRole for RoleServer {
3738
type PeerReq = ClientRequest;
3839
type PeerResp = ClientResult;
3940
type PeerNot = ClientNotification;
40-
type Info = ServerInfo;
41-
type PeerInfo = ClientInfo;
41+
type Info = InitializeResult;
42+
type PeerInfo = InitializeRequestParams;
4243

4344
type InitializeError = ServerInitializeError;
4445
const IS_CLIENT: bool = false;

0 commit comments

Comments
 (0)