#![cfg_attr(coverage_nightly, coverage(off))]
use anyhow::Result;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, Stdout};
use tokio::sync::{mpsc, oneshot};
use tracing::{debug, info};
use crate::services::analysis_service::{
AnalysisInput, AnalysisOperation, AnalysisOptions, AnalysisService,
};
use crate::services::quality_gate_service::{
QualityCheck, QualityGateInput, QualityGateOutput, QualityGateService,
};
use crate::services::service_base::Service;
#[derive(Clone)]
pub struct ClaudeCodeAgentMcpServer {
config: AgentConfig,
monitored_projects: HashMap<String, MonitoredProject>,
quality_monitor: Option<mpsc::Sender<QualityMonitorCommand>>,
quality_gate_service: Arc<QualityGateService>,
analysis_service: Arc<AnalysisService>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentConfig {
pub name: String,
pub version: String,
pub complexity_threshold: u32,
pub watch_patterns: Vec<String>,
pub update_interval: u64,
pub max_projects: usize,
}
impl Default for AgentConfig {
fn default() -> Self {
Self {
name: "pmat-agent".to_string(),
version: "1.0.0".to_string(),
complexity_threshold: 20, watch_patterns: vec![
"**/*.rs".to_string(),
"**/*.py".to_string(),
"**/*.js".to_string(),
"**/*.ts".to_string(),
"**/*.java".to_string(),
"**/*.go".to_string(),
"**/*.cpp".to_string(),
"**/*.c".to_string(),
"**/*.hpp".to_string(),
"**/*.h".to_string(),
],
update_interval: 5, max_projects: 10,
}
}
}
#[derive(Debug, Clone)]
pub struct MonitoredProject {
pub path: PathBuf,
pub name: String,
pub watch_patterns: Vec<String>,
pub complexity_threshold: u32,
pub last_analysis: Option<ProjectAnalysisResult>,
pub started_at: std::time::SystemTime,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectAnalysisResult {
pub timestamp: String,
pub quality_score: f64,
pub files_analyzed: usize,
pub functions_analyzed: usize,
pub avg_complexity: f64,
pub hotspot_functions: usize,
pub satd_issues: usize,
pub quality_gate_status: String,
pub recommendations: Vec<String>,
}
#[derive(Debug)]
pub enum QualityMonitorCommand {
StartMonitoring {
project_path: PathBuf,
config: Box<MonitoredProject>,
},
StopMonitoring {
project_id: String,
},
GetStatus {
project_id: String,
response_tx: Box<oneshot::Sender<Option<ProjectAnalysisResult>>>,
},
Shutdown,
}
include!("mcp_server_protocol.rs");
include!("mcp_server_tool_defs.rs");
include!("mcp_server_capabilities.rs");
include!("mcp_server_monitoring.rs");
include!("mcp_server_quality.rs");
#[cfg(test)]
#[path = "mcp_server_tests.rs"]
mod tests;