feat(model): add ServerConfig and ClientConfig (#1266)
This commit is contained in:
parent
fbfc5cc96e
commit
165ff92df1
6 changed files with 331 additions and 303 deletions
|
|
@ -3,7 +3,7 @@ use std::env;
|
|||
use anyhow::{Context, Result};
|
||||
use rmcp::{
|
||||
ServiceExt,
|
||||
model::InitializeRequestParams,
|
||||
model::ClientConfig,
|
||||
transport::{
|
||||
StreamableHttpClientTransport,
|
||||
auth::{AuthClient, ClientCredentialsConfig, OAuthState},
|
||||
|
|
@ -73,7 +73,7 @@ async fn main() -> Result<()> {
|
|||
);
|
||||
|
||||
// Connect to MCP server and list tools
|
||||
let client_service = InitializeRequestParams::default();
|
||||
let client_service = ClientConfig::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::InitializeRequestParams,
|
||||
model::ClientConfig,
|
||||
service::RunningService,
|
||||
transport::{
|
||||
StreamableHttpClientTransport,
|
||||
|
|
@ -58,7 +58,7 @@ async fn callback_handler(
|
|||
|
||||
enum ConnectOutcome {
|
||||
/// The server accepted the unauthenticated connection.
|
||||
Connected(RunningService<RoleClient, InitializeRequestParams>),
|
||||
Connected(RunningService<RoleClient, ClientConfig>),
|
||||
/// 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 InitializeRequestParams::default().serve(transport).await {
|
||||
match ClientConfig::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, InitializeRequestParams>> {
|
||||
) -> Result<RunningService<RoleClient, ClientConfig>> {
|
||||
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(InitializeRequestParams::default().serve(transport).await?)
|
||||
Ok(ClientConfig::default().serve(transport).await?)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use clap::{Parser, ValueEnum};
|
|||
use rmcp::{
|
||||
ClientHandler, ServiceExt,
|
||||
model::{
|
||||
CallToolRequestParams, ClientCapabilities, Implementation, InitializeRequestParams,
|
||||
CallToolRequestParams, ClientCapabilities, ClientConfig, Implementation,
|
||||
ProgressNotificationParam,
|
||||
},
|
||||
service::{NotificationContext, RoleClient},
|
||||
|
|
@ -121,8 +121,8 @@ impl ClientHandler for ProgressAwareClient {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_info(&self) -> InitializeRequestParams {
|
||||
InitializeRequestParams::new(
|
||||
fn get_info(&self) -> ClientConfig {
|
||||
ClientConfig::new(
|
||||
ClientCapabilities::default(),
|
||||
Implementation::new("progress-test-client", "1.0.0"),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ use anyhow::Result;
|
|||
use rmcp::{
|
||||
ClientLifecycleMode, ClientServiceExt,
|
||||
model::{
|
||||
CallToolRequestParams, ClientCapabilities, Implementation, InitializeRequestParams,
|
||||
ProtocolVersion,
|
||||
CallToolRequestParams, ClientCapabilities, ClientConfig, Implementation, ProtocolVersion,
|
||||
},
|
||||
transport::StreamableHttpClientTransport,
|
||||
};
|
||||
|
|
@ -19,7 +18,7 @@ async fn main() -> Result<()> {
|
|||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
let transport = StreamableHttpClientTransport::from_uri("http://localhost:8000/mcp");
|
||||
let client_info = InitializeRequestParams::new(
|
||||
let client_info = ClientConfig::new(
|
||||
ClientCapabilities::default(),
|
||||
Implementation::new("streamable-http-client", "0.0.1"),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rmcp::{
|
||||
ClientLifecycleMode, ClientServiceExt,
|
||||
model::{InitializeRequestParams, ProtocolVersion, SubscriptionFilter},
|
||||
model::{ClientConfig, 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 = InitializeRequestParams::default()
|
||||
let client = ClientConfig::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::InitializeRequestParams::new(
|
||||
let client_info = rmcp::model::ClientConfig::new(
|
||||
ClientCapabilities::builder().enable_tasks().build(),
|
||||
rmcp::model::Implementation::from_build_env(),
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue