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
16 changed files with 323 additions and 286 deletions
|
|
@ -3,7 +3,7 @@ use std::env;
|
|||
use anyhow::{Context, Result};
|
||||
use rmcp::{
|
||||
ServiceExt,
|
||||
model::ClientInfo,
|
||||
model::InitializeRequestParams,
|
||||
transport::{
|
||||
StreamableHttpClientTransport,
|
||||
auth::{AuthClient, ClientCredentialsConfig, OAuthState},
|
||||
|
|
@ -73,7 +73,7 @@ async fn main() -> Result<()> {
|
|||
);
|
||||
|
||||
// Connect to MCP server and list tools
|
||||
let client_service = ClientInfo::default();
|
||||
let client_service = InitializeRequestParams::default();
|
||||
let client = client_service.serve(transport).await?;
|
||||
tracing::info!("Connected to MCP server");
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use axum::{
|
|||
};
|
||||
use rmcp::{
|
||||
RoleClient, ServiceExt,
|
||||
model::ClientInfo,
|
||||
model::InitializeRequestParams,
|
||||
service::RunningService,
|
||||
transport::{
|
||||
StreamableHttpClientTransport,
|
||||
|
|
@ -58,7 +58,7 @@ async fn callback_handler(
|
|||
|
||||
enum ConnectOutcome {
|
||||
/// The server accepted the unauthenticated connection.
|
||||
Connected(RunningService<RoleClient, ClientInfo>),
|
||||
Connected(RunningService<RoleClient, InitializeRequestParams>),
|
||||
/// The server answered 401; authorize with this `WWW-Authenticate`
|
||||
/// challenge and reconnect.
|
||||
AuthRequired(String),
|
||||
|
|
@ -72,7 +72,7 @@ async fn try_connect(http_client: reqwest::Client, server_url: &str) -> Result<C
|
|||
http_client,
|
||||
StreamableHttpClientTransportConfig::with_uri(server_url),
|
||||
);
|
||||
match ClientInfo::default().serve(transport).await {
|
||||
match InitializeRequestParams::default().serve(transport).await {
|
||||
Ok(client) => Ok(ConnectOutcome::Connected(client)),
|
||||
Err(error) => match error.auth_challenge() {
|
||||
Some(challenge) => Ok(ConnectOutcome::AuthRequired(challenge.to_string())),
|
||||
|
|
@ -90,7 +90,7 @@ async fn authorize_and_connect(
|
|||
client_metadata_url: &str,
|
||||
code_receiver: oneshot::Receiver<CallbackParams>,
|
||||
output: &mut BufWriter<tokio::io::Stdout>,
|
||||
) -> Result<RunningService<RoleClient, ClientInfo>> {
|
||||
) -> Result<RunningService<RoleClient, InitializeRequestParams>> {
|
||||
tracing::info!("Server requires authorization: {challenge}");
|
||||
|
||||
// initialize oauth state machine
|
||||
|
|
@ -156,7 +156,7 @@ async fn authorize_and_connect(
|
|||
auth_client,
|
||||
StreamableHttpClientTransportConfig::with_uri(server_url),
|
||||
);
|
||||
Ok(ClientInfo::default().serve(transport).await?)
|
||||
Ok(InitializeRequestParams::default().serve(transport).await?)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use clap::{Parser, ValueEnum};
|
|||
use rmcp::{
|
||||
ClientHandler, ServiceExt,
|
||||
model::{
|
||||
CallToolRequestParams, ClientCapabilities, ClientInfo, Implementation,
|
||||
CallToolRequestParams, ClientCapabilities, Implementation, InitializeRequestParams,
|
||||
ProgressNotificationParam,
|
||||
},
|
||||
service::{NotificationContext, RoleClient},
|
||||
|
|
@ -121,8 +121,8 @@ impl ClientHandler for ProgressAwareClient {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_info(&self) -> ClientInfo {
|
||||
ClientInfo::new(
|
||||
fn get_info(&self) -> InitializeRequestParams {
|
||||
InitializeRequestParams::new(
|
||||
ClientCapabilities::default(),
|
||||
Implementation::new("progress-test-client", "1.0.0"),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ use anyhow::Result;
|
|||
use rmcp::{
|
||||
ClientLifecycleMode, ClientServiceExt,
|
||||
model::{
|
||||
CallToolRequestParams, ClientCapabilities, ClientInfo, Implementation, ProtocolVersion,
|
||||
CallToolRequestParams, ClientCapabilities, Implementation, InitializeRequestParams,
|
||||
ProtocolVersion,
|
||||
},
|
||||
transport::StreamableHttpClientTransport,
|
||||
};
|
||||
|
|
@ -18,7 +19,7 @@ async fn main() -> Result<()> {
|
|||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
let transport = StreamableHttpClientTransport::from_uri("http://localhost:8000/mcp");
|
||||
let client_info = ClientInfo::new(
|
||||
let client_info = InitializeRequestParams::new(
|
||||
ClientCapabilities::default(),
|
||||
Implementation::new("streamable-http-client", "0.0.1"),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rmcp::{
|
||||
ClientLifecycleMode, ClientServiceExt,
|
||||
model::{ClientInfo, ProtocolVersion, SubscriptionFilter},
|
||||
model::{InitializeRequestParams, ProtocolVersion, SubscriptionFilter},
|
||||
transport::StreamableHttpClientTransport,
|
||||
};
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
.init();
|
||||
|
||||
let transport = StreamableHttpClientTransport::from_uri("http://127.0.0.1:8000/mcp");
|
||||
let client = ClientInfo::default()
|
||||
let client = InitializeRequestParams::default()
|
||||
.serve_with_lifecycle(
|
||||
transport,
|
||||
ClientLifecycleMode::Discover {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ async fn main() -> Result<()> {
|
|||
.init();
|
||||
|
||||
// Declare the tasks extension in our client capabilities (SEP-2663).
|
||||
let client_info = rmcp::model::ClientInfo::new(
|
||||
let client_info = rmcp::model::InitializeRequestParams::new(
|
||||
ClientCapabilities::builder().enable_tasks().build(),
|
||||
rmcp::model::Implementation::from_build_env(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -206,8 +206,8 @@ impl Counter {
|
|||
#[tool_handler(meta = MetaObject(rmcp::object!({"tool_meta_key": "tool_meta_value"})))]
|
||||
#[prompt_handler(meta = MetaObject(rmcp::object!({"router_meta_key": "router_meta_value"})))]
|
||||
impl ServerHandler for Counter {
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
InitializeResult::new(
|
||||
ServerCapabilities::builder()
|
||||
.enable_prompts()
|
||||
.enable_resources()
|
||||
|
|
|
|||
|
|
@ -131,8 +131,8 @@ impl ProgressDemo {
|
|||
|
||||
#[tool_handler]
|
||||
impl ServerHandler for ProgressDemo {
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(ServerCapabilities::builder().enable_tools().build())
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
InitializeResult::new(ServerCapabilities::builder().enable_tools().build())
|
||||
.with_protocol_version(ProtocolVersion::V_2024_11_05)
|
||||
.with_server_info(Implementation::from_build_env())
|
||||
.with_instructions(
|
||||
|
|
|
|||
|
|
@ -151,8 +151,8 @@ impl ServerHandler for TaskDemo {
|
|||
self.tasks.cancel_task(&request.task_id)
|
||||
}
|
||||
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
InitializeResult::new(
|
||||
ServerCapabilities::builder()
|
||||
.enable_tools()
|
||||
.enable_tasks()
|
||||
|
|
|
|||
|
|
@ -310,8 +310,8 @@ impl SqlQueryServer {
|
|||
|
||||
#[prompt_handler(router = self.prompt_router)]
|
||||
impl ServerHandler for SqlQueryServer {
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
InitializeResult::new(
|
||||
ServerCapabilities::builder()
|
||||
.enable_completions()
|
||||
.enable_prompts()
|
||||
|
|
|
|||
|
|
@ -155,8 +155,8 @@ impl ElicitationEnumFormServer {
|
|||
|
||||
#[tool_handler(router = self.tool_router)]
|
||||
impl ServerHandler for ElicitationEnumFormServer {
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(ServerCapabilities::builder().enable_tools().build())
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
InitializeResult::new(ServerCapabilities::builder().enable_tools().build())
|
||||
.with_server_info(Implementation::from_build_env())
|
||||
.with_instructions(
|
||||
"Simple server demonstrating elicitation for enum selection".to_string(),
|
||||
|
|
|
|||
|
|
@ -147,8 +147,8 @@ impl ElicitationServer {
|
|||
|
||||
#[tool_handler(router = self.tool_router)]
|
||||
impl ServerHandler for ElicitationServer {
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(ServerCapabilities::builder().enable_tools().build())
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
InitializeResult::new(ServerCapabilities::builder().enable_tools().build())
|
||||
.with_server_info(Implementation::from_build_env())
|
||||
.with_instructions(
|
||||
"Simple server demonstrating elicitation for user name collection".to_string(),
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ fn finish_weather_request(
|
|||
}
|
||||
|
||||
impl ServerHandler for WeatherServer {
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
let mut info = ServerInfo::new(ServerCapabilities::builder().enable_tools().build());
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
let mut info = InitializeResult::new(ServerCapabilities::builder().enable_tools().build());
|
||||
// MRTR requires 2026-07-28 or newer.
|
||||
info.protocol_version = ProtocolVersion::V_2026_07_28;
|
||||
info
|
||||
|
|
@ -173,8 +173,8 @@ impl ServerHandler for WeatherServer {
|
|||
struct InteractiveClient;
|
||||
|
||||
impl ClientHandler for InteractiveClient {
|
||||
fn get_info(&self) -> ClientInfo {
|
||||
ClientInfo::new(
|
||||
fn get_info(&self) -> InitializeRequestParams {
|
||||
InitializeRequestParams::new(
|
||||
ClientCapabilities::builder().enable_elicitation().build(),
|
||||
Implementation::new("mrtr-example-client", env!("CARGO_PKG_VERSION")),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -363,12 +363,13 @@ impl PromptServer {
|
|||
|
||||
#[prompt_handler(router = self.prompt_router)]
|
||||
impl ServerHandler for PromptServer {
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(ServerCapabilities::builder().enable_prompts().build()).with_instructions(
|
||||
"This server provides various prompt templates for code review, data analysis, \
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
InitializeResult::new(ServerCapabilities::builder().enable_prompts().build())
|
||||
.with_instructions(
|
||||
"This server provides various prompt templates for code review, data analysis, \
|
||||
writing assistance, debugging help, and personalized learning paths. \
|
||||
All prompts are designed to provide structured, context-aware assistance.",
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ use tracing_subscriber::{self, EnvFilter};
|
|||
pub struct SamplingDemoServer;
|
||||
|
||||
impl ServerHandler for SamplingDemoServer {
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(ServerCapabilities::builder().enable_tools().build())
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
InitializeResult::new(ServerCapabilities::builder().enable_tools().build())
|
||||
.with_instructions(concat!(
|
||||
"This is a demo server that requests sampling from clients. It provides tools that use LLM capabilities.\n\n",
|
||||
"IMPORTANT: This server requires a client that supports the 'sampling/createMessage' method. ",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::{borrow::Cow, time::Duration};
|
|||
|
||||
use rmcp::{
|
||||
ErrorData, ServerHandler,
|
||||
model::{ProtocolVersion, ServerCapabilities, ServerInfo, SubscriptionFilter},
|
||||
model::{InitializeResult, ProtocolVersion, ServerCapabilities, SubscriptionFilter},
|
||||
service::SubscriptionContext,
|
||||
transport::streamable_http_server::{
|
||||
StreamableHttpServerConfig, StreamableHttpService, session::local::LocalSessionManager,
|
||||
|
|
@ -18,8 +18,8 @@ impl ServerHandler for SubscriptionServer {
|
|||
Cow::Borrowed(&[ProtocolVersion::V_2026_07_28])
|
||||
}
|
||||
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(
|
||||
fn get_info(&self) -> InitializeResult {
|
||||
InitializeResult::new(
|
||||
ServerCapabilities::builder()
|
||||
.enable_tools()
|
||||
.enable_tool_list_changed()
|
||||
|
|
|
|||
Loading…
Reference in a new issue