EDT-MCP — adding a new MCP tool (canonical)
The procedure that actually compiles, passes every ratchet, and validates live. It tracks the real current API — verify each class/method before use (grep/Read, don't invent). Companion skills: edt-mcp-architecture (where things live), edt-mcp-tool-conventions (naming/errors/output), edt-mcp-bilingual (ru/en), edt-mcp-e2e-testing (e2e suite), edt-mcp-build-test (build).
A new tool touches MANY places. Miss one and either a ratchet goes red (unit-coverage, e2e-coverage, tool-contract, golden) or the live
tools/listdrifts. Walk the whole list.
Steps
Class in
tools/impl/XxxTool.java:implements IMcpTool(read/action) orextends AbstractMetadataWriteToolfor a tool that MUTATES the model — the base runsexecuteOnUiThread(params)on the UI thread (model mutation is safe only there), givesresolveProjectAndConfig(projectName)+unwrapCauseMessage(e)+ defaultgetResponseType()=JSON.tools/impl/holds the tool only (utilities/bases →utils/,tools/base/). Declarepublic static final String NAME = "xxx";(snake_case:get_/list_/create_/adopt_…).IMcpTool surface:
getName()→NAME.getDescription()— short, for the AI client (what it does + when). End with"… Full parameters and examples: call get_tool_guide('<name>')."(a unit test checks this; keep the description compact — thetools/listbudget is shared).getInputSchema()viaJsonSchemaBuilder.object().stringProperty(name, desc[, required]).integerProperty(...).enumProperty(name, desc, "a","b").objectArrayProperty(...).build(). Required is the boolean 3rd argument of a property; there is NO.required(...)method. Parameter names are lowerCamelCase (ToolContractConsistencyTestfails snake_case). Canonical:projectName,fqn,modulePath,limit/offset(seeedt-mcp-tool-conventions).getOutputSchema()— declare the JSON result keys (for JSON tools).- Guide — full how-to (parameters, examples, gotchas, how to revert), served on-demand through the guide-resource channel. Do NOT override
getGuide(): the default loads the bundled Markdownguides/<name>.mdviaGuideLoader. Author the guide as that file (one per tool); the body is the## Guidesection (the renderer adds the# <name>H1, description and the## Parameterstable itself, so use## Parameter detailsfor param prose).GuideCoverageTestfails the build if a registered tool has no guide. OverridegetGuide()only for a guide that must be computed at runtime. getResponseType()— TEXT/JSON/MARKDOWN/YAML/IMAGE (may be omitted when extending AbstractMetadataWriteTool → JSON).- Every parameter read in execute() must be in the schema, and vice versa.
execute / executeOnUiThread:
- Arguments —
JsonUtils.extractStringArgument/extractIntArgument/extractBooleanArgument/extractObjectArray; required ones —JsonUtils.requireArguments(params, "projectName", "fqn")(returns a ready error-JSON or null). - Project/configuration —
ProjectContext.of(name)(utils) orresolveProjectAndConfig(name)(write base). NOTResourcesPlugin.getWorkspace()…by hand. - Model only inside a transaction boundary (hard rule, CLAUDE.md): reads in a read boundary, writes via
BmTransactions.write(...). A bare write only enqueues the async.mdoexport — persist viaBmTransactions.forceExportToDisk(project, [topObjectFqn, configurationFqn])(pass the TOP FQN; for a member, its parent top; add theConfigurationFQN =((IBmObject)config).bmGetFqn()because its collection changed). - Metadata resolution by FQN — use the SHARED resolvers (don't write the 47th copy):
MetadataTypeUtils.normalizeFqn/findObject(bilingual),MetadataNodeResolver.resolveExisting(existing) /resolveForCreate(new),FormStructureReader.resolveMdForm(forms — expectsType.Name.Forms.FormNameorCommonForm.Name). Synonym is keyed by the language CODE (seeedt-mcp-bilingual). - EDT services: typed via
Activator.getDefault().getXxx()(getConfigurationProvider,getV8ProjectManager,getDtProjectManager,getBmModelManager,getMdRefactoringService) orServiceAccess.get(IFoo.class)for a wired service (binding.toService()) — and add the package to MANIFEST Import-Package (step 5). - Errors ONLY via
ToolResult.error(msg).toJson()(no exceptions escaping the tool, no bare"Error: …"). Success —ToolResult.success().put(k, v)….toJson(). An error must be actionable (name the bad value + how to fix / sibling tool).
- Arguments —
Registration — in
tools/BuiltInToolRegistrar:import …impl.XxxTool;+registry.register(new XxxTool());(next to siblings).MANIFEST.MF Import-Package — add each NEW imported
com._1c.g5.*package (e.g.com._1c.g5.v8.dt.md.extension.adopt). A miss is a runtimeClassNotFound, not a compile error.Unit test — MANDATORY (
mcp/tests/.../tools/impl/XxxToolTest.java).BuiltInToolTestCoverageTestfails the build if a registered tool has noXxxToolTest. Contract (no live runtime): NAME,getResponseType(), description containsget_tool_guide('<name>'), schema contains every parameter, the required array is correct (and excludes optional ones), output-schema keys. Deeper behaviour is e2e.e2e test — MANDATORY (
tests/e2e/tools/test_<tool>.py). The e2e coverage ratchet fails if a tool intools/listhas none. Readedt-mcp-e2e-testing. happy + negative + error-quality; anti-cheat ("would the test fail if the tool were broken?"). A mutating tool: prefer non-mutating cases headless (the harness resets only the BASE fixture per-test, not the extension) + validate the mutating happy path LIVE; for a write-metadata tool that runs headless, check both the model read-back AND the on-disk structure (poll_diff_contains).Golden — a new tool changes
tools/list; regenerate and commit:EDT_MCP_UPDATE_GOLDEN=1 python tests/e2e/run_all.py --project TestConfiguration --filter test_tools_list_matches_committed_golden_snapshot, thengit add tests/e2e/tools_list.golden.json.README — bump the tool COUNT (two places), add the tool to its group table, to the flat tool table, and to the detailed section (parameters must match the schema).
Full contour (don't say "done" without it):
bash source/compile.sh(compile + unit tests + every ratchet) → adversarial Opus review → redeploy to the dev EDT copy (edt-redeploy.ps1; the signal is the log lineMCP server UP on 8765) → live validation against:8765→ commit. A freshly deployed tool is NOT in this session's MCP deferred list — to check it live, call it through the e2e harness client (python→harness.initialize(); harness.call("<name>", {...})) orInvoke-RestMethod, not the tool's MCP wrapper. Seeedt-mcp-build-testand the dev-loop memory.
Gotchas
((IBmObject)x).bmGetFqn()is valid ONLY on a TOP object — on a member (attribute/form/…) it throws "may be called on top objects only". For a top, usebmGetTopObject().bmGetFqn(); for a member, report the input FQN.- Model writes happen on the UI thread (the write base does this; a bare
IMcpToolmust wrap inDisplay.syncExecitself). forceExportToDiskwants the TOP FQN; a member change exports the parent top + (for a new top) theConfigurationFQN.- Cyrillic in string literals/regexes goes through
\uXXXX(Tycho non-UTF-8 safety); surface text is English only.
Readiness checklist
- Class in
tools/impl/, NAME snake_case, parameters lowerCamelCase, every parameter in the schema - description →
get_tool_guide('<name>');guides/<name>.mdauthored; getOutputSchema present - Shared resolvers +
ToolResult.error; model only in a tx boundary; persist (forceExport) if a write - Registered in
BuiltInToolRegistrar; new packages in MANIFEST Import-Package -
XxxToolTest(unit ratchet) +test_<tool>.py(e2e ratchet) - Golden regenerated; README count + group + table + detail
-
compile.shgreen → Opus review → redeploy → live validation → commit