Files
IdeaSDK/docs/services.md
Blomios b5a35563b6 docs(sdk): lancement des serveurs MCP JavaScript packagés — #294 (manifest: aucune substitution ${node}/${runtimeNode}/${hostNode} ni champ runtime, IdeA ne fournit pas de runtime Node plugin-scoped; command n'est pas du shell — démarrage direct avec args séparés, pas de fichiers de startup/alias/PATH du shell de login; command relatif résolu sous pluginRoot — command:"node" sans allowAbsoluteCommand devient ${pluginRoot}/node (cause ENOENT UnityPlugin #12); absolu littéral refusé sans allowAbsoluteCommand=true, command devenu absolu après substitution ${pluginRoot}/${appDataDir} passé tel quel; shebang #!/usr/bin/env node dépend du node visible du process app IdeA; recommandations: exécutable packagé incluant son runtime ou runtime géré sous stockage plugin/app pointé via ${pluginRoot}/${appDataDir}, sinon dépendance hôte explicite absolue /usr/bin/node avec allowAbsoluteCommand=true et scripts dans args; même règle pour command:"bash"; packaging-distribution: section Packaged Executables And Runtimes — bit exécutable et shebang valides dans le package installé, éviter le bare command:"node" en plugins distribués/multi-harness; services: distinction runCommand() (exécutable hôte de l'environnement task, aucune substitution) vs règles manifest mcpServers avec lien croisé; affirmations vérifiées par Git contre l'hôte crates/application/src/plugin/mod.rs:3199 substitution puis looks_absolute/allow_absolute_command sinon préfixage pluginRoot, et validation :3637 absolu littéral sans flag rejeté; QA verte reconfirmée par Git: npm run check — build, typecheck:examples, package:hello-plugin)
2026-09-09 16:24:16 +02:00

3.0 KiB

Services

ctx.services is the stable public host facade. It is available to plugins that declare ui or tooling capabilities.

{
  "capabilities": ["ui", "tooling"]
}

Workspace

services.workspace reads the focused/current project, project context and project-owned files. Paths are relative to the project root; hosts reject absolute paths and traversal outside the workspace.

Key APIs:

  • getCurrentProject()
  • getProjectRoot(projectId?)
  • readProjectContext(projectId?)
  • updateProjectContext(content, projectId?)
  • readTextFile(path, projectId?)
  • writeTextFile(path, content, projectId?)
  • readBinaryFile(path, projectId?)
  • writeBinaryFile(path, bytes, projectId?)
  • listDirectory(path?, projectId?)
  • stat(path, projectId?)
  • watch(path, handler, projectId?)
  • queryStructure(query?)

Tasks

services.tasks launches and inspects host-managed command tasks.

Use runCommand() only after preconditions are satisfied. ownerAgentId must be a real agent id when work belongs to an agent workflow.

runCommand() keeps its cwd project/workspace scoped: cwd must be a relative path under the project root. The host does not implicitly resolve command or args against the plugin package. Use the absolute ctx.pluginRoot supplied at activation time to construct an explicit path to a packaged script, and pass that path as command or as an argument to its interpreter. Treat package files as read-only. Unlike manifest-declared MCP servers, runCommand() does not substitute ${pluginRoot} or ${appDataDir}.

const script = `${ctx.pluginRoot.replace(/[\\/]+$/, "")}/scripts/check.mjs`;
await ctx.services.tasks.runCommand({
  projectId,
  ownerAgentId,
  label: "Run packaged check",
  command: "node",
  args: [script],
  cwd: "."
});

This task example uses node as a host executable visible to the task environment. That is not the contract for contributes.mcpServers: MCP server command values are resolved by the plugin manifest rules documented in Manifest, where a bare command: "node" is package-relative unless external host-command handling is explicitly enabled.

Tooling

services.tooling.diagnose() checks executables, environment values and files from the host-controlled runtime.

Events

services.events.subscribe() provides best-effort bounded subscriptions to public plugin events such as workspace file changes and background task changes. Dispose subscriptions when no longer needed.

Config

services.config reads and updates structured JSON documents in project-owned locations. Use it for configuration the user expects to review/version.

Terminal

services.terminal opens, reattaches and closes terminal sessions:

  • open({ cwd?, rows?, cols?, onData? })
  • reattach(sessionId, { onData? })
  • close(sessionId)

Windows

services.windows.open({ layoutType, state? }) opens a detached OS window for one of the calling plugin's declared layout contributions. See Windows.