@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.
- package/client.cjs.js +1 -1
- package/client.es.js +3 -7
- package/index.cjs.js +1 -1
- package/index.es.js +24 -277
- package/lib/ai-block-generation.cjs.js +3 -4
- package/lib/ai-block-generation.es.js +143 -182
- package/lib/ai-client.cjs.js +1 -1
- package/lib/ai-client.d.ts +1 -1
- package/lib/ai-client.es.js +101 -135
- package/lib/ai-config.cjs.js +1 -1
- package/lib/ai-config.es.js +89 -108
- package/lib/ai-cortex-widget-builder.cjs.js +1 -1
- package/lib/ai-cortex-widget-builder.es.js +56 -70
- package/lib/ai-global-agent-content-ops-tools.cjs.js +1 -1
- package/lib/ai-global-agent-content-ops-tools.d.ts +1943 -68
- package/lib/ai-global-agent-content-ops-tools.es.js +185 -199
- package/lib/ai-global-agent-custom-block-tools.cjs.js +1 -1
- package/lib/ai-global-agent-custom-block-tools.d.ts +2160 -95
- package/lib/ai-global-agent-custom-block-tools.es.js +226 -223
- package/lib/ai-global-agent-db-tools.cjs.js +1 -1
- package/lib/ai-global-agent-db-tools.d.ts +2708 -98
- package/lib/ai-global-agent-db-tools.es.js +1013 -986
- package/lib/ai-global-agent-ecommerce.cjs.js +1 -1
- package/lib/ai-global-agent-ecommerce.es.js +3 -7
- package/lib/ai-global-agent-site-tools.cjs.js +2 -3
- package/lib/ai-global-agent-site-tools.d.ts +10695 -500
- package/lib/ai-global-agent-site-tools.es.js +750 -757
- package/lib/ai-global-agent-theming-tools.cjs.js +1 -3
- package/lib/ai-global-agent-theming-tools.d.ts +2905 -105
- package/lib/ai-global-agent-theming-tools.es.js +326 -396
- package/lib/ai-global-agent-tools.cjs.js +2 -2
- package/lib/ai-global-agent-tools.d.ts +4 -2230
- package/lib/ai-global-agent-tools.es.js +3899 -4328
- package/lib/ai-key-crypto.cjs.js +1 -1
- package/lib/ai-key-crypto.es.js +63 -82
- package/lib/ai-key-verification.cjs.js +1 -1
- package/lib/ai-key-verification.es.js +74 -63
- package/lib/ai-model-catalog.cjs.js +1 -1
- package/lib/ai-model-catalog.es.js +18 -22
- package/lib/ai-model-registry.cjs.js +2 -2
- package/lib/ai-model-registry.es.js +246 -309
- package/lib/ai-seo-metadata.cjs.js +2 -3
- package/lib/ai-seo-metadata.es.js +143 -185
- package/lib/ai-vision.cjs.js +2 -2
- package/lib/ai-vision.d.ts +6 -6
- package/lib/ai-vision.es.js +161 -215
- package/lib/block-content-schemas.cjs.js +1 -1
- package/lib/block-content-schemas.es.js +324 -254
- package/lib/cortex-widget-registry.cjs.js +1 -1
- package/lib/cortex-widget-registry.es.js +35 -43
- package/lib/cortex-widget-schema.cjs.js +2 -3
- package/lib/cortex-widget-schema.es.js +280 -309
- package/lib/editor-document-from-html.cjs.js +1 -1
- package/lib/editor-document-from-html.es.js +334 -278
- package/lib/fetch-host-guard.cjs.js +1 -0
- package/lib/fetch-host-guard.d.ts +2 -0
- package/lib/fetch-host-guard.es.js +30 -0
- package/lib/mcp-server.cjs.js +1 -1
- package/lib/mcp-server.es.js +155 -173
- package/lib/mcp-tokens.cjs.js +1 -1
- package/lib/mcp-tokens.es.js +95 -107
- package/lib/mcp-tool-registry.cjs.js +5 -6
- package/lib/mcp-tool-registry.es.js +533 -411
- package/lib/site-brief.cjs.js +2 -2
- package/lib/site-brief.es.js +102 -108
- package/lib/vision-image-download.cjs.js +1 -0
- package/lib/vision-image-download.d.ts +43 -0
- package/lib/vision-image-download.es.js +120 -0
- package/lib/zod-config.cjs.js +1 -1
- package/lib/zod-config.es.js +5 -6
- 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 };
|
package/lib/mcp-server.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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;
|
package/lib/mcp-server.es.js
CHANGED
|
@@ -1,182 +1,164 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
36
|
-
|
|
49
|
+
function w(e) {
|
|
50
|
+
return typeof e != "string" || !e ? u : p.includes(e) ? e : d;
|
|
37
51
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
|
84
|
-
|
|
101
|
+
function D(e) {
|
|
102
|
+
return !!(e && e.toLowerCase().includes("text/event-stream"));
|
|
85
103
|
}
|
|
86
|
-
async function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
166
|
-
|
|
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 };
|
package/lib/mcp-tokens.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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;
|