github-mcp 0.1.0

GitHub v3 REST API MCP server, generated by mcpify.
Documentation
// GitHub v3 REST API MCP server — generated by mcpify. Do not hand-edit.
//
// Minimal Prometheus-text-format counters, exposed at GET /metrics.
// Request/duration histograms are recorded via OpenTelemetry
// (core/otel.rs); this module only surfaces a couple of MCP-specific
// counters that are simplest to track as plain in-process counters.

use std::collections::HashMap;
use std::sync::{LazyLock, Mutex};

static COUNTERS: LazyLock<Mutex<HashMap<String, u64>>> =
    LazyLock::new(|| Mutex::new(HashMap::new()));

pub fn increment(name: &str) {
    let mut counters = COUNTERS.lock().unwrap();
    *counters.entry(name.to_string()).or_insert(0) += 1;
}

pub fn render_metrics() -> String {
    let counters = COUNTERS.lock().unwrap();
    let mut lines: Vec<String> = counters
        .iter()
        .map(|(name, value)| format!("{name} {value}"))
        .collect();
    lines.sort();
    lines.push(String::new());
    lines.join("\n")
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn increments_and_renders_a_counter() {
        increment("test_counter_metrics_rs");
        increment("test_counter_metrics_rs");
        let rendered = render_metrics();
        assert!(rendered.contains("test_counter_metrics_rs 2"));
    }
}