Skip to content

Language service HTTP API ​

Every plugin service exposes the same endpoints, implemented by startLanguageService in @mdeo/service-common. A plugin author normally never touches them — this page documents the contract for debugging, and for anyone implementing a plugin service in another stack.

All endpoints except GET / and the static assets require a JWT issued by the backend, presented as Authorization: Bearer <token>, and are checked against a scope (see Scopes).

A caller can say how long it is willing to wait by sending X-Mdeo-Timeout-Ms with the milliseconds it has left. The backend sends it with every plugin request, never more than its own configured maximum. A file data computation is shared by every request waiting for the same data, so the plugin always gets the configured maximum for it; each request only stops waiting at its own deadline and leaves the computation to the others. A handler sees the limit as context.signal, which aborts when the time is up or the caller disconnects; every serverApi call made while handling the request is aborted with it and passes the remaining time on to the backend. A handler that fails after its deadline passed is answered with 504.

Responses larger than 1 KiB are compressed with gzip or deflate when the caller sends Accept-Encoding, and a request body sent with Content-Encoding: gzip or deflate is accepted. The backend, the execution services and the workbench proxy compress the same way, and WebSocket connections negotiate permessage-deflate. A service implemented in another stack should do the same: the platform's payloads are JSON that shrinks by an order of magnitude.

Limits apply to what a body or message inflates to, not to its compressed size, so a small compressed body cannot expand past them. Request bodies may inflate to 64 MiB, the same as a plain body. WebSocket messages between services may be 512 MiB; the browser's connection to the backend takes 64 MiB. A peer that exceeds a WebSocket limit is disconnected with close code 1009.

Errors ​

Every service of the platform reports a failure the same way. Over HTTP, an error status comes with

json
{ "error": { "code": "NotFound", "message": "Unknown language: sql" } }

and an error message on a WebSocket carries the same object in its error field, as in {"messageType": "exec/error", "requestId": "…", "error": {"code": …, "message": …}}. The code is one of ErrorCodes (@mdeo/plugin, and com.mdeo.common.model.ErrorCodes in Kotlin). The general codes follow the status: BadRequest (400), Unauthenticated (401), Forbidden (403), NotFound (404), Conflict (409), Internal (500), Unavailable (502, 503) and DeadlineExceeded (504). An area can use a more specific code, such as FileNotFound or ExecutionNotFound. The message is for people and may change; branch on the code.

errorResponse(status, message, code?) from @mdeo/plugin builds the body in TypeScript, and call.respondError(status, message, code?) from the Kotlin common module answers with it. A service built on @mdeo/service-common or the Kotlin plugin service module answers unknown routes, unreadable bodies and uncaught handler errors in this shape too.

A 5xx answer says only that something went wrong inside; what went wrong is logged. A 4xx message, and the message an execution handler fails with, are shown to the user as they are, so they must not carry internal detail such as addresses or stack traces. When the backend passes a failure on, it passes on only the message of an answer in this shape, never the raw body.

Sessions are the exception: what travels on them is a protocol the plugin defines, and they are refused with WebSocket close codes.

Scopes ​

Each scope grants exactly one capability, and every service serving that capability checks the same scope, so a token passed on from one hop to the next is accepted for the same thing at each. The constants are Scopes in @mdeo/plugin and com.mdeo.common.auth.Scopes in Kotlin. Scopes checked by plugin and execution services start with plugin:; the others are checked by the backend.

ScopeGrantsChecked by
files:readReading the project's filesBackend
file-data:readReading computed file dataBackend
execution:writeReporting an execution's state and metadataBackend
session:openGetting the token that opens a sessionBackend
session:contributions:readReading which contribution plugins a lang: session loadsBackend
plugin:file-data:computePOST /data/:languageId/:keyPlugin service
plugin:request:sendPOST /request/:kind/:targetId/:key, directly or through the backendBackend, plugin service
plugin:execution:startStarting an executionPlugin service, execution service
plugin:execution:readAn execution's summary and result filesPlugin service, execution service
plugin:execution:cancelCancelling an executionPlugin service, execution service
plugin:execution:deleteDeleting an executionPlugin service, execution service
plugin:session:connectOpening a sessionPlugin service

The backend issues one token per purpose. It carries the scope for that purpose plus what the handler needs to do its work:

