@upassist/neos-mcp 2.0.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +33 -0
- package/dist/index.js +69 -3
- package/package.json +3 -2
- package/src/server.ts +2 -0
- package/src/tools/createContentNode.ts +2 -1
- package/src/tools/createDocumentNode.ts +2 -1
- package/src/tools/updateNodeProperty.ts +6 -1
- package/src/tools/uploadAsset.ts +74 -0
- package/test/linkPropertyValues.test.ts +86 -0
- package/test/support/env.ts +3 -0
- package/test/uploadAsset.test.ts +144 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.2.0](https://github.com/UpAssist/neos-mcp-client/compare/2.1.0...2.2.0) (2026-10-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* document link property values for the write tools ([#4](https://github.com/UpAssist/neos-mcp-client/issues/4)) ([c775e8f](https://github.com/UpAssist/neos-mcp-client/commit/c775e8f314c20b60923f8779ac3acf1e00bf7d48))
|
|
11
|
+
|
|
12
|
+
## [2.1.0](https://github.com/UpAssist/neos-mcp-client/compare/2.0.2...2.1.0) (2026-10-08)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add neos_upload_asset tool ([0870e67](https://github.com/UpAssist/neos-mcp-client/commit/0870e6756da461b051fa51c50a6dea41faddead6))
|
|
18
|
+
|
|
5
19
|
### [2.0.2](https://github.com/UpAssist/neos-mcp-client/compare/2.0.1...2.0.2) (2026-09-23)
|
|
6
20
|
|
|
7
21
|
|
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ This is the client-side component. It runs locally on your machine and translate
|
|
|
13
13
|
|
|
14
14
|
> **v2 auto-detects** the bridge API version. A single MCP server v2 works with both Neos 8 and Neos 9 bridges.
|
|
15
15
|
|
|
16
|
+
> **`neos_upload_asset`** (client 2.1+) needs a bridge with the `uploadAsset` endpoint: upassist/neos-mcp **2.1+** (Neos 9) or **1.1+** (Neos 8). Against an older bridge the other tools keep working and the upload call fails with a 404.
|
|
17
|
+
|
|
16
18
|
## Requirements
|
|
17
19
|
|
|
18
20
|
- Node.js 18+
|
|
@@ -142,12 +144,36 @@ Once connected, your AI assistant can use these tools:
|
|
|
142
144
|
| `neos_move_node` | Move or reorder a node |
|
|
143
145
|
| `neos_delete_node` | Remove a node |
|
|
144
146
|
|
|
147
|
+
Property values are passed to the bridge unchanged and resolved there against the NodeType's property type:
|
|
148
|
+
|
|
149
|
+
- Image/asset properties: the asset `identifier` (e.g. from `neos_list_assets` or `neos_upload_asset`).
|
|
150
|
+
- Link properties (`Neos\Neos\Domain\Link\Link`, edited with the LinkEditor): a URI string such as `node://<nodeAggregateId>`, `asset://<id>` or `https://…`, or an object `{ "href": "…", "title": "…", "target": "_blank" }`. An empty string clears the link. A `node://` target must exist in the workspace, otherwise the bridge rejects the write. Needs a Neos 9 bridge with Link property support (see the [bridge README](https://github.com/UpAssist/neos-mcp#property-resolution)).
|
|
151
|
+
|
|
145
152
|
### Media
|
|
146
153
|
|
|
147
154
|
| Tool | Description |
|
|
148
155
|
| --- | --- |
|
|
149
156
|
| `neos_list_assets` | Browse images and files from the Media Manager |
|
|
150
157
|
| `neos_list_asset_tags` | List available asset tags |
|
|
158
|
+
| `neos_upload_asset` | Upload a file (local path, URL or base64) to the Media Manager, incl. title, caption, tags and collections. Identical files are deduplicated. |
|
|
159
|
+
|
|
160
|
+
#### Uploading files
|
|
161
|
+
|
|
162
|
+
`neos_upload_asset` takes exactly one source:
|
|
163
|
+
|
|
164
|
+
| Parameter | Description |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| `file_path` | Absolute path of a local file, read by this MCP server |
|
|
167
|
+
| `url` | HTTP(S) URL, downloaded by this MCP server (the Neos bridge never fetches remote URLs) |
|
|
168
|
+
| `base64_content` | Raw base64 content (a `data:` URI prefix is allowed); requires `filename` |
|
|
169
|
+
|
|
170
|
+
Optional: `filename` (overrides the name taken from the path or URL), `title`, `caption`, `copyright_notice`, `tags`, `asset_collections` (missing tags and collections are created) and `allow_duplicate`.
|
|
171
|
+
|
|
172
|
+
- The result contains the asset `identifier`, which you can pass to `neos_update_node_property` (or the create tools) for image/asset properties.
|
|
173
|
+
- If a file with identical content already exists, that asset is returned with `duplicate: true` and the title, caption, tags and collections you passed are **not** applied to it. Set `allow_duplicate` to force a new asset.
|
|
174
|
+
- The file travels as base64 in one request, so it is about 33% larger on the wire. The size limit is set by the bridge's PHP (`post_max_size`) and web server configuration. Large files are better added through the Media Manager.
|
|
175
|
+
- Requires a bridge that has the `uploadAsset` endpoint (see the [bridge README](https://github.com/UpAssist/neos-mcp#post-neosmcpuploadasset)). It works with both the Neos 8 and the Neos 9 bridge.
|
|
176
|
+
- A rejected token comes back as a bridge error `401` or `403`.
|
|
151
177
|
|
|
152
178
|
### Review and publish
|
|
153
179
|
|
|
@@ -204,6 +230,9 @@ npm run dev
|
|
|
204
230
|
# Type check
|
|
205
231
|
npm run typecheck
|
|
206
232
|
|
|
233
|
+
# Run the unit tests
|
|
234
|
+
npm test
|
|
235
|
+
|
|
207
236
|
# Build for production
|
|
208
237
|
npm run build
|
|
209
238
|
|
|
@@ -211,6 +240,10 @@ npm run build
|
|
|
211
240
|
npm start
|
|
212
241
|
```
|
|
213
242
|
|
|
243
|
+
### Tests
|
|
244
|
+
|
|
245
|
+
`npm test` bundles `test/*.test.ts` with esbuild and runs them with Node's built-in test runner. The tests start the real MCP server in-process (via the SDK's in-memory transport) and replace `fetch`, so they check the exact HTTP requests sent to the bridge without needing a Neos instance. For a true end-to-end check, point `NEOS_MCP_URL` at a Neos instance with the bridge installed and call the tool through any MCP client.
|
|
246
|
+
|
|
214
247
|
### Adding a new tool
|
|
215
248
|
|
|
216
249
|
1. Create a file in `src/tools/` (e.g. `myNewTool.ts`)
|
package/dist/index.js
CHANGED
|
@@ -21201,7 +21201,7 @@ function registerCreateContentNode(server) {
|
|
|
21201
21201
|
"Node type name, e.g. UpAssist.Site:Content.Headline"
|
|
21202
21202
|
),
|
|
21203
21203
|
properties: external_exports.record(external_exports.unknown()).default({}).describe(
|
|
21204
|
-
"Property key-value pairs to set on the new node. Use neos_list_node_types to see available properties."
|
|
21204
|
+
"Property key-value pairs to set on the new node. Use neos_list_node_types to see available properties. Values are resolved like in neos_update_node_property (asset identifiers, link URIs or { href, \u2026 } objects)."
|
|
21205
21205
|
),
|
|
21206
21206
|
workspace: external_exports.string().default("mcp").describe("Draft workspace name")
|
|
21207
21207
|
},
|
|
@@ -21227,7 +21227,9 @@ function registerUpdateNodeProperty(server) {
|
|
|
21227
21227
|
"Node identifier \u2014 use nodeAggregateId (Neos 9) or contextPath/path (Neos 8)"
|
|
21228
21228
|
),
|
|
21229
21229
|
property: external_exports.string().describe("Property name to update"),
|
|
21230
|
-
value: external_exports.unknown().describe(
|
|
21230
|
+
value: external_exports.unknown().describe(
|
|
21231
|
+
'New property value (string, number, boolean, or object). Image/asset properties: the asset identifier. Link properties (type Neos\\Neos\\Domain\\Link\\Link): a URI string such as "node://<nodeAggregateId>", "asset://<id>" or "https://\u2026", or an object { href, title?, target?, rel?, download? }; an empty string clears the link. A node:// target must exist in the workspace (check with neos_list_pages), otherwise the write is rejected.'
|
|
21232
|
+
),
|
|
21231
21233
|
workspace: external_exports.string().default("mcp").describe("Workspace to write to")
|
|
21232
21234
|
},
|
|
21233
21235
|
async ({ node_id, property, value, workspace }) => {
|
|
@@ -21289,7 +21291,7 @@ function registerCreateDocumentNode(server) {
|
|
|
21289
21291
|
"Document node type name, e.g. UpAssist.Site:Document.Page"
|
|
21290
21292
|
),
|
|
21291
21293
|
properties: external_exports.record(external_exports.unknown()).default({}).describe(
|
|
21292
|
-
'Property key-value pairs, e.g. { title: "About us", uriPathSegment: "about-us" }'
|
|
21294
|
+
'Property key-value pairs, e.g. { title: "About us", uriPathSegment: "about-us" }. Values are resolved like in neos_update_node_property (asset identifiers, link URIs or { href, \u2026 } objects).'
|
|
21293
21295
|
),
|
|
21294
21296
|
workspace: external_exports.string().default("mcp").describe("Draft workspace name"),
|
|
21295
21297
|
node_name: external_exports.string().optional().describe(
|
|
@@ -21491,6 +21493,69 @@ function registerEntityCrudTools(server) {
|
|
|
21491
21493
|
);
|
|
21492
21494
|
}
|
|
21493
21495
|
|
|
21496
|
+
// src/tools/uploadAsset.ts
|
|
21497
|
+
var import_promises = require("node:fs/promises");
|
|
21498
|
+
var import_node_path = require("node:path");
|
|
21499
|
+
async function loadSource(filePath, url, base64Content, filename) {
|
|
21500
|
+
const sources = [filePath, url, base64Content].filter((s) => s !== void 0 && s !== "");
|
|
21501
|
+
if (sources.length !== 1) {
|
|
21502
|
+
throw new Error("Provide exactly one of file_path, url or base64_content.");
|
|
21503
|
+
}
|
|
21504
|
+
if (filePath) {
|
|
21505
|
+
const buffer = await (0, import_promises.readFile)(filePath);
|
|
21506
|
+
return { filename: filename || (0, import_node_path.basename)(filePath), content: buffer.toString("base64") };
|
|
21507
|
+
}
|
|
21508
|
+
if (url) {
|
|
21509
|
+
const response = await fetch(url);
|
|
21510
|
+
if (!response.ok) {
|
|
21511
|
+
throw new Error(`Download failed (${response.status}): ${url}`);
|
|
21512
|
+
}
|
|
21513
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
21514
|
+
const urlFilename = decodeURIComponent((0, import_node_path.basename)(new URL(url).pathname));
|
|
21515
|
+
const resolvedFilename = filename || urlFilename;
|
|
21516
|
+
if (!resolvedFilename) {
|
|
21517
|
+
throw new Error("Could not derive a filename from the URL, please pass filename.");
|
|
21518
|
+
}
|
|
21519
|
+
return { filename: resolvedFilename, content: buffer.toString("base64") };
|
|
21520
|
+
}
|
|
21521
|
+
if (!filename) {
|
|
21522
|
+
throw new Error("filename is required when using base64_content.");
|
|
21523
|
+
}
|
|
21524
|
+
return { filename, content: base64Content.replace(/^data:[^;]+;base64,/, "") };
|
|
21525
|
+
}
|
|
21526
|
+
function registerUploadAsset(server) {
|
|
21527
|
+
server.tool(
|
|
21528
|
+
"neos_upload_asset",
|
|
21529
|
+
"Upload a file (image, PDF, video, \u2026) into the Neos Media Manager. Provide exactly one source: a local file_path, a url to download, or base64_content. If a file with identical content already exists, the existing asset is returned (duplicate: true). The returned identifier can be used as value for image/asset properties via neos_update_node_property.",
|
|
21530
|
+
{
|
|
21531
|
+
file_path: external_exports.string().optional().describe("Absolute path to a local file to upload"),
|
|
21532
|
+
url: external_exports.string().optional().describe("HTTP(S) URL of a file to download and upload"),
|
|
21533
|
+
base64_content: external_exports.string().optional().describe("Base64 encoded file content (data URI prefix allowed); requires filename"),
|
|
21534
|
+
filename: external_exports.string().optional().describe("Target filename incl. extension. Defaults to the name from file_path or url."),
|
|
21535
|
+
title: external_exports.string().default("").describe("Asset title"),
|
|
21536
|
+
caption: external_exports.string().default("").describe("Asset caption"),
|
|
21537
|
+
copyright_notice: external_exports.string().default("").describe("Copyright notice"),
|
|
21538
|
+
tags: external_exports.array(external_exports.string()).default([]).describe("Tag labels to assign; missing tags are created"),
|
|
21539
|
+
asset_collections: external_exports.array(external_exports.string()).default([]).describe("Asset collection titles to add the asset to; missing collections are created"),
|
|
21540
|
+
allow_duplicate: external_exports.boolean().default(false).describe("Create a new asset even if identical content already exists")
|
|
21541
|
+
},
|
|
21542
|
+
async ({ file_path, url, base64_content, filename, title, caption, copyright_notice, tags, asset_collections, allow_duplicate }) => {
|
|
21543
|
+
const source = await loadSource(file_path, url, base64_content, filename);
|
|
21544
|
+
const data = await callBridge("uploadAsset", "POST", {
|
|
21545
|
+
filename: source.filename,
|
|
21546
|
+
content: source.content,
|
|
21547
|
+
title,
|
|
21548
|
+
caption,
|
|
21549
|
+
copyrightNotice: copyright_notice,
|
|
21550
|
+
tags,
|
|
21551
|
+
assetCollections: asset_collections,
|
|
21552
|
+
allowDuplicate: allow_duplicate
|
|
21553
|
+
});
|
|
21554
|
+
return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
|
|
21555
|
+
}
|
|
21556
|
+
);
|
|
21557
|
+
}
|
|
21558
|
+
|
|
21494
21559
|
// src/server.ts
|
|
21495
21560
|
function createServer() {
|
|
21496
21561
|
const server = new McpServer({
|
|
@@ -21514,6 +21579,7 @@ function createServer() {
|
|
|
21514
21579
|
registerRestart(server);
|
|
21515
21580
|
registerListAssets(server);
|
|
21516
21581
|
registerListAssetTags(server);
|
|
21582
|
+
registerUploadAsset(server);
|
|
21517
21583
|
registerEntityCrudTools(server);
|
|
21518
21584
|
return server;
|
|
21519
21585
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upassist/neos-mcp",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "MCP server for Neos CMS — connects AI assistants to any UpAssist.Neos.Mcp bridge",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"release:patch": "npx standard-version -t '' -r patch && npm publish --access public && git push --follow-tags",
|
|
17
17
|
"release:minor": "npx standard-version -t '' -r minor && npm publish --access public && git push --follow-tags",
|
|
18
18
|
"release:major": "npx standard-version -t '' -r major && npm publish --access public && git push --follow-tags",
|
|
19
|
-
"release": "yarn release:patch"
|
|
19
|
+
"release": "yarn release:patch",
|
|
20
|
+
"test": "esbuild test/*.test.ts --bundle --platform=node --format=esm --target=node20 --outdir=.test-build --out-extension:.js=.mjs --packages=external && node --test .test-build/"
|
|
20
21
|
},
|
|
21
22
|
"engines": {
|
|
22
23
|
"node": ">=18.0.0"
|
package/src/server.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { registerRestart } from './tools/restart.js';
|
|
|
17
17
|
import { registerListAssets } from './tools/listAssets.js';
|
|
18
18
|
import { registerListAssetTags } from './tools/listAssetTags.js';
|
|
19
19
|
import { registerEntityCrudTools } from './tools/entityCrud.js';
|
|
20
|
+
import { registerUploadAsset } from './tools/uploadAsset.js';
|
|
20
21
|
|
|
21
22
|
export function createServer(): McpServer {
|
|
22
23
|
const server = new McpServer({
|
|
@@ -41,6 +42,7 @@ export function createServer(): McpServer {
|
|
|
41
42
|
registerRestart(server);
|
|
42
43
|
registerListAssets(server);
|
|
43
44
|
registerListAssetTags(server);
|
|
45
|
+
registerUploadAsset(server);
|
|
44
46
|
registerEntityCrudTools(server);
|
|
45
47
|
|
|
46
48
|
return server;
|
|
@@ -14,7 +14,8 @@ export function registerCreateContentNode(server: McpServer): void {
|
|
|
14
14
|
'Node type name, e.g. UpAssist.Site:Content.Headline'
|
|
15
15
|
),
|
|
16
16
|
properties: z.record(z.unknown()).default({}).describe(
|
|
17
|
-
'Property key-value pairs to set on the new node. Use neos_list_node_types to see available properties.'
|
|
17
|
+
'Property key-value pairs to set on the new node. Use neos_list_node_types to see available properties. ' +
|
|
18
|
+
'Values are resolved like in neos_update_node_property (asset identifiers, link URIs or { href, … } objects).'
|
|
18
19
|
),
|
|
19
20
|
workspace: z.string().default('mcp').describe('Draft workspace name'),
|
|
20
21
|
},
|
|
@@ -16,7 +16,8 @@ export function registerCreateDocumentNode(server: McpServer): void {
|
|
|
16
16
|
'Document node type name, e.g. UpAssist.Site:Document.Page'
|
|
17
17
|
),
|
|
18
18
|
properties: z.record(z.unknown()).default({}).describe(
|
|
19
|
-
'Property key-value pairs, e.g. { title: "About us", uriPathSegment: "about-us" }'
|
|
19
|
+
'Property key-value pairs, e.g. { title: "About us", uriPathSegment: "about-us" }. ' +
|
|
20
|
+
'Values are resolved like in neos_update_node_property (asset identifiers, link URIs or { href, … } objects).'
|
|
20
21
|
),
|
|
21
22
|
workspace: z.string().default('mcp').describe('Draft workspace name'),
|
|
22
23
|
node_name: z.string().optional().describe(
|
|
@@ -11,7 +11,12 @@ export function registerUpdateNodeProperty(server: McpServer): void {
|
|
|
11
11
|
'Node identifier — use nodeAggregateId (Neos 9) or contextPath/path (Neos 8)'
|
|
12
12
|
),
|
|
13
13
|
property: z.string().describe('Property name to update'),
|
|
14
|
-
value: z.unknown().describe(
|
|
14
|
+
value: z.unknown().describe(
|
|
15
|
+
'New property value (string, number, boolean, or object). Image/asset properties: the asset identifier. ' +
|
|
16
|
+
'Link properties (type Neos\\Neos\\Domain\\Link\\Link): a URI string such as "node://<nodeAggregateId>", "asset://<id>" or "https://…", ' +
|
|
17
|
+
'or an object { href, title?, target?, rel?, download? }; an empty string clears the link. ' +
|
|
18
|
+
'A node:// target must exist in the workspace (check with neos_list_pages), otherwise the write is rejected.'
|
|
19
|
+
),
|
|
15
20
|
workspace: z.string().default('mcp').describe('Workspace to write to'),
|
|
16
21
|
},
|
|
17
22
|
async ({ node_id, property, value, workspace }) => {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { callBridge } from '../bridge.js';
|
|
6
|
+
|
|
7
|
+
async function loadSource(
|
|
8
|
+
filePath?: string,
|
|
9
|
+
url?: string,
|
|
10
|
+
base64Content?: string,
|
|
11
|
+
filename?: string
|
|
12
|
+
): Promise<{ filename: string; content: string }> {
|
|
13
|
+
const sources = [filePath, url, base64Content].filter((s) => s !== undefined && s !== '');
|
|
14
|
+
if (sources.length !== 1) {
|
|
15
|
+
throw new Error('Provide exactly one of file_path, url or base64_content.');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (filePath) {
|
|
19
|
+
const buffer = await readFile(filePath);
|
|
20
|
+
return { filename: filename || basename(filePath), content: buffer.toString('base64') };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (url) {
|
|
24
|
+
const response = await fetch(url);
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw new Error(`Download failed (${response.status}): ${url}`);
|
|
27
|
+
}
|
|
28
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
29
|
+
const urlFilename = decodeURIComponent(basename(new URL(url).pathname));
|
|
30
|
+
const resolvedFilename = filename || urlFilename;
|
|
31
|
+
if (!resolvedFilename) {
|
|
32
|
+
throw new Error('Could not derive a filename from the URL, please pass filename.');
|
|
33
|
+
}
|
|
34
|
+
return { filename: resolvedFilename, content: buffer.toString('base64') };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!filename) {
|
|
38
|
+
throw new Error('filename is required when using base64_content.');
|
|
39
|
+
}
|
|
40
|
+
return { filename, content: (base64Content as string).replace(/^data:[^;]+;base64,/, '') };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function registerUploadAsset(server: McpServer): void {
|
|
44
|
+
server.tool(
|
|
45
|
+
'neos_upload_asset',
|
|
46
|
+
'Upload a file (image, PDF, video, …) into the Neos Media Manager. Provide exactly one source: a local file_path, a url to download, or base64_content. If a file with identical content already exists, the existing asset is returned (duplicate: true). The returned identifier can be used as value for image/asset properties via neos_update_node_property.',
|
|
47
|
+
{
|
|
48
|
+
file_path: z.string().optional().describe('Absolute path to a local file to upload'),
|
|
49
|
+
url: z.string().optional().describe('HTTP(S) URL of a file to download and upload'),
|
|
50
|
+
base64_content: z.string().optional().describe('Base64 encoded file content (data URI prefix allowed); requires filename'),
|
|
51
|
+
filename: z.string().optional().describe('Target filename incl. extension. Defaults to the name from file_path or url.'),
|
|
52
|
+
title: z.string().default('').describe('Asset title'),
|
|
53
|
+
caption: z.string().default('').describe('Asset caption'),
|
|
54
|
+
copyright_notice: z.string().default('').describe('Copyright notice'),
|
|
55
|
+
tags: z.array(z.string()).default([]).describe('Tag labels to assign; missing tags are created'),
|
|
56
|
+
asset_collections: z.array(z.string()).default([]).describe('Asset collection titles to add the asset to; missing collections are created'),
|
|
57
|
+
allow_duplicate: z.boolean().default(false).describe('Create a new asset even if identical content already exists'),
|
|
58
|
+
},
|
|
59
|
+
async ({ file_path, url, base64_content, filename, title, caption, copyright_notice, tags, asset_collections, allow_duplicate }) => {
|
|
60
|
+
const source = await loadSource(file_path, url, base64_content, filename);
|
|
61
|
+
const data = await callBridge('uploadAsset', 'POST', {
|
|
62
|
+
filename: source.filename,
|
|
63
|
+
content: source.content,
|
|
64
|
+
title,
|
|
65
|
+
caption,
|
|
66
|
+
copyrightNotice: copyright_notice,
|
|
67
|
+
tags,
|
|
68
|
+
assetCollections: asset_collections,
|
|
69
|
+
allowDuplicate: allow_duplicate,
|
|
70
|
+
});
|
|
71
|
+
return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { test, before, after, beforeEach } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import './support/env.js';
|
|
5
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
6
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
7
|
+
import { createServer } from '../src/server.js';
|
|
8
|
+
import { setApiVersion } from '../src/bridge.js';
|
|
9
|
+
|
|
10
|
+
type Call = { url: string; body: any };
|
|
11
|
+
|
|
12
|
+
const realFetch = globalThis.fetch;
|
|
13
|
+
let calls: Call[] = [];
|
|
14
|
+
let client: Client;
|
|
15
|
+
|
|
16
|
+
/** Records bridge calls; the bridge resolves link values, so the client must pass them through untouched. */
|
|
17
|
+
function mockFetch() {
|
|
18
|
+
globalThis.fetch = (async (input: any, init: any = {}) => {
|
|
19
|
+
calls.push({ url: String(input), body: init.body ? JSON.parse(init.body) : undefined });
|
|
20
|
+
return new Response(JSON.stringify({ success: true }), {
|
|
21
|
+
status: 200,
|
|
22
|
+
headers: { 'content-type': 'application/json' },
|
|
23
|
+
});
|
|
24
|
+
}) as typeof fetch;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
before(async () => {
|
|
28
|
+
setApiVersion(2);
|
|
29
|
+
const server = createServer();
|
|
30
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
31
|
+
client = new Client({ name: 'test', version: '0.0.0' });
|
|
32
|
+
await Promise.all([server.connect(serverTransport), client.connect(clientTransport)]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
after(() => {
|
|
36
|
+
globalThis.fetch = realFetch;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
calls = [];
|
|
41
|
+
mockFetch();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('neos_update_node_property: a link URI string is sent as is', async () => {
|
|
45
|
+
const result = await client.callTool({
|
|
46
|
+
name: 'neos_update_node_property',
|
|
47
|
+
arguments: { node_id: 'n1', property: 'linkObject', value: 'node://target-id' },
|
|
48
|
+
});
|
|
49
|
+
assert.notEqual(result.isError, true);
|
|
50
|
+
|
|
51
|
+
assert.equal(calls.length, 1);
|
|
52
|
+
assert.equal(calls[0].url, 'http://bridge.test/neos/mcp/updateNodeProperty');
|
|
53
|
+
assert.equal(calls[0].body.nodeAggregateId, 'n1');
|
|
54
|
+
assert.equal(calls[0].body.value, 'node://target-id');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('neos_update_node_property: a link object is sent as a JSON object, not stringified', async () => {
|
|
58
|
+
const link = { href: 'node://target-id', title: 'Zur Seite', target: '_blank' };
|
|
59
|
+
const result = await client.callTool({
|
|
60
|
+
name: 'neos_update_node_property',
|
|
61
|
+
arguments: { node_id: 'n1', property: 'linkObject', value: link },
|
|
62
|
+
});
|
|
63
|
+
assert.notEqual(result.isError, true);
|
|
64
|
+
|
|
65
|
+
assert.deepEqual(calls[0].body.value, link);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('neos_create_content_node: link objects inside properties are sent unchanged', async () => {
|
|
69
|
+
const properties = { title: '<h2>Teaser</h2>', linkObject: { href: 'https://example.org', target: '_blank' } };
|
|
70
|
+
const result = await client.callTool({
|
|
71
|
+
name: 'neos_create_content_node',
|
|
72
|
+
arguments: { parent_id: 'p1', node_type: 'Vendor.Site:Content.Teaser', properties },
|
|
73
|
+
});
|
|
74
|
+
assert.notEqual(result.isError, true);
|
|
75
|
+
|
|
76
|
+
assert.equal(calls[0].url, 'http://bridge.test/neos/mcp/createContentNode');
|
|
77
|
+
assert.deepEqual(calls[0].body.properties, properties);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('the link formats are described on the value parameter', async () => {
|
|
81
|
+
const { tools } = await client.listTools();
|
|
82
|
+
const tool = tools.find((t) => t.name === 'neos_update_node_property');
|
|
83
|
+
const description = (tool?.inputSchema.properties as any)?.value?.description ?? '';
|
|
84
|
+
assert.match(description, /node:\/\//);
|
|
85
|
+
assert.match(description, /href/);
|
|
86
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { test, before, after, beforeEach } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
import './support/env.js';
|
|
8
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
9
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
10
|
+
import { createServer } from '../src/server.js';
|
|
11
|
+
|
|
12
|
+
type Call = { url: string; method: string; headers: Record<string, string>; body: any };
|
|
13
|
+
|
|
14
|
+
const realFetch = globalThis.fetch;
|
|
15
|
+
let calls: Call[] = [];
|
|
16
|
+
let tmp: string;
|
|
17
|
+
let client: Client;
|
|
18
|
+
|
|
19
|
+
const PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==', 'base64');
|
|
20
|
+
|
|
21
|
+
/** Replaces fetch: remote downloads get `remote`, bridge calls are recorded and answered with a canned asset. */
|
|
22
|
+
function mockFetch(remote: { status?: number; body?: Buffer } = {}) {
|
|
23
|
+
globalThis.fetch = (async (input: any, init: any = {}) => {
|
|
24
|
+
const url = String(input);
|
|
25
|
+
if (url.startsWith('http://bridge.test/')) {
|
|
26
|
+
calls.push({
|
|
27
|
+
url,
|
|
28
|
+
method: init.method ?? 'GET',
|
|
29
|
+
headers: init.headers ?? {},
|
|
30
|
+
body: init.body ? JSON.parse(init.body) : undefined,
|
|
31
|
+
});
|
|
32
|
+
return new Response(JSON.stringify({ success: true, duplicate: false, asset: { identifier: 'abc', filename: 'x' } }), {
|
|
33
|
+
status: 200,
|
|
34
|
+
headers: { 'content-type': 'application/json' },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return new Response(remote.body ?? Buffer.alloc(0), { status: remote.status ?? 200 });
|
|
38
|
+
}) as typeof fetch;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function callUpload(args: Record<string, unknown>) {
|
|
42
|
+
return client.callTool({ name: 'neos_upload_asset', arguments: args });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
before(async () => {
|
|
46
|
+
tmp = mkdtempSync(join(tmpdir(), 'neos-mcp-upload-'));
|
|
47
|
+
writeFileSync(join(tmp, 'photo.png'), PNG);
|
|
48
|
+
const server = createServer();
|
|
49
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
50
|
+
client = new Client({ name: 'test', version: '0.0.0' });
|
|
51
|
+
await Promise.all([server.connect(serverTransport), client.connect(clientTransport)]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
after(() => {
|
|
55
|
+
globalThis.fetch = realFetch;
|
|
56
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
calls = [];
|
|
61
|
+
mockFetch();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('the tool is registered', async () => {
|
|
65
|
+
const { tools } = await client.listTools();
|
|
66
|
+
assert.ok(tools.some((t) => t.name === 'neos_upload_asset'));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('file_path: reads the file, defaults the filename, base64-encodes it and posts to uploadAsset', async () => {
|
|
70
|
+
const result = await callUpload({ file_path: join(tmp, 'photo.png'), title: 'T', tags: ['a'], asset_collections: ['C'] });
|
|
71
|
+
assert.notEqual(result.isError, true);
|
|
72
|
+
|
|
73
|
+
assert.equal(calls.length, 1);
|
|
74
|
+
const [call] = calls;
|
|
75
|
+
assert.equal(call.url, 'http://bridge.test/neos/mcp/uploadAsset');
|
|
76
|
+
assert.equal(call.method, 'POST');
|
|
77
|
+
assert.equal(call.body.filename, 'photo.png');
|
|
78
|
+
assert.equal(call.body.content, PNG.toString('base64'));
|
|
79
|
+
assert.equal(call.body.title, 'T');
|
|
80
|
+
assert.deepEqual(call.body.tags, ['a']);
|
|
81
|
+
assert.deepEqual(call.body.assetCollections, ['C']);
|
|
82
|
+
assert.equal(call.body.allowDuplicate, false);
|
|
83
|
+
assert.equal(call.headers['Authorization'], 'Bearer unit-test-token');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('file_path: an explicit filename wins over the path', async () => {
|
|
87
|
+
await callUpload({ file_path: join(tmp, 'photo.png'), filename: 'renamed.png' });
|
|
88
|
+
assert.equal(calls[0].body.filename, 'renamed.png');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('url: downloads client-side and uploads the bytes, filename derived from the URL', async () => {
|
|
92
|
+
mockFetch({ body: PNG });
|
|
93
|
+
await callUpload({ url: 'https://example.com/some%20dir/Logo%20Final.png?x=1' });
|
|
94
|
+
assert.equal(calls[0].body.filename, 'Logo Final.png');
|
|
95
|
+
assert.equal(calls[0].body.content, PNG.toString('base64'));
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('url: a failed download is reported as a tool error and nothing reaches the bridge', async () => {
|
|
99
|
+
mockFetch({ status: 404 });
|
|
100
|
+
const result = await callUpload({ url: 'https://example.com/missing.png' });
|
|
101
|
+
assert.equal(result.isError, true);
|
|
102
|
+
assert.match(JSON.stringify(result.content), /Download failed \(404\)/);
|
|
103
|
+
assert.equal(calls.length, 0);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('base64_content: strips a data: URI prefix and requires a filename', async () => {
|
|
107
|
+
await callUpload({ base64_content: `data:image/png;base64,${PNG.toString('base64')}`, filename: 'inline.png' });
|
|
108
|
+
assert.equal(calls[0].body.content, PNG.toString('base64'));
|
|
109
|
+
assert.equal(calls[0].body.filename, 'inline.png');
|
|
110
|
+
|
|
111
|
+
calls = [];
|
|
112
|
+
const result = await callUpload({ base64_content: PNG.toString('base64') });
|
|
113
|
+
assert.equal(result.isError, true);
|
|
114
|
+
assert.match(JSON.stringify(result.content), /filename is required/);
|
|
115
|
+
assert.equal(calls.length, 0);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('exactly one source must be given', async () => {
|
|
119
|
+
for (const args of [{}, { file_path: join(tmp, 'photo.png'), url: 'https://example.com/a.png' }]) {
|
|
120
|
+
const result = await callUpload(args);
|
|
121
|
+
assert.equal(result.isError, true);
|
|
122
|
+
assert.match(JSON.stringify(result.content), /exactly one of file_path, url or base64_content/);
|
|
123
|
+
}
|
|
124
|
+
assert.equal(calls.length, 0);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('a missing local file is a tool error', async () => {
|
|
128
|
+
const result = await callUpload({ file_path: join(tmp, 'does-not-exist.png') });
|
|
129
|
+
assert.equal(result.isError, true);
|
|
130
|
+
assert.equal(calls.length, 0);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('allow_duplicate and copyright_notice are passed to the bridge under the bridge parameter names', async () => {
|
|
134
|
+
await callUpload({ file_path: join(tmp, 'photo.png'), allow_duplicate: true, copyright_notice: '(c) me', caption: 'cap' });
|
|
135
|
+
assert.equal(calls[0].body.allowDuplicate, true);
|
|
136
|
+
assert.equal(calls[0].body.copyrightNotice, '(c) me');
|
|
137
|
+
assert.equal(calls[0].body.caption, 'cap');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('the bridge response is returned to the caller', async () => {
|
|
141
|
+
const result = await callUpload({ file_path: join(tmp, 'photo.png') });
|
|
142
|
+
const text = (result.content as Array<{ text: string }>)[0].text;
|
|
143
|
+
assert.equal(JSON.parse(text).asset.identifier, 'abc');
|
|
144
|
+
});
|