@nextblock-cms/cortex 0.20.3 → 0.21.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.
Files changed (71) hide show
  1. package/client.cjs.js +1 -1
  2. package/client.es.js +3 -7
  3. package/index.cjs.js +1 -1
  4. package/index.es.js +24 -277
  5. package/lib/ai-block-generation.cjs.js +3 -4
  6. package/lib/ai-block-generation.es.js +143 -182
  7. package/lib/ai-client.cjs.js +1 -1
  8. package/lib/ai-client.d.ts +1 -1
  9. package/lib/ai-client.es.js +101 -135
  10. package/lib/ai-config.cjs.js +1 -1
  11. package/lib/ai-config.es.js +89 -108
  12. package/lib/ai-cortex-widget-builder.cjs.js +1 -1
  13. package/lib/ai-cortex-widget-builder.es.js +56 -70
  14. package/lib/ai-global-agent-content-ops-tools.cjs.js +1 -1
  15. package/lib/ai-global-agent-content-ops-tools.d.ts +1943 -68
  16. package/lib/ai-global-agent-content-ops-tools.es.js +185 -199
  17. package/lib/ai-global-agent-custom-block-tools.cjs.js +1 -1
  18. package/lib/ai-global-agent-custom-block-tools.d.ts +2160 -95
  19. package/lib/ai-global-agent-custom-block-tools.es.js +226 -223
  20. package/lib/ai-global-agent-db-tools.cjs.js +1 -1
  21. package/lib/ai-global-agent-db-tools.d.ts +2708 -98
  22. package/lib/ai-global-agent-db-tools.es.js +1013 -986
  23. package/lib/ai-global-agent-ecommerce.cjs.js +1 -1
  24. package/lib/ai-global-agent-ecommerce.es.js +3 -7
  25. package/lib/ai-global-agent-site-tools.cjs.js +2 -3
  26. package/lib/ai-global-agent-site-tools.d.ts +10695 -500
  27. package/lib/ai-global-agent-site-tools.es.js +750 -757
  28. package/lib/ai-global-agent-theming-tools.cjs.js +1 -3
  29. package/lib/ai-global-agent-theming-tools.d.ts +2905 -105
  30. package/lib/ai-global-agent-theming-tools.es.js +326 -396
  31. package/lib/ai-global-agent-tools.cjs.js +2 -2
  32. package/lib/ai-global-agent-tools.d.ts +4 -2230
  33. package/lib/ai-global-agent-tools.es.js +3899 -4328
  34. package/lib/ai-key-crypto.cjs.js +1 -1
  35. package/lib/ai-key-crypto.es.js +63 -82
  36. package/lib/ai-key-verification.cjs.js +1 -1
  37. package/lib/ai-key-verification.es.js +74 -63
  38. package/lib/ai-model-catalog.cjs.js +1 -1
  39. package/lib/ai-model-catalog.es.js +18 -22
  40. package/lib/ai-model-registry.cjs.js +2 -2
  41. package/lib/ai-model-registry.es.js +246 -309
  42. package/lib/ai-seo-metadata.cjs.js +2 -3
  43. package/lib/ai-seo-metadata.es.js +143 -185
  44. package/lib/ai-vision.cjs.js +2 -2
  45. package/lib/ai-vision.d.ts +6 -6
  46. package/lib/ai-vision.es.js +161 -215
  47. package/lib/block-content-schemas.cjs.js +1 -1
  48. package/lib/block-content-schemas.es.js +324 -254
  49. package/lib/cortex-widget-registry.cjs.js +1 -1
  50. package/lib/cortex-widget-registry.es.js +35 -43
  51. package/lib/cortex-widget-schema.cjs.js +2 -3
  52. package/lib/cortex-widget-schema.es.js +280 -309
  53. package/lib/editor-document-from-html.cjs.js +1 -1
  54. package/lib/editor-document-from-html.es.js +334 -278
  55. package/lib/fetch-host-guard.cjs.js +1 -0
  56. package/lib/fetch-host-guard.d.ts +2 -0
  57. package/lib/fetch-host-guard.es.js +30 -0
  58. package/lib/mcp-server.cjs.js +1 -1
  59. package/lib/mcp-server.es.js +155 -173
  60. package/lib/mcp-tokens.cjs.js +1 -1
  61. package/lib/mcp-tokens.es.js +95 -107
  62. package/lib/mcp-tool-registry.cjs.js +5 -6
  63. package/lib/mcp-tool-registry.es.js +533 -411
  64. package/lib/site-brief.cjs.js +2 -2
  65. package/lib/site-brief.es.js +102 -108
  66. package/lib/vision-image-download.cjs.js +1 -0
  67. package/lib/vision-image-download.d.ts +43 -0
  68. package/lib/vision-image-download.es.js +120 -0
  69. package/lib/zod-config.cjs.js +1 -1
  70. package/lib/zod-config.es.js +5 -6
  71. package/package.json +8 -8
