#![allow(
clippy::todo,
clippy::unimplemented,
clippy::panic,
clippy::unwrap_used,
clippy::expect_used,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::doc_markdown,
clippy::needless_pass_by_value,
clippy::too_many_arguments,
clippy::unused_async,
clippy::diverging_sub_expression,
clippy::no_effect_underscore_binding,
clippy::let_unit_value,
clippy::used_underscore_binding,
clippy::let_underscore_untyped,
clippy::struct_field_names,
clippy::manual_let_else,
clippy::map_unwrap_or,
clippy::redundant_pub_crate,
dead_code,
unreachable_code,
unused_assignments,
unused_mut,
unused_imports,
unused_variables
)]
mod upstream;
use arcp::error::ARCPError;
use arcp::{Envelope, ErrorCode};
use serde_json::{json, Value};
use tokio::sync::mpsc;
use crate::upstream::{upstream_params, ClientSession};
async fn advertise_from_mcp(mcp: &ClientSession) -> Vec<String> {
mcp.list_tools()
.await
.into_iter()
.map(|t| format!("arcpx.mcp.tool.{t}.v1"))
.collect()
}
async fn call_via_mcp(
_mcp: &ClientSession,
tool: &str,
arguments: Value,
) -> Result<Value, ARCPError> {
let _ = (tool, arguments);
todo!()
}
async fn handle_invoke(
send: &mpsc::Sender<Envelope>,
mcp: &ClientSession,
request: Envelope,
) -> Result<(), ARCPError> {
let job_id = "job_<rand>";
let tool: String = todo!(); let arguments: Value = todo!(); match call_via_mcp(mcp, &tool, arguments).await {
Ok(_result) => {
}
Err(_exc) => {
}
}
let _ = (send, request);
Ok(())
}
async fn run_bridge(
send: mpsc::Sender<Envelope>,
mut inbound: mpsc::Receiver<Envelope>,
) -> Result<(), ARCPError> {
let _params = upstream_params();
let mcp = ClientSession;
mcp.initialize().await;
let extensions = advertise_from_mcp(&mcp).await;
println!("bridged: {extensions:?}");
while let Some(envelope) = inbound.recv().await {
handle_invoke(&send, &mcp, envelope).await?;
}
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (send_tx, _send_rx) = mpsc::channel::<Envelope>(64); let (_inbound_tx, inbound_rx) = mpsc::channel::<Envelope>(64);
run_bridge(send_tx, inbound_rx).await?;
Ok(())
}