feat: migrate JsonRpcMessage/Request/Response/Error/Notification from internal mcp crates to rmcp versions (#3564)

This commit is contained in:
Alex Hancock
2025-07-22 13:45:00 -04:00
committed by GitHub
parent 246ba19256
commit 3e5c9b8505
27 changed files with 256 additions and 246 deletions
+2 -3
View File
@@ -6,7 +6,6 @@ use std::sync::Arc;
use anyhow::{anyhow, Result};
use futures::stream::BoxStream;
use futures::{stream, FutureExt, Stream, StreamExt, TryStreamExt};
use mcp_core::protocol::JsonRpcMessage;
use crate::agents::extension::{ExtensionConfig, ExtensionError, ExtensionResult, ToolInfo};
use crate::agents::extension_manager::{get_parameter_names, ExtensionManager};
@@ -45,7 +44,7 @@ use crate::scheduler_trait::SchedulerTrait;
use crate::tool_monitor::{ToolCall, ToolMonitor};
use mcp_core::{protocol::GetPromptResult, tool::Tool, ToolError, ToolResult};
use regex::Regex;
use rmcp::model::{Content, Prompt};
use rmcp::model::{Content, JsonRpcMessage, Prompt};
use serde_json::Value;
use tokio::sync::{mpsc, Mutex, RwLock};
use tokio_util::sync::CancellationToken;
@@ -775,7 +774,7 @@ impl Agent {
let mcp_notifications = self.get_mcp_notifications().await;
for notification in mcp_notifications {
if let JsonRpcMessage::Notification(notif) = &notification {
if let Some(data) = notif.params.as_ref().and_then(|p| p.get("data")) {
if let Some(data) = notif.notification.params.get("data") {
if let (Some(subagent_id), Some(_message)) = (
data.get("subagent_id").and_then(|v| v.as_str()),
data.get("message").and_then(|v| v.as_str()),
+3 -2
View File
@@ -827,9 +827,10 @@ mod tests {
use mcp_client::client::Error;
use mcp_client::client::McpClientTrait;
use mcp_core::protocol::{
CallToolResult, GetPromptResult, InitializeResult, JsonRpcMessage, ListPromptsResult,
ListResourcesResult, ListToolsResult, ReadResourceResult,
CallToolResult, GetPromptResult, InitializeResult, ListPromptsResult, ListResourcesResult,
ListToolsResult, ReadResourceResult,
};
use rmcp::model::JsonRpcMessage;
use serde_json::json;
use tokio::sync::mpsc;
+18 -14
View File
@@ -6,10 +6,11 @@ use crate::{
};
use anyhow::anyhow;
use chrono::{DateTime, Utc};
use mcp_core::protocol::{JsonRpcMessage, JsonRpcNotification};
use mcp_core::{handler::ToolError, tool::Tool};
use rmcp::model::{JsonRpcMessage, JsonRpcNotification, JsonRpcVersion2_0, Notification};
use rmcp::object;
use serde::{Deserialize, Serialize};
use serde_json::{self, json};
// use serde_json::{self};
use std::{collections::HashMap, sync::Arc};
use tokio::sync::{Mutex, RwLock};
use tracing::{debug, error, instrument};
@@ -112,18 +113,21 @@ impl SubAgent {
/// Send an MCP notification about the subagent's activity
pub async fn send_mcp_notification(&self, notification_type: &str, message: &str) {
let notification = JsonRpcMessage::Notification(JsonRpcNotification {
jsonrpc: "2.0".to_string(),
method: "notifications/message".to_string(),
params: Some(json!({
"level": "info",
"logger": format!("subagent_{}", self.id),
"data": {
"subagent_id": self.id,
"type": notification_type,
"message": message,
"timestamp": Utc::now().to_rfc3339()
}
})),
jsonrpc: JsonRpcVersion2_0,
notification: Notification {
method: "notifications/message".to_string(),
params: object!({
"level": "info",
"logger": format!("subagent_{}", self.id),
"data": {
"subagent_id": self.id,
"type": notification_type,
"message": message,
"timestamp": Utc::now().to_rfc3339()
}
}),
extensions: Default::default(),
},
});
if let Err(e) = self.config.mcp_tx.send(notification).await {
@@ -7,10 +7,11 @@ use crate::agents::subagent_execution_tool::task_execution_tracker::{
use crate::agents::subagent_execution_tool::tasks::process_task;
use crate::agents::subagent_execution_tool::workers::spawn_worker;
use crate::agents::subagent_task_config::TaskConfig;
use mcp_core::protocol::JsonRpcMessage;
use rmcp::model::JsonRpcMessage;
use std::sync::atomic::AtomicUsize;
use std::sync::Arc;
use tokio::sync::mpsc;
use tokio::sync::mpsc::Sender;
use tokio::time::Instant;
const EXECUTION_STATUS_COMPLETED: &str = "completed";
@@ -46,7 +47,7 @@ pub async fn execute_single_task(
pub async fn execute_tasks_in_parallel(
tasks: Vec<Task>,
notifier: mpsc::Sender<JsonRpcMessage>,
notifier: Sender<JsonRpcMessage>,
task_config: TaskConfig,
) -> ExecutionResponse {
let task_execution_tracker = Arc::new(TaskExecutionTracker::new(
@@ -6,14 +6,14 @@ use crate::agents::subagent_execution_tool::{
tasks_manager::TasksManager,
};
use crate::agents::subagent_task_config::TaskConfig;
use mcp_core::protocol::JsonRpcMessage;
use rmcp::model::JsonRpcMessage;
use serde_json::{json, Value};
use tokio::sync::mpsc;
use tokio::sync::mpsc::Sender;
pub async fn execute_tasks(
input: Value,
execution_mode: ExecutionMode,
notifier: mpsc::Sender<JsonRpcMessage>,
notifier: Sender<JsonRpcMessage>,
task_config: TaskConfig,
tasks_manager: &TasksManager,
) -> Result<Value, String> {
@@ -8,7 +8,7 @@ use crate::agents::{
subagent_execution_tool::task_types::ExecutionMode,
subagent_execution_tool::tasks_manager::TasksManager, tool_execution::ToolCallResult,
};
use mcp_core::protocol::JsonRpcMessage;
use rmcp::model::JsonRpcMessage;
use tokio::sync::mpsc;
use tokio_stream;
@@ -1,5 +1,5 @@
use mcp_core::protocol::{JsonRpcMessage, JsonRpcNotification};
use serde_json::json;
use rmcp::model::{JsonRpcMessage, JsonRpcNotification, JsonRpcVersion2_0, Notification};
use rmcp::object;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::{mpsc, RwLock};
@@ -12,6 +12,7 @@ use crate::agents::subagent_execution_tool::notification_events::{
use crate::agents::subagent_execution_tool::task_types::{Task, TaskInfo, TaskResult, TaskStatus};
use crate::agents::subagent_execution_tool::utils::{count_by_status, get_task_name};
use serde_json::Value;
use tokio::sync::mpsc::Sender;
#[derive(Debug, Clone, PartialEq)]
pub enum DisplayMode {
@@ -67,7 +68,7 @@ impl TaskExecutionTracker {
pub fn new(
tasks: Vec<Task>,
display_mode: DisplayMode,
notifier: mpsc::Sender<JsonRpcMessage>,
notifier: Sender<JsonRpcMessage>,
) -> Self {
let task_map = tasks
.into_iter()
@@ -155,11 +156,14 @@ impl TaskExecutionTracker {
if let Err(e) =
self.notifier
.try_send(JsonRpcMessage::Notification(JsonRpcNotification {
jsonrpc: "2.0".to_string(),
method: "notifications/message".to_string(),
params: Some(json!({
"data": event.to_notification_data()
})),
jsonrpc: JsonRpcVersion2_0,
notification: Notification {
method: "notifications/message".to_string(),
params: object!({
"data": event.to_notification_data()
}),
extensions: Default::default(),
},
}))
{
tracing::warn!("Failed to send live output notification: {}", e);
@@ -228,11 +232,14 @@ impl TaskExecutionTracker {
if let Err(e) = self
.notifier
.try_send(JsonRpcMessage::Notification(JsonRpcNotification {
jsonrpc: "2.0".to_string(),
method: "notifications/message".to_string(),
params: Some(json!({
"data": event.to_notification_data()
})),
jsonrpc: JsonRpcVersion2_0,
notification: Notification {
method: "notifications/message".to_string(),
params: object!({
"data": event.to_notification_data()
}),
extensions: Default::default(),
},
}))
{
tracing::warn!("Failed to send tasks update notification: {}", e);
@@ -289,11 +296,14 @@ impl TaskExecutionTracker {
if let Err(e) = self
.notifier
.try_send(JsonRpcMessage::Notification(JsonRpcNotification {
jsonrpc: "2.0".to_string(),
method: "notifications/message".to_string(),
params: Some(json!({
"data": event.to_notification_data()
})),
jsonrpc: JsonRpcVersion2_0,
notification: Notification {
method: "notifications/message".to_string(),
params: object!({
"data": event.to_notification_data()
}),
extensions: Default::default(),
},
}))
{
tracing::warn!("Failed to send tasks complete notification: {}", e);
@@ -1,6 +1,6 @@
use crate::agents::extension_manager::ExtensionManager;
use crate::providers::base::Provider;
use mcp_core::protocol::JsonRpcMessage;
use rmcp::model::JsonRpcMessage;
use std::fmt;
use std::sync::Arc;
use tokio::sync::{mpsc, RwLock};
+1 -1
View File
@@ -4,7 +4,7 @@ use std::sync::Arc;
use async_stream::try_stream;
use futures::stream::{self, BoxStream};
use futures::{Stream, StreamExt};
use mcp_core::protocol::JsonRpcMessage;
use rmcp::model::JsonRpcMessage;
use tokio::sync::Mutex;
use crate::config::permission::PermissionLevel;