use crate::mcp::tools::agent_context_tools::{
FindSimilarTool, GetFunctionTool, IndexManager, IndexStatsTool, McpTool as InnerMcpTool,
QueryCodeTool,
};
use async_trait::async_trait;
use pmcp::{Error as PmcpError, RequestHandlerExtra, Result as PmcpResult, ToolHandler};
use serde_json::Value;
use std::sync::Arc;
macro_rules! impl_pmat_handler {
($wrapper:ident, $inner:ident) => {
pub struct $wrapper {
inner: $inner,
}
impl $wrapper {
pub fn new(mgr: Arc<IndexManager>) -> Self {
Self {
inner: $inner::new(mgr),
}
}
}
#[async_trait]
impl ToolHandler for $wrapper {
async fn handle(
&self,
args: Value,
_extra: RequestHandlerExtra,
) -> PmcpResult<Value> {
self.inner.execute(args).await.map_err(PmcpError::internal)
}
}
};
}
impl_pmat_handler!(PmatQueryCodeHandler, QueryCodeTool);
impl_pmat_handler!(PmatGetFunctionHandler, GetFunctionTool);
impl_pmat_handler!(PmatFindSimilarHandler, FindSimilarTool);
impl_pmat_handler!(PmatIndexStatsHandler, IndexStatsTool);