Add an MCP tool
Register a new callable capability with a real schema, handler, and projection instead of an unreachable or undocumented one
Goal
Add a new strata19.* MCP tool that is callable, correctly advertised, and rendered without falling through to a generic fallback.
Before you start
- A working checkout of this repository with
pnpm installrun at the root. - Familiarity with
reference/tool-groupsand an existing tool similar to the one you're adding — most new tools belong in an existing file undersrc/mcp/facade/, not a new one. - A concept of whether the tool is a first-choice capability, a specialist utility, or an internal implementation detail — this decides its
exposurein step 4.
Steps
Write the input and output contracts
Define a Zod schema for the tool's input. src/mcp/facade/facade-tools.ts and the tool-group files under src/mcp/facade/ (for example change-impact-tools.ts) show the pattern — a z.object({...}) with .describe() on every field, since that text is what a model reads to fill the call correctly.
Write the handler
Write a FacadeExecute function: (input, ctx: { projectRoot, allowModelAssist?, onProgress? }) => Promise<Output>. It must not throw for an ordinary failure — return a typed, honest result instead (an UNSUPPORTED verdict, an empty result with a reason, a refusal object). src/mcp/facade/tool-registry-kit.ts is where FacadeExecute and FacadeTool are defined.
Build the description with describe()
Every tool description is the same three-block shape, asserted by tests/unit/plugin/facade-tool-invocation.test.ts:
export function describe(parts: {
summary: string
useWhen: string
alsoUseWhen: string
doNotUseWhen: string
}): string {
return [
parts.summary,
'',
`USE WHEN: ${parts.useWhen}`,
`ALSO USE WHEN: ${parts.alsoUseWhen}`,
`DO NOT USE WHEN: ${parts.doNotUseWhen}`,
].join('\n')
}useWhen is phrasing a user actually says. doNotUseWhen is what keeps your tool from over-firing on a request that belongs to an existing one — a model has no other signal than this text to route correctly.
Choose annotations
Call readOnly(title), writes(title, idempotent, destructive?), or writesAndSpends(title, idempotent) from tool-registry-kit.ts. These set the MCP readOnlyHint/destructiveHint/idempotentHint/openWorldHint a host uses for approval friction, and they also derive the tool's sideEffectClass (read / local_write / remote_write / destructive), which gates the call under the project's write authority. Use writesAndSpends only if the call reaches a model endpoint on the user's own key — it is what tells a host the call can cost money.
Assemble and register the FacadeTool
A complete, real entry looks like this (src/mcp/facade/facade-tools.ts:10805):
{
name: 'strata19.get_finding_detail',
annotations: readOnly('Finding detail'),
description: describe({
summary:
'Full evidence for one already-known finding: the source snippet, real file/line, which detector ' +
'fired, and why. Runs no check itself.',
useWhen: '"tell me more about that finding" · "why is that flagged"',
alsoUseWhen: 'after verify_implementation surfaces findings the user engages with',
doNotUseWhen:
'no finding exists yet — run verify_implementation first; or the user wants the FIX, not evidence — ' +
'use remediate_finding',
}),
inputSchema: FindingDetailInputSchema,
outputSchema: FindingDetailOutputSchema,
execute: d4Guarded(getFindingDetail as FacadeExecute),
}Wrap your execute in d4Guarded(...) — every registry execute is wrapped so outbound text passes sanitizeClaim before any consumer sees it; this is the single enforcement point for that guarantee. Add the object to the facadeTools array (or to the tool-group array your file exports, which facade-tools.ts spreads in at its tail).
Declare its projection
A handler in facadeTools alone is unreachable and unrendered. Add exactly one entry to PUBLIC_PROJECTIONS (or INTERNAL_PROJECTIONS if the tool should never appear in tools/list) in src/mcp/facade/tool-projection-registry.ts:
{
toolName: "strata19.<your_new_tool>",
exposure: "expert", // 'intent' | 'expert' | 'composite_member' | 'internal_only' | 'human_surface_required'
advertisedContexts: ['default', 'full'],
presentation: { kind: 'text_only', reason: "fully_actionable_text" },
widgetCall: { allowed: false, reason: "..." },
skillOwners: [],
reachFixture: null,
payloadSchemaVersion: null,
lifecycle: 'live',
}An empty skillOwners is a real, honest value — leave it [] unless a packaged skill you also wrote references strata19.<your_new_tool> by name. If the tool should render a compact card rather than text, add a branch in buildViewModel/buildWidgetProps (src/mcp/facade/view-models.ts) and, if the widget should be able to call it directly, add its name to WIDGET_ACCESSIBLE_TOOLS (src/mcp/facade/app-resources.ts) — Interface and packaging owns that wiring in full.
Write tests, then rebuild
Prove schema validation, dispatch, error shape, and projection with a real test — Test an extension names the boundaries and the files that already exercise them. Only after tests pass, rebuild and reinstall the plugin: see Interface and packaging for the exact release loop. Editing facade-tools.ts and running pnpm build:plugin does not reach a Codex session that already has the plugin installed until the version is bumped and the plugin is reinstalled.
Verify
Run the projection audit — it fails loudly on exactly this class of mistake:
pnpm audit:projectionsThen confirm the tool is actually advertised where you intended:
pnpm gate:mcp-tools-list:plugin-artifactThis runs tools/list against the real built plugins/strata19/server/facade-stdio.js and checks the result against the schema and manifest. Your tool should appear under the advertisedContexts you declared, with the exact identifier spelling strata19.<your_new_tool>, and nowhere else.
If it doesn't work
pnpm audit:projectionsreports a tool infacadeToolswith no projection entry, or a projection entry naming a toolfacadeToolsdoes not have. The two registries are meant to be exhaustive over each other — add or fix the missing side; there is no third place either one can be inherited from.- The widget renders
No datafor a tool that does havepresentationset.presentation.kind: 'compact_domain_card'needs a matching branch inbuildViewModel/buildWidgetProps(view-models.ts) — a projection entry alone does not create the renderer. - The registry grants
widgetCall.allowed: truebut the widget can never reach the tool.assertWidgetAccessibleToolsMatchRegistry()(app-resources.ts) runs eagerly at module load and throws:"The projection registry grants widgetCall to N tool(s) absent from the live facadeTools registry: ..."— fixtool-projection-registry.tsor the tool's name infacade-tools.tsso the two agree. - The tool works in a source-level test but not in an installed host. The plugin cache is version-keyed; a rebuilt bundle with no version bump ships nothing. See Interface and packaging.
Related
- Interface and packaging — the full release loop and widget-projection wiring this page links to rather than repeats.
- Test an extension — the contract, registry, and package tests a new tool needs before it ships.
- Package a skill — teach a host to use the tool you just added.
reference/tool-groups— where existing tools are grouped, so you can find the file a new tool belongs next to.