mcp-agent-guardrails-spring-boot-starter
Health Uyari
- License — License: Apache-2.0
- Description — Repository has a description
- Active repo — Last push 0 days ago
- Low visibility — Only 5 GitHub stars
Code Gecti
- Code scan — Scanned 11 files during light audit, no dangerous patterns found
Permissions Gecti
- Permissions — No dangerous permissions requested
Bu listing icin henuz AI raporu yok.
Security & governance guardrails for MCP agents in Java — audit trail, agent-to-tool authorization, prompt-injection detection and rate limiting as a zero-config Spring Boot starter.
MCP Agent Guardrails
MCP Agent Guardrails helps you put security and governance controls around
MCP tool calls in Java / Spring Boot applications with
absolute minimum fuss. Every tool invocation runs through a chain of guardrails — audit,
authorization, prompt-injection detection and rate limiting — before the tool executes.
When you expose MCP tools to LLM agents, the "client" is a model deciding on its own what to
invoke and with which arguments. This project closes the four gaps that opens.
Our primary goals are:
- Work with zero configuration: add one dependency and all four guardrails are active with
sensible in-memory defaults. - Be opinionated, but get out of the way: every store, policy source and rule set is a port —
expose your own bean and the default backs off. - Fail closed: a guardrail that throws denies the call rather than passing it (including
AuditGuardrailwhen recording the initialTOOL_INVOKEDevent). The one deliberate exception
is recording the post-chain decision and approval trace in the starter — a broken audit store
degrades trace observability rather than turning an already-allowed call into a failure. - Never persist tool arguments (PII/secret risk) — audit trails carry metadata only.
Modules
| Module | Description |
|---|---|
| guardrails-core | Shared model, Guardrail and ResultGuardrail SPIs, inbound and outbound chains, and the MCP tool-call interceptor |
| guardrails-audit | Audit trail of every invocation, every guardrail decision, both chains and every human approval |
| guardrails-authz | Declarative agent→tool authorization policy (first-match-wins rules) |
| guardrails-injection-guard | Rule-based prompt-injection detection over tool arguments and indirect prompt-injection inspection over tool results |
| guardrails-ratelimit | Fixed-window rate limiting per (agent, tool) pair |
| guardrails-tool-integrity | Pre-TOFU tool-poisoning scan + trust-on-first-use fingerprint of each tool definition, blocking poisoned tools and rug-pulls |
| guardrails-credential-leak-guard | Detects credentials in tool arguments and redacts the ones a tool returns |
| guardrails-egress-control | Allowlist of outbound destinations for tools with network capability, empty by default |
| guardrails-anomaly-detector | Escalates an agent whose recent history looks like a loop or a sweep across tools it never used |
| guardrails-approval-gate | Holds an escalated invocation until a person approves or rejects it; silence denies |
| guardrails-trifecta-correlator | Escalates a session where private data, untrusted content and outbound communication all meet |
| spring-boot-starter | Auto-configuration that assembles everything — the artifact you import |
Installation and Getting Started
Add the starter — that is all it takes:
<dependency>
<groupId>io.github.tikyparkinson</groupId>
<artifactId>mcp-guardrails-spring-boot-starter</artifactId>
<version>0.3.0</version>
</dependency>
Any SyncToolSpecification or AsyncToolSpecification bean (including List beans of either)
in your MCP server is decorated automatically; you do not change how you register tools. A denied
call returns an isError MCP result and the tool never runs.
Authenticating agent identity in production
By default, AgentIdResolver reads the client-declared clientInfo.name from the MCP handshake,
which works out of the box for local/single-client setups but can be spoofed by untrusted clients.
In multi-client deployments where authz, ratelimit or anomaly-detector depend on agent
identity, publish your own AgentIdResolver bean — for exampleAgentIdResolver.fromTransportContext("auth.subject") backed by a Spring Security / OAuth2 / mTLS
transport filter. The starter logs a start-up warning when the default resolver is paired with
identity-dependent guardrails.
Out of the box
With no configuration all eleven modules load and every one of them allows: the guardrails that
need a policy start with an empty one, so upgrading never begins rejecting calls you were already
making. You get the audit trail, the tool-definition baseline and the anomaly history immediately;
the rest start protecting you as you declare what your tools do.
Two things are worth turning on deliberately, because they are what most of the chain reasons
about:
- which tools reach outside, for
egress-control - what each tool can do, for
trifecta-correlator
Configuring the modules
Every module has its own prefix and its own enabled flag. Note that three prefixes are shorter
than the module name: egress, anomaly and trifecta.
mcp:
guardrails:
enabled: true # master switch; false disables everything
authz: # who may call what
default-effect: DENY
rules:
- { agent: "prod-agent", tool: "*", effect: ALLOW }
- { agent: "*", tool: "drop_database", effect: ESCALATE }
tool-integrity: # pre-TOFU poisoning scan + rug-pull detection
on-mismatch: DENY
on-unknown-definition: ALLOW
scan-on-first-use: true
on-poisoned-definition: DENY
injection-guard: # prompt injection in tool arguments and results
built-in-rules-enabled: true
scan-results: true
on-result-injection: BLOCK
result-min-severity: MALICIOUS
credential-leak: # secrets in arguments, and in what tools return
on-confirmed-input: DENY
on-suspected-input: ESCALATE
on-output-text: REDACT
egress: # where tools are allowed to send data
on-violation: DENY
allowed-destinations: ["api.internal.example.com"]
tools:
- { name: "http_post", destination-arguments: ["url"] }
anomaly: # loops and sweeps in recent history
window: PT1M
repeat-threshold: 5
novel-tool-threshold: 3
trifecta: # private data + untrusted content + egress in one session
session-idle-timeout: PT30M
session-max-duration: PT2H
tools:
- { name: "read_customer", capabilities: [PRIVATE_DATA] }
- { name: "fetch_page", capabilities: [UNTRUSTED_CONTENT] }
- { name: "send_email", capabilities: [EXTERNAL_COMMS] }
approval: # holds an escalated call until a person decides
timeout: PT2M
max-pending: 20
ratelimit:
max-invocations: 60
window: PT1M
audit:
in-memory-max-events: 1000
Setting a module's enabled: false removes its guardrail from the chain and leaves the rest
running. Each module README documents its full property list and its pluggable port.
How a call is evaluated
Guardrails run in a fixed order and all of them always evaluate, so you get the full decision
trace even when the first one already denied:
audit → tool-integrity → authz → injection-guard → credential-leak
→ egress-control → anomaly-detector → trifecta-correlator → ratelimit
audit runs first so a denied call is still recorded; ratelimit runs last so a call rejected
earlier does not consume quota. Verdicts combine as Deny > Escalate > Allow.
After the tool returns, a second chain inspects the response — credential-leak redacts
secrets (including Base64/Base64URL payloads and printable BlobResourceContents) andinjection-guard blocks or quarantines indirect prompt injection returned by tools.
Escalation needs somewhere to go
An Escalate verdict is not a rejection: it is a request for a human decision.
guardrails-approval-gate holds the invocation until someone approves or
rejects it, and silence denies. It is on the classpath by default, but it needs a channel: the
starter publishes ResolveApprovalUseCase as a bean for you to inject into your own controller,
and ships no HTTP endpoint of its own. That endpoint decides who may lift a block, so protect it
like one.
If no EscalationResolver is present, an escalation returns an error to the agent — fail-closed,
but indistinguishable from a failure. The starter warns about exactly that at start-up.
Getting Help
- Check the module READMEs linked above — each documents configuration properties and how to
replace the default adapter. - Read ARCHITECTURE.md, the project's law: hexagonal architecture rules,
quality gates and the Definition of Done. - The formal specs live in docs/specs — one spec plus one approval record
(*-DONE.md) per module. - Report bugs at github.com/TikyParkinson/mcp-agent-guardrails-spring-boot-starter/issues.
Contributing
We welcome contributions of all kinds! Please read our
contribution guidelines before submitting a pull request — the project has
a strict quality bar (ARCHITECTURE.md is the law). Security issues go
through SECURITY.md, never public issues.
Reporting Issues
- Before you log a bug, please search the issue tracker to see if someone has already reported
the problem. - Please provide as much information as possible: project version, JVM version, MCP SDK version
and, if possible, a test case that replicates the problem.
Building from Source
You need JDK 25 and Docker (the audit and ratelimit modules run integration tests against a
real PostgreSQL through Testcontainers).
$ mvn verify
mvn verify fails the build unless everything holds: 163 tests, Jacoco coverage ≥ 80% lines
and branches per module (currently 100%/100% on all six), Spotless formatting and Checkstyle.
CI runs the same command on every push and pull request
(ci.yml); releases are published to Maven Central from v*.*.*
tags (release.yml).
License
MCP Agent Guardrails is Open Source software released under the
Apache 2.0 license.
Yorumlar (0)
Yorum birakmak icin giris yap.
Yorum birakSonuc bulunamadi