Termix icon indicating copy to clipboard operation
Termix copied to clipboard

Optionally serve the OpenAPI spec from the Termix server

Open pacnpal opened this issue 2 weeks ago • 3 comments

What problem would this solve?

I'm wiring Termix into other tools through the API. The main one is an MCP gateway that turns an OpenAPI document into tools. Right now the only spec is the one the docs site publishes at docs.termix.site/openapi/core.json, plus one file per plugin under /openapi/plugins/. That causes three problems for a self-hosted instance.

The published spec follows the latest release. If my server or one of my plugins is a version behind, the spec can describe routes or fields my instance doesn't have.

It only covers bundled plugins. Community plugins and plugins I wrote myself aren't in it at all, even though their routes already have @openapi comments.

The servers entry is a {server} placeholder. Every tool that reads the spec has to be told the real URL by hand.

The server is the only thing that knows its own version, which plugins are enabled, and its own URL. So it's the right place to serve this.

What would you like?

An admin setting, off by default, that serves a merged spec at something like /openapi.json. The spec would cover core plus every enabled plugin at its installed version, with servers set to the instance's own URL. The route should still require sign-in or an API key.

As far as I can tell from the source, it would take three changes:

  1. Run npm run generate:openapi during the image build and ship core.json with the server. The source with the @openapi comments isn't in the image, so the server can't build the spec at runtime.
  2. Have termix-plugin pack run the SDK's buildOpenApi on the plugin's backend and put an openapi.json in the .tmxplug. The docs site already runs that same builder for each plugin in scripts/sync-content.mjs, so pack would be doing work that already exists.
  3. Add a route that merges core with the spec from each enabled plugin, puts each plugin's paths under /plugin-api/<id>/, and fills in servers.

A package without a spec just gets left out. That way older .tmxplug files keep working.

Alternatives

Pulling the files from docs.termix.site works, but has the version and plugin gaps above. Building the spec from a source checkout of every plugin also works, but it's a lot of setup just to get an accurate route list.

Anything else?

#1465 covers how accurate and complete the spec is. This issue is about where the spec is served, so the two don't overlap. Serving it from the instance would also make gaps like the ones in #1465 easier to find, since anyone can compare what their server says it has with what it actually does.

pacnpal avatar Nov 19 '26 13:11 pacnpal

Auto-triage

Request to serve a merged OpenAPI spec from the Termix server instance, covering core and enabled plugins with the correct version and URL.

Field Value
Type Feature request
Difficulty 3/5 (Moderate)
Priority Low

A maintainer will take a look. If anything above looks wrong, just say so.

termix-triage-bot[bot] avatar Nov 19 '26 13:11 termix-triage-bot[bot]

Added for Termix 26.11.3 (not released yet). Set SERVE_OPENAPI=true and the server answers GET /version/openapi.json to a signed in user or an API key. It is off (404) otherwise.

  • Core's spec is now built into the image with the backend (dist/backend/openapi.json).
  • Plugins already ship dist/openapi.json in their .tmxplug, since termix-plugin build runs the same builder. Each active plugin's paths are merged in, but only routes under its own /plugin-api/<id>/. A package without a spec is left out.
  • servers is set to the address the request came in on, and info.version is the running version.

I used an environment variable rather than a settings screen for now, under /version so no proxy changes are needed.

LukeGus avatar Nov 20 '26 05:11 LukeGus

This shipped in v26.11.3. Update Termix to the latest version to get it. Thanks for the report!

termix-triage-bot[bot] avatar Nov 21 '26 13:11 termix-triage-bot[bot]