fix!: omit resultType for legacy protocol sessions (#1038)
This commit is contained in:
parent
76988023b2
commit
6839cfd613
2 changed files with 438 additions and 109 deletions
|
|
@ -55,7 +55,8 @@ impl<H: ServerHandler> Service<RoleServer> for H {
|
|||
) -> Result<<RoleServer as ServiceRole>::Resp, McpError> {
|
||||
// `context` is moved into the dispatch below, so read the negotiated version first.
|
||||
let protocol_version = context.protocol_version();
|
||||
let mrtr_supported = protocol_version
|
||||
// SEP-2322 (`resultType` discriminator, MRTR) exists from 2026-07-28.
|
||||
let sep_2322_supported = protocol_version
|
||||
.as_ref()
|
||||
.is_some_and(|v| v.as_str() >= ProtocolVersion::V_2026_07_28.as_str());
|
||||
let requested_version = context.meta.protocol_version();
|
||||
|
|
@ -240,13 +241,18 @@ impl<H: ServerHandler> Service<RoleServer> for H {
|
|||
.map(ServerResult::task_ack)
|
||||
}
|
||||
};
|
||||
let result = result.and_then(|result| {
|
||||
if matches!(result, ServerResult::InputRequiredResult(_)) && !mrtr_supported {
|
||||
let result = result.and_then(|mut result| {
|
||||
if matches!(result, ServerResult::InputRequiredResult(_)) && !sep_2322_supported {
|
||||
Err(McpError::invalid_request(
|
||||
"InputRequiredResult requires negotiated protocol version 2026-07-28 or newer",
|
||||
None,
|
||||
))
|
||||
} else {
|
||||
// Peers on protocol versions older than 2026-07-28 keep the
|
||||
// legacy wire shape without `resultType: "complete"`.
|
||||
if !sep_2322_supported {
|
||||
result.strip_result_type_for_legacy_peer();
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -108,13 +108,7 @@ impl IntoGetPromptResult for InputRequiredResult {
|
|||
|
||||
impl IntoGetPromptResult for Vec<PromptMessage> {
|
||||
fn into_get_prompt_result(self) -> Result<GetPromptResponse, crate::ErrorData> {
|
||||
Ok(GetPromptResult {
|
||||
result_type: Default::default(),
|
||||
description: None,
|
||||
messages: self,
|
||||
meta: None,
|
||||
}
|
||||
.into())
|
||||
Ok(GetPromptResult::new(self).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue