feat(model): add ServerConfig and ClientConfig (#1266)

This commit is contained in:
Dale Seo 2026-09-14 15:30:41 -04:00 • committed by GitHub
commit 165ff92df1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 331 additions and 303 deletions

View file

@ -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) -> InitializeResult {
InitializeResult::new(
fn get_info(&self) -> ServerConfig {
ServerConfig::new(
ServerCapabilities::builder()
.enable_prompts()
.enable_resources()

View file

@ -131,8 +131,8 @@ impl ProgressDemo {
#[tool_handler]
impl ServerHandler for ProgressDemo {
fn get_info(&self) -> InitializeResult {
InitializeResult::new(ServerCapabilities::builder().enable_tools().build())
fn get_info(&self) -> ServerConfig {
ServerConfig::new(ServerCapabilities::builder().enable_tools().build())
.with_protocol_version(ProtocolVersion::V_2024_11_05)
.with_server_info(Implementation::from_build_env())
.with_instructions(

View file

@ -151,8 +151,8 @@ impl ServerHandler for TaskDemo {
self.tasks.cancel_task(&request.task_id)
}
fn get_info(&self) -> InitializeResult {
InitializeResult::new(
fn get_info(&self) -> ServerConfig {
ServerConfig::new(
ServerCapabilities::builder()
.enable_tools()
.enable_tasks()

View file

@ -310,8 +310,8 @@ impl SqlQueryServer {
#[prompt_handler(router = self.prompt_router)]
impl ServerHandler for SqlQueryServer {
fn get_info(&self) -> InitializeResult {
InitializeResult::new(
fn get_info(&self) -> ServerConfig {
ServerConfig::new(
ServerCapabilities::builder()
.enable_completions()
.enable_prompts()

View file

@ -155,8 +155,8 @@ impl ElicitationEnumFormServer {
#[tool_handler(router = self.tool_router)]
impl ServerHandler for ElicitationEnumFormServer {
fn get_info(&self) -> InitializeResult {
InitializeResult::new(ServerCapabilities::builder().enable_tools().build())
fn get_info(&self) -> ServerConfig {
ServerConfig::new(ServerCapabilities::builder().enable_tools().build())
.with_server_info(Implementation::from_build_env())
.with_instructions(
"Simple server demonstrating elicitation for enum selection".to_string(),

View file

@ -147,8 +147,8 @@ impl ElicitationServer {
#[tool_handler(router = self.tool_router)]
impl ServerHandler for ElicitationServer {
fn get_info(&self) -> InitializeResult {
InitializeResult::new(ServerCapabilities::builder().enable_tools().build())
fn get_info(&self) -> ServerConfig {
ServerConfig::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(),

View file

@ -113,8 +113,8 @@ fn finish_weather_request(
}
impl ServerHandler for WeatherServer {
fn get_info(&self) -> InitializeResult {
let mut info = InitializeResult::new(ServerCapabilities::builder().enable_tools().build());
fn get_info(&self) -> ServerConfig {
let mut info = ServerConfig::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) -> InitializeRequestParams {
InitializeRequestParams::new(
fn get_info(&self) -> ClientConfig {
ClientConfig::new(
ClientCapabilities::builder().enable_elicitation().build(),
Implementation::new("mrtr-example-client", env!("CARGO_PKG_VERSION")),
)

View file

@ -363,13 +363,12 @@ impl PromptServer {
#[prompt_handler(router = self.prompt_router)]
impl ServerHandler for PromptServer {
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, \
fn get_info(&self) -> ServerConfig {
ServerConfig::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.",
)
)
}
}

View file

@ -21,8 +21,8 @@ use tracing_subscriber::{self, EnvFilter};
pub struct SamplingDemoServer;
impl ServerHandler for SamplingDemoServer {
fn get_info(&self) -> InitializeResult {
InitializeResult::new(ServerCapabilities::builder().enable_tools().build())
fn get_info(&self) -> ServerConfig {
ServerConfig::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. ",

View file

@ -2,7 +2,7 @@ use std::{borrow::Cow, time::Duration};
use rmcp::{
ErrorData, ServerHandler,
model::{InitializeResult, ProtocolVersion, ServerCapabilities, SubscriptionFilter},
model::{ProtocolVersion, ServerCapabilities, ServerConfig, 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) -> InitializeResult {
InitializeResult::new(
fn get_info(&self) -> ServerConfig {
ServerConfig::new(
ServerCapabilities::builder()
.enable_tools()
.enable_tool_list_changed()