@mainsoft/agent-cms 0.6.1 → 0.7.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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0
4
+
5
+ - **Anonymous MCP read:** `createCmsHandler({ mcp: { anonymous: "read" } })` lets agents use `/mcp` without a key. They get the read tools only (`ANONYMOUS_READ_TOOLS`) and see published documents of collections anyone may read. Off by default.
6
+ - Releases are published with npm trusted publishing (OIDC) and provenance only; no npm token is stored in the repository.
7
+
3
8
  ## 0.6.1
4
9
 
5
10
  - **Renamed to `@mainsoft/agent-cms`** and published to npmjs.com (with provenance) instead of GitHub Packages: `npm i @mainsoft/agent-cms` needs no `.npmrc` or token. Import paths change scope only (`@mainsoft-2024/agent-cms/http` → `@mainsoft/agent-cms/http`). `@mainsoft-2024/agent-cms` on GitHub Packages stays at 0.6.0. See "New name on npmjs" in [UPGRADE-0.6.md](./UPGRADE-0.6.md).
package/README.md CHANGED
@@ -281,6 +281,18 @@ Register `https://app.example.com/api/cms/mcp` with the header
281
281
  Published documents are also resources (`cms://<collection>/<slug>`), and
282
282
  two prompts (`answer_from_cms`, `edit_document`) show the safe way to work.
283
283
 
284
+ For public docs that any agent may read without a key, turn on anonymous read:
285
+
286
+ ```ts
287
+ createCmsHandler({ cms, resolveUser, mcp: { anonymous: "read" } });
288
+ ```
289
+
290
+ A request without a key then gets the read tools only (`list_collections`,
291
+ `search_documents`, `read_for_answer`, `list_documents`, `get_document`) and
292
+ sees published documents of collections anyone may read. Write tools are not
293
+ listed and calling one fails with `unknown_tool`. Requests with a key work as
294
+ before. The default stays off (401 without a key).
295
+
284
296
  ### CLI
285
297
 
286
298
  ```
package/dist/bin.js CHANGED
@@ -1062,7 +1062,7 @@ function unifiedDiff(a, b, o = {}) {
1062
1062
  }
1063
1063
 
1064
1064
  // src/version.ts
1065
- var VERSION = "0.6.1";
1065
+ var VERSION = "0.7.0";
1066
1066
 
1067
1067
  // src/registry.ts
1068
1068
  var sha = (s) => createHash("sha256").update(s).digest("hex");
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  VERSION
3
- } from "./chunk-QIUXAUQ6.js";
3
+ } from "./chunk-Y63XQS2J.js";
4
4
  import {
5
5
  CMS_TOOL_NAMES,
6
6
  toolsFor
@@ -25,6 +25,7 @@ import {
25
25
  ReadResourceRequestSchema
26
26
  } from "@modelcontextprotocol/sdk/types.js";
27
27
  import { toJSONSchema as toJSONSchemaV4 } from "zod/v4";
28
+ var ANONYMOUS_READ_TOOLS = ["list_collections", "search_documents", "read_for_answer", "list_documents", "get_document"];
28
29
  function toJsonSchema(schema) {
29
30
  const v4 = schema._zod;
30
31
  if (v4) {
@@ -115,7 +116,7 @@ var textResult = (value) => {
115
116
  function createMcpServer(cms, actor) {
116
117
  const core = coreOf(cms);
117
118
  const server = new Server({ name: "agent-cms", version: VERSION }, { capabilities: { tools: {}, resources: {}, prompts: {} }, instructions: MCP_INSTRUCTIONS });
118
- const visible = () => toolsFor(core, actor);
119
+ const visible = () => toolsFor(core, actor, actor.kind === "anonymous" ? ANONYMOUS_READ_TOOLS : void 0);
119
120
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
120
121
  tools: visible().map((t) => ({ name: t.name, description: t.description, inputSchema: toJsonSchema(t.input) }))
121
122
  }));
@@ -209,8 +210,8 @@ Question: ${a.question ?? ""}`
209
210
  }
