Skip to main content
Glama
Beste-Oztunc

Payment-Risk-Exception-AI-Agent-MCP

by Beste-Oztunc

Payment-Risk-Exception-AI-Agent

A local application example that demonstrates a hybrid payment-decisioning workflow. A rule based deterministic decision policy first assesess transactions and automatically approves or denies. The transactions that have mismatched info but not severe enough to trigger a denial is routed to an LLM agent which reviews the transactions then approves/denies or sends for human-review.

This example uses the following:

  • Stripe's official Python SDK (stripe-python)

  • Stripe's official mock server (stripe-mock)

  • Rule based deterministic decision policy

  • Simulated Merchant Data

  • LLM Agent

  • MCP Server with discoverable tools

  • FastAPI REST endpoints

  • SQLite

  • Docker

  • Postman API testing

  • Analyst dashboard

The four demo transactions

  1. Everything matches

  2. Travel mismatch

  3. Compounding risk

  4. Mixed evidence

Related MCP server: Payments Agent Gateway (MCP)

LLM Agent MCP flow

For exception transactions, the model itself selects the tools:

LLM
  └─ calls get_transaction_context through MCP
       └─ receives Stripe + merchant context and deterministic signals
  └─ then calls exactly one MCP terminal tool:
       ├─ record_ai_decision (approve or deny)
       └─ create_human_review

The Python orchestrator executes the tool calls requested by the model. It does not silently replace the model with a deterministic fallback and does not choose the terminal MCP action on the model's behalf.

Setup

For testing, please create an .env file and provide the LLM key.

Run:

docker compose up --build

Open:

  • Dashboard: http://localhost:8000

  • Health/API configuration: http://localhost:8000/api/health

  • FastAPI docs: http://localhost:8000/docs

  • MCP endpoint: http://localhost:8001/mcp

  • Stripe Mock: http://localhost:12111

Important boundaries

  • Stripe Mock returns fixture-based Stripe objects. It does not process money, run Stripe risk models, or preserve a real payment lifecycle.

  • Merchant session and account data are simulated demo data.

  • Clean transactions stay on deterministic policy; the model is called only for exceptions.

  • The MCP server allows context retrieval, AI decision persistence, and human-review creation.

  • Human-review resolution is intentionally absent from MCP. Only the analyst REST/dashboard path can resolve it.

Screenshots:

Main Screen:

Main Screen

Rules Fired:

Rules Fired

AI Explanation:

AI Explanation

Transaction Details:

Transaction Details

Video Preview:

https://github.com/user-attachments/assets/84ff0226-a9cb-4c60-a4f7-ed301f0b5f5d

Related MCP Connectors

Related MCP Servers