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.
This commit is contained in:
parent
a5d1169e20
commit
3075dc9152
6 changed files with 323 additions and 286 deletions
|
|
@ -275,7 +275,7 @@ macro_rules! client_handler_methods {
|
|||
}
|
||||
|
||||
fn get_info(&self) -> ClientInfo {
|
||||
ClientInfo::default()
|
||||
InitializeRequestParams::default()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -601,7 +601,7 @@ macro_rules! server_handler_methods {
|
|||
}
|
||||
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::default()
|
||||
InitializeResult::default()
|
||||
}
|
||||
|
||||
/// SEP-2663 `tasks/get`: return the current [`DetailedTask`] state.
|
||||
|
|
|
|||
|
|
@ -1119,7 +1119,26 @@ impl InitializeResult {
|
|||
}
|
||||
}
|
||||
|
||||
/// Full server initialize payload (`InitializeResult`).
|
||||
///
|
||||
/// Prefer [`InitializeResult`]. The name collides with the protocol's
|
||||
/// `serverInfo` field, which is only the [`Implementation`] identity (#1082).
|
||||
//
|
||||
// The signatures this crate publishes (`ServerHandler::get_info`,
|
||||
// `DiscoverResult::from_server_info`, and the `ClientInfo` equivalents below)
|
||||
// keep spelling the alias. It resolves to the same type, so the spelling makes
|
||||
// no difference to callers, but rustdoc records the name as written and the
|
||||
// public API check treats a respelling as a changed item. Moving those
|
||||
// signatures onto the canonical names is a documented API change and belongs in
|
||||
// the next major release.
|
||||
#[deprecated(note = "use `InitializeResult` instead")]
|
||||
pub type ServerInfo = InitializeResult;
|
||||
|
||||
/// Full client initialize params (`InitializeRequestParams`).
|
||||
///
|
||||
/// Prefer [`InitializeRequestParams`]. The name collides with the protocol's
|
||||
/// `clientInfo` field, which is only the [`Implementation`] identity (#1082).
|
||||
#[deprecated(note = "use `InitializeRequestParams` instead")]
|
||||
pub type ClientInfo = InitializeRequestParams;
|
||||
|
||||
/// Information negotiated about a server peer.
|
||||
|
|
@ -1284,7 +1303,7 @@ impl DiscoverResult {
|
|||
supported_versions: Vec<ProtocolVersion>,
|
||||
server_info: ServerInfo,
|
||||
) -> Self {
|
||||
let ServerInfo {
|
||||
let InitializeResult {
|
||||
capabilities,
|
||||
server_info,
|
||||
instructions,
|
||||
|
|
@ -1332,9 +1351,9 @@ impl ServerPeerInfo {
|
|||
}
|
||||
|
||||
#[allow(clippy::derivable_impls)]
|
||||
impl Default for ServerInfo {
|
||||
impl Default for InitializeResult {
|
||||
fn default() -> Self {
|
||||
ServerInfo {
|
||||
InitializeResult {
|
||||
protocol_version: ProtocolVersion::default(),
|
||||
capabilities: ServerCapabilities::default(),
|
||||
server_info: Implementation::from_build_env(),
|
||||
|
|
@ -1345,9 +1364,9 @@ impl Default for ServerInfo {
|
|||
}
|
||||
|
||||
#[allow(clippy::derivable_impls)]
|
||||
impl Default for ClientInfo {
|
||||
impl Default for InitializeRequestParams {
|
||||
fn default() -> Self {
|
||||
ClientInfo {
|
||||
InitializeRequestParams {
|
||||
meta: None,
|
||||
protocol_version: ProtocolVersion::default(),
|
||||
capabilities: ClientCapabilities::default(),
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ use crate::{
|
|||
model::{
|
||||
ArgumentInfo, CacheScope, CallToolRequest, CallToolRequestParams, CallToolResponse,
|
||||
CallToolResult, CancelTaskParams, CancelTaskRequest, CancelledNotification,
|
||||
CancelledNotificationParam, ClientInfo, ClientJsonRpcMessage, ClientNotification,
|
||||
ClientRequest, ClientResult, CompleteRequest, CompleteRequestParams, CompleteResult,
|
||||
CompletionContext, CompletionInfo, DEFAULT_MRTR_MAX_ROUNDS, DiscoverRequest,
|
||||
DiscoverRequestParams, DiscoverResult, ErrorData, GetExtensions, GetMeta, GetPromptRequest,
|
||||
CancelledNotificationParam, ClientJsonRpcMessage, ClientNotification, ClientRequest,
|
||||
ClientResult, CompleteRequest, CompleteRequestParams, CompleteResult, CompletionContext,
|
||||
CompletionInfo, DEFAULT_MRTR_MAX_ROUNDS, DiscoverRequest, DiscoverRequestParams,
|
||||
DiscoverResult, ErrorData, GetExtensions, GetMeta, GetPromptRequest,
|
||||
GetPromptRequestParams, GetPromptResponse, GetPromptResult, GetTaskParams, GetTaskRequest,
|
||||
GetTaskResult, InitializeRequest, InitializedNotification, InputRequest,
|
||||
InputRequiredResult, InputResponses, JsonRpcResponse, ListPromptsRequest,
|
||||
GetTaskResult, InitializeRequest, InitializeRequestParams, InitializedNotification,
|
||||
InputRequest, InputRequiredResult, InputResponses, JsonRpcResponse, ListPromptsRequest,
|
||||
ListPromptsResult, ListResourceTemplatesRequest, ListResourceTemplatesResult,
|
||||
ListResourcesRequest, ListResourcesResult, ListToolsRequest, ListToolsResult,
|
||||
NumberOrString, PaginatedRequestParams, ProgressNotification, ProgressNotificationParam,
|
||||
|
|
@ -266,7 +266,7 @@ impl ServiceRole for RoleClient {
|
|||
type PeerReq = ServerRequest;
|
||||
type PeerResp = ServerResult;
|
||||
type PeerNot = ServerNotification;
|
||||
type Info = ClientInfo;
|
||||
type Info = InitializeRequestParams;
|
||||
type PeerInfo = ServerPeerInfo;
|
||||
type InitializeError = ClientInitializeError;
|
||||
const IS_CLIENT: bool = true;
|
||||
|
|
@ -870,7 +870,7 @@ async fn legacy_startup<S, T>(
|
|||
transport: &mut T,
|
||||
id_provider: &Arc<AtomicU32RequestIdProvider>,
|
||||
peer: &Peer<RoleClient>,
|
||||
client_info: ClientInfo,
|
||||
client_info: InitializeRequestParams,
|
||||
) -> Result<(), ClientInitializeError>
|
||||
where
|
||||
S: Service<RoleClient>,
|
||||
|
|
@ -919,7 +919,7 @@ async fn discover_startup<S, T>(
|
|||
transport: &mut T,
|
||||
id_provider: &Arc<AtomicU32RequestIdProvider>,
|
||||
peer: &Peer<RoleClient>,
|
||||
client_info: &ClientInfo,
|
||||
client_info: &InitializeRequestParams,
|
||||
preferred_versions: Vec<ProtocolVersion>,
|
||||
) -> Result<DiscoverOutcome, ClientInitializeError>
|
||||
where
|
||||
|
|
|
|||
|
|
@ -13,14 +13,15 @@ use super::*;
|
|||
use crate::model::{ElicitRequest, ElicitRequestParams, ElicitResult, ElicitationAction};
|
||||
use crate::{
|
||||
model::{
|
||||
CancelledNotification, CancelledNotificationParam, ClientInfo, ClientJsonRpcMessage,
|
||||
CancelledNotification, CancelledNotificationParam, ClientJsonRpcMessage,
|
||||
ClientNotification, ClientRequest, ClientResult, CreateMessageRequest,
|
||||
CreateMessageRequestParams, CreateMessageResult, EmptyResult, ErrorData, ListRootsRequest,
|
||||
ListRootsResult, LoggingMessageNotification, LoggingMessageNotificationParam,
|
||||
ProgressNotification, ProgressNotificationParam, PromptListChangedNotification,
|
||||
ProtocolVersion, ResourceListChangedNotification, ResourceUpdatedNotification,
|
||||
ResourceUpdatedNotificationParam, ServerInfo, ServerNotification, ServerRequest,
|
||||
ServerResult, SubscriptionFilter, SubscriptionsAcknowledgedNotification,
|
||||
CreateMessageRequestParams, CreateMessageResult, EmptyResult, ErrorData,
|
||||
InitializeRequestParams, InitializeResult, ListRootsRequest, ListRootsResult,
|
||||
LoggingMessageNotification, LoggingMessageNotificationParam, ProgressNotification,
|
||||
ProgressNotificationParam, PromptListChangedNotification, ProtocolVersion,
|
||||
ResourceListChangedNotification, ResourceUpdatedNotification,
|
||||
ResourceUpdatedNotificationParam, ServerNotification, ServerRequest, ServerResult,
|
||||
SubscriptionFilter, SubscriptionsAcknowledgedNotification,
|
||||
SubscriptionsAcknowledgedNotificationParams, ToolListChangedNotification,
|
||||
},
|
||||
transport::DynamicTransportError,
|
||||
|
|
@ -37,8 +38,8 @@ impl ServiceRole for RoleServer {
|
|||
type PeerReq = ClientRequest;
|
||||
type PeerResp = ClientResult;
|
||||
type PeerNot = ClientNotification;
|
||||
type Info = ServerInfo;
|
||||
type PeerInfo = ClientInfo;
|
||||
type Info = InitializeResult;
|
||||
type PeerInfo = InitializeRequestParams;
|
||||
|
||||
type InitializeError = ServerInitializeError;
|
||||
const IS_CLIENT: bool = false;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ use crate::{
|
|||
model::{
|
||||
ClientCapabilities, ClientJsonRpcMessage, ClientNotification, ClientRequest, ErrorCode,
|
||||
ErrorData, GetExtensions, GetMeta, Implementation, InitializeRequest,
|
||||
InitializeRequestParams, InitializedNotification, JsonObject, JsonRpcError,
|
||||
ProtocolVersion, RequestId, ServerInfo, ServerJsonRpcMessage, ServerResult,
|
||||
InitializeRequestParams, InitializeResult, InitializedNotification, JsonObject,
|
||||
JsonRpcError, ProtocolVersion, RequestId, ServerJsonRpcMessage, ServerResult,
|
||||
},
|
||||
serve_server,
|
||||
service::{
|
||||
|
|
@ -367,7 +367,7 @@ impl<S: Service<RoleServer>> Service<RoleServer> for NegotiatingStatelessHttpSer
|
|||
self.0.handle_notification(notification, context).await
|
||||
}
|
||||
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
self.0.get_info()
|
||||
}
|
||||
|
||||
|
|
@ -2111,7 +2111,7 @@ where
|
|||
Ok(accepted_response())
|
||||
}
|
||||
|
||||
/// Build a `ClientInfo` (peer_info) for a stateless request so that
|
||||
/// Build a `InitializeRequestParams` (peer_info) for a stateless request so that
|
||||
/// `context.protocol_version()` returns the correct value inside handlers.
|
||||
///
|
||||
/// `serve_directly` skips the MCP handshake and accepts `peer_info = None`,
|
||||
|
|
|
|||
Loading…
Reference in a new issue