TokenScopes
Plugin request, from the workbench or a plugin that does not delegateplugin:request:send, files:read, file-data:read; bound to the caller's file data computation when it has one
File data computationplugin:file-data:compute, files:read, file-data:read, plugin:request:send
Execution run, kept by the execution for its lifetimeplugin:execution:start, files:read, file-data:read, plugin:request:send, session:open, execution:write
Reading, cancelling or deleting an executionthe one plugin:execution:* scope, files:read, file-data:read, plugin:request:send
Sessionplugin:session:connect, plus session:contributions:read for a lang: target

A service never mints a token of its own. A plugin request sent through the backend reaches the target plugin with a new plugin request token, which can read the project and nothing else, whatever the caller's token may do. A caller that hands its work over sets X-Mdeo-Delegate-Token: true (sendPluginRequest(…, { delegate: true })), and the backend then forwards the caller's own token instead. That is how the config plugin passes an execution on to the contribution plugin that runs it: the run token reaches the contribution plugin, and that plugin's execution service accepts it through plugin:execution:start. Delegating trusts the target plugin with everything the token grants, so delegate only the work the token was issued for.

GET / ​

Returns the plugin manifest. This is the only endpoint the backend needs to register a plugin.

Static asset paths in the response are rewritten to static/ or static/<SERVICE_VERSION>/.

bash
curl http://localhost:3000/ | jq

