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

Function send_mcp_app_message

src/apps/desktop/src/api/mcp_api.rs:725–797  ·  view source on GitHub ↗
(
    state: State<'_, AppState>,
    request: SendMCPAppMessageRequest,
)

Source from the content-addressed store, hash-verified

723
724#[tauri::command]
725pub async fn send_mcp_app_message(
726 state: State<'_, AppState>,
727 request: SendMCPAppMessageRequest,
728) -> Result<SendMCPAppMessageResponse, String> {
729 let mcp_service = state
730 .mcp_service
731 .as_ref()
732 .ok_or_else(|| "MCP service not initialized".to_string())?;
733
734 let connection = mcp_service
735 .server_manager()
736 .get_connection(&request.server_id)
737 .await
738 .ok_or_else(|| format!("MCP server not connected: {}", request.server_id))?;
739
740 let msg = &request.message;
741 let method = msg
742 .get("method")
743 .and_then(|m| m.as_str())
744 .ok_or_else(|| "Missing method".to_string())?;
745 let id = msg.get("id").cloned();
746 let params = msg
747 .get("params")
748 .cloned()
749 .unwrap_or(serde_json::Value::Null);
750
751 let result_value: serde_json::Value = match method {
752 "tools/call" => {
753 let name = params
754 .get("name")
755 .and_then(|n| n.as_str())
756 .ok_or_else(|| "tools/call: missing name".to_string())?;
757 let arguments = params.get("arguments").cloned();
758 let result = connection
759 .call_tool(name, arguments)
760 .await
761 .map_err(|e| e.to_string())?;
762 serde_json::to_value(result).map_err(|e| e.to_string())?
763 }
764 "resources/read" => {
765 let uri = params
766 .get("uri")
767 .and_then(|u| u.as_str())
768 .ok_or_else(|| "resources/read: missing uri".to_string())?;
769 let result = connection
770 .read_resource(uri)
771 .await
772 .map_err(|e| e.to_string())?;
773 serde_json::to_value(result).map_err(|e| e.to_string())?
774 }
775 "ping" => {
776 connection.ping().await.map_err(|e| e.to_string())?;
777 serde_json::json!({})
778 }
779 _ => {
780 let code = -32601;
781 let error_msg = format!("Method not found: {}", method);
782 let response = serde_json::json!({

Callers

nothing calls this directly

Calls 7

server_managerMethod · 0.80
get_connectionMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45
call_toolMethod · 0.45
read_resourceMethod · 0.45
pingMethod · 0.45

Tested by

no test coverage detected