Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core-web/apps/mcp-server/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This is a **Model Context Protocol (MCP) server** for dotCMS, built with [xmcp](

### Core Architecture

**Framework**: xmcp auto-discovers tools from `src/tools/`. Each tool exports `schema`, `metadata`, and a default handler function.
**Framework**: xmcp auto-discovers tools from `src/tools/`. Each tool exports `schema`, `metadata`, and a default handler function. `src/skills/` is served through the MCP Skills extension (`io.modelcontextprotocol/skills`): the files are embedded at build time and read back as `skill://` resources. The one skill today is `dot-ui-vtl-migration`, vendored from `dotCMS/agent-toolkit` (see `scripts/skill-upstream.json`). `scripts/check-skill-drift.mjs` fails the build when that copy drifts.

**Entry Point**: xmcp generates the entry point at build time (`dist/stdio.js`).

Expand Down
4 changes: 3 additions & 1 deletion core-web/apps/mcp-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Before setting up the MCP server, you need these environment variables to connec

Get up and running with the dotCMS MCP Server in minutes.

The server runs on both **Node.js** (≥20) and **Bun** — the correct sandbox implementation is selected automatically at runtime.
The server runs on both **Node.js** (≥22.12, the version xmcp 1.10.2 and later require) and **Bun** — the correct sandbox implementation is selected automatically at runtime.

### The short way

Expand Down Expand Up @@ -439,6 +439,8 @@ The built server works with both `node` and `bun` — the correct sandbox is sel
```
apps/mcp-server/ # MCP server (thin xmcp host)
├── src/
│ ├── skills/ # Agent skills served over the MCP Skills extension
│ │ └── dot-ui-vtl-migration/ # Vendored from dotCMS/agent-toolkit; see scripts/skill-upstream.json
│ ├── tools/ # One 3-line file per tool — xmcp loads every module here
│ │ ├── search.ts
│ │ ├── execute.ts
Expand Down
2 changes: 1 addition & 1 deletion core-web/apps/mcp-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"homepage": "https://github.com/dotCMS/core/tree/main/core-web/apps/mcp-server",
"engines": {
"node": ">=20.0.0"
"node": ">=22.12.0"
},
"dependencies": {},
"publishConfig": {
Expand Down
1 change: 1 addition & 0 deletions core-web/apps/mcp-server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"options": {
"commands": [
"node scripts/check-tools-dir.mjs",
"node scripts/check-skill-drift.mjs",
"xmcp build",
"cp package.json ../../dist/apps/mcp-server/",
"cp README.md ../../dist/apps/mcp-server/"
Expand Down
117 changes: 117 additions & 0 deletions core-web/apps/mcp-server/scripts/check-skill-drift.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* The VTL skill served by this app is a vendored copy of
* `dotCMS/agent-toolkit` at the commit in `skill-upstream.json`.
*
* That repository is the source of truth. This check downloads those files and
* fails when the copy here differs from them. The JSON lists the only edits
* this server is allowed to make (frontmatter the MCP Skills extension rejects,
* and two phrases that cite a dotCMS checkout). Each edit must match the
* upstream bytes exactly once. Anything else is drift.
*
* The build runs this before `xmcp build`, so a stale skill never ships.
*/
import { createHash } from 'node:crypto';
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

const APP_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
const PIN = JSON.parse(readFileSync(join(APP_ROOT, 'scripts/skill-upstream.json'), 'utf8'));

const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex');

/**
* @param {string} repository `owner/name`
* @param {string} commit
* @param {string} upstreamPath
* @returns {Promise<Buffer>}
*/
async function fetchUpstream(repository, commit, upstreamPath) {
const url = `https://raw.githubusercontent.com/${repository}/${commit}/${upstreamPath}`;
const response = await fetch(url, { signal: AbortSignal.timeout(30_000) });
if (!response.ok) {
throw new Error(`${url} returned HTTP ${response.status}`);
}
return Buffer.from(await response.arrayBuffer());
}

/**
* @param {Buffer} bytes
* @param {{ from: string, to: string, reason: string }[]} replacements
* @param {string} label
*/
function applyReplacements(bytes, replacements, label) {
let text = bytes.toString('utf8');
for (const replacement of replacements) {
const found = text.split(replacement.from).length - 1;
if (found !== 1) {
throw new Error(
`${label}: expected the allowed edit to match once, found ${found}.\n` +
` reason: ${replacement.reason}\n` +
` looking for: ${JSON.stringify(replacement.from).slice(0, 180)}`
);
}
text = text.replace(replacement.from, replacement.to);
}
return Buffer.from(text, 'utf8');
}

const failures = [];

for (const file of PIN.files) {
const localPath = join(APP_ROOT, file.served);
let upstream;
try {
upstream = await fetchUpstream(PIN.repository, PIN.commit, file.upstream);
} catch (error) {
failures.push(
`${file.upstream}: ${(error instanceof Error ? error : new Error(String(error))).message}`
);
continue;
}

let expected;
try {
expected = applyReplacements(upstream, file.replacements ?? [], file.upstream);
} catch (error) {
failures.push(error instanceof Error ? error.message : String(error));
continue;
}

let local;
try {
local = readFileSync(localPath);
} catch (error) {
failures.push(`${file.served}: ${error instanceof Error ? error.message : String(error)}`);
continue;
}

if (!local.equals(expected)) {
failures.push(
[
`${file.served} does not match ${PIN.repository}@${PIN.commit.slice(0, 12)}:${file.upstream}`,
` after the ${file.replacements?.length ?? 0} allowed edit(s).`,
` upstream+edits sha256 ${sha256(expected)} (${expected.byteLength} bytes)`,
` served sha256 ${sha256(local)} (${local.byteLength} bytes)`
].join('\n')
);
}
}

