Dev.to Security 🔐 Cybersecurity 👁 0 📖 3 min read

#KiroweenHackathon26 - How I Built PurposeGovGate: Spec-Driven AI Governance with Kiro IDE and MCP

Autonomous AI agents are increasingly being trusted with real tools—reading support tickets, issuing refunds, and interacting with customer databases. But when an agent acts in the wild, who holds the keys? What happens

#KiroweenHackathon26 - How I Built PurposeGovGate: Spec-Driven AI Governance with Kiro IDE and MCP

Autonomous AI agents are increasingly being trusted with real tools—reading support tickets, issuing refunds, and interacting with customer databases. But when an agent acts in the wild, who holds the keys? What happens when a model hallucinates a parameter, attempts unauthorized data access, or triggers a high-impact financial transaction?

For the Kiroween Hackathon 2026, I built PurposeGovGate (Agent Action → Governance Gate). It is a purpose-bound governance proxy that intercepts agent operations, enforces least-privilege permissions, requires cryptographic human approval for high-risk actions, and records immutable, append-only audit evidence.

In this post, I want to share my experience building this project end-to-end using Kiro IDE, and how Kiro's spec-driven development, custom steering, and Model Context Protocol (MCP) capabilities made building a secure system remarkably efficient.

1. Spec-Driven Development with Kiro Specs

Instead of jumping straight into prompt engineering and ad-hoc coding, I used Kiro Specs in .kiro/specs/purposegovgate-mvp/. This was a game-changer for project architecture:

  • Requirements (requirements.md): Formally cataloged 34 testable requirements across 9 distinct capability areas (identity, authorization, human-in-the-loop approval, transactional atomicity, redacting audit trail, hosted model governor, monitoring, MCP, and maintenance).
  • Design (design.md): Modeled state transitions (from REQUEST_RECEIVED through REQUIRE_APPROVAL to EXECUTED or OUTPUT_WITHHELD), role-based access control (8 distinct personas), and deterministic policy reason codes.
  • Tasks (tasks.md): Structured the entire build into phase-gated slices (S1 through S6).

Having Kiro steer the development through these formal specs ensured zero scope creep and zero dropped edge cases.

2. Guiding Architecture with Kiro Steering

Security-critical applications require strict boundaries. Through Kiro Steering, I set project-wide architectural constraints that guided the coding assistant:

  • Zero-Trust Boundary Isolation: The gateway, policy engine, and database communicate through strict typed boundaries.
  • Transactional Atomic Commits: Local effects (like creating a refund row), audit log generation, and approval consumption must commit together in a single PostgreSQL transaction—or roll back entirely.
  • Separation of Duties: Requester personas can never self-approve sensitive requests (REQUESTER_CANNOT_APPROVE).

Kiro adhered to these steering guidelines across hundreds of lines of backend TypeScript code.

3. Extending Kiro with the Model Context Protocol (MCP)

To allow external AI agents and IDE workflows to interact with governance data without bypassing database security, I implemented a read-only Model Context Protocol (MCP) server (apps/mcp) using @modelcontextprotocol/sdk.

It exposes 6 focused tools over stdio:

  1. list_agents: View active registered agents and their statuses.
  2. get_agent_scope: Inspect purpose statements and permitted actions.
  3. get_pending_approvals: Fetch items waiting for human review.
  4. get_request_audit_timeline: Read immutable event trails for any request.
  5. list_alerts_and_violations: Retrieve policy violations and threshold alerts.
  6. explain_decision: Query deterministic policy evaluation rationale.

By integrating MCP, agents inside Kiro can self-inspect their permitted boundaries before attempting an operation.

4. Property-Based Testing (PBT) for Cryptographic Invariants

One of the highlights of using Kiro for rigorous systems development was implementing Property-Based Testing (PBT) using fast-check alongside Vitest.

Approvals in PurposeGovGate are bound to a keyed HMAC-SHA256 digest of material parameters. To guarantee that variations in JSON formatting or key ordering could never bypass an approval gate, PBT generated hundreds of randomized JSON shapes to prove that RFC-8785 canonical serialization (canonicalize) produced identical cryptographic hashes regardless of payload permutation.

5. The Result: 640+ Tests and Zero Accessibility Violations

With Kiro powering the workflow, the final build includes:

  • 641 transactional database integration tests (npm run test:db) running against an isolated local PostgreSQL instance on port 55432.
  • 58 Playwright end-to-end tests with automated @axe-core/playwright accessibility audits passing with 0 violations (WCAG 2.1 AA).
  • Fully synthetic, reproducible demo data with 8 operational roles.

Conclusion & What's Next

Building with Kiro demonstrated how spec-driven workflows and steering transform AI-assisted programming from unpredictable autocomplete into disciplined systems engineering.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.