Skip to main content

gitcortex_mcp/mcp/
server.rs

1use std::path::PathBuf;
2
3use anyhow::{Context, Result};
4use rmcp::{transport::io::stdio, ServiceExt};
5
6use crate::mcp::tools::GitCortexServer;
7
8pub async fn serve(repo_root: PathBuf) -> Result<()> {
9    let handler = GitCortexServer::new(&repo_root).context("failed to open graph store")?;
10
11    let transport = stdio();
12    tracing::info!("GitCortex MCP server started (stdio)");
13
14    // `serve` returns a `RunningService` that owns the message loop. Dropping
15    // it immediately tears the connection down — the client only ever sees the
16    // `initialize` response, then the process exits. Hold it and `waiting()`
17    // until the transport closes (client disconnects / EOF on stdin).
18    let service = handler.serve(transport).await.context("MCP server error")?;
19    service.waiting().await.context("MCP server stopped")?;
20
21    Ok(())
22}