if (failures.length > 0) {
console.error(
[
'',
`Skill drift: served files must match ${PIN.repository}@${PIN.commit}`,
'except the edits listed in scripts/skill-upstream.json.',
'',
...failures.map((failure) => failure),
''
].join('\n')
);
process.exit(1);
}

console.log(
`skill drift: ${PIN.files.length} file(s) match ${PIN.repository}@${PIN.commit.slice(0, 12)}`
);
14 changes: 8 additions & 6 deletions core-web/apps/mcp-server/scripts/check-tools-dir.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
* Fails the build when `src/tools/` holds anything that is not a tool.
*
* xmcp loads EVERY module under the configured tools path (see `paths.tools` in
* xmcp.config.ts) and awaits them all at startup — its discovery glob is hard-coded to
* `<toolsPath>/**\/*.{ts,tsx}` and offers no exclude option, so a colocated test file is
* bundled into the published artifact and executed as a tool. `describe` does not exist at
* runtime, so the server dies with `ReferenceError: describe is not defined` before it reads
* any configuration, for every user. That is exactly what shipped as @dotcms/mcp-server@0.1.0
* (issue #37337).
* xmcp.config.ts) and awaits them all at startup. Confirmed against the 1.13 compiler
* (`packages/compiler/src/compiler/index.ts`): the discovery glob is still hard-coded to
* `<toolsPath>/**\/*.{ts,tsx}` and still has no exclude option. A file with no default
* export is skipped only after that module has been evaluated, so a colocated test file
* is bundled into the published artifact and executed as a tool. `describe` does not exist
* at runtime, so the server dies with `ReferenceError: describe is not defined` before it
* reads any configuration, for every user. That is exactly what shipped as
* @dotcms/mcp-server@0.1.0 (issue #37337).
*
* The rule this enforces: tests for tool code live next to the logic they cover — in
* `libs/sdk/ai/src/tools/` (`@dotcms/ai/tools`), where the tools are defined — never in
Expand Down
49 changes: 49 additions & 0 deletions core-web/apps/mcp-server/scripts/skill-upstream.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"repository": "dotCMS/agent-toolkit",
"commit": "895ba10e8d639276099e674eb59d7a7f25b0c4d8",
"files": [
{
"upstream": "skills/dot-ui-vtl-migration/SKILL.md",
"served": "src/skills/dot-ui-vtl-migration/SKILL.md",
"replacements": [
{
"from": "name: dotcms-custom-field-migration",
"to": "name: dot-ui-vtl-migration",
"reason": "xmcp and the Agent Skills spec require the frontmatter name to equal the directory name. Upstream calls the skill dotcms-custom-field-migration while the directory, and the URI this server must publish, is dot-ui-vtl-migration."
},
{
"from": " Also trigger when the user pastes a VTL snippet and asks \"what needs to change\" or \"can you update this\", asks for an inline, single-file or one-file migration (\"un solo archivo\"), wants to paste the result into the content type editor, or wants to collapse a _new/_old/router migration into one file or split an inline one. Also trigger when the user asks to migrate ALL custom fields, every legacy field, or \"the whole instance\": the skill finds, downloads, and safely republishes every legacy custom field on a live dotCMS instance through the dotCMS MCP server (see \"Migrate a whole instance\" below). If in doubt, use this skill.",
"to": " Also use it for a pasted snippet, an inline single-file migration (\"un solo archivo\"), or migrating every legacy field on an instance through the dotCMS MCP server.",
"reason": "xmcp rejects a description longer than 1024 characters (upstream is 1476). The served description keeps the opening sentences and a shorter form of the remaining triggers. The whole-instance procedure itself stays in the skill body."
}
]
},
{
"upstream": "skills/dot-ui-vtl-migration/reference/instance-migration.md",
"served": "src/skills/dot-ui-vtl-migration/reference/instance-migration.md",
"replacements": []
},
{
"upstream": "skills/dot-ui-vtl-migration/reference/migration-guide.md",
"served": "src/skills/dot-ui-vtl-migration/reference/migration-guide.md",
"replacements": [
{
"from": "core-web/apps/dotcms-ui/src/daisyui-theme.css",
"to": "the admin UI theme stylesheet (daisyui-theme.css)",
"reason": "The served skill must not cite a path inside the dotCMS checkout. The stylesheet name stays so the advice is still findable."
}
]
},
{
"upstream": "skills/dot-ui-vtl-migration/scripts/vtl_migration.py",
"served": "src/skills/dot-ui-vtl-migration/scripts/vtl_migration.py",
"replacements": [
{
"from": "copied from dotCMS/core's migrate_custom_fields.py",
"to": "copied from the original custom-field migration script",
"reason": "The comment cited the core repository script. The logic is unchanged."
}
]
}
]
}
Loading
Loading