Skip to main content
Glama
SHREELASYABEZAWADA

api-testing-agent

MCP API Testing Agent

AIを利用したAPIテストエージェント。Model Context Protocol (MCP) を使用して、APIテストケースの生成、実行、失敗分析を自動化します。

機能

  1. OpenAPI/Swaggerスペック(MCPツール)からエンドポイントを検出します。

  2. LLM(LangChain + OpenAI)を使用して、各エンドポイントの正常系と異常系のテストシナリオ(有効な入力、必須フィールドの欠落、誤った型、境界値、認証失敗など)を生成します。

  3. リクエストを送信し、レスポンスを検証し、HTTPステータスコードを分析するMCPツールを通じて、各テストケースを実APIに対して実行します。

  4. 期待されるレスポンスと実際のレスポンスを比較し、テストがなぜ失敗したのか、その深刻度をLLMに説明させることで、失敗を分析します。

  5. 結果を、構造化されたMarkdown/JSONテストレポートとして報告します。

FastAPIサービスはパーライン全体をラップし、HTTP(POST /agent/run)経由でトリガーできるようにしています(例: CI、スケジューラー、またはUI)。また、MCPサーバーはスタンドアローンで実行し、任意のMCP互換クライアント(Claude Desktop、Claude Code など)に組み込むこともできます。

Related MCP server: MCP-QA

アーキテクチャ

┌─────────────────────┐      OpenAPI spec / target base URL
│   FastAPI Service    │◄──────────────────────────────────
│   (api/main.py)      │
└──────────┬───────────┘
           │ triggers
