Skip to content

Commit 6268726

Browse files
authored
feat: add server_supports_completion method (#104)
1 parent 7083e54 commit 6268726

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

crates/rust-mcp-sdk/src/mcp_traits/mcp_client.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ pub trait McpClient: Sync + Send {
131131
.map(|server_details| server_details.capabilities.logging.is_some())
132132
}
133133

134+
/// Checks if the server supports argument autocompletion suggestions.
135+
///
136+
/// This function retrieves the server information and checks if the
137+
/// server has completions capabilities listed. If the server info has
138+
/// not been retrieved yet, it returns `None`. Otherwise, it returns
139+
/// `Some(true)` if completions is supported, or `Some(false)` if not.
140+
///
141+
/// # Returns
142+
/// - `None` if server information is not yet available.
143+
/// - `Some(true)` if completions is supported by the server.
144+
/// - `Some(false)` if completions is not supported by the server.
145+
fn server_supports_completion(&self) -> Option<bool> {
146+
self.server_info()
147+
.map(|server_details| server_details.capabilities.completions.is_some())
148+
}
149+
134150
fn instructions(&self) -> Option<String> {
135151
self.server_info()?.instructions
136152
}

crates/rust-mcp-sdk/src/schema.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#[cfg(feature = "2025_06_18")]
22
pub use rust_mcp_schema::*;
33

4+
#[cfg(not(feature = "2025_06_18"))]
5+
pub use rust_mcp_schema::{ParseProtocolVersionError, ProtocolVersion};
6+
47
#[cfg(all(
58
feature = "2025_03_26",
69
not(any(feature = "2024_11_05", feature = "2025_06_18"))

examples/hello-world-mcp-server-stdio/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
mod handler;
22
mod tools;
33

4-
use std::sync::Arc;
5-
64
use handler::MyServerHandler;
75
use rust_mcp_sdk::schema::{
86
Implementation, InitializeResult, ServerCapabilities, ServerCapabilitiesTools,
97
LATEST_PROTOCOL_VERSION,
108
};
11-
129
use rust_mcp_sdk::{
1310
error::SdkResult,
1411
mcp_server::{server_runtime, ServerRuntime},
1512
McpServer, StdioTransport, TransportOptions,
1613
};
14+
use std::sync::Arc;
1715

1816
#[tokio::main]
1917
async fn main() -> SdkResult<()> {

0 commit comments

Comments
 (0)