coolify-mcp
CLAUDE.md608 starsChanged 10 months agoMITView on GitHub
MCP (Model Context Protocol) server for Coolify that provides 46 token-optimized tools for AI assistants to manage infrastructure through natural language. Tools cover servers, projects, environments, applications, databases, services, deployments, private keys, teams, cloud tokens, documentation search, smart diagnostics, and batch operations. v2.0.0 reduced token usage by ~81% (from ~43,000 to ~8,300 tokens) by consolidating related operations into single tools with action parameters. Self-contained package (own package.json/toolchain, like site/) that treats tool descriptions as prompts and measures them. If you…
- Reads credentials
- Installs packages
- Commits and pushes
In this repositoryOne other file it gives its agents.
- coolifySkill
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
30 rules. About 0 are common, 19 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈19
Distinctive · estimate
This author's own choices. Worth a look.
11
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 43
When adding new Coolify API endpoints, follow this order:
- Very specific: line 45
src/types/coolify.ts: - Add TypeScript interfaces
- Very specific: line 46
src/lib/coolify-client.ts: - Add API client method with explicit return type
- Very specific: line 47
src/lib/mcp-server.ts: - Add MCP tool definition
- Very specific: line 56
src/types/coolify.ts: - All Coolify API type definitions
- Very specific: line 73
Verify endpoint exists in docs/openapi-chunks/
- Very specific: line 74
Add types to src/types/coolify.ts
- Distinctive: line 75
Add client method with explicit return type
- Very specific: line 76
Add MCP tool to src/lib/mcp-server.ts
- Distinctive: line 77
Add mocked tests (required for codecov coverage)
- Distinctive: line 81
IMPORTANT: All new client methods MUST have test coverage to pass codecov checks.
- Distinctive: line 83
When adding new client methods, you must add:
- Distinctive: line 86
Test the HTTP method (GET, POST, PATCH, DELETE)
- Distinctive: line 87
Test the endpoint path
- Distinctive: line 88
Test the request body if applicable
- Distinctive: line 89
Follow the existing test patterns in the file
- Very specific: line 92
Add expect(typeof client.methodName).toBe('function').
- Very specific: line 95
codecov will fail PRs with uncovered lines: Always run npm test before committing.
- Distinctive: line 117
After fixing bugs, always verify fixes work against the real Coolify instance — not just unit tests.
- Distinctive: line 158
Always include explicit return types on functions
- Distinctive: line 159
No implicit any types
- Distinctive: line 160
Follow existing patterns in the codebase
- Distinctive: line 164
Commit frequently to trigger pre-commit hooks (linting, formatting, tests)
- Distinctive: line 165
Always stage all modified files after making changes
- Distinctive: line 180
When making changes to the codebase, ensure documentation is updated:
- Distinctive: line 182
CHANGELOG.md: - Add entry under appropriate version with:
- Distinctive: line 186
Follow Keep a Changelog format
- Very specific: line 188
README.md / docs/tools.md: - Update if:
- Very specific: line 193
This file (CLAUDE.md): - Update tool count if changed (currently 46 tools).
- Distinctive: line 197
Always work on a feature branch and include documentation updates in the same PR as code changes.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md 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
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
MCP (Model Context Protocol) server for Coolify that provides 46 token-optimized tools for AI assistants to manage infrastructure through natural language. Tools cover servers, projects, environments, applications, databases, services, deployments, private keys, teams, cloud tokens, documentation search, smart diagnostics, and batch operations. v2.0.0 reduced token usage by ~81% (from ~43,000 to ~8,300 tokens) by consolidating related operations into single tools with action parameters.
Commands
npm install # Install dependencies
npm run build # Build TypeScript to dist/
npm test # Run all tests
npm run lint # Run ESLint
npm run format # Run Prettier
# Run locally
COOLIFY_BASE_URL="https://your-coolify.com" COOLIFY_ACCESS_TOKEN="token" node dist/index.jsEvals & red teaming (evals/)
Self-contained package (own package.json/toolchain, like site/) that treats
tool descriptions as prompts and measures them. If you edit a tool's name,
description, schema or annotation, evals tool-contract snapshots will fail
until you review and npm run snapshots:update. Layers: (1) contract snapshots,
(2) tool-selection evals, (2b) outcome-scored task evals (npm run evals:tasks,
not run in CI), (3) prompt-injection regression, (4) promptfoo red team. All runs use a fixture backend that refuses to start if COOLIFY_URL
looks real. See evals/README.md; findings in evals/FINDINGS.md — note #4
(secret-exfiltration-via-log-injection on weak models, fixed: asUntrustedLogs
frames every model-facing log surface — logs, application_logs, diagnose_app,
diagnose_server validation output, and all deployment/deploy build output
(logs_tail, get, list_for_app) — as untrusted data, with a per-call nonce so
the boundary can't be forged;
5/5→0/5 leaks on Gemini) and
#5 (frontier models act on vague requests, validating the elicitation guard).
Architecture
File Structure Pattern
When adding new Coolify API endpoints, follow this order:
- src/types/coolify.ts - Add TypeScript interfaces
- src/lib/coolify-client.ts - Add API client method with explicit return type
- src/lib/mcp-server.ts - Add MCP tool definition
- src/tests/mcp-server.test.ts - Add mocked test
Key Files
- src/index.ts - Entry point, starts MCP server
- src/lib/coolify-client.ts - HTTP client wrapping Coolify REST API
- src/lib/mcp-server.ts - MCP tool definitions and handlers, plus prompt and resource registration
- src/lib/prompts.ts - the prompt workflows as pure text builders. They never call the API:
prompts/gethas no error channel a human can act on, and embedding build output in the returned message would put attacker-influenceable text in a user-role message, outside theasUntrustedLogsboundary. A prompt may only name tools that are registered in the current mode —definePrompt'srequiresdrops the whole prompt,ctx.has()drops a single step. Seedocs/prompts-and-resources.md - src/types/coolify.ts - All Coolify API type definitions
- src/data/coolify-docs.json - the bundled Coolify docs index
search_docsserves (#372). Generated —npm run docs:indexrefreshes it from coolify.io/docs/llms.txt, the publish workflow refreshes it at release time, and a weekly workflow opens a PR when it falls behind. Never hand-edit. - docs/coolify-openapi.yaml - vendored upstream OpenAPI spec; ground truth for "does Coolify support X"
- docs/openapi-chunks/ - the same spec split by resource for reference. Generated — run
npm run build:chunksafter re-vendoring the spec, never hand-edit.npm run check:chunk-driftfails CI if they diverge.
Protocol eras (#337)
The server speaks both 2025-era MCP and revision 2026-07-28. stdio always connects through the 2025 handshake; only HTTP mode (createMcpHandler) reaches 2026-07-28, which is where server/discover (installed by the SDK), input_required confirmations (#341) and cache fields apply. CACHE_HINTS in mcp-server.ts sets ttlMs/cacheScope on the list results; without it the SDK emits ttlMs: 0. Tools are listed in registration order, which a test pins as stable.
Roots, Sampling and Logging are deliberately not adopted. They are on a 12-month deprecation clock from 2026-07-28 (SEP-2577), and nothing here needs them: paths are Coolify uuids, not client roots; the server never asks the client's model for anything; diagnostics go to stderr and the audit log.
Context-Optimized Responses
List endpoints return summaries (uuid, name, status) not full objects. This reduces response sizes by 90-99%. Use get_* tools for full details of a single resource.
Adding New Endpoints
- Verify endpoint exists in
docs/openapi-chunks/ - Add types to
src/types/coolify.ts - Add client method with explicit return type
- Add MCP tool to
src/lib/mcp-server.ts - Add mocked tests (required for codecov coverage)
Testing Requirements
IMPORTANT: All new client methods MUST have test coverage to pass codecov checks.
When adding new client methods, you must add:
- Client method tests in
src/__tests__/coolify-client.test.ts:- Test the HTTP method (GET, POST, PATCH, DELETE)
- Test the endpoint path
- Test the request body if applicable
- Follow the existing test patterns in the file
- Method existence tests in
src/__tests__/mcp-server.test.ts:- Add
expect(typeof client.methodName).toBe('function');in the appropriate section - Ensures the method is properly exported and accessible
- Add
codecov will fail PRs with uncovered lines. Always run npm test before committing.
Client Method Example
async getResource(uuid: string): Promise<Resource> {
return this.request<Resource>(`/resources/${uuid}`);
}Test Example
it('should call client method', async () => {
const spy = jest.spyOn(server['client'], 'getResource').mockResolvedValue({ uuid: 'test' });
await server.get_resource('test-uuid');
expect(spy).toHaveBeenCalledWith('test-uuid');
});Smoke Testing Against Live Server
After fixing bugs, always verify fixes work against the real Coolify instance — not just unit tests.
/smoke-test— Slash command that builds the project and runs integration smoke tests against the live server. Use this after any bug fix to confirm the fix works end-to-end.npm run test:integration— Runs all integration tests (requires.envwithCOOLIFY_URLandCOOLIFY_TOKEN).- Integration test files live in
src/__tests__/integration/and are excluded fromnpm test(CI). Add new smoke tests there when fixing bugs that involve API interaction.
Coolify API Gotchas
The Coolify OpenAPI docs are unreliable — always test against the real API. Known issues:
docker_compose_rawrequires base64 — The API expects base64-encoded YAML, but the field name suggests raw content. The client auto-encodes this field so models and callers can pass plain YAML.- Validation errors vary in format — The
errorsfield in API error responses can containstring[]or plainstringvalues. The client handles both. - Env var field names are
is_buildtimeandis_runtime(one word each), notis_build_time(two words). OnPOST /applications/{uuid}/envsandPATCH /applications/{uuid}/envsthe wrong name returns HTTP 422"This field is not allowed."; onPATCH /applications/{uuid}/envs/bulkthe wrong name is silently ignored (request returns 201 but the flag stays at the default). Verified against Coolify v4.0.0-beta.473 in #174 / #135. When adding env-var related code or tests, mirror the API field names exactly — do not paraphrase tois_build_time. - Application CREATE and UPDATE accept different field sets. Coolify's
app/Http/Controllers/Api/ApplicationsController.phphas two separate$allowedFieldsarrays — one used by everycreate_*endpoint (create_applicationhelper around line 1014) and a different one used byupdate_by_uuid(around line 2497).removeUnnecessaryFieldsFromRequest()runs that allowlist BEFORE the sharedsharedDataApplications()validation rules apply, so fields outside the allowlist are silently dropped, never validated, never reach the DB. Practical effects:dockerfile_target_buildis UPDATE-only: present in the update allowlist, absent from the create allowlist. Sending it on anycreate_*is silently dropped. Theapplicationtool exposes it in the zod schema but only wires it throughupdate.create_dockerimageacceptshealth_check_*+ports_mappingsbut NOTbase_directory/publish_directory/install_command/build_command/start_command/watch_paths/dockerfile_location— the endpoint is for pre-built registry images and has no build step. Theapplicationtool'screate_dockerimagehandler intentionally forwards only health-check fields, even though the shared zod schema accepts build-config inputs.- Coolify's
openapi.yamlrequest bodies are an incomplete projection of the real allowlists. Check both controller$allowedFieldsarrays before assuming a field is accepted on a given action. Verified againstcoollabsio/coolifymainwhile fixing #178.
State-changing endpoints changed HTTP method in v4.2, and not uniformly. v4.2 (
coollabsio/coolify#10872) requiresPOSTon start/stop/restart/deploy/enable/disable/validate and returns405forGET. But the endpoints split into two groups, verified against upstreamroutes/api.phpat v4.1.2, v4.0.0 and older betas:- Application/database/service
start/stop/restartand/deploywere alreadyRoute::match(['get','post'])long before v4.2 — sendPOSTunconditionally, it works on every version. /enable,/disableand/servers/{uuid}/validatewereRoute::getonly up to v4.1.2 andRoute::postonly from v4.2 — no single method works across both. These go throughpostWithLegacyGetFallback, which sends POST, retries GET when the router rejects the method, and caches the resolved method per endpoint. The cache self-heals if a remembered GET is later rejected (instance upgraded mid-session).
A rejected method does not always mean 405.
routes/api.phpends withRoute::any('/{any}', ...)returning404 {"message":"Not found.","docs":"..."}, which swallows an unmatched method+path before Laravel can raise a 405 — so a pre-4.2 instance answers POST on a GET-only route with 404. Verified live against 4.1.2; a 405-only fallback silently never fired, which is how #296 shipped broken. The fallback therefore triggers on a 405 or on a 404 carrying the catch-all'sdocskey, and that body-shape check is what keeps a controller's genuine "resource not found" out of the retry path.Only ever trigger the fallback on those two: both mean no controller ran, so nothing executed. Retrying a
500could double-fire a state change. When adding a new endpoint from the v4.2 breaking list, check which group it belongs to before assuming a blanketPOSTis safe.- Application/database/service
- v4.2 hides secrets and makes Member-role tokens read-only. From v4.2, sensitive fields are stripped from responses unless the token has sensitive-read scope (
coollabsio/coolify#9893), so response types holding secrets (PrivateKey.private_key,EnvironmentVariable.value) must be optional — a required type turns a withheld secret into a silentundefined. Separately, Member-role tokens can read but not write, so a sudden403on every write after an upgrade is a role problem, not a token problem. is_previewonly means anything on application env vars. Preview deployments are an application concept. Upstream's service env-var controller does not validate or persistis_previewat all, so passing it to a service or database env var is silently ignored rather than rejected —ServicesController::create_envhas no$allowedFields/extraFieldsallowlist, unlike the application endpoints, so an unknown field does not 422 there. Theenv_varstool accepts it on all three resources for a consistent surface; it is a no-op on two of them. (cleanRequestDatastripsundefined, so it is only ever sent when a caller explicitly passes it.)- Coolify auto-creates a preview twin for every production application env var.
EnvironmentVariable::booted()has astatic::createdhook: creating a production env var on an Application (not services/databases) also creates a matching row withis_preview = true, andGET /applications/{uuid}/envsmerges both scopes into one flat list. So two rows per variable is normal, not a duplicate-write bug. Never dedupe env vars bykeyalone — a key existing in both scopes is valid config, and deleting the "extra" row destroys preview configuration. Present since at least v4.0.0.update_env_by_uuidalso scopes byis_preview, so an update that omits the flag only ever touches the production row and lets the twin drift. GET /applicationsreturns neitherproject_uuidnorserver_uuid. Both fields exist on theApplicationtype and neither is populated by the list endpoint — verified live against 4.1.2, where none of 26 applications carried either. What you actually get isenvironment_id(numeric) and a nesteddestinationobject carryingserver_id. Consequences, both of which shipped as silent bugs: filtering apps byproject_uuidmatches nothing (useGET /projects/{uuid}→environments[].id→ matchapp.environment_id, which is whatapplicationsInProjectdoes), and counting distinct servers byserver_uuidcounts nothing (usedestination.server_id— and do not.filter(Boolean)it, because Coolify's built-in localhost server is id0).delete_volumesdefaults totrueon every DELETE endpoint. Applications, databases and services all documentdelete_volumesas an optional query param withdefault: true(docs/coolify-openapi.yaml). So omitting it destroys the data — the opposite of what an unset optional boolean reads like at a call site.buildQueryStringdropsundefined, so "I didn't pass the flag" and "I passed true" hit the same upstream behaviour. Anything that reports to a human what a delete is about to do must treatundefinedas destructive; only an explicitfalsepreserves volumes.- Log
linesis normalized upstream, silently.normalizeLogLines(bootstrap/helpers/docker.php) caps the count at 10000 from v4.3.0 and falls back to the default 100 for anything that is not an integer. Below 1 differs by version: at v4.3.0 it also gets 100, soall(which failsFILTER_VALIDATE_INT) quietly returns 100 lines with no error; on upstreammain(after 4.3.0)alland-1mean every line,0means none, and below -1 gets 100. That is whylogsandapplication_logstakelinesas an integer from 1 to 10000 and offer noall: a-1would pull a whole container log into context on a current Coolify and do nothing useful on an older one. The client methods (getApplicationLogsand friends) still take a bare number; the bound lives in the tool schemas. POST /applications/dockercomposeno longer exists upstream. Coolify deprecated it (7c0cb2f5, Jan 2026) and removed the route + controller method entirely (6ee75cfa, "remove deprecated docker compose application endpoint") in favour ofPOST /services. The removal shipped inv4.1.0, so it 404s against any current self-hosted Coolify release. Compose-based apps are created through theservicetool /POST /servicesinstead.CoolifyClient#createApplicationDockerComposestill exists but is deprecated and deliberately NOT exposed as anapplicationtool action — do not wire it up (see #235). It only works on instances still onv4.0.xor older.GET /teams/currentis gone from the spec but not from the router. The vendored spec (re-vendored 2026-09-30 against upstreammain, 287 operations, #416) documentsGET /teamandGET /team/membersinstead. Upstream still routes/teams/currentand/teams/current/membersas deprecated aliases, and/teamonly exists from Coolify 4.3.0, so the client (getCurrentTeam,getCurrentTeamMembers) and HTTP mode's proof-of-access (validateCoolifyToken) keep calling/teams/currentwhileTESTED_RANGEinsrc/lib/doctor.tsstarts below 4.3. Source:routes/api.phpat tagv4.3.0registers/teamand/team/members(lines 71–72) beside the/teams/currentaliases (74–75); atv4.2.0only/teams/currentexists (56–57).check:spec-driftis method-blind and matches/teams/currentagainst/teams/{id}by segment count, so it will not flag this; switch to/teamonly whenTESTED_RANGE.minreaches 4.3.
TypeScript Standards
- Always include explicit return types on functions
- No implicit any types
- Follow existing patterns in the codebase
Git Workflow
- Commit frequently to trigger pre-commit hooks (linting, formatting, tests)
- Always stage all modified files after making changes
- Push changes to remote after committing
- Work on feature branches, not main
Publishing
CI auto-publishes to npm via trusted publishing on version bump. Use:
npm version patch|minor|major
git push origin main --tagsDocumentation Standards
When making changes to the codebase, ensure documentation is updated:
- CHANGELOG.md - Add entry under appropriate version with:
### Added- New features### Changed- Breaking changes or significant modifications### Fixed- Bug fixes- Follow Keep a Changelog format
- README.md / docs/tools.md - Update if:
- Tool count changes (README one-liner;
npm run check:tool-count:fix) - New tools or actions added (add to the category table in
docs/tools.md) - New example prompts needed (README)
- Tool count changes (README one-liner;
- This file (CLAUDE.md) - Update tool count if changed (currently 46 tools);
package.json,manifest.json,server.jsonand README carry the same count.npm run check:tool-count(CI-gated) compares every claim against the evals roster snapshot and checks thedocs/tools.mdtable names every tool;npm run check:tool-count:fixrewrites the counts. - docs/ is the reference; README is the front door. Detail belongs in
docs/tools.md(surface, compatibility, gotchas),docs/http-mode.md(remote),docs/fleet.md,docs/doctor.md,docs/security.md. Keep README to one paragraph per topic plus a link. The site (site/) links out to these files and generatesllms.txtfrom them at build.
Always work on a feature branch and include documentation updates in the same PR as code changes.
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.

