Skip to main content
Glama

CodeGraph CLI MCP Server

by Jakedismo
lib.rsโ€ข2.46 kB
use anyhow::Result; use axum::Router; use axum_test::TestServer; use codegraph_api::{create_router, AppState}; use codegraph_core::ConfigManager; use serial_test::serial; use std::{path::PathBuf, sync::Arc}; use tempfile::TempDir; pub struct TestContext { pub server: TestServer, pub tmpdir: TempDir, } impl TestContext { pub fn base_url(&self) -> &str { self.server.base_url() } } /// Create an axum TestServer with isolated working directory and clean RocksDB path. #[allow(dead_code)] pub async fn setup_test_server() -> Result<TestContext> { // Isolate filesystem side-effects per test let tmpdir = tempfile::tempdir()?; // Move CWD so that graph storage at ./data/graph.db stays under tmpdir let original_cwd = std::env::current_dir()?; std::env::set_current_dir(tmpdir.path())?; // Ensure data dir is clean let data_dir = PathBuf::from("data"); if data_dir.exists() { let _ = std::fs::remove_dir_all(&data_dir); } // Minimal config let config = ConfigManager::new_watching(Some("test".to_string())) .expect("Failed to init ConfigManager"); let state = AppState::new(config) .await .expect("Failed to create AppState"); let app: Router = create_router(state); let server = TestServer::new(app).expect("Failed to create TestServer"); // Restore CWD after server init so relative paths in tests are stable std::env::set_current_dir(original_cwd)?; Ok(TestContext { server, tmpdir }) } /// Helper to write a small source tree to a temp directory and return its path. #[allow(dead_code)] pub fn write_sample_repo(tmpdir: &TempDir) -> std::path::PathBuf { let root = tmpdir.path().join("repo"); std::fs::create_dir_all(&root).unwrap(); // Rust file std::fs::write( root.join("lib.rs"), r#"pub fn add(a: i32, b: i32) -> i32 { a + b } pub struct Foo { pub x: i32 } "#, ) .unwrap(); // Python file let py_dir = root.join("py"); std::fs::create_dir_all(&py_dir).unwrap(); std::fs::write( py_dir.join("util.py"), r#"def greet(name): return f"Hello, {name}!" "#, ) .unwrap(); // JavaScript file let js_dir = root.join("js"); std::fs::create_dir_all(&js_dir).unwrap(); std::fs::write( js_dir.join("index.js"), r#"export function mul(a, b) { return a * b } export const NAME = 'cg'; "#, ) .unwrap(); root }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Jakedismo/codegraph-rust'

If you have feedback or need assistance with the MCP directory API, please join our Discord server