Skip to content

fix: support clients with older versions of mcp protocol #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cmp::Ordering;

use crate::cli::CommandArguments;
use crate::error::ServiceError;
use crate::{error::ServiceResult, fs_service::FileSystemService, tools::*};
Expand All @@ -6,6 +8,7 @@ use rust_mcp_schema::{
schema_utils::CallToolError, CallToolRequest, CallToolResult, ListToolsRequest,
ListToolsResult, RpcError,
};
use rust_mcp_schema::{InitializeRequest, InitializeResult};
use rust_mcp_sdk::mcp_server::ServerHandler;
use rust_mcp_sdk::McpServer;

Expand Down Expand Up @@ -68,6 +71,27 @@ impl ServerHandler for MyServerHandler {
})
}

async fn handle_initialize_request(
&self,
initialize_request: InitializeRequest,
runtime: &dyn McpServer,
) -> std::result::Result<InitializeResult, RpcError> {
runtime
.set_client_details(initialize_request.params.clone())
.map_err(|err| RpcError::internal_error().with_message(format!("{}", err)))?;

let mut server_info = runtime.server_info().to_owned();
// Provide compatibility for clients using older MCP protocol versions.
if server_info
.protocol_version
.cmp(&initialize_request.params.protocol_version)
== Ordering::Greater
{
server_info.protocol_version = initialize_request.params.protocol_version;
}
Ok(server_info)
}

async fn handle_call_tool_request(
&self,
request: CallToolRequest,
Expand Down