Commit Graph

49 Commits

Author SHA1 Message Date
Matt Godbolt
312846230a Add built-in MCP endpoint for LLM tool integration (#8644)
Expose Compiler Explorer's compile, list, shortlink and asm-docs APIs
via a Model Context Protocol (MCP) endpoint mounted at `/mcp`. This lets
MCP-aware clients (Claude, etc.) drive CE directly as a tool.

## Tools exposed at `/mcp`

- **`compile`** — compile source and return assembly / stdout / stderr,
with optional execution.
- `compiler` is **optional**; falls back to the language's
`defaultCompiler` from `list_languages` ("compile this hello world in
C++" is one call).
- `libraries[].version` accepts **either** the version id (`"188"`) or
the human form (`"1.88.0"`) — both work.
- When `execute: true` and the build fails,
`buildResult.stdout`/`stderr` carry the real compiler diagnostics with
**ANSI codes stripped** so an LLM caller sees clean text.
- Caps: `maxAsmLines` / `maxStdoutLines` / `maxStderrLines` with
truncation flags + total counts.
- **`list_compilers`** — with `language`, `instructionSet` (closed enum
from `InstructionSetsList`), `match` (case-insensitive AND-of-tokens;
numeric/dotted-version tokens treated as version-prefix), `lean: true`,
`maxResults`, `latestPerMajor: true`, and `includeExperimental: true`.
- Hard cap of 200 entries on lean responses with a refinement hint —
prevents the unfiltered call from overflowing.
- Each entry exposes `releaseTrack` (`stable | nightly | prerelease |
experimental`) and `supportsExecute` / `supportsBinary`.
- **`list_libraries`** — with `match`, `lean`, `maxResults` (same
lean-cap behaviour).
- **`list_languages`** — minimal listing including `defaultCompiler` and
`compilerCount` per language.
- **`generate_short_url`** — returns `{url}`. Library versions are
normalised before saving.
- **`get_shortlink_info`** — returns saved sessions in the **same shape
`compile` accepts** (`{compiler, options, libraries:[{id, version}]}`)
for direct round-tripping. Multi-pane shortlinks (executors,
conformance, CMake trees) are flattened to the basic compile inputs.
- **`lookup_asm_instruction`** — `instruction_set` is a closed enum
derived from the registered providers (no hand-listed enum values; one
source of truth in `lib/asm-docs/`).

## Implementation

- New `lib/mcp/` module wiring `@modelcontextprotocol/sdk` into the
existing Express router via `StreamableHTTPServerTransport` (stateless
mode — one server per request).
- `lib/mcp/utils.ts`: tokenised `match` with version-prefix matching for
numeric/dotted-version tokens (so `"gcc 14.1"` matches `"gcc 14.1"` and
`"gcc 14.1.0"` but NOT `"gcc 14.10"` or `"gcc 14.0.1"`); `applyCap` with
both per-call lean degradation and an absolute hard cap; `truncateLines`
strips ANSI escapes via the existing `filterEscapeSequences` helper from
`lib/utils.ts`.
- `lib/mcp/library-utils.ts`: `normaliseLibraryVersion` and
`normaliseRequestLibraries` — single source of truth for "accept id or
human version" semantics, used by both `compile` and
`generate_short_url`.
- Schema descriptions are tight (LLM context cost matters) and derive
closed-set enums programmatically from `InstructionSetsList`,
`RELEASE_TRACKS`, and a new `availableAsmDocsKeys` export — no
hand-listed values that can rot.
- Refactor `StorageBase` static helpers (`encodeBuffer`, `isCleanText`,
`getSafeHash`) to module-level functions with type-checked input so MCP
tools can build shortlink hashes without instantiating a storage
backend.
- Expose `ApiHandler.compileHandler` and split out
`getAvailableLanguages()` so MCP can reuse the same code paths the REST
API uses; new `ApiHandler.getDefaultCompilerFor()` for the
compile-default-compiler resolution.
- Browser-friendly CORS on `/mcp`: OPTIONS preflight advertises
`Access-Control-Allow-Methods: POST, OPTIONS` (the shared `cors`
middleware doesn't set Methods); 405 responses on other verbs use the
same Allow header.
- `docs/API.md`: clarify that `/api/shortener` requires a JSON object
body (the prior docs implied but didn't state it).

## Tester feedback addressed

A Claude tester drove the staging deployment through several rounds;
full thread in PR comments. Round-by-round refinements:

- Compile diagnostics surfaced on execute-mode build failures (the
original "silent `Build failed` with empty stderr" bug).
- `execute: true` schema description rewritten to reflect the actual
behaviour.
- Library `version` accepts both forms; clean errors when neither
matches with a sample of available versions.
- `latestPerMajor` rebuilt on top of the `releaseTrack` field added in
#8685, with `includeExperimental` opt-in for c++ proposal forks.
- Lean mode (`lean: true`) for catalog browsing, plus a hard 200-item
cap so even unfiltered calls don't overflow the host.
- Tokenised `match` with version-prefix semantics for
numeric/dotted-version tokens. **Behaviour change** vs the old
`/api/compilers?fields=...` text matching: bare numeric tokens are now
treated as version segments — `"2024"` no longer substring-matches
inside `"v2024beta"`, and `"14.1"` no longer wrongly matches `"14.0.1"`.
Strict improvements but worth a release-note line for callers depending
on the prior loose behaviour.
- ANSI escape code stripping from compile output.
- `instructionSet` as a structured filter (instead of relying on `match`
strings).
- `supportsExecute` / `supportsBinary` on `list_compilers` so an agent
knows whether `execute: true` will work without trying.
- `compilerCount` per language so an agent can tell well-stocked vs
niche languages at a glance.
- Compiler-not-found / library-not-found errors point at the right
`list_*` tool.

## Depends on

#8685 (releaseTrack metadata on `CompilerInfo`) — merged.

## Test plan

- [x] `npm run test -- --run mcp release-track` — all pass (78 + 22)
- [x] `npm run test-min` — full minus expensive, all green
- [x] `make pre-commit` — exits 0
- [x] Multi-round driving on staging via the live MCP endpoint,
including: default-compiler hello-world (no compiler arg), human-form
library version (`"1.88.0"`), broken-compile-with-execute (verifies
buildResult), compile+run with stdin, compile+library Boost 1.90,
parallel `-O0` vs `-O3` diff, `list_compilers latestPerMajor` for
c++/rust/go/csharp, `list_libraries match boost/fmt/json`,
`lookup_asm_instruction MOV amd64`, full `generate_short_url` →
`get_shortlink_info` → re-`compile` round-trip with library
normalisation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Matt Godbolt <mattgodbolt@hudson-trading.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: mattgodbolt-molty <mattgodbolt-molty@users.noreply.github.com>
2026-05-08 10:50:09 -04:00
Matt Godbolt (bot acct)
37f73b9b67 Add releaseTrack metadata to CompilerInfo (#8685)
## Summary

Adds a structured `releaseTrack: 'stable' | 'nightly' | 'prerelease' |
'experimental'` field on `CompilerInfo` so consumers can distinguish
release tracks that aren't currently separable from the existing
`isSemVer` / `isNightly` / `semver` fields.

Today every compiler with a non-numeric semver and `isNightly=true`
looks the same from the outside: Rust nightly, Rust beta, gcc snapshot,
and gcc's various experimental forks (`gcontracts-trunk`,
`gcc-modules-trunk`, `glambda-p2034-trunk`, ...) all share the same
shape. Anything that wants to ask "what's the canonical newest build of
language X" — a UI badge, the upcoming MCP `latestPerMajor` knob
(#8644), etc. — has no way to tell those apart.

## Implementation

- **Heuristic** in `lib/release-track.ts` driven by `asSafeVer` + the
existing `isSemVer`/`isNightly` flags. Real semvers with a prerelease
segment (e.g. micropython `1.28.0-preview`) are flagged `prerelease`;
semvers containing `trunk`/`main` and the literal `nightly` tag go to
`nightly`; bare `beta`/`alpha`/`rc` tags go to `prerelease`; `isNightly`
with anything else (the c++ experimental forks) goes to `experimental`;
everything else stays `stable`.
- **Override:** `compiler.releaseTrack=` / `group.releaseTrack=` in
`.properties` for cases the heuristic can't reach from structural
fields. Used here for `rustccggcc-master` / `mrustc-master`, where
"master" lives in the compiler id but not the semver field.
- **Backfill** in `loadPrediscovered()` so cached discovery JSON written
before this field existed doesn't break, and so a hand-edited invalid
value gets re-inferred rather than violating the type contract.
- **Tests:** 18 unit tests covering each rule + edge cases (whitespace,
mixed case, prerelease segments) and the `isReleaseTrack` type guard.

## API exposure

`releaseTrack` is on `CompilerInfo` so it appears via
`/api/compilers?fields=all`. It is **not** in the default field set, so
existing API responses are unchanged. UI consumers can opt in.

## Why this is a separate PR

This started as a piece of #8644 (MCP endpoint) — the MCP
`list_compilers` `latestPerMajor` knob needs this distinction to give
clean answers ("newest GCC" should not return a sea of experimental
forks). Rather than hack around the missing metadata in just the MCP
layer, the metadata belongs at the source where other features (UI
badging, etc.) can consume it. #8644 will rebase on top of this.

## Test plan

- [ ] `npm run test -- --run release-track` — 18/18 pass
- [ ] `npm run test:props` — 90/90 pass
- [ ] `make pre-commit` — exits 0 (pre-existing warnings only)
- [ ] Manual sanity check on staging:
`/api/compilers/c%2B%2B?fields=all` returns `releaseTrack` for each
compiler

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: mattgodbolt-molty <mattgodbolt-molty@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 19:26:03 -04:00
Matt Fowles Kulukundis
93a5a224bb Update API.md (#8574) 2026-03-21 21:22:22 +01:00
Patrick Quist
b7a44e62b5 Add /noscript/clientstate/ endpoint for noscript mode (#8385) 2026-01-18 16:46:29 +01:00
Patrick Quist
f70ab79be4 Add new /api/tools/<language> API endpoint (#7950) 2025-07-27 13:47:06 +02:00
Patrick Quist
bbe966f115 Update API doc to AI's liking (#7771) 2025-06-18 14:23:14 +02:00
Patrick Quist
d3b67fcd5e Update API documentation for missing endpoints (fixes #4395) (#7821) 2025-06-17 09:56:57 +02:00
Matt Godbolt
fac3bf59c1 Documentation improvements (#7672)
This PR includes various documentation improvements:

- Fix grammar in README.md introduction
- Update Node.js version references to consistently indicate 'Node.js 20
or higher'
- Enhance macOS installation and setup guide with detailed instructions
- Fix broken link in API.md
- Fix formatting inconsistencies in WhatIsCompilerExplorer.md

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-05-11 16:46:05 -05:00
Mats Jun Larsen
bcd6394435 Ensure that content type for formatting requests is JSON (#7327)
Ideally I'd add a middleware or something else that requires JSON, but I
suppose this is fine for now.

cc @dkm
2025-01-29 10:46:56 -06:00
Ofek Shilon
407e0f9e83 Unhide another word in markdown 2024-10-27 08:40:25 +02:00
Alcaro
910f35e1d8 Unhide secret words (#7026) 2024-10-26 23:23:05 +02:00
goto40
03ce528a0a feat: added ability to receive a base64 with compressed clientstate, #6918 (#6919)
I encountered a problem with large URLs when using the "clientstate" API
with base64 strings: see #6918

* I found that it was quite easy to include this feature, just by
searching for `/clientstate/`.
* I "tested" my feature interactively with `npm run dev` and this
[link](http://localhost:10240/zclientstate/eNq1VduK2zAQ/ZXBhWITJc6lVye7sBT6uIWl9CUOiyJPYm1syUjyZsOSf+/Idm5tWuhD7YCs0cyZM5doXgOL1kqtbJDA/DWQGa0jBkHB1brma6RtIHq9gERW10Y0glTFMYiqMrhCg0pgArlzlU3iGNXg/GAgdBlvYxLFQivHpUITl5mtuErVG6lEUWcIM6mtM8jL23PhAdLw7WAtXV4va4vGw6ByDfBGbzbadnixlWpdYD9Hnh2dDPKqIlDFS6StQLAuwxe48es0Vf51WFYFdzgTBbcW7m6BgpNrpQ2Cy6WFNDiopAHkFBeDlTZ0hlDqkrik6lnLDCojlRtnITG0Du7e8ghegR6Cu/KEN1ztwO0qhLsoVV5EqCFBgCR+wyktM+ADfPHhhsNoCr2eJMhW91z/qdV/OtcfNfpPF/r+obiTROjawYy0Q8lIhb4osjSYeqpfer3xJAE+p6PFyXZ/+ryASIOUkhhM22PS2v8WKYHeawc211uVwE7XILgCX0ejC9jmUuSQyRIo1dmOKiXFJeUjClfZb+ZNFbDUZgcF33lS4ddvD98f7u7jL5RWn56Sui48JsJLMu74fHHzOmJjNmHv2Hv2gX1kn9jnfRcHr50G3rYJviRJ20yhtyODSdRkKke5zh2Drcxc3todWoBHTXN1vG299OaWwXxldAmDwQCcjs5ckcbo5I12nUPOOtGqLorHtrSsyX/JN/hYcWnCIYNR1DKyWKBwYPQWhlSZecKGyWhBJVJX6tbv989Ld6DuqUTTS27jP3K7JDKKfpXRVTK5JEe0iBQbJZN/Jzb2xPY+s4RnkP6TApsOKOheoTq4nMyPtaM0U1vzpX5uz5LG7HppZ7JNrJe0abaN6KDVNeahBNfFtweEthMfC1y52783zb8TmtDvV0fGY7ae/qOXUzhXnPgBQVdyJQs0zSxZkABfUJBf0w2XwzntukkTCD9nHp2p1cYjFHJ5NNaV6+ZS0CciNzSFxsNgf+bnW+2q2v2QVi4LP5cIBvcLen8CkW8rEQ==).

I have no insights in the underlying architecture, but I already have
**some comments on my PR** (and I am willing to work on these, if I get
some feedback/hints):

* the **decompression happens synchronously** (`zlib.inflateSync`). This
can be changed easily, once I understand how async operations are done
for the compiler explorer software.
* the link is `/zclientstate/` (in addition to `/clientstate/`) - I am
open for alternatives...
* I have **not added automated tests** (could be done, give me a
hint/example)

The modified SW worked for me! I hope to get some feedback... **This
would enable larger code-examples to be sent via clientstate as before
with smaller URLs**.
2024-10-02 07:58:51 -05:00
Michał Krzywkowski
de22d191f1 docs/API.md: Document /api/asm/<instructionSet>/<opcode> (#6339) 2024-04-10 11:34:25 +02:00
Patrick Quist
455d92916a Execution with heaptrack (#5644) 2023-11-07 23:59:40 +01:00
Matt Godbolt
1fc878d7a2 Bump all the things forward (#5563)
also run the lint and format nonsense
2023-10-05 21:43:33 -05:00
AliG
1efe5a3eaf Add ForCompile project to API.md. (#5516) (#5522)
ForCompile - A Fortran library to access the API

by @gha3mi.
2023-09-26 07:07:32 -05:00
Matt Godbolt
316992bfe7 Fix up formatting 2023-09-06 21:28:33 -05:00
Marcus Tillmanns
783f09a7c0 Fix link to formatter section (#5437)
Changed Link
"https://github.com/compiler-explorer/compiler-explorer/blob/main/etc/config/compiler-explorer.amazon.properties#L43"
to a relative link and fixed the display to be less huge.
2023-08-29 19:34:00 -05:00
Marcus Tillmanns
16d838186c Fix clientstate.ts link (#5436) 2023-08-29 15:39:05 +02:00
Jeremy Rifkin
60ce06b02f Improve cache handling on the frontend, cache executions on the backend, and improve controls on the exec pane (#5111) 2023-06-11 19:10:30 -04:00
fodinabor
e28e67d972 Add new "Debug intrinsics" filter. (#5045)
For now, this removes all `llvm.dbg.*` calls from LLVM IR. This is
useful to keep coloring the line correspondence between source and IR,
while not polluting the IR with the debug intrinsics.

Admittedly, I don't have much of a clue of what's going on here, so I
might be missing obvious adaptions (e.g. can we disable this for all
non-LLVM compilers for now somehow?).
Also, not really a Node.JS testing wizard either... 🤷🏼 

Just wanted this really bad for a workshop that's coming up soon ^^

Only tested with my system's default `clang` for now.

Fixes #5044

---------

Co-authored-by: Matt Godbolt <matt@godbolt.org>
2023-05-22 22:35:01 -05:00
Jeremy Rifkin
07f37abe76 The War of The Types (#4490) 2023-01-13 19:22:25 -05:00
Marc Poulhiès
69055681d9 Support for compiling to binary object (#3232) 2023-01-11 19:39:25 +01:00
Jeremy Rifkin
cb4157e186 Two quick markdown formatting changes prettier performed 2022-12-28 08:51:30 -07:00
Rubén Rincón Blanco
2e85575145 Add note about API not supporting external files (#4483) 2022-12-24 19:46:45 +01:00
partouf
3f36aa96cb formatting 2022-10-12 18:07:44 +02:00
Jackson Machado
2bc257d89d docs(api): improved clientstate API documentation describing need for unicode conversion (#4114)
* docs(api): improved clientstate API documentation describing need for unicode conversion

* docs: improve CONTRIBUTORS.md
2022-10-10 13:40:06 +02:00
Bogdan Grigoruță
99baaee978 Add neovim plugin to docs (#4052) 2022-09-12 17:49:33 +02:00
Mats Larsen
c165eb8cdb Mention where to find formatter type keys in API docs 2022-06-17 11:22:15 +02:00
Matt Godbolt
f2c1e0bd31 The Grand Reformat (#3643)
* The Grand Reformat

- everything made prettier...literally
- some tweaks to include a few more files, including documentation
- minor changes to format style
- some tiny `// prettier-ignore` changes to keep a few things the way we like them
- a couple of super minor tweaks to embedded document types to ensure they format correctly
2022-05-09 23:13:50 -05:00
Gregory Anders
7f0bc32ae4 API: Change 'filters' option to be additive (#3206) 2021-12-28 15:35:46 +01:00
Headline
909cac58a7 Add new properties to formatter requests (#3067) 2021-10-28 14:46:41 +02:00
Mats Larsen
53b9e0ac59 Support multiple formatter types for /api/format (#2818)
* Make /api/format handle multiple formatter types
* Ignore preferred style if the formatter is a 'one true style' formatter
* Add tests for base formatter
* Document /api/formats and /api/format/<formatter> usage
* Document adding a new formatter
* Update amazon config

Co-authored-by: Matt Godbolt <matt@godbolt.org>
2021-08-24 18:46:38 -05:00
RabsRincon
2306073103 Grammar check pass on docs
Used WebStorm built-in spellchecker and updated the docs where necessary
2021-07-13 12:01:07 +02:00
Matt Godbolt
17b2bb8a58 Move /shortener to /api/shortener (#2426)
We still support /shortener (though will scrape logs to see when
we can remove).

The route under /api/shortener will have the CORS headers set up
properly for things like @foonathan's lexy visualiser.
2021-02-15 12:52:46 -06:00
Matt Godbolt
e66f4c4b57 More master->main. Will do the PP one in the PP branch 2021-02-13 17:27:43 -06:00
Michał Krzywkowski
57f32d3bb8 docs/API.md: Mention Emacs client (#2413) 2021-02-04 12:41:17 +01:00
Patrick Quist
ab2f8e209a Compilers API changes (#2170)
* dont return all compilerproperties always in /api/compilers

* fields=all ipv ?all

* use fields=all with remote instances

* add to documentation

* cover more paths with tests
2020-09-02 21:36:02 +02:00
Rubén Rincón Blanco
6b19e59300 Minor improvement to compilation API docs
Removes the `req.body.compiler` fallback when looking for the compiler - It could never be reached
2020-08-03 15:41:08 +02:00
Waqar Ahmed
f685bbe934 Add link to QCompilerExplorer frontend (#2071) 2020-07-12 16:56:31 +02:00
RabsRincon
790702f0ed Add missing backendOptions keys to documentation 2020-06-23 04:57:46 +02:00
Matt Godbolt
84e9b282fd Canonical URLs now https://github.com/compiler-explorer/compiler-explorer! Hooray :) 2020-05-16 11:09:30 -05:00
RabsRincon
a0df8a06f8 Allow executeParameters to be json array
Closes #1810
2020-02-07 01:52:34 +01:00
Partouf
05f15ddc10 append to documentation 2019-10-27 15:37:02 +01:00
Partouf
90b171773f add to documentation 2019-09-07 18:16:25 +02:00
Patrick Quist
de7b26d695 Attempt to cleanup API documentation 2019-07-13 18:43:02 +02:00
Partouf
e70aa4f3b3 extend documentation 2019-07-12 15:10:08 +02:00
Partouf
10f7c58296 extra documentation 2019-02-16 03:30:56 +01:00
Partouf
29c4684add API doc move and update 2018-11-01 00:37:39 +01:00