@@ -0,0 +1,30 @@
1
+ //#region libs/cortex/src/lib/fetch-host-guard.ts
2
+ function e(e) {
3
+ let t = e.match(/^::ffff:(.+)$/i);
4
+ if (!t) return null;
5
+ let n = t[1];
6
+ if (/^\d{1,3}(\.\d{1,3}){3}$/.test(n)) return n;
7
+ let r = n.match(/^([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
8
+ if (!r) return null;
9
+ let i = Number.parseInt(r[1], 16), a = Number.parseInt(r[2], 16);
10
+ return [
11
+ i >> 8 & 255,
12
+ i & 255,
13
+ a >> 8 & 255,
14
+ a & 255
15
+ ].join(".");
16
+ }
17
+ function t(n) {
18
+ let r = n.trim().toLowerCase().replace(/\.$/, "").replace(/^\[|\]$/g, "");
19
+ if (!r || r === "localhost" || r.endsWith(".localhost") || r.endsWith(".local") || r.endsWith(".internal") || r === "metadata.google.internal" || r === "0.0.0.0" || r === "::" || r === "::1" || r.startsWith("fe80:") || r.startsWith("fc") || r.startsWith("fd")) return !0;
20
+ let i = e(r);
21
+ if (i) return t(i);
22
+ let a = r.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
23
+ if (a) {
24
+ let e = Number(a[1]), t = Number(a[2]);
25
+ if (e === 10 || e === 127 || e === 0 || e === 192 && t === 168 || e === 169 && t === 254 || e === 172 && t >= 16 && t <= 31) return !0;
26
+ }
27
+ return !1;
28
+ }
29
+ //#endregion
30
+ export { t as isBlockedFetchHost };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./mcp-tool-registry.cjs.js"),C="nextblock-cortex-ai",E="NextBlock Cortex AI",M="2025-06-18",f="2025-11-25",R="2026-07-28",T=[R,f,"2025-06-18","2025-03-26","2024-11-05"],x=-32700,p=-32600,S=-32601,_=-32602,O=-32603;function u(t,o){return{body:{id:t,jsonrpc:"2.0",result:o},status:200}}function a(t,o,i,e=200,c){return{body:{error:{code:o,message:i},id:t,jsonrpc:"2.0"},status:e}}const s={body:null,status:202};function N(t){return typeof t.method=="string"&&t.id===void 0}function b(t,o){const i=t.params?._meta;if(i&&typeof i=="object"){const e=i["io.modelcontextprotocol/protocolVersion"];if(typeof e=="string"&&e>=R)return!0}return!!(o&&o>=R)}function g(t){return typeof t!="string"||!t?M:T.includes(t)?t:f}function A(t,o){const i=t.scopes.includes("write");return{capabilities:{prompts:{},resources:{},tools:{}},instructions:t.instructions??["NextBlock Cortex AI exposes this CMS through typed tools.","Call get_database_schema first when you are unsure what exists.","Conventions: a page or post feature_image_id renders as a full-width title banner above the content and is its share preview — give posts one, never the home page or a page with its own hero section (use update_site_identity social_image for the site-wide preview); mark hero sections is_hero:true; slider:true plus slides makes a carousel.",i?"Page builds should go through generate_jsonb_layout, which stages a reviewable Live Draft rather than publishing directly.":"This connection is READ-ONLY. Mutating tools are not available on this token."].join(" "),protocolVersion:g(o),serverInfo:{name:C,title:E,version:t.serverVersion,websiteUrl:"https://nextblock.dev"}}}function v(t){return{authentication:{header:"Authorization",instructions:"POST JSON-RPC 2.0 messages with `Authorization: Bearer <token>`. Create the token in the NextBlock CMS (Settings → Cortex AI → MCP server access) or set MCP_BEARER_TOKEN in the environment. Cortex AI must be active on the site.",required:!0,schemes:["bearer"]},capabilities:{prompts:{},resources:{},tools:{}},endpoint:{transport:"streamable-http",url:t.endpointUrl},name:C,protocolVersions:T,serverCard:t.serverCardUrl,status:"ok",title:E,version:t.serverVersion,websiteUrl:"https://nextblock.dev"}}function y(t){return!!(t&&t.toLowerCase().includes("text/event-stream"))}async function I(t,o){if(t===null||typeof t!="object"||Array.isArray(t))return a(null,p,"Expected a single JSON-RPC message.",400);if(typeof t.method!="string")return"result"in t||"error"in t?s:a(t.id??null,p,'Missing "method".',400);const{method:i}=t,e=t.id??null,c=N(t);if(i.startsWith("notifications/"))return s;switch(i){case"initialize":return c?s:u(e,A(o,t.params?.protocolVersion));case"ping":return c?s:u(e,{});case"tools/list":return c?s:u(e,{tools:l.buildCortexMcpToolDefinitions({context:o.context,scopes:o.scopes})});case"tools/call":{if(c)return s;const n=t.params?.name;if(typeof n!="string"||!n)return a(e,_,"tools/call requires params.name.");try{const r=await l.callCortexMcpTool({args:t.params?.arguments,context:o.context,name:n,scopes:o.scopes});return u(e,r)}catch(r){return r instanceof l.CortexMcpUnknownToolError||r instanceof l.CortexMcpForbiddenToolError?a(e,_,r.message):a(e,O,r instanceof Error?r.message:"Tool execution failed.")}}case"resources/list":return c?s:u(e,{resources:l.CORTEX_MCP_RESOURCES});case"resources/templates/list":return c?s:u(e,{resourceTemplates:[]});case"resources/read":{if(c)return s;const n=t.params?.uri;if(typeof n!="string"||!n)return a(e,_,"resources/read requires params.uri.");try{const r=await l.readCortexMcpResource({context:o.context,uri:n});return r?u(e,{contents:[r]}):a(e,_,`Unknown resource: ${n}`)}catch(r){return a(e,O,r instanceof Error?r.message:"Resource read failed.")}}case"prompts/list":return c?s:u(e,{prompts:l.CORTEX_MCP_PROMPTS});case"prompts/get":{if(c)return s;const n=t.params?.name;if(typeof n!="string"||!n)return a(e,_,"prompts/get requires params.name.");const r=t.params?.arguments,P={};if(r&&typeof r=="object")for(const[m,d]of Object.entries(r))typeof d=="string"&&(P[m]=d);const h=l.getCortexMcpPrompt({args:P,name:n});return h?u(e,h):a(e,_,`Unknown prompt: ${n}`)}default:return c?s:a(e,S,`Method not found: ${i}`)}}exports.CORTEX_MCP_DEFAULT_PROTOCOL_VERSION=M;exports.CORTEX_MCP_LATEST_LEGACY_PROTOCOL_VERSION=f;exports.CORTEX_MCP_MODERN_PROTOCOL_VERSION=R;exports.CORTEX_MCP_SERVER_NAME=C;exports.CORTEX_MCP_SERVER_TITLE=E;exports.CORTEX_MCP_SUPPORTED_PROTOCOL_VERSIONS=T;exports.JSON_RPC_INTERNAL_ERROR=O;exports.JSON_RPC_INVALID_PARAMS=_;exports.JSON_RPC_INVALID_REQUEST=p;exports.JSON_RPC_METHOD_NOT_FOUND=S;exports.JSON_RPC_PARSE_ERROR=x;exports.buildCortexMcpDiscoveryDocument=v;exports.handleCortexMcpMessage=I;exports.isJsonRpcNotification=N;exports.isModernEraMessage=b;exports.wantsMcpEventStream=y;
1
+ const e=require("./mcp-tool-registry.cjs.js");var t=`nextblock-cortex-ai`,n=`NextBlock Cortex AI`,r=`2025-06-18`,i=`2025-11-25`,a=`2026-07-28`,o=[a,i,`2025-06-18`,`2025-03-26`,`2024-11-05`],s=-32700,c=-32600,l=-32601,u=-32602,d=-32603;function f(e,t){return{body:{id:e,jsonrpc:`2.0`,result:t},status:200}}function p(e,t,n,r=200,i){return{body:{error:{code:t,message:n,...i===void 0?{}:{data:i}},id:e,jsonrpc:`2.0`},status:r}}var m={body:null,status:202};function h(e){return typeof e.method==`string`&&e.id===void 0}function g(e,t){let n=e.params?._meta;if(n&&typeof n==`object`){let e=n[`io.modelcontextprotocol/protocolVersion`];if(typeof e==`string`&&e>=`2026-07-28`)return!0}return!!(t&&t>=`2026-07-28`)}function _(e){return typeof e!=`string`||!e?r:o.includes(e)?e:i}function v(e,r){let i=e.scopes.includes(`write`);return{capabilities:{prompts:{},resources:{},tools:{}},instructions:e.instructions??[`NextBlock Cortex AI exposes this CMS through typed tools.`,`Call get_database_schema first when you are unsure what exists.`,`Conventions: a page or post feature_image_id renders as a full-width title banner above the content and is its share preview — give posts one, never the home page or a page with its own hero section (use update_site_identity social_image for the site-wide preview); mark hero sections is_hero:true; slider:true plus slides makes a carousel.`,i?`Page builds should go through generate_jsonb_layout, which stages a reviewable Live Draft rather than publishing directly.`:`This connection is READ-ONLY. Mutating tools are not available on this token.`].join(` `),protocolVersion:_(r),serverInfo:{name:t,title:n,version:e.serverVersion,websiteUrl:`https://nextblock.dev`}}}function y(e){return{authentication:{header:`Authorization`,instructions:"POST JSON-RPC 2.0 messages with `Authorization: Bearer <token>`. Create the token in the NextBlock CMS (Settings → Cortex AI → MCP server access) or set MCP_BEARER_TOKEN in the environment. Cortex AI must be active on the site.",required:!0,schemes:[`bearer`]},capabilities:{prompts:{},resources:{},tools:{}},endpoint:{transport:`streamable-http`,url:e.endpointUrl},name:t,protocolVersions:o,serverCard:e.serverCardUrl,status:`ok`,title:n,version:e.serverVersion,websiteUrl:`https://nextblock.dev`}}function b(e){return!!(e&&e.toLowerCase().includes(`text/event-stream`))}async function x(t,n){if(typeof t!=`object`||!t||Array.isArray(t))return p(null,c,`Expected a single JSON-RPC message.`,400);if(typeof t.method!=`string`)return`result`in t||`error`in t?m:p(t.id??null,c,`Missing "method".`,400);let{method:r}=t,i=t.id??null,a=h(t);if(r.startsWith(`notifications/`))return m;switch(r){case`initialize`:return a?m:f(i,v(n,t.params?.protocolVersion));case`ping`:return a?m:f(i,{});case`tools/list`:return a?m:f(i,{tools:e.buildCortexMcpToolDefinitions({context:n.context,scopes:n.scopes})});case`tools/call`:{if(a)return m;let r=t.params?.name;if(typeof r!=`string`||!r)return p(i,u,`tools/call requires params.name.`);try{return f(i,await e.callCortexMcpTool({args:t.params?.arguments,context:n.context,name:r,scopes:n.scopes}))}catch(t){return t instanceof e.CortexMcpUnknownToolError||t instanceof e.CortexMcpForbiddenToolError?p(i,u,t.message):p(i,d,t instanceof Error?t.message:`Tool execution failed.`)}}case`resources/list`:return a?m:f(i,{resources:e.CORTEX_MCP_RESOURCES});case`resources/templates/list`:return a?m:f(i,{resourceTemplates:[]});case`resources/read`:{if(a)return m;let r=t.params?.uri;if(typeof r!=`string`||!r)return p(i,u,`resources/read requires params.uri.`);try{let t=await e.readCortexMcpResource({context:n.context,uri:r});return t?f(i,{contents:[t]}):p(i,u,`Unknown resource: ${r}`)}catch(e){return p(i,d,e instanceof Error?e.message:`Resource read failed.`)}}case`prompts/list`:return a?m:f(i,{prompts:e.CORTEX_MCP_PROMPTS});case`prompts/get`:{if(a)return m;let n=t.params?.name;if(typeof n!=`string`||!n)return p(i,u,`prompts/get requires params.name.`);let r=t.params?.arguments,o={};if(r&&typeof r==`object`)for(let[e,t]of Object.entries(r))typeof t==`string`&&(o[e]=t);let s=e.getCortexMcpPrompt({args:o,name:n});return s?f(i,s):p(i,u,`Unknown prompt: ${n}`)}default:return a?m:p(i,l,`Method not found: ${r}`)}}exports.CORTEX_MCP_DEFAULT_PROTOCOL_VERSION=r,exports.CORTEX_MCP_LATEST_LEGACY_PROTOCOL_VERSION=i,exports.CORTEX_MCP_MODERN_PROTOCOL_VERSION=a,exports.CORTEX_MCP_SERVER_NAME=t,exports.CORTEX_MCP_SERVER_TITLE=n,exports.CORTEX_MCP_SUPPORTED_PROTOCOL_VERSIONS=o,exports.JSON_RPC_INTERNAL_ERROR=d,exports.JSON_RPC_INVALID_PARAMS=u,exports.JSON_RPC_INVALID_REQUEST=c,exports.JSON_RPC_METHOD_NOT_FOUND=l,exports.JSON_RPC_PARSE_ERROR=s,exports.buildCortexMcpDiscoveryDocument=y,exports.handleCortexMcpMessage=x,exports.isJsonRpcNotification=h,exports.isModernEraMessage=g,exports.wantsMcpEventStream=b;
@@ -1,182 +1,164 @@
1
- import { getCortexMcpPrompt as x, readCortexMcpResource as M, callCortexMcpTool as P, CortexMcpUnknownToolError as b, CortexMcpForbiddenToolError as g, buildCortexMcpToolDefinitions as v, CORTEX_MCP_PROMPTS as S, CORTEX_MCP_RESOURCES as y } from "./mcp-tool-registry.es.js";
2
- const E = "nextblock-cortex-ai", d = "NextBlock Cortex AI", N = "2025-06-18", O = "2025-11-25", p = "2026-07-28", m = [
3
- p,
4
- O,
5
- "2025-06-18",
6
- "2025-03-26",
7
- "2024-11-05"
8
- ], V = -32700, R = -32600, w = -32601, l = -32602, h = -32603;
9
- function u(t, o) {
10
- return { body: { id: t, jsonrpc: "2.0", result: o }, status: 200 };
1
+ import { CORTEX_MCP_PROMPTS as e, CORTEX_MCP_RESOURCES as t, CortexMcpForbiddenToolError as n, CortexMcpUnknownToolError as r, buildCortexMcpToolDefinitions as i, callCortexMcpTool as a, getCortexMcpPrompt as o, readCortexMcpResource as s } from "./mcp-tool-registry.es.js";
2
+ //#region libs/cortex/src/lib/mcp-server.ts
3
+ var c = "nextblock-cortex-ai", l = "NextBlock Cortex AI", u = "2025-06-18", d = "2025-11-25", f = "2026-07-28", p = [
4
+ f,
5
+ d,
6
+ "2025-06-18",
7
+ "2025-03-26",
8
+ "2024-11-05"
9
+ ], m = -32700, h = -32600, g = -32601, _ = -32602, v = -32603;
10
+ function y(e, t) {
11
+ return {
12
+ body: {
13
+ id: e,
14
+ jsonrpc: "2.0",
15
+ result: t
16
+ },
17
+ status: 200
18
+ };
11
19
  }
12
- function a(t, o, i, e = 200, c) {
13
- return {
14
- body: {
15
- error: { code: o, message: i },
16
- id: t,
17
- jsonrpc: "2.0"
18
- },
19
- status: e
20
- };
20
+ function b(e, t, n, r = 200, i) {
21
+ return {
22
+ body: {
23
+ error: {
24
+ code: t,
25
+ message: n,
26
+ ...i === void 0 ? {} : { data: i }
27
+ },
28
+ id: e,
29
+ jsonrpc: "2.0"
30
+ },
31
+ status: r
32
+ };
21
33
  }
22
- const s = { body: null, status: 202 };
23
- function A(t) {
24
- return typeof t.method == "string" && t.id === void 0;
34
+ var x = {
35
+ body: null,
36
+ status: 202
37
+ };
38
+ function S(e) {
39
+ return typeof e.method == "string" && e.id === void 0;
25
40
  }
26
- function D(t, o) {
27
- const i = t.params?._meta;
28
- if (i && typeof i == "object") {
29
- const e = i["io.modelcontextprotocol/protocolVersion"];
30
- if (typeof e == "string" && e >= p)
31
- return !0;
32
- }
33
- return !!(o && o >= p);
41
+ function C(e, t) {
42
+ let n = e.params?._meta;
43
+ if (n && typeof n == "object") {
44
+ let e = n["io.modelcontextprotocol/protocolVersion"];
45
+ if (typeof e == "string" && e >= "2026-07-28") return !0;
46
+ }
47
+ return !!(t && t >= "2026-07-28");
34
48
  }
35
- function k(t) {
36
- return typeof t != "string" || !t ? N : m.includes(t) ? t : O;
49
+ function w(e) {
50
+ return typeof e != "string" || !e ? u : p.includes(e) ? e : d;
37
51
  }
38
- function I(t, o) {
39
- const i = t.scopes.includes("write");
40
- return {
41
- capabilities: {
42
- // listChanged is deliberately absent: the tool set is static per token, so
43
- // advertising change notifications we never send would be a lie a client
44
- // could wait on.
45
- prompts: {},
46
- resources: {},
47
- tools: {}
48
- },
49
- instructions: t.instructions ?? [
50
- "NextBlock Cortex AI exposes this CMS through typed tools.",
51
- "Call get_database_schema first when you are unsure what exists.",
52
- "Conventions: a page or post feature_image_id renders as a full-width title banner above the content and is its share preview — give posts one, never the home page or a page with its own hero section (use update_site_identity social_image for the site-wide preview); mark hero sections is_hero:true; slider:true plus slides makes a carousel.",
53
- i ? "Page builds should go through generate_jsonb_layout, which stages a reviewable Live Draft rather than publishing directly." : "This connection is READ-ONLY. Mutating tools are not available on this token."
54
- ].join(" "),
55
- protocolVersion: k(o),
56
- serverInfo: {
57
- name: E,
58
- title: d,
59
- version: t.serverVersion,
60
- websiteUrl: "https://nextblock.dev"
61
- }
62
- };
52
+ function T(e, t) {
53
+ let n = e.scopes.includes("write");
54
+ return {
55
+ capabilities: {
56
+ prompts: {},
57
+ resources: {},
58
+ tools: {}
59
+ },
60
+ instructions: e.instructions ?? [
61
+ "NextBlock Cortex AI exposes this CMS through typed tools.",
62
+ "Call get_database_schema first when you are unsure what exists.",
63
+ "Conventions: a page or post feature_image_id renders as a full-width title banner above the content and is its share preview — give posts one, never the home page or a page with its own hero section (use update_site_identity social_image for the site-wide preview); mark hero sections is_hero:true; slider:true plus slides makes a carousel.",
64
+ n ? "Page builds should go through generate_jsonb_layout, which stages a reviewable Live Draft rather than publishing directly." : "This connection is READ-ONLY. Mutating tools are not available on this token."
65
+ ].join(" "),
66
+ protocolVersion: w(t),
67
+ serverInfo: {
68
+ name: c,
69
+ title: l,
70
+ version: e.serverVersion,
71
+ websiteUrl: "https://nextblock.dev"
72
+ }
73
+ };
63
74
  }
64
- function U(t) {
65
- return {
66
- authentication: {
67
- header: "Authorization",
68
- instructions: "POST JSON-RPC 2.0 messages with `Authorization: Bearer <token>`. Create the token in the NextBlock CMS (Settings → Cortex AI → MCP server access) or set MCP_BEARER_TOKEN in the environment. Cortex AI must be active on the site.",
69
- required: !0,
70
- schemes: ["bearer"]
71
- },
72
- capabilities: { prompts: {}, resources: {}, tools: {} },
73
- endpoint: { transport: "streamable-http", url: t.endpointUrl },
74
- name: E,
75
- protocolVersions: m,
76
- serverCard: t.serverCardUrl,
77
- status: "ok",
78
- title: d,
79
- version: t.serverVersion,
80
- websiteUrl: "https://nextblock.dev"
81
- };
75
+ function E(e) {
76
+ return {
77
+ authentication: {
78
+ header: "Authorization",
79
+ instructions: "POST JSON-RPC 2.0 messages with `Authorization: Bearer <token>`. Create the token in the NextBlock CMS (Settings → Cortex AI → MCP server access) or set MCP_BEARER_TOKEN in the environment. Cortex AI must be active on the site.",
80
+ required: !0,
81
+ schemes: ["bearer"]
82
+ },
83
+ capabilities: {
84
+ prompts: {},
85
+ resources: {},
86
+ tools: {}
87
+ },
88
+ endpoint: {
89
+ transport: "streamable-http",
90
+ url: e.endpointUrl
91
+ },
92
+ name: c,
93
+ protocolVersions: p,
94
+ serverCard: e.serverCardUrl,
95
+ status: "ok",
96
+ title: l,
97
+ version: e.serverVersion,
98
+ websiteUrl: "https://nextblock.dev"
99
+ };
82
100
  }
83
- function j(t) {
84
- return !!(t && t.toLowerCase().includes("text/event-stream"));
101
+ function D(e) {
102
+ return !!(e && e.toLowerCase().includes("text/event-stream"));
85
103
  }
86
- async function J(t, o) {
87
- if (t === null || typeof t != "object" || Array.isArray(t))
88
- return a(null, R, "Expected a single JSON-RPC message.", 400);
89
- if (typeof t.method != "string")
90
- return "result" in t || "error" in t ? s : a(t.id ?? null, R, 'Missing "method".', 400);
91
- const { method: i } = t, e = t.id ?? null, c = A(t);
92
- if (i.startsWith("notifications/"))
93
- return s;
94
- switch (i) {
95
- case "initialize":
96
- return c ? s : u(e, I(o, t.params?.protocolVersion));
97
- case "ping":
98
- return c ? s : u(e, {});
99
- case "tools/list":
100
- return c ? s : u(e, {
101
- tools: v({ context: o.context, scopes: o.scopes })
102
- });
103
- case "tools/call": {
104
- if (c)
105
- return s;
106
- const n = t.params?.name;
107
- if (typeof n != "string" || !n)
108
- return a(e, l, "tools/call requires params.name.");
109
- try {
110
- const r = await P({
111
- args: t.params?.arguments,
112
- context: o.context,
113
- name: n,
114
- scopes: o.scopes
115
- });
116
- return u(e, r);
117
- } catch (r) {
118
- return r instanceof b || r instanceof g ? a(e, l, r.message) : a(
119
- e,
120
- h,
121
- r instanceof Error ? r.message : "Tool execution failed."
122
- );
123
- }
124
- }
125
- case "resources/list":
126
- return c ? s : u(e, { resources: y });
127
- case "resources/templates/list":
128
- return c ? s : u(e, { resourceTemplates: [] });
129
- case "resources/read": {
130
- if (c)
131
- return s;
132
- const n = t.params?.uri;
133
- if (typeof n != "string" || !n)
134
- return a(e, l, "resources/read requires params.uri.");
135
- try {
136
- const r = await M({ context: o.context, uri: n });
137
- return r ? u(e, { contents: [r] }) : a(e, l, `Unknown resource: ${n}`);
138
- } catch (r) {
139
- return a(
140
- e,
141
- h,
142
- r instanceof Error ? r.message : "Resource read failed."
143
- );
144
- }
145
- }
146
- case "prompts/list":
147
- return c ? s : u(e, { prompts: S });
148
- case "prompts/get": {
149
- if (c)
150
- return s;
151
- const n = t.params?.name;
152
- if (typeof n != "string" || !n)
153
- return a(e, l, "prompts/get requires params.name.");
154
- const r = t.params?.arguments, f = {};
155
- if (r && typeof r == "object")
156
- for (const [T, C] of Object.entries(r))
157
- typeof C == "string" && (f[T] = C);
158
- const _ = x({ args: f, name: n });
159
- return _ ? u(e, _) : a(e, l, `Unknown prompt: ${n}`);
160
- }
161
- default:
162
- return c ? s : a(e, w, `Method not found: ${i}`);
163
- }
104
+ async function O(c, l) {
105
+ if (typeof c != "object" || !c || Array.isArray(c)) return b(null, h, "Expected a single JSON-RPC message.", 400);
106
+ if (typeof c.method != "string") return "result" in c || "error" in c ? x : b(c.id ?? null, h, "Missing \"method\".", 400);
107
+ let { method: u } = c, d = c.id ?? null, f = S(c);
108
+ if (u.startsWith("notifications/")) return x;
109
+ switch (u) {
110
+ case "initialize": return f ? x : y(d, T(l, c.params?.protocolVersion));
111
+ case "ping": return f ? x : y(d, {});
112
+ case "tools/list": return f ? x : y(d, { tools: i({
113
+ context: l.context,
114
+ scopes: l.scopes
115
+ }) });
116
+ case "tools/call": {
117
+ if (f) return x;
118
+ let e = c.params?.name;
119
+ if (typeof e != "string" || !e) return b(d, _, "tools/call requires params.name.");
120
+ try {
121
+ return y(d, await a({
122
+ args: c.params?.arguments,
123
+ context: l.context,
124
+ name: e,
125
+ scopes: l.scopes
126
+ }));
127
+ } catch (e) {
128
+ return e instanceof r || e instanceof n ? b(d, _, e.message) : b(d, v, e instanceof Error ? e.message : "Tool execution failed.");
129
+ }
130
+ }
131
+ case "resources/list": return f ? x : y(d, { resources: t });
132
+ case "resources/templates/list": return f ? x : y(d, { resourceTemplates: [] });
133
+ case "resources/read": {
134
+ if (f) return x;
135
+ let e = c.params?.uri;
136
+ if (typeof e != "string" || !e) return b(d, _, "resources/read requires params.uri.");
137
+ try {
138
+ let t = await s({
139
+ context: l.context,
140
+ uri: e
141
+ });
142
+ return t ? y(d, { contents: [t] }) : b(d, _, `Unknown resource: ${e}`);
143
+ } catch (e) {
144
+ return b(d, v, e instanceof Error ? e.message : "Resource read failed.");
145
+ }
146
+ }
147
+ case "prompts/list": return f ? x : y(d, { prompts: e });
148
+ case "prompts/get": {
149
+ if (f) return x;
150
+ let e = c.params?.name;
151
+ if (typeof e != "string" || !e) return b(d, _, "prompts/get requires params.name.");
152
+ let t = c.params?.arguments, n = {};
153
+ if (t && typeof t == "object") for (let [e, r] of Object.entries(t)) typeof r == "string" && (n[e] = r);
154
+ let r = o({
155
+ args: n,
156
+ name: e
157
+ });
158
+ return r ? y(d, r) : b(d, _, `Unknown prompt: ${e}`);
159
+ }
160
+ default: return f ? x : b(d, g, `Method not found: ${u}`);
161
+ }
164
162
  }
165
- export {
166
- N as CORTEX_MCP_DEFAULT_PROTOCOL_VERSION,
167
- O as CORTEX_MCP_LATEST_LEGACY_PROTOCOL_VERSION,
168
- p as CORTEX_MCP_MODERN_PROTOCOL_VERSION,
169
- E as CORTEX_MCP_SERVER_NAME,
170
- d as CORTEX_MCP_SERVER_TITLE,
171
- m as CORTEX_MCP_SUPPORTED_PROTOCOL_VERSIONS,
172
- h as JSON_RPC_INTERNAL_ERROR,
173
- l as JSON_RPC_INVALID_PARAMS,
174
- R as JSON_RPC_INVALID_REQUEST,
175
- w as JSON_RPC_METHOD_NOT_FOUND,
176
- V as JSON_RPC_PARSE_ERROR,
177
- U as buildCortexMcpDiscoveryDocument,
178
- J as handleCortexMcpMessage,
179
- A as isJsonRpcNotification,
180
- D as isModernEraMessage,
181
- j as wantsMcpEventStream
182
- };
163
+ //#endregion
164
+ export { u as CORTEX_MCP_DEFAULT_PROTOCOL_VERSION, d as CORTEX_MCP_LATEST_LEGACY_PROTOCOL_VERSION, f as CORTEX_MCP_MODERN_PROTOCOL_VERSION, c as CORTEX_MCP_SERVER_NAME, l as CORTEX_MCP_SERVER_TITLE, p as CORTEX_MCP_SUPPORTED_PROTOCOL_VERSIONS, v as JSON_RPC_INTERNAL_ERROR, _ as JSON_RPC_INVALID_PARAMS, h as JSON_RPC_INVALID_REQUEST, g as JSON_RPC_METHOD_NOT_FOUND, m as JSON_RPC_PARSE_ERROR, E as buildCortexMcpDiscoveryDocument, O as handleCortexMcpMessage, S as isJsonRpcNotification, C as isModernEraMessage, D as wantsMcpEventStream };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("node:crypto"),M="Cortex AI MCP token utilities can only be imported from server-side code.";function c(){if(!(typeof window>"u"))throw new Error(M)}const E="cortex_ai_mcp_settings",l="mcp_access_tokens",_="nbmcp_",m=32,k=8,C=["read","write"],a={allowLocalhostWithoutToken:!0,enabled:!1};function d(e){const t=e&&typeof e=="object"&&!Array.isArray(e)?e:{};return{allowLocalhostWithoutToken:typeof t.allowLocalhostWithoutToken=="boolean"?t.allowLocalhostWithoutToken:a.allowLocalhostWithoutToken,enabled:typeof t.enabled=="boolean"?t.enabled:a.enabled}}async function O(e){if(e)try{const{data:t}=await e.from("site_settings").select("value").eq("key",E).maybeSingle();if(t?.value)return d(t.value)}catch{}return{...a}}function r(e){return c(),i.createHash("sha256").update(e.trim(),"utf8").digest("hex")}function R(){c();const e=`${_}${i.randomBytes(m).toString("base64url")}`;return{token:e,tokenHash:r(e),tokenPrefix:e.slice(0,_.length+k)}}function v(e){const t=e?.trim();if(!t)return null;const o=/^Bearer\s+(.+)$/i.exec(t);return(o?o[1]:t).trim()||null}function x(e){const o=(Array.isArray(e)?e:[]).filter(n=>C.includes(n));return o.length>0?Array.from(new Set(o)):["read"]}async function I(e,t,o=new Date){c();const n=t?.trim();if(!n||n.length<16)return{reason:"malformed",valid:!1};const f=r(n),{data:T,error:p}=await e.from(l).select("id, name, scopes, token_prefix, created_at, created_by, expires_at, last_used_at, revoked_at").eq("token_hash",f).maybeSingle();if(p||!T)return{reason:"unknown",valid:!1};const S=Buffer.from(f,"utf8");if(!i.timingSafeEqual(S,Buffer.from(r(n),"utf8")))return{reason:"unknown",valid:!1};const s=T;return s.revoked_at?{reason:"revoked",valid:!1}:s.expires_at&&new Date(s.expires_at).getTime()<=o.getTime()?{reason:"expired",valid:!1}:{scopes:x(s.scopes),token:s,valid:!0}}async function N(e,t,o=new Date){try{await e.from(l).update({last_used_at:o.toISOString()}).eq("id",t)}catch{}}const y=new Set(["localhost","127.0.0.1","[::1]","::1","0.0.0.0"]);function A(e){const t=e?.trim().toLowerCase();if(!t)return!1;const o=t.startsWith("[")?t.replace(/\]:\d+$/,"]"):t.replace(/:\d+$/,"");return y.has(o)||o.endsWith(".localhost")}function P(e){return!e.settings.allowLocalhostWithoutToken||process.env.NODE_ENV==="production"?!1:A(e.hostHeader)}const h="MCP_BEARER_TOKEN",u=32;function g(e=process.env){const t=e[h]?.trim();return!t||t.length<u?null:t}function L(e,t){c();const o=e?.trim(),n=t?.trim();return!o||!n||n.length<u?!1:i.timingSafeEqual(Buffer.from(r(o),"utf8"),Buffer.from(r(n),"utf8"))}exports.CORTEX_AI_MCP_ENV_TOKEN_MIN_LENGTH=u;exports.CORTEX_AI_MCP_ENV_TOKEN_VAR=h;exports.CORTEX_AI_MCP_SCOPES=C;exports.CORTEX_AI_MCP_SETTINGS_DEFAULTS=a;exports.CORTEX_AI_MCP_SETTINGS_KEY=E;exports.CORTEX_AI_MCP_TOKENS_TABLE=l;exports.CORTEX_AI_MCP_TOKEN_PREFIX=_;exports.hashCortexAiMcpToken=r;exports.isLocalhostHost=A;exports.matchesCortexAiMcpEnvToken=L;exports.mintCortexAiMcpToken=R;exports.normalizeCortexAiMcpSettings=d;exports.parseBearerToken=v;exports.readCortexAiMcpEnvToken=g;exports.resolveCortexAiMcpSettings=O;exports.shouldTrustLocalMcpRequest=P;exports.touchCortexAiMcpToken=N;exports.verifyCortexAiMcpToken=I;
1
+ let e=require("node:crypto");var t=`Cortex AI MCP token utilities can only be imported from server-side code.`;function n(){if(typeof window<`u`)throw Error(t)}var r=`cortex_ai_mcp_settings`,i=`mcp_access_tokens`,a=`nbmcp_`,o=32,s=[`read`,`write`],c={allowLocalhostWithoutToken:!0,enabled:!1};function l(e){let t=e&&typeof e==`object`&&!Array.isArray(e)?e:{};return{allowLocalhostWithoutToken:typeof t.allowLocalhostWithoutToken==`boolean`?t.allowLocalhostWithoutToken:c.allowLocalhostWithoutToken,enabled:typeof t.enabled==`boolean`?t.enabled:c.enabled}}async function u(e){if(e)try{let{data:t}=await e.from(`site_settings`).select(`value`).eq(`key`,r).maybeSingle();if(t?.value)return l(t.value)}catch{}return{...c}}function d(t){return n(),(0,e.createHash)(`sha256`).update(t.trim(),`utf8`).digest(`hex`)}function f(){n();let t=`${a}${(0,e.randomBytes)(o).toString(`base64url`)}`;return{token:t,tokenHash:d(t),tokenPrefix:t.slice(0,14)}}function p(e){let t=e?.trim();if(!t)return null;let n=/^Bearer\s+(.+)$/i.exec(t);return(n?n[1]:t).trim()||null}function m(e){let t=(Array.isArray(e)?e:[]).filter(e=>s.includes(e));return t.length>0?Array.from(new Set(t)):[`read`]}async function h(t,r,a=new Date){n();let o=r?.trim();if(!o||o.length<16)return{reason:`malformed`,valid:!1};let s=d(o),{data:c,error:l}=await t.from(i).select(`id, name, scopes, token_prefix, created_at, created_by, expires_at, last_used_at, revoked_at`).eq(`token_hash`,s).maybeSingle();if(l||!c)return{reason:`unknown`,valid:!1};let u=Buffer.from(s,`utf8`);if(!(0,e.timingSafeEqual)(u,Buffer.from(d(o),`utf8`)))return{reason:`unknown`,valid:!1};let f=c;return f.revoked_at?{reason:`revoked`,valid:!1}:f.expires_at&&new Date(f.expires_at).getTime()<=a.getTime()?{reason:`expired`,valid:!1}:{scopes:m(f.scopes),token:f,valid:!0}}async function g(e,t,n=new Date){try{await e.from(i).update({last_used_at:n.toISOString()}).eq(`id`,t)}catch{}}var _=new Set([`localhost`,`127.0.0.1`,`[::1]`,`::1`,`0.0.0.0`]);function v(e){let t=e?.trim().toLowerCase();if(!t)return!1;let n=t.startsWith(`[`)?t.replace(/\]:\d+$/,`]`):t.replace(/:\d+$/,``);return _.has(n)||n.endsWith(`.localhost`)}function y(e){return!e.settings.allowLocalhostWithoutToken||process.env.NODE_ENV===`production`?!1:v(e.hostHeader)}var b=`MCP_BEARER_TOKEN`,x=32;function S(e=process.env){let t=e[b]?.trim();return!t||t.length<32?null:t}function C(t,r){n();let i=t?.trim(),a=r?.trim();return!i||!a||a.length<32?!1:(0,e.timingSafeEqual)(Buffer.from(d(i),`utf8`),Buffer.from(d(a),`utf8`))}exports.CORTEX_AI_MCP_ENV_TOKEN_MIN_LENGTH=x,exports.CORTEX_AI_MCP_ENV_TOKEN_VAR=b,exports.CORTEX_AI_MCP_SCOPES=s,exports.CORTEX_AI_MCP_SETTINGS_DEFAULTS=c,exports.CORTEX_AI_MCP_SETTINGS_KEY=r,exports.CORTEX_AI_MCP_TOKENS_TABLE=i,exports.CORTEX_AI_MCP_TOKEN_PREFIX=a,exports.hashCortexAiMcpToken=d,exports.isLocalhostHost=v,exports.matchesCortexAiMcpEnvToken=C,exports.mintCortexAiMcpToken=f,exports.normalizeCortexAiMcpSettings=l,exports.parseBearerToken=p,exports.readCortexAiMcpEnvToken=S,exports.resolveCortexAiMcpSettings=u,exports.shouldTrustLocalMcpRequest=y,exports.touchCortexAiMcpToken=g,exports.verifyCortexAiMcpToken=h;