LOOP Developer Agent

LOOP Developer Agent

MCP server for LOOP financial infrastructure, enabling AI agents to inspect projects, generate payment integration code, and execute sandbox-validated transactions (M-Pesa, LOOP, PesaLink) with a deterministic policy engine.

Category
访问服务器

README

LOOP Developer Agent

AI-powered developer platform for building on LOOP financial infrastructure. Built for the LOOP Hackathon — Sandbox environment.


What is this?

LOOP Developer Agent is an MCP-compliant AI platform that:

  1. Inspects your project — detects framework (Django, FastAPI, Flask, Next.js, Express), package manager, and existing payment integrations.
  2. Generates integration code — produces production-ready LOOP payment code tailored to your stack.
  3. Runs sandbox tests — validates signing, authentication, and API calls against the real LOOP sandbox.
  4. Enforces policy — a deterministic policy engine gates every financial operation before the LLM can act.
  5. Provides a full CLIloop init, loop dev, loop tools, loop doctor, loop test.

The demo: a developer says "Add LOOP payments" → the agent inspects the Django shop → discovers the MCP server → generates the integration code → runs sandbox validation → detects issues → fixes → marks READY.


Architecture

┌─────────────────────────────────────────────────────────────┐
│  Developer (CLI / Claude Desktop / IDE)                     │
└──────────────────────┬──────────────────────────────────────┘
                       │ MCP protocol (stdio)
┌──────────────────────▼──────────────────────────────────────┐
│  MCP Server (mcp_server/server.py)                          │
│  14 tools  ·  2 resources  ·  2 prompts                     │
└──────────┬────────────────────────┬────────────────────────-┘
           │                        │
┌──────────▼──────────┐   ┌─────────▼─────────────────────────┐
│  Policy Engine      │   │  Service Layer (mcp_server/        │
│  (policy/engine.py) │   │  service.py) — idempotency,        │
│  ALLOW / DENY /     │   │  credential validation             │
│  REQUIRES_APPROVAL  │   └──────────────┬────────────────────-┘
└─────────────────────┘                  │
                                ┌────────▼────────────────────┐
                                │  LOOP Adapter               │
                                │  (loop/adapters/sandbox.py) │
                                │  All 10 LOOP APIs           │
                                └────────────────────────────-┘

Quick Start