GET /static/* ​

The built ES modules and stylesheets referenced by the manifest — language.js, editor.js, styles.css, and any workers. Served with CORS enabled and with the COOP/COEP headers the workbench requires.

POST /data/:languageId/:key ​

Computes file data. Called by the backend when a cached entry is missing or has been invalidated.

Scope: plugin:file-data:compute

json
{
  "project": "0a2f…",
  "source": {
    "path": "/models/plan.m",
    "content": "using \"./tasks.mm\"\n…",
    "version": 7
  },
  "contributionPlugins": []
}

source is omitted for directory-level computations. contributionPlugins carries the payloads of the contribution plugins active for the project, and is part of the key under which the service pools its Langium instances.

Contribution hashes. Every request also carries contributionHash, which identifies the contribution set. A service that answers with the header X-Mdeo-Contribution-Hashes tells the backend it keeps sets by hash; from then on the backend sends contributionHash without contributionPlugins. A service that does not hold the set a hash stands for — after a restart, or when the set changed — answers 409 with X-Mdeo-Contributions-Unknown, and the backend sends the request again with the payloads. This applies to /data, /request and /executions alike, and @mdeo/service-common does all of it; a service in another stack can ignore it and always receives the payloads.

json
{
  "data": { },
  "fileDependencies": [{ "path": "/models/tasks.mm", "version": 3 }],
  "dataDependencies": [{ "path": "/models/tasks.mm", "key": "ast" }]
}

The dependency lists are what let the backend invalidate correctly. Anything a handler reads through context.serverApi is tracked automatically and merged into whatever the handler returns.

File data read through context.serverApi.getFileData is cached for the rest of the request, and reads started together — a Promise.all over several files — reach the backend as one POST /api/projects/{projectId}/file-data-batch request with {"requests": [{"path", "key"}]}. The backend computes the entries concurrently and answers {"results": [...]} in request order, each either {"data", "version"} or {"error": {"code", "message"}}, so one failing entry does not fail the others. The backend answers at most 256 entries per request, the first ones; serverApi asks again for the rest.

Responses:

StatusWhen
403The token lacks the scope
404Unknown language, or no handler for the data key
409Only a contribution hash was sent, and this service does not hold that set; the answer carries X-Mdeo-Contributions-Unknown and the backend sends the request again with the payloads
503Every Langium instance stayed busy for LANGIUM_ACQUIRE_TIMEOUT_MS
504The caller's deadline passed

POST /request/:kind/:targetId/:key ​

An arbitrary request, addressed at a plugin target: lang:<id> or contrib:<id>, written into the path as two segments the same way a session address is. Both kinds answer on this one channel, so a contribution is called exactly like a language plugin.

Scope: plugin:request:send

json
{
  "project": "0a2f…",
  "body": { },
  "contributionPlugins": []
}

contributionPlugins carries the project's contributions for the addressed language. A request addressed at a contribution carries none: it is served by the plugin that ships that contribution, which already holds it.

The response is { "data": … }, or { "data": null } when the handler produced nothing. It fails with the same statuses as /data.

This is the channel the config language uses to talk to its contribution plugins: config to compute section data, and the config-execution-* keys to manage runs.

A lang: request is served on a Langium instance of that language, registered in a language's requestHandlers. A target that owns no instance — every contribution — registers in the service's requests map instead, keyed by address and then by request key:

ts
requests: {
    "contrib:my-contribution": {
        version: async ({ body, serverApi, signal }) => ({ version: "1.4.0" })
    }
}

In a Kotlin plugin service the same handlers are declared on the contribution itself, see Kotlin plugin services.

When to use a request, and when a session ​

A request is one call with one answer and nothing kept afterwards. A session is a connection that stays open and may hold state between messages. Reach for a request when there is nothing to remember — asking a service what it offers, or for something the workbench needs before any run exists — and for a session when there is.

POST /:languageId/executions ​

Starts an execution. Registered only if the service has executionHandlers.

Scope: plugin:execution:start

json
{
  "executionId": "b71c…",
  "project": "0a2f…",
  "filePath": "/optimize.config",
  "fileContent": "problem {\n…",
  "fileVersion": 12,
  "data": { },
  "contributionPlugins": []
}

The executionId is created by the backend beforehand, so progress can be attributed to it from the first moment. data is the payload the language's action handler produced when the user triggered the action.

Execution follow-ups ​

EndpointPurpose
GET /:languageId/executions/:executionId/summaryMarkdown summary of the run
GET /:languageId/executions/:executionId/filesThe result file tree
GET /:languageId/executions/:executionId/files/*One result file
POST /:languageId/executions/:executionId/cancelCancel a running execution
DELETE /:languageId/executions/:executionIdDelete an execution and its results

The summary and file reads need plugin:execution:read, cancelling needs plugin:execution:cancel, and deleting needs plugin:execution:delete. The same scopes authorize the same requests on the /ws/executions WebSocket.

WebSocket ​

Two WebSocket endpoints are attached to the same HTTP server, dispatched by path:

PathPurpose
/ws/executionsExecution results and progress, read by the backend on a connection it keeps between requests
/ws/sessions/:kind/:targetId/:nameA session: a long-lived binary connection between one execution and one plugin target

The execution endpoint authorizes each request on the connection separately, because one connection is shared by unrelated callers. A session authorizes once, at the handshake, because one connection is one conversation.

Configuration ​

parseServiceConfigFromEnv() reads:

VariableDefaultMeaning
PORT3000Listening port
HOST0.0.0.0Bind address
BACKEND_API_URLhttp://localhost:8080/apiBackend base URL for the ServerApi
JWT_ISSUERmdeo-platformExpected issuer of incoming tokens
MAX_LANGIUM_INSTANCES5Size of the Langium instance pool
MAX_SESSION_INSTANCES2How many pool instances open sessions may hold at once
MAX_SESSIONS64How many sessions may be open at once, on every target together
MAX_CONTRIBUTION_SETS64How many contribution sets the service remembers by hash; a forgotten set is sent again
LANGIUM_ACQUIRE_TIMEOUT_MS30000How long a request waits for a free instance before failing
MAX_REQUEST_BODY_BYTES64 MiBUpper bound on a request body; file contents travel in the body
SERVICE_VERSION—When set, static assets are served under /static/<version>/

A numeric variable set to something that is not a whole number in its range stops the service at startup.

Language-specific variables are read by the plugin itself — for example SCRIPT_EXECUTION_SERVICE_URL and MODEL_TRANSFORMATION_EXECUTION_SERVICE_URL.

The Langium instance pool ​

Each language keeps a pool of Langium instances keyed by the set of active contribution plugins, because two projects with different plugin sets need different grammars. Instances are reused when the key matches, evicted least-recently-used when the pool is full, and reset after every request so that no document survives into the next one.

This is why MAX_LANGIUM_INSTANCES is a memory-versus-concurrency trade-off rather than a straightforward throughput setting.

A session on a language target takes its instance out of the pool for the lifetime of the connection, so it is governed by its own budget rather than by this one. A request that finds every instance held now fails after LANGIUM_ACQUIRE_TIMEOUT_MS instead of waiting indefinitely.

Released under the terms of the repository licence.