Skip to main content
Glama
README.md
<div align="center">

<img src="docs/media/hero.svg" alt="Kalkan, MCP security gateway for AI agents" width="100%">

**A security gateway that lets AI agents use enterprise systems through the Model Context Protocol — with access control, human approval, audit logging and AI-based threat detection on every tool call.**

![Status](https://img.shields.io/badge/status-active%20development-4A63B5)
![CI](https://github.com/numanak-b221210105/kalkan/actions/workflows/ci.yml/badge.svg)
![Python](https://img.shields.io/badge/python-3.13-3776AB?logo=python&logoColor=white)
![MCP](https://img.shields.io/badge/protocol-MCP-1B2A6B)
![License](https://img.shields.io/badge/license-MIT-1B2A6B)

**English** · [Türkçe](README.tr.md)

</div>

---

## Overview

Companies are connecting LLM agents to CRM and ERP systems. In practice an agent often runs on a
single, broadly privileged service account, which means:

- there is no record of **which agent did what, on whose behalf**,
- critical actions such as deleting records or bulk exports have **no approval step**,
- an agent manipulated by content it read (prompt injection) **goes unnoticed**.

The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) standardises how agents reach
tools, and recent research documents serious security gaps in its ecosystem. Vendors now ship their
own MCP servers — Salesforce's hosted MCP servers became generally available in April 2026 and
Salesforce itself recommends an **MCP gateway** for central governance across vendors. This project
builds that gateway: a **zero-trust policy enforcement point** between agents and enterprise systems.

**Design principle:** the agent is not trusted, even when its owner is. An agent that read a poisoned
email behaves like an insider controlled by the attacker.

## Architecture

<p align="center"><img src="docs/diagrams/architecture.svg" alt="System architecture" width="100%"></p>

Every tool call passes six steps: **receive → authenticate → authorise → approve if critical → call
the enterprise system → screen the returned free text** before it reaches the agent. Every decision
is written to an append-only audit log that feeds the anomaly detector.

<details>
<summary><b>One tool call, step by step (UML sequence diagram)</b></summary>
<p align="center"><img src="docs/diagrams/sequence.png" alt="Sequence diagram" width="100%"></p>
</details>

<details>
<summary><b>Admin dashboard wireframes</b></summary>

| Overview | Approval queue |
|---|---|
| ![Overview](docs/diagrams/wireframe_overview.png) | ![Approvals](docs/diagrams/wireframe_approvals.png) |
| **Audit log** | **Policies** |
| ![Audit log](docs/diagrams/wireframe_audit.png) | ![Policies](docs/diagrams/wireframe_policies.png) |

</details>

## See it run

<p align="center"><img src="docs/media/demo.svg" alt="Demo client run against a local Kalkan gateway" width="100%"></p>

Condensed output of `scripts/demo_client.py` against a local gateway: an allowed call, three blocked attacks, an RBAC denial, one critical action approved and one rejected by an administrator, and the per agent rate limit. Injection screening needs [Gözcü](https://github.com/numanak-b221210105/gozcu) running next to the gateway.

### Admin dashboard (design prototype)

<p align="center"><img src="docs/media/dashboard.svg" alt="Admin dashboard design prototype" width="100%"></p>

A design prototype of the planned admin dashboard. The approval API, alerts API and audit log behind it already work; the screen itself is not built yet and the numbers are sample data.

## Components

| Component | Description |
|---|---|
| **Gateway core** | MCP server (Streamable HTTP) — the single entry point for agents; routes tool calls to connectors |
| **Access control** | Signed tokens binding agent and user, role-based access control per tool and operation, least privilege — NIST SP 800-207 zero-trust |
| **Human approval** | Critical actions wait in an approval queue until an administrator decides; requests expire automatically |
| **Audit log** | Every call recorded: agent, user, tool, parameters (masked), decisions, result, latency — append-only |
| **Injection detection** | Free-text tool output is screened by the [Gözcü](https://github.com/numanak-b221210105/gozcu), my Turkish and English prompt injection detector, before it reaches the agent |
| **Anomaly detection** *(planned)* | Learns normal behaviour per agent; Isolation Forest compared with an LSTM sequence model |
| **Connectors** | Mock ERP and mail connectors for reproducible tests; Salesforce Developer Edition (REST API) is next |
| **Admin dashboard** *(planned)* | Roles and policies, audit log, approval queue, alerts |

## Quick start

Implemented so far: MCP endpoint, Ed25519 agent tokens, RBAC with effective permissions
(agent role ∩ user roles), per-agent rate limit, approval flow for critical actions,
prompt injection screening of tool output (with the companion detector), append-only audit log,
mock ERP and mail connectors.

```bash
python -m venv .venv && .venv\Scripts\activate     # Linux/macOS: source .venv/bin/activate
pip install -r requirements.txt
pytest                          # unit + integration tests
python scripts/gen_keys.py      # once: signing keys + admin token in keys/ (never committed)
docker run --rm -p 8000:8000 pidetect          # optional: detector from Gözcü
$env:GATEWAY_DETECTOR_URL = "http://127.0.0.1:8000"   # PowerShell; Linux/macOS: export ...
python -m gateway               # gateway on http://127.0.0.1:8080/mcp
python scripts/demo_client.py   # second terminal: allowed calls, approvals, blocked attacks
python scripts/approvals.py     # administrator: pending approvals; `approve <id>` / `reject <id>`
```

Policies: [`config/policies.toml`](config/policies.toml) · decisions: [D-005 – D-008](docs/decisions.md)

## Security analysis

The [threat model](docs/analysis/threat_model.md) covers 5 trust boundaries, 4 attacker types and
18 STRIDE threats, each mapped to a requirement and to the penetration test that will check it.
OWASP Top 10 for LLM Applications coverage: LLM01 Prompt Injection, LLM02 Sensitive Information
Disclosure, LLM05 Improper Output Handling, LLM06 Excessive Agency, LLM10 Unbounded Consumption.

## Evaluation plan

| Test | Method | Target |
|---|---|---|
| Penetration | Token forgery, RBAC bypass, approval replay, prompt-injection suite, OWASP ZAP | Every STRIDE threat checked; attack success rate drops sharply vs. direct connection |
| Latency | Overhead per tool call | < 100 ms on average |
| Load | 50 concurrent agent sessions (k6 / Locust) | Stable operation |
| Anomaly detection | Replayed normal and abnormal call sequences | Precision / recall, Isolation Forest vs. LSTM |
| Usability | 2–3 users on the approval flow and dashboard | Task completion, feedback |

## Documentation

| Topic | Document |
|---|---|
| Requirements (30 functional, 12 non-functional, 9 use cases) | [requirements.md](docs/analysis/requirements.md) |
| Threat model — STRIDE, OWASP LLM mapping | [threat_model.md](docs/analysis/threat_model.md) |
| MCP endpoint and admin API | [api_design.md](docs/analysis/api_design.md) |
| Traceability matrix | [traceability.md](docs/analysis/traceability.md) |
| Diagrams (architecture, DFD, ER, UML, flowcharts, wireframes) | [docs/diagrams](docs/diagrams) |
| Decision log · References | [decisions.md](docs/decisions.md) · [references.md](docs/references.md) |

## Project structure

```
kalkan/
├── gateway/         MCP server, authentication, access control, approval, screening, audit
├── connectors/      Mock ERP and mail connectors (Salesforce next)
├── anomaly/         Anomaly detection models (planned)
├── dashboard/       Admin web interface (planned)
├── tests/           128 unit and integration tests
└── docs/            Analysis, diagrams, decisions
```

## Status

**Working now:** MCP endpoint (`initialize`, `tools/list`, `tools/call`), Ed25519 agent tokens, RBAC with
effective permissions and per agent rate limit, approval flow for critical actions with SSE progress and an
admin API, prompt injection screening of tool output through Gözcü, append only audit log, mock ERP and mail
connectors, CI with Ruff and pytest.

**Next:** Salesforce connector, persistent approval queue on PostgreSQL, anomaly detection (Isolation Forest
compared with an LSTM), admin dashboard, penetration and load tests.

## Tech stack

**Built with:** Python 3.13 · FastAPI · MCP (Streamable HTTP, checked against the official SDK client) ·
Ed25519 signed JWT (PyJWT, cryptography) · SQLite · pytest · Ruff · GitHub Actions

**Planned:** PostgreSQL · scikit-learn · PyTorch · React · TypeScript · Docker Compose · k6 / Locust

## Author

**Numan Ak** · [GitHub](https://github.com/numanak-b221210105) · [LinkedIn](https://www.linkedin.com/in/numan-ak-b93555210)

## License

[MIT](LICENSE)