MCPcopy Create free account
hub / github.com/GCWing/BitFun / execute_mcp_add

Method execute_mcp_add

src/apps/cli/src/modes/chat.rs:2515–2644  ·  view source on GitHub ↗

Execute MCP server add (called from main loop after render)

(
        &mut self,
        name: &str,
        config_json_str: &str,
        _chat_view: &mut ChatView,
        chat_state: &mut ChatState,
        rt_handle: &tokio::runtime::Handle,
    )

Source from the content-addressed store, hash-verified

2513
2514 /// Execute MCP server add (called from main loop after render)
2515 fn execute_mcp_add(
2516 &mut self,
2517 name: &str,
2518 config_json_str: &str,
2519 _chat_view: &mut ChatView,
2520 chat_state: &mut ChatState,
2521 rt_handle: &tokio::runtime::Handle,
2522 ) {
2523 let mcp_service = match crate::get_mcp_service() {
2524 Some(svc) => svc.clone(),
2525 None => {
2526 chat_state.add_system_message("MCP service not initialized".to_string());
2527 return;
2528 }
2529 };
2530
2531 let config_value: serde_json::Value = match serde_json::from_str(config_json_str) {
2532 Ok(v) => v,
2533 Err(e) => {
2534 chat_state.add_system_message(format!("Invalid JSON: {}", e));
2535 _chat_view.set_status(None);
2536 return;
2537 }
2538 };
2539
2540 let name_owned = name.to_string();
2541 let task_name = name_owned.clone();
2542 let handle = rt_handle.spawn(async move {
2543 let config_obj = config_value.as_object().ok_or_else(|| {
2544 bitfun_core::util::errors::BitFunError::Validation(
2545 "MCP server config must be a JSON object".to_string(),
2546 )
2547 })?;
2548
2549 let server_type = match config_obj.get("type").and_then(|v| v.as_str()) {
2550 Some("sse") => bitfun_core::service::mcp::MCPServerType::Remote,
2551 Some("streamable-http") | Some("streamable_http") | Some("http") => {
2552 bitfun_core::service::mcp::MCPServerType::Remote
2553 }
2554 _ => bitfun_core::service::mcp::MCPServerType::Local,
2555 };
2556
2557 let transport = match config_obj.get("type").and_then(|v| v.as_str()) {
2558 Some("sse") => bitfun_core::service::mcp::MCPServerTransport::Sse,
2559 Some("streamable-http") | Some("streamable_http") | Some("http") => {
2560 bitfun_core::service::mcp::MCPServerTransport::StreamableHttp
2561 }
2562 _ => bitfun_core::service::mcp::MCPServerTransport::Stdio,
2563 };
2564
2565 let command = config_obj
2566 .get("command")
2567 .and_then(|v| v.as_str())
2568 .map(|s| s.to_string());
2569 let args = config_obj
2570 .get("args")
2571 .and_then(|v| v.as_array())
2572 .map(|values| {

Callers 1

runMethod · 0.80

Calls 12

get_mcp_serviceFunction · 0.85
add_system_messageMethod · 0.80
iterMethod · 0.80
add_serverMethod · 0.80
server_managerMethod · 0.80
cloneMethod · 0.45
set_statusMethod · 0.45
spawnMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45
okMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected