Skip to content

Mcp features ii #771

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

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions refact-agent/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ walkdir = "2.3"
which = "7.0.1"
zerocopy = "0.8.14"

# There you can use a local copy:
mcp_client_rs = { git = "https://github.com/smallcloudai/mcp_client_rust.git" }
#mcp_client_rs = { path = "../../../mcp_client_rust" }


# There you can use a local copy
# rmcp = { path = "../../../rust-sdk/crates/rmcp/", "features" = ["client", "transport-child-process", "transport-sse"] }
rmcp = { git = "https://github.com/smallcloudai/rust-sdk", branch = "cleanup-zombie-processes-for-child-process-client", features = ["client", "transport-child-process", "transport-sse"] }
6 changes: 6 additions & 0 deletions refact-agent/engine/src/files_in_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tracing::info;
use crate::files_correction::{canonical_path, CommandSimplifiedDirExt};
use crate::git::operations::git_ls_files;
use crate::global_context::GlobalContext;
use crate::integrations::running_integrations::load_integrations;
use crate::telemetry;
use crate::file_filter::{is_valid_file, SOURCE_FILE_EXTENSIONS};
use crate::ast::ast_indexer_thread::ast_indexer_enqueue_files;
Expand Down Expand Up @@ -626,6 +627,8 @@ pub async fn on_workspaces_init(gcx: Arc<ARwLock<GlobalContext>>) -> i32
{
// Called from lsp and lsp_like
// Not called from main.rs as part of initialization
let allow_experimental = gcx.read().await.cmdline.experimental;

watcher_init(gcx.clone()).await;
let files_enqueued = enqueue_all_files_from_workspace_folders(gcx.clone(), false, false).await;

Expand All @@ -634,6 +637,9 @@ pub async fn on_workspaces_init(gcx: Arc<ARwLock<GlobalContext>>) -> i32
crate::git::checkpoints::init_shadow_repos_if_needed(gcx_clone).await;
});

// Start or connect to mcp servers
let _ = load_integrations(gcx.clone(), allow_experimental, &["**/mcp_*".to_string()]).await;

files_enqueued
}

Expand Down
22 changes: 17 additions & 5 deletions refact-agent/engine/src/http/routers/v1/v1_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rust_embed::RustEmbed;
use crate::custom_error::ScratchError;
use crate::global_context::GlobalContext;
use crate::integrations::setting_up_integrations::split_path_into_project_and_integration;
use crate::integrations::integr_mcp::SessionMCP;
use crate::integrations::mcp::session_mcp::SessionMCP;


pub async fn handle_v1_integrations(
Expand Down Expand Up @@ -206,20 +206,32 @@ pub async fn handle_v1_integrations_mcp_logs(
let session = gcx.read().await.integration_sessions.get(&session_key).cloned()
.ok_or(ScratchError::new(StatusCode::NOT_FOUND, format!("session {} not found", session_key)))?;

let logs_arc = {
let (logs_arc, stderr_file_path, stderr_cursor) = {
let mut session_locked = session.lock().await;
let session_downcasted = session_locked.as_any_mut().downcast_mut::<SessionMCP>()
.ok_or(ScratchError::new(StatusCode::INTERNAL_SERVER_ERROR, "Session is not a MCP session".to_string()))?;
session_downcasted.logs.clone()
(
session_downcasted.logs.clone(),
session_downcasted.stderr_file_path.clone(),
session_downcasted.stderr_cursor.clone(),
)
};

let logs = logs_arc.lock().await.clone();
if let Some(stderr_path) = &stderr_file_path {
if let Err(e) = crate::integrations::mcp::session_mcp::update_logs_from_stderr(
stderr_path,
stderr_cursor,
logs_arc.clone()
).await {
tracing::warn!("Failed to read stderr file: {}", e);
}
}

return Ok(Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "application/json")
.body(Body::from(serde_json::json!({
"logs": logs,
"logs": logs_arc.lock().await.clone(),
}).to_string()))
.unwrap())
}
Loading
Loading