This commit is contained in:
Danielle Jenkins 2025-03-12 17:51:28 -07:00
parent 4171c923e6
commit 5eab86417d
11 changed files with 28 additions and 28 deletions

View file

@ -11,28 +11,25 @@ use reqwest::Client;
use serde_json::{json, Value}; use serde_json::{json, Value};
use tokio::sync::Mutex; use tokio::sync::Mutex;
#[cfg(test)]
mod tests;
// Cache for documentation lookups to avoid repeated requests // Cache for documentation lookups to avoid repeated requests
#[derive(Clone)] #[derive(Clone)]
struct DocCache { pub struct DocCache {
cache: Arc<Mutex<std::collections::HashMap<String, String>>>, cache: Arc<Mutex<std::collections::HashMap<String, String>>>,
} }
impl DocCache { impl DocCache {
fn new() -> Self { pub fn new() -> Self {
Self { Self {
cache: Arc::new(Mutex::new(std::collections::HashMap::new())), cache: Arc::new(Mutex::new(std::collections::HashMap::new())),
} }
} }
async fn get(&self, key: &str) -> Option<String> { pub async fn get(&self, key: &str) -> Option<String> {
let cache = self.cache.lock().await; let cache = self.cache.lock().await;
cache.get(key).cloned() cache.get(key).cloned()
} }
async fn set(&self, key: String, value: String) { pub async fn set(&self, key: String, value: String) {
let mut cache = self.cache.lock().await; let mut cache = self.cache.lock().await;
cache.insert(key, value); cache.insert(key, value);
} }

4
src/tools/docs/mod.rs Normal file
View file

@ -0,0 +1,4 @@
pub mod docs;
mod tests;
pub use docs::DocRouter;

View file

@ -1,6 +1,5 @@
use super::*; use crate::tools::{DocRouter, DocCache};
use mcp_core::{Content, ToolError}; use mcp_core::{Content, ToolError};
use mcp_server::Router;
use serde_json::json; use serde_json::json;
#[tokio::test] #[tokio::test]

View file

@ -1,3 +1,4 @@
mod docs; pub mod docs;
pub use docs::DocRouter; pub use docs::DocRouter;
pub use docs::docs::DocCache;

View file

@ -6,14 +6,14 @@ use axum::{
routing::get, routing::get,
Router, Router,
}; };
use futures::{Stream, StreamExt, TryStreamExt};
#[cfg(test)]
mod tests;
use futures::{stream::Stream, StreamExt, TryStreamExt};
use mcp_server::{ByteTransport, Server}; use mcp_server::{ByteTransport, Server};
use std::collections::HashMap; use std::collections::HashMap;
use tokio_util::codec::FramedRead; use tokio_util::codec::FramedRead;
#[cfg(test)]
// Tests in ../tests.rs
use anyhow::Result; use anyhow::Result;
use mcp_server::router::RouterService; use mcp_server::router::RouterService;
use crate::{transport::jsonrpc_frame_codec::JsonRpcFrameCodec, tools::DocRouter}; use crate::{transport::jsonrpc_frame_codec::JsonRpcFrameCodec, tools::DocRouter};

View file

@ -0,0 +1,4 @@
mod http_sse_server;
mod tests;
pub use http_sse_server::*;

View file

@ -1,18 +1,11 @@
use super::*; use crate::transport::http_sse_server::App;
use axum::{
body::Body,
http::{Method, Request},
};
use tokio::sync::RwLock;
// Comment out tower imports for now, as we'll handle router testing differently // Comment out tower imports for now, as we'll handle router testing differently
// use tower::Service; // use tower::Service;
// use tower::util::ServiceExt; // use tower::util::ServiceExt;
// Helper function to create an App with an empty state // Helper function to create an App with an empty state
fn create_test_app() -> App { fn create_test_app() -> App {
App { App::new()
txs: Arc::new(RwLock::new(HashMap::new())),
}
} }
#[tokio::test] #[tokio::test]

View file

@ -3,8 +3,6 @@ use tokio_util::codec::Decoder;
#[derive(Default)] #[derive(Default)]
pub struct JsonRpcFrameCodec; pub struct JsonRpcFrameCodec;
#[cfg(test)]
mod tests;
impl Decoder for JsonRpcFrameCodec { impl Decoder for JsonRpcFrameCodec {
type Item = tokio_util::bytes::Bytes; type Item = tokio_util::bytes::Bytes;
type Error = tokio::io::Error; type Error = tokio::io::Error;

View file

@ -0,0 +1,4 @@
mod jsonrpc_frame_codec;
mod tests;
pub use jsonrpc_frame_codec::JsonRpcFrameCodec;

View file

@ -1,5 +1,6 @@
use super::*; use crate::transport::jsonrpc_frame_codec::JsonRpcFrameCodec;
use tokio_util::bytes::BytesMut; use tokio_util::bytes::BytesMut;
use tokio_util::codec::Decoder;
#[test] #[test]
fn test_decode_single_line() { fn test_decode_single_line() {

View file

@ -1,5 +1,4 @@
use cratedocs_mcp::{tools::DocRouter, transport::jsonrpc_frame_codec::JsonRpcFrameCodec}; use cratedocs_mcp::{tools::DocRouter, transport::jsonrpc_frame_codec::JsonRpcFrameCodec};
use mcp_core::Tool;
use mcp_server::Router; use mcp_server::Router;
use serde_json::{json, Value}; use serde_json::{json, Value};
use tokio_util::codec::Decoder; use tokio_util::codec::Decoder;