mcp-crawl4ai-ts
Copilot instructions13 starsChanged 16 months agoMITView on GitHub
Concise, project-specific guidance for AI coding agents. Optimize for correctness, safety, and existing test expectations.
- Reads credentials
The file
We split this copilot-instructions.md into the rules it gives an agent
7 rules. About 0 are common, 5 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 30
Add service method if it maps to a new Crawl4AI endpoint (pure HTTP + validation of URL / JS content.
- Very specific: line 33
Write tests: unit (schema + handler success/failure), integration (happy path with mocked or real endpoint).
- Distinctive: line 34
Update README tool table if user-facing, and CHANGELOG + version bump.
- Very specific: line 45
NEVER invoke jest directly for integration tests.
- Distinctive: line 53
Keep responses minimal & textual.
- Distinctive: line 55
Commit style: conventional commits.
- Distinctive: line 60
If something is ambiguous, inspect existing handlers first and mirror the closest established pattern before inventing a new one.
≈ “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
Copilot Instructions: mcp-crawl4ai-ts
Concise, project-specific guidance for AI coding agents. Optimize for correctness, safety, and existing test expectations.
Architecture & Flow
- Entrypoint
src/index.ts: loads dotenv only ifCRAWL4AI_BASE_URLunset; fails fast if missing. Passes env + version intoCrawl4AIServer. src/server.ts: registers MCP tools, keeps aMap<string, SessionInfo>for persistent browser sessions, and usesvalidateAndExecute(Zod parse + invariant error message format). Do NOT alter error text pattern:Invalid parameters for <tool>: ...(tests & LLM reliability depend on it).- Service layer
src/crawl4ai-service.ts: pure HTTP wrapper around Crawl4AI endpoints; centralizes axios timeout & error translation (preserve wording likeRequest timed out,Request failed with status <code>:— tests rely on these substrings). - Handlers (
src/handlers/*.ts): orchestration & response shaping (text content arrays). No direct business logic inside server class beyond wiring. - Validation schemas (
src/schemas/validation-schemas.ts+ helpers): all tool inputs defined here. UsecreateStatelessSchemafor stateless tools; session/persistent tools have discriminated unions.
Tool Model
- Stateless tools (e.g.
get_markdown,capture_screenshot,execute_js) spin up a fresh browser each call. - Session-based operations use
manage_session(create/list/clear) +crawlfor persistent state, allowing chained JS + screenshot/pdf in ONE call. Never try to chain separate stateless calls to reflect JS mutations. - Output always returned as base64/text blocks; do not add file system side-effects unless explicitly using a save path param already supported (screenshots: optional local save dir).
JS & Input Validation Nuances
- JS code schema rejects: HTML entities ("), literal
\ntokens outside strings, embedded HTML tags. ReuseJsCodeSchema—do not duplicate logic. - For
get_markdown: if filter isbm25orllm,querybecomes required (enforced via.refine). Keep this logic centralized.
Sessions
SessionInfotrackscreated_at&last_used. Updatelast_usedwhenever a session-based action runs. Don't leak sessions:clearmust delete map entry.
Error Handling Pattern
- Handlers wrap service calls; on failure use
this.formatError(error, '<operation>')(seeBaseHandler). Preserve format:Failed to <operation>: <detail>. - Zod validation errors: keep exact join pattern of
path: messagesegments.
Adding / Modifying a Tool (Checklist)
- Define or extend schema in
validation-schemas.ts(prefer composing existing small schemas; wrap withcreateStatelessSchemaif ephemeral). - Add service method if it maps to a new Crawl4AI endpoint (pure HTTP + validation of URL / JS content; reuse existing validators).
- Implement handler method (assemble request body, post-process response to
content: [{ type: 'text', text }]). - Register in
setupHandlers()list (tool description should mirror README style & clarify stateless vs session). - Write tests: unit (schema + handler success/failure), integration (happy path with mocked or real endpoint). Place under matching folder in
src/__tests__/. - Update README tool table if user-facing, and CHANGELOG + version bump.
Commands & Workflows
- Install:
npm install - Build:
npm run build(tsconfig.build.json) - Dev (watch):
npm run dev - Tests:
npm run test| unit only:npm run test:unit| integration:npm run test:integration| coverage:npm run test:coverage - Lint/Format:
npm run lint,npm run lint:fix,npm run format:check - Pre-flight composite:
npm run check
Testing Invariants
- NEVER invoke
jestdirectly for integration tests; rely onnpm run test:integration(injectsNODE_OPTIONS=--experimental-vm-modules+JEST_TEST_TYPE=integration). - Unit tests auto-set
CRAWL4AI_BASE_URLinjest.setup.cjs; integration tests require real env vars (CRAWL4AI_BASE_URL, optionalCRAWL4AI_API_KEY, LLM vars) via.envor exported. - To run a single integration file:
npm run test:integration -- path/to/file.test.ts. - Jest pinned at 29.x with
ts-jest@29; do not upgrade one without the other. - Symptom mapping: import syntax error or hang at first test => you bypassed the npm script.
Conventions & Invariants
- No
any; preferunknown+ narrowing. - Keep responses minimal & textual; do not introduce new top-level fields in tool results without updating all tests.
- Timeout remains 120s in axios clients—changing requires test updates.
- Commit style: conventional commits; no emojis, AI signoffs, or verbose bodies.
References
- README (tools & examples), CLAUDE.md (contrib rules), CHANGELOG (release notes), coverage report for quality gates.
If something is ambiguous, inspect existing handlers first and mirror the closest established pattern before inventing a new one.
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.

