feat(plugins): advertise plugin tools on the MCP server

The advertise path, shaped like trip-warnings.mcp.ts: gate on the kill
switch, fan out over providersOf, let a failing provider contribute
nothing rather than fail the surface.

A tool is advertised only if the signed manifest declares it AND the
running build reported implementing it, the same two-sided check
callPlugin makes for exports. The manifest half is what makes the text
auditable: the child composes its loaded payload after onLoad, so without
it a sha256-pinned artifact could change what it publishes on every
restart with no re-consent.

The result envelope is built here, always. The registry returns a
handler's value verbatim and skips output validation without an
outputSchema, so a plugin returning {ok: true, data} would emit a result
with no content key and every conforming client would error. A failed or
timed-out invoke becomes isError rather than a JSON-RPC fault, so the
model can see it and try something else.

Gates in order: kill switch, then demo mode. The plugins domain had no
demo call site before, and the child has none of its own.

The service owns the process-level source rather than PluginRuntimeService
beside the other sinks, because it needs PluginHooks and PluginHooks
injects PluginRuntimeService. It clears the source on destroy, which the
existing setPluginChannelSource forgets to do: a torn-down buildApp()
would otherwise leave a live source closing over a dead runtime and bleed
into the next suite.

mcpToolCapabilities is a parallel reader rather than a capabilityList
generalisation, since that one returns string[]. It re-runs the manifest
parser instead of trusting the stored blob, which was written by whatever
parser was current at install time and whose caps are the security
control.

Two caps not in the brief: MCP_TOOLS_TOTAL_MAX across all plugins, since
8 each times twenty installed plugins would put 160 tools in front of a
model already choosing from ~200. Truncation is logged, because a
truncated surface reads exactly like a plugin that published nothing.

MCPTOOLS-001 to MCPTOOLS-019.
This commit is contained in:
Renzo Beux
2026-08-28 13:47:22 -03:00
committed by Maurice
parent c6027f9e68
commit 21fd04647f
5 changed files with 466 additions and 9 deletions
@@ -5,6 +5,7 @@ import { JourneyDomainModule } from '../../journey/journey-domain.module';
import { PlaceDetailsController } from './place-details.controller';
import { TripWarningsController } from './trip-warnings.controller';
import { TripWarningsMcp } from './trip-warnings.mcp';
import { PluginMcpToolsService } from './plugin-mcp-tools.service';
import { ViewContributionsController } from './view-contributions.controller';
import { TripCardContributionsController } from './trip-card-contributions.controller';
import { PluginPhotosController } from './plugin-photos.controller';
@@ -47,9 +48,13 @@ import { JournalEntryRowsController } from './journal-entry-rows.controller';
AtlasLayersController,
JournalEntryRowsController,
],
// The only contribution with an MCP counterpart so far. It belongs to this module
// rather than to the trip read model because the plugin runtime and the trip
// aggregate already import each other's modules; see trip-warnings.mcp.ts.
providers: [TripWarningsMcp],
// The contributions with an MCP counterpart. TripWarningsMcp belongs to this
// module rather than to the trip read model because the plugin runtime and the
// trip aggregate already import each other's modules; see trip-warnings.mcp.ts.
//
// PluginMcpToolsService owns the process-level tool source. It lives here, and
// not on PluginRuntimeService beside the other sinks, because it needs
// PluginHooks and PluginHooks injects PluginRuntimeService.
providers: [TripWarningsMcp, PluginMcpToolsService],
})
export class PluginContributionsModule {}