210
211
  var MAX_BODY_BYTES = 512 * 1024;
211
212
  var rpcError = (status, code, message, extra = {}) => new Response(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code, message } }), { status, headers: { "content-type": "application/json", ...extra } });
212
- async function handleMcp(cms, actor, req) {
213
- if (actor.kind === "anonymous") return rpcError(401, -32001, "API key required", { "www-authenticate": 'Bearer realm="agent-cms"' });
213
+ async function handleMcp(cms, actor, req, opts = {}) {
214
+ if (actor.kind === "anonymous" && opts.anonymous !== "read") return rpcError(401, -32001, "API key required", { "www-authenticate": 'Bearer realm="agent-cms"' });
214
215
  if (req.method.toUpperCase() !== "POST") return rpcError(405, -32e3, "Method not allowed (stateless server: POST only)", { allow: "POST" });
215
216
  const text = await req.text();
216
217
  if (text.length > MAX_BODY_BYTES) return rpcError(413, -32600, "Request too large");
@@ -241,6 +242,7 @@ async function handleMcp(cms, actor, req) {
241
242
  var MCP_TOOL_NAMES = CMS_TOOL_NAMES;
242
243
 
243
244
  export {
245
+ ANONYMOUS_READ_TOOLS,
244
246
  toJsonSchema,
245
247
  MCP_INSTRUCTIONS,
246
248
  createMcpServer,
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "0.6.1";
2
+ var VERSION = "0.7.0";
3
3
 
4
4
  export {
5
5
  VERSION
package/dist/cli.cjs CHANGED
@@ -1102,7 +1102,7 @@ function unifiedDiff(a, b, o = {}) {
1102
1102
  }
1103
1103
 
1104
1104
  // src/version.ts
1105
- var VERSION = "0.6.1";
1105
+ var VERSION = "0.7.0";
1106
1106
 
1107
1107
  // src/registry.ts
1108
1108
  var sha = (s) => (0, import_node_crypto.createHash)("sha256").update(s).digest("hex");
package/dist/cli.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-IW3D4I7Q.js";
17
17
  import {
18
18
  VERSION
19
- } from "./chunk-QIUXAUQ6.js";
19
+ } from "./chunk-Y63XQS2J.js";
20
20
  import {
21
21
  CmsRemoteError,
22
22
  createCmsClient,
package/dist/http.cjs CHANGED
@@ -591,9 +591,10 @@ function toolsFor(cms, actor, only) {
591
591
  }
592
592
 
593
593
  // src/version.ts
594
- var VERSION = "0.6.1";
594
+ var VERSION = "0.7.0";
595
595
 
596
596
  // src/mcp.ts
597
+ var ANONYMOUS_READ_TOOLS = ["list_collections", "search_documents", "read_for_answer", "list_documents", "get_document"];
597
598
  function toJsonSchema(schema) {
598
599
  const v4 = schema._zod;
599
600
  if (v4) {
@@ -684,7 +685,7 @@ var textResult = (value) => {
684
685
  function createMcpServer(cms, actor) {
685
686
  const core = coreOf(cms);
686
687
  const server = new import_server.Server({ name: "agent-cms", version: VERSION }, { capabilities: { tools: {}, resources: {}, prompts: {} }, instructions: MCP_INSTRUCTIONS });
687
- const visible = () => toolsFor(core, actor);
688
+ const visible = () => toolsFor(core, actor, actor.kind === "anonymous" ? ANONYMOUS_READ_TOOLS : void 0);
688
689
  server.setRequestHandler(import_types3.ListToolsRequestSchema, async () => ({
689
690
  tools: visible().map((t) => ({ name: t.name, description: t.description, inputSchema: toJsonSchema(t.input) }))
690
691
  }));
@@ -778,8 +779,8 @@ Question: ${a.question ?? ""}`
778
779
  }
779
780
  var MAX_BODY_BYTES = 512 * 1024;
780
781
  var rpcError = (status, code, message, extra = {}) => new Response(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code, message } }), { status, headers: { "content-type": "application/json", ...extra } });
781
- async function handleMcp(cms, actor, req) {
782
- if (actor.kind === "anonymous") return rpcError(401, -32001, "API key required", { "www-authenticate": 'Bearer realm="agent-cms"' });
782
+ async function handleMcp(cms, actor, req, opts = {}) {
783
+ if (actor.kind === "anonymous" && opts.anonymous !== "read") return rpcError(401, -32001, "API key required", { "www-authenticate": 'Bearer realm="agent-cms"' });
783
784
  if (req.method.toUpperCase() !== "POST") return rpcError(405, -32e3, "Method not allowed (stateless server: POST only)", { allow: "POST" });
784
785
  const text = await req.text();
785
786
  if (text.length > MAX_BODY_BYTES) return rpcError(413, -32600, "Request too large");
@@ -914,7 +915,7 @@ function createCmsHandler(opts) {
914
915
  if (opts.requireIfMatch && v === void 0) throw new CmsError("precondition_required", {}, { messages: core.messages });
915
916
  return v;
916
917
  };
917
- if (seg[0] === "mcp" && seg.length === 1) return handleMcp(core, actor, req);
918
+ if (seg[0] === "mcp" && seg.length === 1) return handleMcp(core, actor, req, opts.mcp);
918
919
  if (seg[0] === "_me" && m === "GET") {
919
920
  return json({
920
921
  actor: actor.kind === "anonymous" ? { kind: "anonymous" } : { kind: actor.kind, label: actor.label, id: "id" in actor ? actor.id : null },
package/dist/http.d.cts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { C as CmsLike } from './cms-D6D89-qZ.cjs';
2
+ import { McpOptions } from './mcp.cjs';
2
3
  import { Actor } from './types.cjs';
3
4
  import 'zod';
4
5
  import './diff.cjs';
5
6
  import './errors.cjs';
6
7
  import './repo-CeDxUxO6.cjs';
8
+ import '@modelcontextprotocol/sdk/server/index.js';
7
9
 
8
10
  /**
9
11
  * REST API + MCP endpoint over one catch-all route. Mount as
@@ -56,6 +58,12 @@ interface CmsHandlerOptions {
56
58
  basePath?: string;
57
59
  /** Refuse PATCH and DELETE of a document without If-Match / expectedVersion (428). Default false. */
58
60
  requireIfMatch?: boolean;
61
+ /**
62
+ * MCP options. `anonymous: "read"` lets requests without a key use the MCP
63
+ * endpoint with read tools only (published documents of collections anyone
64
+ * can read). Default: a key is required (401).
65
+ */
66
+ mcp?: McpOptions;
59
67
  }
60
68
  declare function json(data: unknown, status?: number, headers?: Record<string, string>): Response;
61
69
  declare function errorResponse(err: unknown, cms?: CmsLike): Response;
package/dist/http.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { C as CmsLike } from './cms-BPp01z-8.js';
2
+ import { McpOptions } from './mcp.js';
2
3
  import { Actor } from './types.js';
3
4
  import 'zod';
4
5
  import './diff.js';
5
6
  import './errors.js';
6
7
  import './repo-BWI2Pkrv.js';
8
+ import '@modelcontextprotocol/sdk/server/index.js';
7
9
 
8
10
  /**
9
11
  * REST API + MCP endpoint over one catch-all route. Mount as
@@ -56,6 +58,12 @@ interface CmsHandlerOptions {
56
58
  basePath?: string;
57
59
  /** Refuse PATCH and DELETE of a document without If-Match / expectedVersion (428). Default false. */
58
60
  requireIfMatch?: boolean;
61
+ /**
62
+ * MCP options. `anonymous: "read"` lets requests without a key use the MCP
63
+ * endpoint with read tools only (published documents of collections anyone
64
+ * can read). Default: a key is required (401).
65
+ */
66
+ mcp?: McpOptions;
59
67
  }
60
68
  declare function json(data: unknown, status?: number, headers?: Record<string, string>): Response;
61
69
  declare function errorResponse(err: unknown, cms?: CmsLike): Response;
package/dist/http.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  handleMcp,
3
3
  toJsonSchema
4
- } from "./chunk-BTO42652.js";
5
- import "./chunk-QIUXAUQ6.js";
4
+ } from "./chunk-EXV6JNLY.js";
5
+ import "./chunk-Y63XQS2J.js";
6
6
  import "./chunk-QQV6VLYJ.js";
7
7
  import {
8
8
  BULK_ACTIONS,
@@ -132,7 +132,7 @@ function createCmsHandler(opts) {
132
132
  if (opts.requireIfMatch && v === void 0) throw new CmsError("precondition_required", {}, { messages: core.messages });
133
133
  return v;
134
134
  };
135
- if (seg[0] === "mcp" && seg.length === 1) return handleMcp(core, actor, req);
135
+ if (seg[0] === "mcp" && seg.length === 1) return handleMcp(core, actor, req, opts.mcp);
136
136
  if (seg[0] === "_me" && m === "GET") {
137
137
  return json({
138
138
  actor: actor.kind === "anonymous" ? { kind: "anonymous" } : { kind: actor.kind, label: actor.label, id: "id" in actor ? actor.id : null },
package/dist/index.cjs CHANGED
@@ -3007,7 +3007,7 @@ function docFromMarkdown(text2, fallbackSlug) {
3007
3007
  }
3008
3008
 
3009
3009
  // src/version.ts
3010
- var VERSION = "0.6.1";
3010
+ var VERSION = "0.7.0";
3011
3011
  // Annotate the CommonJS export names for ESM import in node:
3012
3012
  0 && (module.exports = {
3013
3013
  AUDIT_ACTIONS,
package/dist/index.d.cts CHANGED
@@ -14,6 +14,6 @@ import 'drizzle-orm/pg-core';
14
14
  import './markdown.cjs';
15
15
 
16
16
  /** Package version (kept in step with package.json by `src/parts.test.ts`). */
17
- declare const VERSION = "0.6.1";
17
+ declare const VERSION = "0.7.0";
18
18
 
19
19
  export { VERSION };
package/dist/index.d.ts CHANGED
@@ -14,6 +14,6 @@ import 'drizzle-orm/pg-core';
14
14
  import './markdown.js';
15
15
 
16
16
  /** Package version (kept in step with package.json by `src/parts.test.ts`). */
17
- declare const VERSION = "0.6.1";
17
+ declare const VERSION = "0.7.0";
18
18
 
19
19
  export { VERSION };
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  } from "./chunk-IW3D4I7Q.js";
22
22
  import {
23
23
  VERSION
24
- } from "./chunk-QIUXAUQ6.js";
24
+ } from "./chunk-Y63XQS2J.js";
25
25
  import {
26
26
  CmsRemoteError,
27
27
  createCmsClient,
package/dist/mcp.cjs CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/mcp.ts
21
21
  var mcp_exports = {};
22
22
  __export(mcp_exports, {
23
+ ANONYMOUS_READ_TOOLS: () => ANONYMOUS_READ_TOOLS,
23
24
  MCP_INSTRUCTIONS: () => MCP_INSTRUCTIONS,
24
25
  MCP_TOOL_NAMES: () => MCP_TOOL_NAMES,
25
26
  createMcpServer: () => createMcpServer,
@@ -422,9 +423,10 @@ function toolsFor(cms, actor, only) {
422
423
  }
423
424
 
424
425
  // src/version.ts
425
- var VERSION = "0.6.1";
426
+ var VERSION = "0.7.0";
426
427
 
427
428
  // src/mcp.ts
429
+ var ANONYMOUS_READ_TOOLS = ["list_collections", "search_documents", "read_for_answer", "list_documents", "get_document"];
428
430
  function toJsonSchema(schema) {
429
431
  const v4 = schema._zod;
430
432
  if (v4) {
@@ -515,7 +517,7 @@ var textResult = (value) => {
515
517
  function createMcpServer(cms, actor) {
516
518
  const core = coreOf(cms);
517
519
  const server = new import_server.Server({ name: "agent-cms", version: VERSION }, { capabilities: { tools: {}, resources: {}, prompts: {} }, instructions: MCP_INSTRUCTIONS });
518
- const visible = () => toolsFor(core, actor);
520
+ const visible = () => toolsFor(core, actor, actor.kind === "anonymous" ? ANONYMOUS_READ_TOOLS : void 0);
519
521
  server.setRequestHandler(import_types3.ListToolsRequestSchema, async () => ({
520
522
  tools: visible().map((t) => ({ name: t.name, description: t.description, inputSchema: toJsonSchema(t.input) }))
521
523
  }));
@@ -609,8 +611,8 @@ Question: ${a.question ?? ""}`
609
611
  }
610
612
  var MAX_BODY_BYTES = 512 * 1024;
611
613
  var rpcError = (status, code, message, extra = {}) => new Response(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code, message } }), { status, headers: { "content-type": "application/json", ...extra } });
612
- async function handleMcp(cms, actor, req) {
613
- if (actor.kind === "anonymous") return rpcError(401, -32001, "API key required", { "www-authenticate": 'Bearer realm="agent-cms"' });
614
+ async function handleMcp(cms, actor, req, opts = {}) {
615
+ if (actor.kind === "anonymous" && opts.anonymous !== "read") return rpcError(401, -32001, "API key required", { "www-authenticate": 'Bearer realm="agent-cms"' });
614
616
  if (req.method.toUpperCase() !== "POST") return rpcError(405, -32e3, "Method not allowed (stateless server: POST only)", { allow: "POST" });
615
617
  const text = await req.text();
616
618
  if (text.length > MAX_BODY_BYTES) return rpcError(413, -32600, "Request too large");
@@ -641,6 +643,7 @@ async function handleMcp(cms, actor, req) {
641
643
  var MCP_TOOL_NAMES = CMS_TOOL_NAMES;
642
644
  // Annotate the CommonJS export names for ESM import in node:
643
645
  0 && (module.exports = {
646
+ ANONYMOUS_READ_TOOLS,
644
647
  MCP_INSTRUCTIONS,
645
648
  MCP_TOOL_NAMES,
646
649
  createMcpServer,
package/dist/mcp.d.cts CHANGED
@@ -17,6 +17,16 @@ import './repo-CeDxUxO6.cjs';
17
17
  * from the CMS and how to edit it safely.
18
18
  */
19
19
 
20
+ interface McpOptions {
21
+ /**
22
+ * `"read"`: requests without a key get the read tools below and see only
23
+ * published documents of collections anyone may read. Default `false`
24
+ * (401 without a key).
25
+ */
26
+ anonymous?: "read" | false;
27
+ }
28
+ /** Tools a keyless caller gets with `mcp: { anonymous: "read" }`. */
29
+ declare const ANONYMOUS_READ_TOOLS: readonly ["list_collections", "search_documents", "read_for_answer", "list_documents", "get_document"];
20
30
  /**
21
31
  * JSON Schema for a zod schema (the subset tool inputs and collection fields
22
32
  * use). Reads `_def.typeName` rather than `instanceof`, so schemas made by
@@ -27,7 +37,7 @@ declare function toJsonSchema(schema: z.ZodTypeAny): Record<string, unknown>;
27
37
  declare const MCP_INSTRUCTIONS: string;
28
38
  /** The MCP server for one actor (stateless: built per request). */
29
39
  declare function createMcpServer(cms: CmsLike, actor: Actor): Server;
30
- declare function handleMcp(cms: CmsLike, actor: Actor, req: Request): Promise<Response>;
40
+ declare function handleMcp(cms: CmsLike, actor: Actor, req: Request, opts?: McpOptions): Promise<Response>;
31
41
  declare const MCP_TOOL_NAMES: string[];
32
42
 
33
- export { MCP_INSTRUCTIONS, MCP_TOOL_NAMES, createMcpServer, handleMcp, toJsonSchema };
43
+ export { ANONYMOUS_READ_TOOLS, MCP_INSTRUCTIONS, MCP_TOOL_NAMES, type McpOptions, createMcpServer, handleMcp, toJsonSchema };
package/dist/mcp.d.ts CHANGED
@@ -17,6 +17,16 @@ import './repo-BWI2Pkrv.js';
17
17
  * from the CMS and how to edit it safely.
18
18
  */
19
19
 
20
+ interface McpOptions {
21
+ /**
22
+ * `"read"`: requests without a key get the read tools below and see only
23
+ * published documents of collections anyone may read. Default `false`
24
+ * (401 without a key).
25
+ */
26
+ anonymous?: "read" | false;
27
+ }
28
+ /** Tools a keyless caller gets with `mcp: { anonymous: "read" }`. */
29
+ declare const ANONYMOUS_READ_TOOLS: readonly ["list_collections", "search_documents", "read_for_answer", "list_documents", "get_document"];
20
30
  /**
21
31
  * JSON Schema for a zod schema (the subset tool inputs and collection fields
22
32
  * use). Reads `_def.typeName` rather than `instanceof`, so schemas made by
@@ -27,7 +37,7 @@ declare function toJsonSchema(schema: z.ZodTypeAny): Record<string, unknown>;
27
37
  declare const MCP_INSTRUCTIONS: string;
28
38
  /** The MCP server for one actor (stateless: built per request). */
29
39
  declare function createMcpServer(cms: CmsLike, actor: Actor): Server;
30
- declare function handleMcp(cms: CmsLike, actor: Actor, req: Request): Promise<Response>;
40
+ declare function handleMcp(cms: CmsLike, actor: Actor, req: Request, opts?: McpOptions): Promise<Response>;
31
41
  declare const MCP_TOOL_NAMES: string[];
32
42
 
33
- export { MCP_INSTRUCTIONS, MCP_TOOL_NAMES, createMcpServer, handleMcp, toJsonSchema };
43
+ export { ANONYMOUS_READ_TOOLS, MCP_INSTRUCTIONS, MCP_TOOL_NAMES, type McpOptions, createMcpServer, handleMcp, toJsonSchema };
package/dist/mcp.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import {
2
+ ANONYMOUS_READ_TOOLS,
2
3
  MCP_INSTRUCTIONS,
3
4
  MCP_TOOL_NAMES,
4
5
  createMcpServer,
5
6
  handleMcp,
6
7
  toJsonSchema
7
- } from "./chunk-BTO42652.js";
8
- import "./chunk-QIUXAUQ6.js";
8
+ } from "./chunk-EXV6JNLY.js";
9
+ import "./chunk-Y63XQS2J.js";
9
10
  import "./chunk-QQV6VLYJ.js";
10
11
  import "./chunk-52NUUZC7.js";
11
12
  import "./chunk-6K5ZTGHQ.js";
@@ -16,6 +17,7 @@ import "./chunk-DOADAH4L.js";
16
17
  import "./chunk-CRDW6Q72.js";
17
18
  import "./chunk-2NTK7H4W.js";
18
19
  export {
20
+ ANONYMOUS_READ_TOOLS,
19
21
  MCP_INSTRUCTIONS,
20
22
  MCP_TOOL_NAMES,
21
23
  createMcpServer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mainsoft/agent-cms",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "An add-on CMS that runs inside your web app, edited by people (admin UI) and AI agents (REST, MCP, AI SDK tools) together.",
5
5
  "license": "MIT",
6
6
  "type": "module",