1. Prerequisites

  • Python 3.11+
  • A LOOP Developer Portal account (https://sandbox.loop.co.ke/devportal)
  • Your Consumer Key and Consumer Secret from the portal

2. Install

git clone <this-repo>
cd loop_mcp
pip install -e ".[dev]"

3. Configure

cp .env.example .env

Edit .env — see docs/HUMAN_INPUT_REQUIRED.md for what each value means and where to get it.

Required:

LOOP_CONSUMER_KEY=your_consumer_key
LOOP_CONSUMER_SECRET=your_consumer_secret
LOOP_MERCHANT_TILL=133239           # Use sandbox test till
LOOP_TILL_SECRET_KEY=hyqd7bwMr9Kv-C5PW4n7uF4TiMnMp_hyvyhYYkYlcU8  # Sandbox shared secret

4. Verify everything works

loop doctor

Expected output:

✓ Settings loaded
✓ LOOP credentials present
✓ HMAC test vector: PASS
✓ MCP server importable
✓ Policy engine: ALLOW (sandbox, READ tool)
All checks passed.

5. Start the MCP server

loop dev

6. Explore tools

loop tools        # List all 14 MCP tools
loop sandbox      # Run sandbox scenarios interactively

Demo: Django Laptop Shop

The demo ecommerce application sells a laptop for KES 75,000 and accepts M-Pesa payments via LOOP.

cd demo/django_shop
pip install -r requirements.txt
cp ../../.env .env           # Reuse root .env
python manage.py migrate
python manage.py seed_products
python manage.py runserver

Open http://localhost:8000 — you will see the ProBook Laptop at KES 75,000. Click Buy with M-Pesa to trigger the full LOOP STK Push flow.

Webhook: For the callback to work in sandbox, expose your local server with ngrok http 8000 and set LOOP_WEBHOOK_CALLBACK_URL=https://<your-ngrok>.ngrok.io/loop/webhook/.


CLI Reference

Command Description
loop init Initialise a new LOOP integration in the current project
loop dev Start the MCP server (stdio)
loop tools List all available MCP tools with their LOOP API sources
loop doctor Run health checks (credentials, signing, server import)
loop test Run sandbox integration tests
loop sandbox Interactive sandbox scenarios menu
loop docs Open LOOP API documentation
loop agent Run the developer agent on a project path

MCP Tools

Tool Operation Risk LOOP API
initiate_mpesa_stk_push M-Pesa STK Push WRITE Mpesa Prompt API
initiate_loop_prompt LOOP Prompt WRITE Loop Prompt API
get_transaction_status Transaction inquiry READ Transaction Inquiry API
list_transactions Transaction history READ Transaction History API
pay_to_loop_till Pay to LOOP Till WRITE Pay to Loop Till API
pay_to_mpesa_till Pay to M-Pesa Till WRITE Pay to Mpesa Till API
pay_to_paybill Pay to Paybill WRITE Pay to Paybill API
send_money_loop Send to LOOP SENSITIVE Send Money (LOOP) API
send_money_mpesa Send to M-Pesa SENSITIVE Send Money (Mpesa) API
send_money_pesalink Send via PesaLink SENSITIVE Send Money (PesaLink) API
validate_loop_integration Health check READ
reconcile_transactions Reconciliation READ Transaction History API
get_loop_capabilities Capabilities READ
get_sandbox_credentials Sandbox creds READ

Policy Engine

Every tool call is gated by PolicyEngine.check() before any API call is made. The LLM cannot bypass it.

  • ALLOW — READ tools always; WRITE tools in sandbox.
  • REQUIRES_APPROVAL — SENSITIVE tools always; WRITE tools in production; amounts > KES 10,000.
  • DENY — Invalid amounts; wrong till number; missing credentials.

Project Structure

loop_mcp/
├── loop/                    # Core library
│   ├── config.py            # Settings (pydantic-settings)
│   ├── errors.py            # Typed error hierarchy
│   ├── signing.py           # HMAC-SHA256 signing
│   ├── auth/                # OAuth2 Client Credentials
│   ├── models/              # Pydantic request/response models
│   └── adapters/            # LOOP HTTP client (sandbox + production)
├── policy/                  # Deterministic policy engine
├── mcp_server/              # MCP server (official MCP Python SDK)
│   ├── server.py            # 14 tools, 2 resources, 2 prompts
│   └── service.py           # Service layer with idempotency
├── agent/                   # AI developer agent (Claude)
├── cli/                     # Typer CLI
├── demo/django_shop/        # Demo ecommerce app
├── docs/                    # API inventory, human input guide, security
├── pyproject.toml
├── .env.example
├── Dockerfile
└── docker-compose.yml

Human Input Required

See docs/HUMAN_INPUT_REQUIRED.md for a full list of what must be provided. The critical items:

Variable Where to get it
LOOP_CONSUMER_KEY LOOP Developer Portal → Applications
LOOP_CONSUMER_SECRET LOOP Developer Portal → Applications
LOOP_MERCHANT_TILL Use 133239 for sandbox
LOOP_TILL_SECRET_KEY Use documented sandbox secret (in .env.example)

Security

See docs/security.md for the full security model covering: secret management, OAuth2, HMAC signing, policy engine, idempotency, MCP security, Django app hardening, and OWASP Top 10 mitigations.


What is NOT implemented (by design)

  • No invented endpoints — every API call uses a URL from the official LOOP OpenAPI spec.
  • No production deployment — RealLoopAdapter raises NotImplementedError until the production URL is confirmed.
  • No webhook signature verification — LOOP docs do not specify this; see docs/security.md §Known Gaps.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选