swagger2mcp
Copilot instructions1 starsChanged 12 months agoMITView on GitHub
Key insight: The worker is NOT a request handler - it's a standalone process (npm run worker) that must run separately. Backend and worker share the same codebase but execute different entry points (server.ts vs worker.ts).
The file
We split this copilot-instructions.md into the rules it gives an agent
12 rules. About 0 are common, 7 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 66
All schemas are tied to sessions via Prisma relations
- Distinctive: line 85
Only follows same-domain links to prevent explosion
- Distinctive: line 87
No authentication/headers - public URLs only
- Very specific: line 126
Prisma not generated: Run npx prisma generate after pulling schema changes or npm install.
- Very specific: line 130
Multer file paths: Use req.file.path (absolute) not req.file.filename in job payloads.
- Distinctive: line 144
No automated tests present in codebase
- Very specific: line 145
Test crawling with sample-petstore.json included in root
- Very specific: line 146
Use Petstore URLs like https://petstore.swagger.io/v2/swagger.json for crawl testing
- Distinctive: line 151
Use Chrome DevTools MCP for browser automation and testing.
- Distinctive: line 165
Verify: Take screenshots or check console messages for validation
- Very specific: line 166
Wait: Use wait_for to wait for text/elements to appear
- Distinctive: line 187
Regular: Create via /register for standard user testing
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Swagger2MCP Development Guide
Project Overview
Swagger2MCP generates Model Context Protocol (MCP) servers from OpenAPI/Swagger schemas. The system uses a microservices architecture with separate frontend, backend API, background worker, Redis queue, and PostgreSQL database - all orchestrated via Docker Compose.
Architecture & Data Flow
Service Boundaries
- Frontend (React/Vite on :5173): User interface for uploads and crawling
- Backend (Express on :3000): REST API that enqueues jobs and serves data
- Worker (BullMQ): Processes background jobs (file uploads, web crawls)
- Redis (:6379): Job queue storage with BullMQ
- PostgreSQL (:5432): Stores sessions and schema metadata (not the generated code)
Critical Flow: Upload → Process → Generate
- User uploads file →
POST /api/upload→ Multer saves tobackend/uploads/ - Backend adds
UPLOADjob to Redis queue via BullMQ - Separate worker process (
worker.ts) consumes job, validates OpenAPI spec, saves to PostgreSQL - User clicks "Generate" →
POST /api/generate→ reads schema from DB, generates TypeScript MCP server code in-memory, returns ZIP - Optionally exports to GitHub using Octokit to create repo/commit
Key insight: The worker is NOT a request handler - it's a standalone process (npm run worker) that must run separately. Backend and worker share the same codebase but execute different entry points (server.ts vs worker.ts).
Development Workflows
Local Development Setup
# Start infrastructure only
docker-compose up redis postgres
# Terminal 1: Backend API
cd backend
npm run dev # ts-node-dev with hot reload
# Terminal 2: Worker (CRITICAL - often forgotten!)
cd backend
npm run worker # Separate process required
# Terminal 3: Frontend
cd frontend
npm run devDocker Development (Recommended)
# Full stack with volume mounts for hot reload
docker-compose up --build
# View worker logs separately (common debugging need)
docker-compose logs -f workerDatabase Migrations
cd backend
npx prisma migrate dev --name <description>
npx prisma generate # Run after schema changesProject-Specific Patterns
Session Management
- No user authentication - uses anonymous UUIDs stored in
localStorage - Frontend generates session ID on first visit:
crypto.randomUUID() - Session ID is passed in request bodies (not headers/cookies)
- All schemas are tied to sessions via Prisma relations
Job Queue Architecture
- BullMQ jobs defined in
backend/src/types/jobs.tswith discriminated union:type: 'UPLOAD' | 'CRAWL' - Job progress updates:
await job.updateProgress(percentage)in worker - No WebSocket for real-time updates - frontend polls
/api/schemasafter job creation - Job failures throw errors; BullMQ handles retries automatically
Code Generation Strategy
- Generator lives in
backend/src/services/generator.service.ts - Creates in-memory JSZip with package.json, tsconfig.json, src/index.ts
- No file templates - generates code as strings programmatically
- TypeScript only; Python marked as "not implemented yet"
- Extracts tools from
pathsobject, each operation becomes an MCP tool - Uses
@modelcontextprotocol/sdkv0.6.0 withServerandStdioServerTransport
Web Crawler Heuristics
CrawlerServiceuses recursive depth-first crawl withmaxDepth- Prioritizes links containing 'swagger', 'openapi', 'api-docs', or
.json/.yaml - Only follows same-domain links to prevent explosion
- Validates fetched JSON has
swaggeroropenapiproperty before saving - No authentication/headers - public URLs only
File Upload Handling
- Multer stores uploads in
backend/uploads/with unique names:timestamp-random-originalname - Worker reads file synchronously with
fs.readFileSync(filePath)then validates - Cleanup not implemented - uploaded files persist indefinitely
- Accepts JSON only; YAML parsing not implemented
Integration Points
External Dependencies
- Octokit: GitHub API client for repo creation/commits (uses personal access tokens)
- Axios: HTTP client for crawling and GitHub operations
- Cheerio: HTML parsing for link extraction during crawls
- Prisma: ORM with migrations in
backend/prisma/
Environment Variables
Backend requires:
PORT=3000
REDIS_HOST=redis # Docker service name
REDIS_PORT=6379
DATABASE_URL=postgresql://postgres:postgres@postgres:5432/swagger2mcpFrontend:
VITE_API_URL=http://localhost:3000 # Note: /api suffix added in clientCross-Service Communication
- Frontend talks to backend API only (no direct DB access)
- Backend and worker share Prisma client (
prismasingleton fromlib/db.ts) - Worker and backend share Redis connection (
connectionfromlib/queue.ts) - IORedis config requires
maxRetriesPerRequest: nullfor BullMQ compatibility
Common Gotchas
- Worker not running: Jobs sit in queue forever. Check
docker-compose logs workeror runnpm run workerlocally. - Prisma not generated: Run
npx prisma generateafter pulling schema changes ornpm install. - CORS issues: Backend enables CORS for all origins (
cors()with no options). - Session mismatch: Frontend localStorage and backend DB must share same UUID - test incognito to simulate new sessions.
- GitHub export: Personal access token needs
reposcope; fails silently if permissions insufficient. - Multer file paths: Use
req.file.path(absolute) notreq.file.filenamein job payloads.
Key Files & Responsibilities
backend/src/server.ts: Express app entry point (API only)backend/src/worker.ts: Job processor entry point (runs separately)backend/src/routes/api.ts: All HTTP endpoints, multer configbackend/src/services/generator.service.ts: MCP code generation logicbackend/src/services/crawler.service.ts: Web crawling with depth limitsbackend/src/lib/queue.ts: BullMQ queue/connection singletonsfrontend/src/lib/api.ts: Axios client + session ID managementbackend/prisma/schema.prisma: Database schema (Session → Schema 1:N relation)
Testing Notes
- No automated tests present in codebase
- Test crawling with
sample-petstore.jsonincluded in root - Use Petstore URLs like
https://petstore.swagger.io/v2/swagger.jsonfor crawl testing - Generated MCP servers can be tested with
npx @modelcontextprotocol/inspector
Browser Testing with Chrome DevTools MCP
Use Chrome DevTools MCP for browser automation and testing. This provides direct browser control through Chrome DevTools Protocol.
Available Testing Tools
- Navigation:
mcp_io_github_chr_*tools for page navigation and interaction - Snapshots: Take screenshots and accessibility snapshots for verification
- Form Input: Fill forms, click elements, and interact with UI
- Console: Monitor console messages and errors
- Network: Inspect network requests and responses
- Performance: Record and analyze performance traces
Testing Workflow
- Navigate to page: Use navigation tools to open URLs (e.g.,
http://localhost:5173) - Take snapshot: Get accessibility snapshot to understand page structure and element refs
- Interact: Use
click,fill,fill_formtools with element UIDs from snapshot - Verify: Take screenshots or check console messages for validation
- Wait: Use
wait_forto wait for text/elements to appear
Common Testing Patterns
# Login Flow Testing
1. Navigate to /login
2. Take snapshot to get form element UIDs
3. Fill email and password using mcp_io_github_chr_fill or mcp_io_github_chr_fill_form
4. Click submit button using mcp_io_github_chr_click
5. Wait for navigation/redirect
6. Take screenshot to verify logged-in state
# Admin Access Verification
1. Login as admin user (admin@test.com / adminpass123)
2. Check navbar for "Admin" link with admin badge
3. Navigate to /admin and verify access
4. Test admin-only featuresTest Users
- Admin: admin@test.com / adminpass123 (role: admin)
- Regular: Create via /register for standard user testing
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

