A complete AI-driven Test Architect system that generates API and UI test cases automatically using Retrieval-Augmented Generation (RAG) and Model Context Protocol (MCP) tools.
This project demonstrates how to build an intelligent test generation system that:
- Ingests various documentation sources (OpenAPI specs, wikis, business docs, UI docs)
- Uses RAG to find relevant context for test generation
- Generates canonical API test definitions
- Exports tests to multiple formats (Postman, RestAssured)
- Provides MCP tools for integration with AI assistants like Claude
-
RAG Service (Python + FastAPI)
- Document ingestion and embedding
- Vector similarity search
- API test generation
- Structured logging with correlation IDs
- Data persistence via Docker volumes
-
MCP Server (TypeScript + Node.js)
- MCP tool layer for AI assistants
- OpenAPI spec parsing
- Format converters (Postman, RestAssured)
- RAG service client
-
Sample Data
- OpenAPI specifications (auth, customers)
- Wiki documentation
- Business requirements
- UI specifications
- Sequence diagrams
Documentation β RAG Service β Vector Embeddings β Test Generation
β
MCP Tools β Export Formats (Postman/RestAssured)
- Docker and Docker Compose
- 4GB+ RAM available
- Port 8000 and 3000 available
# Build and start all services
docker-compose up --build
# Wait for health check to pass (check logs)
docker-compose logs -f rag-service# Check RAG service health
curl http://localhost:8000/health
# Expected response:
# {"status":"healthy","timestamp":"...","document_count":0}
# View API documentation
open http://localhost:8000/docs# Run ingestion script
docker-compose exec rag-service python ingest_docs.py
# Check ingestion results in logs
docker-compose logs rag-service | grep "Total documents ingested"Expected output: ~30-40 documents ingested from various sources.
curl -X POST http://localhost:8000/search \
-H "Content-Type: application/json" \
-d '{
"query": "How does login work?",
"top_k": 3
}'curl -X POST http://localhost:8000/api_generate_tests \
-H "Content-Type: application/json" \
-d '{
"query": "POST /login",
"profile": "smoke"
}'Response includes canonical test definitions:
{
"query": "POST /login",
"profile": "smoke",
"tests": [
{
"id": "API_LOGIN_SMOKE_01",
"name": "Valid login - happy path",
"priority": "P0",
"endpoint": {"method": "POST", "path": "/login"},
"request": {
"headers": {"Content-Type": "application/json"},
"body": {"email": "[email protected]", "password": "Correct123!"}
},
"expected": {
"status": 200,
"bodyChecks": ["has property token", "has property refreshToken"]
}
}
]
}Once the MCP server is configured with your AI assistant:
> Generate smoke tests for POST /login endpoint
> Export those tests as a Postman collection
> Generate functional tests for the customers API
> Export as RestAssured Java tests
The system supports different test coverage profiles:
| Profile | Coverage | Use Case |
|---|---|---|
| smoke | Happy path only | Quick sanity checks |
| functional | Positive + negative cases | Standard coverage |
| regression | Deep coverage + edge cases | Comprehensive testing |
| security | Auth, injection, XSS tests | Security validation |
| bugfix | Targeted tests | Bug verification |
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/ingest |
POST | Ingest documents |
/search |
POST | Search for similar docs |
/api_generate_tests |
POST | Generate API tests |
/stats |
GET | Vector store statistics |
/docs |
GET | Swagger UI |
| Tool | Description |
|---|---|
scan_api_specs |
Find OpenAPI files |
index_api_spec |
Ingest OpenAPI spec |
ingest_docs_from_folders |
Ingest all documentation |
api_generate_tests |
Generate tests with RAG |
api_export_postman |
Export to Postman |
api_export_restassured |
Export to RestAssured |
ui_generate_playwright_instructions |
Generate UI tests |
# Run all tests with coverage
docker-compose exec rag-service pytest --cov=. --cov-report=term
# Run specific test file
docker-compose exec rag-service pytest tests/test_embeddings.py -v
# Generate HTML coverage report
docker-compose exec rag-service pytest --cov=. --cov-report=html# Run all tests with coverage
docker-compose exec mcp-test-architect npm test -- --coverage
# Run in watch mode
docker-compose exec mcp-test-architect npm run test:watch
# Run specific test file
docker-compose exec mcp-test-architect npm test -- converters.test.ts# All services
docker-compose logs -f
# Specific service
docker-compose logs -f rag-service
docker-compose logs -f mcp-test-architect
# Filter by level
docker-compose logs rag-service | grep ERRORAll logs are in JSON format with:
timestamp: ISO 8601 timestamplevel: DEBUG, INFO, WARNING, ERRORcorrelation_id: Request tracing IDservice_name: Service identifiermessage: Log message- Additional context fields
Example:
{
"timestamp": "2025-01-08T10:30:00.000Z",
"level": "INFO",
"service_name": "rag-service",
"correlation_id": "abc123",
"message": "Documents ingested successfully",
"count": 25
}# RAG service health
curl http://localhost:8000/health
# Check vector store stats
curl http://localhost:8000/stats.
βββ rag-service/ # Python FastAPI backend
β βββ Dockerfile
β βββ main.py # FastAPI app + endpoints
β βββ models.py # Pydantic models
β βββ vector_store.py # Vector search + persistence
β βββ fake_embedding.py # Deterministic embeddings
β βββ test_generator.py # Test generation logic
β βββ logger.py # Structured logging
β βββ ingest_docs.py # Document ingestion script
β βββ requirements.txt
β βββ tests/ # Unit + integration tests
β
βββ mcp-test-architect/ # TypeScript MCP server
β βββ Dockerfile
β βββ src/
β β βββ server.ts # MCP server + tools
β β βββ rag_client.ts # HTTP client for RAG service
β β βββ converters.ts # Postman/RestAssured exporters
β β βββ openapi_parser.ts
β β βββ logger.ts
β β βββ types.ts
β βββ tests/ # Unit tests
β βββ package.json
β
βββ specs/ # OpenAPI specifications
β βββ auth-openapi.yaml
β βββ customers-openapi.yaml
β
βββ wiki/ # Wiki markdown exports
βββ gdocs/ # Google Docs exports
βββ word/ # Word document exports
βββ ui_docs/ # UI documentation
βββ diagrams/ # Sequence diagrams
βββ data/ # Persisted vector store (volume)
β
βββ docker-compose.yml # Orchestration
βββ README.md # This file
- Place files in appropriate folder (
wiki/,gdocs/, etc.) - Re-run ingestion:
docker-compose exec rag-service python ingest_docs.py
Edit rag-service/test_generator.py:
_generate_smoke_tests()- Happy path tests_generate_functional_tests()- Functional tests_generate_security_tests()- Security tests- etc.
Edit mcp-test-architect/src/converters.ts:
- Add new conversion method
- Update MCP tools in
server.ts
LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR)DATA_DIR: Data persistence directoryCORS_ORIGINS: Allowed CORS origins
RAG_BASE_URL: RAG service URLLOG_LEVEL: Logging levelMCP_PORT: Server port
This project demonstrates:
- Vector Embeddings: Deterministic fake embeddings using character frequency and hashing
- Cosine Similarity: Finding relevant documents through vector similarity
- RAG Pattern: Retrieving context to enhance generation quality
- MCP Protocol: Building tool layers for AI assistant integration
- Docker-First Development: Containerized development and deployment
- Structured Logging: JSON logs with correlation IDs for tracing
- Data Persistence: Docker volumes for stateful services
- Test-Driven Development: 70%+ code coverage with pytest and vitest
# Check logs for errors
docker-compose logs
# Rebuild from scratch
docker-compose down -v
docker-compose build --no-cache
docker-compose up# Verify ingestion
docker-compose exec rag-service python ingest_docs.py
# Check stats
curl http://localhost:8000/stats# Rebuild and run tests
docker-compose build rag-service
docker-compose exec rag-service pytest -v
# Check test dependencies
docker-compose exec rag-service pip list# Change ports in docker-compose.yml
ports:
- "8001:8000" # Change host portFull API documentation available at: http://localhost:8000/docs (Swagger UI)
This is a learning/demonstration project. Feel free to extend it with:
- Actual LLM integration (OpenAI, Anthropic)
- More export formats (k6, Newman, Cypress)
- Additional test profiles
- Real embedding models
- Production deployment configs
MIT License - Feel free to use for learning and experimentation.
- Built using FastAPI, Model Context Protocol, and TypeScript
- Inspired by modern RAG and test automation patterns
- Designed for learning vector embeddings and MCP integration
Happy Testing! π
For questions or issues, check the logs with docker-compose logs -f