Skip to main content
Glama
mcp-platform-tools

mcp-platform-tools

by MuhFawad1
README.md
# mcp-platform-tools: a governed, read-only MCP server for platform status

[![CI](https://github.com/MuhFawad1/mcp-platform-tools/actions/workflows/ci.yml/badge.svg)](https://github.com/MuhFawad1/mcp-platform-tools/actions/workflows/ci.yml)
![TypeScript](https://img.shields.io/badge/typescript-strict-3178C6)
![Node.js 26](https://img.shields.io/badge/node-26-5FA04E)
![MCP](https://img.shields.io/badge/MCP-Streamable%20HTTP%20%2B%20OAuth-black)
[![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)

**A reference implementation** of a Model Context Protocol server that platform teams
can safely hand to AI agents. An SRE copilot or an incident bot can ask:

- "is the llm-gateway canary healthy?"
- "how much error budget is left?"
- "what did the payments team spend on models this week?"

The agent gets an answer without ever touching kubectl, PromQL or credentials.

Four read-only tools sit on top of the platform built in the other repositories:

| Tool | Reads | Scope |
|---|---|---|
| `deployment_status` | a Kubernetes Deployment: desired, ready, updated, available, conditions, images | `platform:k8s.read` |
| `rollout_status` | an Argo Rollouts canary from [gitops-argocd-fleet](https://github.com/MuhFawad1/gitops-argocd-fleet): phase, step, stable and canary revisions, aborted | `platform:k8s.read` |
| `slo_status` | objective, error budget remaining, 1h and 6h burn rates, and firing alerts, from the rules generated by [monitoring-observability-stack](https://github.com/MuhFawad1/monitoring-observability-stack) | `platform:slo.read` |
| `gateway_spend` | [llm-gateway](https://github.com/MuhFawad1/llm-gateway) spend in USD and tokens per team and model over 1h, 24h, 7d or 30d | `platform:finops.read` |

```mermaid
flowchart LR
    A[AI agent<br/>MCP client] -->|Streamable HTTP<br/>Bearer JWT, aud = this server| S[mcp-platform-tools]
    IdP[OAuth 2.1 / OIDC<br/>authorization server] -.->|access token with scopes| A
    S -.->|JWKS| IdP
    S --> G{governed: scope, allowlist,<br/>rate limit, timeout, cap, audit}
    G -->|get only, own service account| K[Kubernetes API]
    G -->|instant queries| P[Prometheus<br/>SLO rules + gateway metrics]
    G --> L[(audit log, JSON lines)]
```

## Governance

Every call goes through the same wrapper
([ADR 0001](docs/adr/0001-governance-in-the-server.md)). A prompt-injected agent can at
most read a summary it was already allowed to read.

- **Authentication.** An OAuth 2.1 resource server. JWT access tokens must name this
  server as their audience (RFC 8707). Protected-resource metadata is published at
  `/.well-known/oauth-protected-resource` (RFC 9728). There is no token passthrough:
  backends are called with the server's own identity
  ([ADR 0002](docs/adr/0002-oauth-resource-server.md)).
- **Authorization.** Each tool needs one scope. Namespaces, services and teams are
  allowlisted in the server's config.
- **Input.** zod schemas: DNS-1123 names and a fixed set of time windows. PromQL is
  built only from values that passed both the schema and the allowlist.
- **Limits.** A token-bucket rate limit per principal, a timeout on every backend call,
  a 16 KB result cap and a 64 KB request cap.
- **Output.** Typed summaries, never raw API objects, so a Deployment's environment
  variables never leave the server. Backend errors reach the agent as a generic
  message.
- **Audit.** One JSON line per call: principal, client, tool, arguments, decision,
  outcome, reason, duration, result size. Denials are logged too.
- **Transport.** Stateless Streamable HTTP. Requests from browser origins outside
  `allowedOrigins` are refused, which protects against DNS rebinding
  ([ADR 0004](docs/adr/0004-stateless-streamable-http.md)).
- **Kubernetes.** `get` on deployments and rollouts, bound per allowlisted namespace.
  No `list`, no Secrets, nothing cluster-wide
  ([ADR 0003](docs/adr/0003-least-privilege-backends.md),
  [deploy/kubernetes](deploy/kubernetes/mcp-platform-tools.yaml)).

## Verified against real systems

The [end-to-end test](test/e2e/live.e2e.ts) calls the tools over HTTP with the MCP SDK
client, against:

- the llm-gateway image under traffic
- Prometheus evaluating monitoring-observability-stack's generated SLO rules
- a Kubernetes cluster
- this repository's container image

It checks that every call is audited. A local run against the gitops fleet and the
monitoring demo stack returned:

```text
rollout_status     {"phase":"Healthy","step":5,"steps":5,"stableRevision":"6b7b985989","aborted":false}
slo_status         availability: objective 0.995, budget remaining -2.83, burn rate 1h 2.88,
                   firing: LlmGatewayAvailabilitySlowBurn (ticket)      <- the demo's deliberate 2% errors
gateway_spend      slo-demo: $0.0241 over 1h, 1389 input and 926 output tokens
deployment_status  kube-system/coredns -> "namespace "kube-system" is not in this server's allowlist"
```

Building the tests caught a real bug. llm-gateway labels token directions
`prompt`/`completion`, not `input`/`output`
([ADR 0005](docs/adr/0005-tested-against-real-systems.md)).

## Run it

```bash
npm ci
npm test               # 28 unit tests
npm run coverage       # coverage gate: 85% lines, 75% branches
npm run build && MCP_CONFIG=config.json npm start
```

Configuration is one JSON file, validated at start-up by
[src/config.ts](src/config.ts):

```json
{
  "resource": "https://mcp.platform.example.com/mcp",
  "auth": {"issuer": "https://login.example.com/", "jwksUrl": "https://login.example.com/.well-known/jwks.json"},
  "allow": {"namespaces": ["llm-gateway"], "services": ["llm-gateway"], "teams": ["payments", "research"]},
  "prometheus": {"url": "http://kube-prometheus-stack-prometheus.monitoring.svc:9090"},
  "kubernetes": {"apiServer": "https://kubernetes.default.svc", "tokenFile": "/var/run/secrets/kubernetes.io/serviceaccount/token"}
}
```

Deploy with [deploy/kubernetes/mcp-platform-tools.yaml](deploy/kubernetes/mcp-platform-tools.yaml),
using the signed image `ghcr.io/muhfawad1/mcp-platform-tools`. Releases are multi-arch,
keyless-signed with Sigstore, with an SBOM and provenance. The signature's identity, this
repository's `release.yml` on a version tag, matches the gitops fleet's Kyverno
signature policy.

## What CI checks

| Job | Checks |
|---|---|
| Test | ESLint (strict, type-checked), `tsc` strict, 28 tests with the coverage gate, build, `npm audit` |
| End to end | the container image against llm-gateway, Prometheus with the SLO rules, and a kind cluster; every call audited, a denial included |
| Image | Trivy finds no fixable HIGH or CRITICAL vulnerabilities in the image, and no misconfigurations in the Kubernetes manifests |

## Design decisions

| ADR | Decision |
|---|---|
| [0001](docs/adr/0001-governance-in-the-server.md) | Governance lives in the server, not in the agent's prompt |
| [0002](docs/adr/0002-oauth-resource-server.md) | An OAuth 2.1 resource server, as the MCP authorization spec describes |
| [0003](docs/adr/0003-least-privilege-backends.md) | Least privilege at every backend |
| [0004](docs/adr/0004-stateless-streamable-http.md) | Stateless Streamable HTTP, behind an Origin check |
| [0005](docs/adr/0005-tested-against-real-systems.md) | Test against the real systems the tools read |

## Layout

```text
src/
  auth.ts           JWT access-token verification, scopes
  governance.ts     scope check, rate limit, timeout, result cap, audit
  tools/            the four tools and their input schemas
  backends/         Prometheus and Kubernetes clients
  server.ts         MCP server with read-only tool annotations
  http.ts           protected-resource metadata, health, /mcp with bearer auth
test/               unit tests; e2e/ against real systems
deploy/kubernetes/  namespace, RBAC per namespace, config, Deployment, Service
```

## Roadmap

- Per-tool, per-principal allowlists from token claims (for example, a team claim
  that limits `gateway_spend` to the caller's own team).
- OpenTelemetry spans per tool call, correlated with the audit log.
- An agent-eval-harness suite where an agent uses these tools to triage an incident.
- Argo Rollouts in the CI cluster, so `rollout_status` runs end to end.
- A Helm chart and an ApplicationSet entry in gitops-argocd-fleet.

## License

[MIT](LICENSE)