┌──────────▼───────────┐
│   Testing Agent        │
│   (agent/*.py)         │
│                         │
│  1. TestGenerator       │──uses──► OpenAI (LangChain)
│     (positive/negative  │
│      scenarios)         │
│                         │
│  2. TestExecutor        │──calls──► MCP Client ──stdio──► MCP Server
│     (runs each case)    │                                  │
│                         │                          ┌───────┴────────┐
│  3. FailureAnalyzer     │                          │  MCP Tools:     │
│     (LLM explains diff) │                          │  - discover_    │
│                         │                          │    endpoints    │
│  4. ReportGenerator     │                          │  - send_request │
│     (md/json report)    │                          │  - validate_    │
└─────────────────────────┘                          │    response     │
                                                       │  - analyze_    │
                                                       │    status_code │
                                                       └────────┬───────┘
                                                                │ HTTP
                                                       ┌────────▼───────┐
                                                       │  Target API     │
                                                       │  (any REST API, │
                                                       │  e.g. sample_   │
                                                       │  target_api/)   │
                                                       └─────────────────┘

プロジェク構成

mcp-api-testing-agent/
├── mcp_server/
│   ├── server.py               # MCP server (FastMCP) exposing the 4 tools
│   └── tools/
│       ├── discover.py         # discover_endpoints — parses OpenAPI spec
│       ├── request_tool.py     # send_request — issues HTTP calls
│       ├── validate.py         # validate_response — schema/status checks
│       └── status_analyzer.py  # analyze_status_code — status code semantics
├── agent/
│   ├── mcp_client.py           # stdio MCP client used by the agent
│   ├── test_generator.py       # LLM-based positive/negative test generation
│   ├── test_executor.py        # runs generated test cases via MCP tools
│   ├── failure_analyzer.py     # LLM explains expected-vs-actual mismatches
│   └── report_generator.py     # Markdown + JSON report writer
├── api/
│   └── main.py                  # FastAPI app: POST /agent/run, GET /agent/reports/{id}
├── schemas/
│   └── models.py                # Pydantic models shared across the app
├── sample_target_api/
│   └── demo_api.py              # tiny FastAPI service to test the agent against
├── scripts/
│   └── run_agent.py             # CLI entrypoint (no FastAPI needed)
├── reports/                     # generated test reports land here
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── .env.example

セットアップ

python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env   # add your OPENAI_API_KEY

デモ対象APIを実行する(テスト対象となる小さなサンプルAPI)

uvicorn sample_target_api.demo_api:app --port 9000

これにより、/搭載のCRUDエードポイントを持つ「Task Manager」APIと、生成されたOpenAPIスペックが htttp://localhost:9000/openapi.json で提供されます。

CLIでエージェントを実行する

python scripts/run_agent.py --spec http://localhost:9000/openapi.json --base-url http://localhost:9000

これでテストケースの生成・実行・失敗分析が行われ、レポートが reports/report_<timestamp>.md と .json に書出されます。

HTTPサービスとしてエージェントを実行する

uvicorn api.main:app --port 8000
curl -X POST http://localhost:8000/agent/run \
  -H "Content-Type: application/json" \
  -d '{"spec_url": "http://localhost:9000/openapi.json", "base_url": "http://localhost:9000"}'

MCPサーバーをスタンドアで実行する

組込みのエージェントではなく、ツールをMCP互換クライアント(Claude Desktop、Claude Code など)に組み込むには:

python -m mcp_server.server

その後、MCPクライアントの設定に追加します。例、Claude Desktop(claude_desktop_config.json)の場合:

{
  "mcpServers": {
    "api-testing-agent": {
      "command": "python",
      "args": ["-m", "mcp_server.server"],
      "cwd": "/absolute/path/to/mcp-api-testing-agent"
    }
  }
}

Dockerですべてを実行する

docker compose up --build

これでデモ用APIとMCPバックドのテストエージェントFastAPIサービスが起動し、./reports がマウントされるため、生成されたレポートがホスト上で利用可できます。

サンプルレポート出力

# API Test Report — 2026-02-03T10:15:00

Target: http://localhost:9000
Total: 18   Passed: 15   Failed: 3   Pass rate: 83%

## Failures

### POST /tasks — missing required field "title" (negative test)
Expected: 422 Unprocessable Entity
Actual:   500 Internal Server Error
Analysis: The endpoint does not validate the request body before hitting the
database layer, so a missing "title" causes an unhandled exception instead
of a client-error response. Severity: High — indicates missing input
validation.

実際のプロでのプロジェクに適応用する際の注意点

  • sample_target_api/ を実際のサーに上げる、または --spec / spec_url を実在するOpenAPI/Swagger JSONエンドポイントに指定します。

  • test_generator.py のプロンプトは、ドメインルール(例、必須の認証ヘッダー、レート制限、テナントID)で拡張できます。

  • CIでは、scripts/run_agent.py をパーインのステップとして実行し、report["summary"]["failed"] > の場合はビルドを失敗させます。

Hmm, wait. I produced some typos due to fast writing. Let me review:

  • "Claude Desktop" — spelling! I need "Claude Desktop" / "Claude Code". I'll ensure correct.

  • "MCP" — "MCP" is correct.

  • "Markdown" — "Markdown" fine.

  • "FastAPI" — fine.

  • ".json" — fine.

Let me carefully rewrite with proper spelling.

Also check "displays" — "公開" — fine.

Also "report[“summary”][“failed”" — the inline code has double quotes, I keep it.

Also "toy "Task Manager" API" — I want 「Task Manager」.

Let me craft the final version slowly with precision:

MCP API Testing Agent

(h1 kept)

blank

AIを搭載したAPIテストエージェント。Model Context Protocol (MCP) を使用して、APIテストケースの生成、実行、失敗分析を自動化します。

Wait, "搭載" is "extraordinary" but fine; more formal: "AIを利用した" ok.

機能

  1. OpenAPI/Speccからエンドポイントを検出します(MCPツール経由)。

  2. LLM(LangChain + OpenAI)を使用して、各エンドポイントの正常系・異常系テストシナリオを生成します — 有効な入力、必須フィールドの欠缺、誤った型、境界値、認証失敗など。

  3. MCPツールを介してリクエストを送信し、レスポンスを検証し、HTTPステータスコードを分析することで、各テストケースを実APIに実行します。

  4. 期待するレスポンスと実際のレスポンスの差分を検討し、なぜ失敗したのか、その深刻さをLLMに説明としてもらい、を分析します。 Hmm too wordy.

Let me clean:

  1. 期待レスポンスと実際のレスポンスを比較(diff)し、なぜ失敗のかとその深刻度をLLMに説明させることで、失敗を分析します。

  2. 結果を、構造化されたMarkdown/JSONテストレポートとして出力します。

Next paragraph:

FastAPIサービスはパイプライン全体をラップし、HTTPエンドポイント(POST /agent/run)から起動できます — 例、CI、スケジュール、UIなど。MCPサーバーはスタンド単機也能、MCP互換クライアント(Claude Desktop、Claude Code など)に組み込むこともできます。

More carefully: "A FastAPI service wraps the whole pipeline so it can be triggered over HTTP ... and the MCP server can also be run standalone and plugged..." — So "FastAPIサービスはパイプライン全体をラップしており、HTTP(POST /agent/run)経由でトリガーできます(例、CI、スケジューラ、UIから)。また、MCPサーバーは、スタンドアロンで実行して、どのMCP互換クライアント(Claude Desktop、Claude Code など)にも組み込むこともできます。

OK.

アーキテクチャ

┌─────────────────────┐      OpenAPI spec / target base URL
│   FastAPI Service    │◄──────────────────────────────────
│   (api/main.py)      │
└──────────┬───────────┘
           │ triggers
┌──────────▼───────────┐
│   Testing Agent        │
│   (agent/*.py)         │
│                         │
│  1. TestGenerator       │──uses──► OpenAI (LangChain)
│     (positive/negative  │
│      scenarios)         │
│                         │
│  2. TestExecutor        │──calls──► MCP Client ──stdio──► MCP Server
│     (runs each case)    │                                  │
│                         │                          ┌───────┴────────┐
│  3. FailureAnalyzer     │                          │  MCP Tools:     │
│     (LLM explains diff) │                          │  - discover_    │
│                         │                          │    endpoints    │
│  4. ReportGenerator     │                          │  - send_request │
│     (md/json report)    │                          │  - validate_    │
└─────────────────────────┘                          │    response     │
                                                       │  - analyze_    │
                                                       │    status_code │
                                                       └────────┬───────┘
                                                                │ HTTP
                                                       ┌────────▼───────┐
                                                       │  Target API     │
                                                       │  (any REST API, │
                                                       │  e.g. sample_   │
                                                       │  target_api/)   │
                                                       └─────────────────┘

プロジェク构構成

mcp-api-testing-agent/
├── mcp_server/
│   ├── server.py               # MCP server (FastMCP) exposing the 4 tools
│   └── tools/
│       ├── discover.py         # discover_endpoints — parses OpenAPI spec
│       ├── request_tool.py     # send_request — issues HTTP calls
│       ├── validate.py         # validate_response — schema/status checks
│       └── status_analyzer.py  # analyze_status_code — status code semantics
├── agent/
│   ├── mcp_client.py           # stdio MCP client used by the agent
│   ├── test_generator.py       # LLM-based positive/negative test generation
│   ├── test_executor.py        # runs generated test cases via MCP tools
│   ├── failure_analyzer.py     # LLM explains expected-vs-actual mismatches
│   └── report_generator.py     # Markdown + JSON report writer
├── api/
│   └── main.py                  # FastAPI app: POST /agent/run, GET /agent/reports/{id}
├── schemas/
│   └── models.py                # Pydantic models shared across the app
├── sample_target_api/
│   └── demo_api.py              # tiny FastAPI service to test the agent against
├── scripts/
│   └── run_agent.py             # CLI entrypoint (no FastAPI needed)
├── reports/                     # generated test reports land here
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── .env.example

セットアップ

python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env   # add your OPENAI_API_KEY

デモ対象APIを実行する(テスト対象の小さなサンプルAPI)

uvicorn sample_target_api.demo_api:app --port 9000

これにより、/CRUD端点を持つ「Task Manager」APIや、http://localhost:9000/openapi.json で公開されるOpenAPIスペックが使えるようになります。

Better: "This exposes a tooy API..." - "これで、/ 搭載のCRUDを持つ「Task Manager」というおもちゃAPIと、htttp://localhost:9000/openapi.json のOpenAPIスペックが露されます。"

I'll choose:

"これにより、/のCRUDエンドポイントを持つ「Task Manager」APIと、生成されたOpenAPI仕様が htttp://localhost:9000/openapi.json で提供されます。"

CLIでエージェントを実行する

python scripts/run_agent.py --spec http://localhost:9000/openapi.json --base-url http://localhost:9000

"これでテストケースを生成し、を実行し、失敗を分析し、レポートを reports/report_<timestamp>.md と .json に書出します。"

HTTPサービスとしてエージェントを実行する

uvicorn api.main:app --port 8000
curl -X POST http://localhost:8000/agent/run \
  -H "Content-Type: application/json" \
  -d '{"spec_url": "http://localhost:9000/openapi.json", "base_url": "http://localhost:9000"}'

MCサーバーをスタンドアンで実行する

組み込みのエージェントの代わりに、MCP互換クライアント(Claude Desktop、Claude Code など)にツールを組み込むには:

python -m mcp_server.server

Then add it to your MCP client config: "続いて、MCPクライアントの設定に追加します。例、Claude Desktop(claude_desktop_config.json):"

{
  "mcpServers": {
    "api-testing-agent": {
      "command": "python",
      "args": ["-m", "mcp_server.server"],
      "cwd": "/absolute/path/to/mcp-api-testing-agent"
    }
  }
}

すべてをDockerで実行する

docker compose up --build

"これにより、デモ対象APIとMCPバックエンドのテストエージェントFastAPIサービスが起動し、./reports がマウントされるため、生成されたレポートがホスト側で利用できます。"

サンプルレポート出力

# API Test Report — 2026-02-03T10:15:00

Target: http://localhost:9000
Total: 18   Passed: 15   Failed: 3   Pass rate: 83%

## Failures

### POST /tasks — missing required field "title" (negative test)
Expected: 422 Unprocessable Entity
Actual:   500 Internal Server Error
Analysis: The endpoint does not validate the request body before hitting the
database layer, so a missing "title" causes an unhandled exception instead
of a client-error response. Severity: High — indicates missing input
validation.

実際のプロジェクとに応用する際の注易点

  • sample_target_api/ を実際のサービスに置き換えるか、--spec / spec_url を実稼働中のOpenAPI/Swagger JSONエンドポイントに合わせます。

  • test_enerator.py のプロンプトには、ドメインのルール(例:必須認証ヘッダー、レートリミット、テナントID)を追記したり。

Wait, "can be extended with" = "拡張できる". So "拡張できます".

  • CIでは、scripts/run_agent.py をパーイプラインステップとして実行し、report["summary"]["failed"] > 0 の場合はビルドを失敗させてください。

Great.

Double-check names: report["summary"]["failed"] > 0 — if this is inside code backticks, I must keep. In original: "if report["summary"]["failed"] > 0." — I'll reproduce that code span exactly along with surrounding Japanese.

Also adjust "test_target_api/" — kept.

Potential character issues: "`TI" — no.

Now final compose with the blocks exactly, ensuring GXP tokens on separate lines with blank line before/after.

I'll now output final clean version.

Need to confirm the H5 title "## Run the demo target API (a small sample API to test against)" — I chose "デモ対象APIを実行する". OK.

One more: "Run everything with Docker" — "すべてをDockerで実行する" (not Docker "一文" fine).

Also note: There is a line in original: "then add it to your MCP client config, e.g. for Claude Desktop (claude_desktop_config.json):" — the claude_desktop_config.json path, keep.

Also GXP placeholders. Good.

Potential caution: "GXP" — "reproduce each one alone on its own line" — yep.

Now# MCP API Testing Agent

AIを利用したAPIテストエージェント。Model Context Protocol (MCP) を使用して、APIテストケースの生成、実行、障害分析を自動化します。

機能

  1. OpenAPI/Swagger仕様(MCPツール経由)からエンドポイントを検出します。

  2. LLM(LangChain + OpenAI)を使用して、各エンドポイントの正常系・異常系テストシナリオ(有効な入力、必須フィールドの欠落、誤った型、境界値、認証失敗など)を生成します。

  3. リクエストを送信し、レスポンスを検証し、HTTPステータスコードを分析するMCPツールを介して、各テストケースを実APIに対して実行します。

  4. 期待されるレスポンスと実際のレスポンスを比較(diff)し、なぜテストが失敗したのか、またその深刻度をLLMに説明させることで、障害を分析します。

  5. 結果を、構造化されたMarkdown/JSONテストレポートとして出力します。

FastAPIサービスはパイプライン全体をラップし、HTTP(POST /agent/run)経由でトリガーできるようにします(例:CI、スケジューラー、UIから)。また、MCPサーバーはスタンドアロンで実行し、MCP互換クライアント(Claude Desktop、Claude Code など)に組み込むこともできます。

アーキテクチャ

┌─────────────────────┐      OpenAPI spec / target base URL
│   FastAPI Service    │◄──────────────────────────────────
│   (api/main.py)      │
└──────────┬───────────┘
           │ triggers
┌──────────▼───────────┐
│   Testing Agent        │
│   (agent/*.py)         │
│                         │
│  1. TestGenerator       │──uses──► OpenAI (LangChain)
│     (positive/negative  │
│      scenarios)         │
│                         │
│  2. TestExecutor        │──calls──► MCP Client ──stdio──► MCP Server
│     (runs each case)    │                                  │
│                         │                          ┌───────┴────────┐
│  3. FailureAnalyzer     │                          │  MCP Tools:     │
│     (LLM explains diff) │                          │  - discover_    │
│                         │                          │    endpoints    │
│  4. ReportGenerator     │                          │  - send_request │
│     (md/json report)    │                          │  - validate_    │
└─────────────────────────┘                          │    response     │
                                                       │  - analyze_    │
                                                       │    status_code │
                                                       └────────┬───────┘
                                                                │ HTTP
                                                       ┌────────▼───────┐
                                                       │  Target API     │
                                                       │  (any REST API, │
                                                       │  e.g. sample_   │
                                                       │  target_api/)   │
                                                       └─────────────────┘

プロジェクト構成

mcp-api-testing-agent/
├── mcp_server/
│   ├── server.py               # MCP server (FastMCP) exposing the 4 tools
│   └── tools/
│       ├── discover.py         # discover_endpoints — parses OpenAPI spec
│       ├── request_tool.py     # send_request — issues HTTP calls
│       ├── validate.py         # validate_response — schema/status checks
│       └── status_analyzer.py  # analyze_status_code — status code semantics
├── agent/
│   ├── mcp_client.py           # stdio MCP client used by the agent
│   ├── test_generator.py       # LLM-based positive/negative test generation
│   ├── test_executor.py        # runs generated test cases via MCP tools
│   ├── failure_analyzer.py     # LLM explains expected-vs-actual mismatches
│   └── report_generator.py     # Markdown + JSON report writer
├── api/
│   └── main.py                  # FastAPI app: POST /agent/run, GET /agent/reports/{id}
├── schemas/
│   └── models.py                # Pydantic models shared across the app
├── sample_target_api/
│   └── demo_api.py              # tiny FastAPI service to test the agent against
├── scripts/
│   └── run_agent.py             # CLI entrypoint (no FastAPI needed)
├── reports/                     # generated test reports land here
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── .env.example

セットアップ

python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env   # add your OPENAI_API_KEY

デモ対象APIを実行する(テスト対象となる小さなサンプルAPI)

uvicorn sample_target_api.demo_api:app --port 9000

これにより、/tasks のCRUDエンドポイントを持つおもちゃの「Task Manager」APIと、生成されたOpenAPI仕様が http://localhost:9000/openapi.json で公開されます。

CLIでエージェントを実行する

python scripts/run_agent.py --spec http://localhost:9000/openapi.json --base-url http://localhost:9000

これでテストケースが生成・実行され、障害が分析されて、レポートが reports/report_<timestamp>.md と .json に書き出されます。

HTTPサービスとしてエージェントを実行する

uvicorn api.main:app --port 8000
curl -X POST http://localhost:8000/agent/run \
  -H "Content-Type: application/json" \
  -d '{"spec_url": "http://localhost:9000/openapi.json", "base_url": "http://localhost:9000"}'

MCPサーバーをスタンドアロンで実行する

組み込みのエージェントの代わりに、ツールをMCP互換クライアント(Claude Desktop、Claude Code など)に組み込むには:

python -m mcp_server.server

次に、MCPクライアントの設定に追加します。例:Claude Desktop(claude_desktop_config.json)の場合:

{
  "mcpServers": {
    "api-testing-agent": {
      "command": "python",
      "args": ["-m", "mcp_server.server"],
      "cwd": "/absolute/path/to/mcp-api-testing-agent"
    }
  }
}

すべてをDockerで実行する

docker compose up --build

これにより、デモ対象APIとMCPバックエンドのテストエージェントFastAPIサービスが起動し、./reports がマウントされるため、生成されたレポートがホスト上で利用できます。

サンプルレポート出力

# API Test Report — 2026-02-03T10:15:00

Target: http://localhost:9000
Total: 18   Passed: 15   Failed: 3   Pass rate: 83%

## Failures

### POST /tasks — missing required field "title" (negative test)
Expected: 422 Unprocessable Entity
Actual:   500 Internal Server Error
Analysis: The endpoint does not validate the request body before hitting the
database layer, so a missing "title" causes an unhandled exception instead
of a client-error response. Severity: High — indicates missing input
validation.

実際のプロジェクトに適用するための注意点

  • sample_target_api/ を実際のサービスに置き換えるか、--spec / spec_url を実稼働中のOpenAPI/Swagger JSONエンドポイントに指定してください。

  • test_generator.py のプロンプトは、ドメインルール(例:必須の認証ヘッダー、レート制限、テナントID)で拡張できます。

  • CIでは、scripts/run_agent.py をパイプラインステップとして実行し、report["summary"]["failed"] > 0 の場合はビルドを失敗させてください。

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    An MCP server for the comprehensive analysis of Swagger 2.0 and OpenAPI 3.x contracts. It allows users to extract detailed information about endpoints, request/response schemas, parameters, and security configurations from API documentation.
    -
  • A
    license
    A
    quality
    F
    maintenance
    MCP server for API test case generation from Swagger/OpenAPI specs. Parses Swagger 2.0 and OpenAPI 3.x, generates test cases across 8 categories (positive, negative, boundary, auth, security, idempotency, pagination, business logic), and exports to Postman, TestRail, Allure, k6, pytest, Gherkin, and CSV. Supports internal corporate APIs with auth headers. Auto-saves export files to your working di
    10
    10 npm
    2
    MIT
  • A
    license
    A
    quality
    C
    maintenance
    Parses Swagger 2.0 and OpenAPI 3.x specifications, exposing API endpoints, schemas, and authentication through MCP tools with local caching to reduce token usage.
    11
    3 npm
    1
    MIT