mcp-api-pentest

mcp-api-pentest

Enables AI assistants to perform automated security audits on APIs, detecting BOLA/IDOR vulnerabilities by comparing responses across user tokens.

Category
访问服务器

README

mcp-api-pentest

An MCP server that lets AI assistants (Claude Desktop, Cursor, Claude Code) perform automated security audits on your APIs. It detects BOLA/IDOR vulnerabilities — the #1 risk in the OWASP API Top 10 — where one user can access another user's data.

Think of it as giving your AI the ability to act like a penetration tester, running requests with different user tokens and comparing the results to find broken authorization logic.


Quickstart in 3 minutes

# 1. Clone and install
git clone https://github.com/josenieto/mcp-api-pentest
cd mcp-api-pentest
uv sync

# 2. Start the mock API (a vulnerable API for safe testing)
uv run mock_api.py

# 3. Start the MCP server
uv run app.py

That's it. The server is now running and waiting for an AI client to connect.


What it does

The project acts as a bridge between an AI and your API:

AI (Claude/Cursor)  ←→  MCP Server  ←→  API Target
                           |
                     Generates REPORTE_PENTEST.md

Example attack flow the AI can run:

  1. Create an invoice with Token A → POST /api/v1/invoices
  2. Read the same invoice with Token B → GET /api/v1/invoices/42
  3. Detect the IDOR → both tokens return 200 OK with 94% similar content
  4. Save the finding → "BOLA/IDOR in invoices endpoint — CRITICAL"
  5. Generate a report → REPORTE_PENTEST.md

All of this happens without writing a single line of code — the AI drives the audit through MCP tools.


Features

  • IDOR detection: Compares API responses with privileged vs unprivileged tokens
  • Chained attacks: Create a resource, capture its ID, then attack it with a different user
  • Multi-session state: Cache dynamic values across requests for complex attack flows
  • Smart truncation: Handles massive JSON responses without flooding the AI's context window
  • Rate limiting: Passive delays to avoid being blocked by WAFs
  • Markdown reports: Automatic generation of security audit reports with evidence
  • Mock API sandbox: 7 intentionally vulnerable endpoints for safe testing
  • CLI entry point: Run from the terminal with mcp-api-pentest --target https://api.example.com

Installation

From source (recommended for now)

git clone https://github.com/josenieto/mcp-api-pentest
cd mcp-api-pentest
uv sync

Requirements

  • Python 3.10 or newer
  • uv package manager

How to Use

Option 1: CLI mode (terminal)

Start the MCP server directly:

uv run app.py

With options:

mcp-api-pentest \
  --swagger spec.json \
  --target https://api.example.com \
  --token-admin "admin123" \
  --token-victim "victim456" \
  --token-attacker "attacker789" \
  --output report.md \
  --delay 1.0

Option 2: Connect an AI client

Add this to your MCP client configuration:

Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "api-logic-pentest": {
      "command": "uv",
      "args": ["run", "app.py"],
      "cwd": "/path/to/mcp-api-pentest"
    }
  }
}

Cursor (.cursor/mcp.json):

{
  "mcpServers": {
    "api-logic-pentest": {
      "command": "uv",
      "args": ["run", "app.py"],
      "cwd": "/path/to/mcp-api-pentest"
    }
  }
}

Claude Code (~/.claude/mcp.json):

{
  "mcpServers": {
    "api-logic-pentest": {
      "command": "uv",
      "args": ["run", "app.py"],
      "cwd": "/path/to/mcp-api-pentest"
    }
  }
}

Option 3: Sandbox mode (test locally)

# Starts a vulnerable mock API on port 8080
uv run mock_api.py

The mock API includes 3 test users with tokens:

User Token Role
Admin admin_secret_token_2026 admin
Victim user_victima_token_abc user
Attacker user_atacante_token_xyz user

Vulnerable endpoints (intentionally broken for testing):

  • GET /api/v1/facturas/{id} — IDOR (no ownership validation)
  • POST /api/v1/invoices — creates invoice, captures ID for chained attacks
  • DELETE /api/v1/invoices/{id} — deletes without ownership check
  • GET /api/v1/users/{id}/profile — reads profile without ownership check
  • PUT /api/v1/users/{id}/profile — mass assignment without ownership (escalate role to admin)
  • GET /api/v1/items — pagination without bounds validation
  • POST /api/v1/items — creates item for chained attacks
  • DELETE /api/v1/items/{id} — deletes without ownership check

Running Tests

# Run all tests (102 tests, all passing)
uv run pytest

# Run with verbose output
uv run pytest -v

# Run tests for a specific module
uv run pytest mcp_api_logic_pentest/idor_detector/tests/

Code quality checks:

# Lint
uv run ruff check .

# Type checking
uv run mypy mcp_api_logic_pentest/ --ignore-missing-imports

Available MCP Tools

The AI can use 11 tools to audit APIs:

Tool What it does
parse_api_spec Reads an OpenAPI/Swagger file and extracts routes
execute_security_request Sends HTTP requests with auth headers and rate limiting
analyze_access_control Compares responses from two tokens to detect IDOR
capture_context Stores a dynamic value (like a created ID) in memory
get_context Retrieves a previously stored value
list_context Lists all stored key-value pairs
clear_context Resets the session cache
extract_json_value Extracts a field from a JSON response using dot-notation
save_security_finding Records a security finding to the audit report
generate_report Returns the full Markdown audit report
export_report_json Exports all findings as structured JSON

Architecture

This project follows a Modular Monolith by Features design.

mcp_api_logic_pentest/
├── config/               → Global settings and logger
├── shared/               → Reusable utilities (JSON truncation)
├── spec_analyzer/        → OpenAPI/Swagger file parsing
├── http_client/          → HTTP communication with auth providers
├── idor_detector/        → Multi-session authorization comparison
├── audit_context/        → In-memory state for chained attacks
├── report_generator/     → Security finding reports (Markdown + JSON)
├── orchestration/        → Cross-module attack flow coordinator
└── adapters/             → Entry points: MCP server and CLI

Each module is self-contained with its own tests. New detection patterns (like Mass Assignment or Rate Limit testing) are added as new modules without touching existing code.

See docs/adr/ADR-001-modular-monolith-by-features.md for the full architecture decision.


Contributing

  1. Create a branch from integration/master
  2. Write your changes plus tests (we follow RED/GREEN/REFACTOR)
  3. Push — CI runs lint, type check, and tests automatically
  4. When CI passes, the merge happens automatically

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选