• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nicholaswilde / aria2-mcp-rs / 22338964268

24 Feb 2026 06:11AM UTC coverage: 90.88% (+8.4%) from 82.491%
22338964268

push

github

nicholaswilde
chore: Bump version to 0.1.17

4584 of 5044 relevant lines covered (90.88%)

6.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.67
/src/server/stdio.rs
1
use anyhow::Result;
2
use mcp_sdk_rs::server::Server;
3
use mcp_sdk_rs::transport::stdio::StdioTransport;
4
use std::sync::Arc;
5
use tokio::sync::RwLock;
6

7
use crate::aria2::notifications::Aria2Notification;
8
use crate::aria2::Aria2Client;
9
use crate::prompts::PromptRegistry;
10
use crate::resources::ResourceRegistry;
11
use crate::server::handler::McpHandler;
12
use crate::tools::ToolRegistry;
13

14
pub fn create_server(
1✔
15
    registry: Arc<RwLock<ToolRegistry>>,
1✔
16
    resource_registry: Arc<RwLock<ResourceRegistry>>,
1✔
17
    prompt_registry: Arc<RwLock<PromptRegistry>>,
1✔
18
    clients: Vec<Arc<Aria2Client>>,
1✔
19
) -> Server {
1✔
20
    let (transport, _sender) = StdioTransport::new();
1✔
21
    let handler = Arc::new(McpHandler::new(
1✔
22
        registry,
1✔
23
        resource_registry,
1✔
24
        prompt_registry,
1✔
25
        clients,
1✔
26
    ));
27
    Server::new(Arc::new(transport), handler)
1✔
28
}
1✔
29

30
pub async fn run_server(
×
31
    registry: Arc<RwLock<ToolRegistry>>,
×
32
    resource_registry: Arc<RwLock<ResourceRegistry>>,
×
33
    prompt_registry: Arc<RwLock<PromptRegistry>>,
×
34
    clients: Vec<Arc<Aria2Client>>,
×
35
    mut notification_rx: tokio::sync::mpsc::Receiver<Aria2Notification>,
×
36
) -> Result<()> {
×
37
    let (transport, sender) = StdioTransport::new();
×
38
    let handler = Arc::new(McpHandler::new(
×
39
        registry,
×
40
        resource_registry,
×
41
        prompt_registry,
×
42
        clients,
×
43
    ));
44
    let server = Server::new(Arc::new(transport), handler);
×
45

46
    tokio::spawn(async move {
×
47
        while let Some(notification) = notification_rx.recv().await {
×
48
            let mcp_notification = notification.to_mcp_notification();
×
49
            // Try to deserialize into the transport's Message type
50
            match serde_json::from_value::<mcp_sdk_rs::transport::Message>(mcp_notification) {
×
51
                Ok(msg) => {
×
52
                    if let Err(e) = sender.send(Ok(msg)) {
×
53
                        log::error!("Failed to send notification to client: {}", e);
×
54
                    }
×
55
                }
56
                Err(e) => {
×
57
                    log::error!("Failed to serialize notification for transport: {}", e);
×
58
                }
59
            }
60
        }
61
    });
×
62

63
    server
×
64
        .start()
×
65
        .await
×
66
        .map_err(|e| anyhow::anyhow!("Server error: {:?}", e))?;
×
67
    Ok(())
×
68
}
×
69

70
#[cfg(test)]
71
mod tests {
72
    use super::*;
73
    use crate::aria2::notifications::{Aria2Event, Aria2EventParams};
74
    use crate::config::Config;
75

76
    #[tokio::test]
77
    async fn test_create_server() {
1✔
78
        let registry = Arc::new(RwLock::new(ToolRegistry::new(&Config::default())));
1✔
79
        let resource_registry = Arc::new(RwLock::new(ResourceRegistry::default()));
1✔
80
        let prompt_registry = Arc::new(RwLock::new(PromptRegistry::default()));
1✔
81
        let client = Arc::new(Aria2Client::new(Config::default()));
1✔
82

83
        let _server = create_server(registry, resource_registry, prompt_registry, vec![client]);
1✔
84
    }
1✔
85

86
    #[tokio::test]
87
    async fn test_notification_loop_logic() {
1✔
88
        let (tx, rx) = tokio::sync::mpsc::channel::<Aria2Notification>(1);
1✔
89
        let (transport_tx, mut transport_rx) = tokio::sync::mpsc::unbounded_channel::<
1✔
90
            Result<mcp_sdk_rs::transport::Message, String>,
1✔
91
        >();
1✔
92

93
        let notification = Aria2Notification {
1✔
94
            jsonrpc: "2.0".to_string(),
1✔
95
            method: Aria2Event::DownloadStart,
1✔
96
            params: vec![Aria2EventParams {
1✔
97
                gid: "123".to_string(),
1✔
98
            }],
1✔
99
        };
1✔
100
        tx.send(notification).await.unwrap();
1✔
101
        drop(tx);
1✔
102

103
        let mut rx = rx;
1✔
104
        if let Some(n) = rx.recv().await {
1✔
105
            let mcp_n = n.to_mcp_notification();
1✔
106
            let msg = serde_json::from_value::<mcp_sdk_rs::transport::Message>(mcp_n).unwrap();
1✔
107
            transport_tx.send(Ok(msg)).unwrap();
1✔
108
        }
1✔
109

110
        let received = transport_rx.recv().await.unwrap().unwrap();
1✔
111
        assert!(format!("{:?}", received).contains("notifications/aria2/event"));
1✔
112
    }
1✔
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc