@elementor/editor-mcp 3.35.0-340 → 3.35.0-341
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/dist/index.d.mts +4 -6
- package/dist/index.d.ts +4 -6
- package/dist/index.js +16 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
- package/src/mcp-registry.ts +14 -19
- package/src/sampler.ts +3 -0
package/dist/index.d.mts
CHANGED
|
@@ -30,13 +30,8 @@ interface MCPRegistryEntry {
|
|
|
30
30
|
mcpServer: McpServer;
|
|
31
31
|
}
|
|
32
32
|
type ResourceList = {
|
|
33
|
-
type: 'resource_link';
|
|
34
33
|
uri: string;
|
|
35
|
-
name: string;
|
|
36
34
|
description: string;
|
|
37
|
-
_meta: Record<string, string>;
|
|
38
|
-
mimeType?: string;
|
|
39
|
-
annotations?: Record<string, unknown>;
|
|
40
35
|
}[];
|
|
41
36
|
type ToolRegistrationOptions<InputArgs extends undefined | z.ZodRawShape = undefined, OutputSchema extends undefined | z.ZodRawShape = undefined, ExpectedOutput = OutputSchema extends z.ZodRawShape ? z.objectOutputType<OutputSchema, z.ZodTypeAny> : string> = {
|
|
42
37
|
name: string;
|
|
@@ -45,7 +40,7 @@ type ToolRegistrationOptions<InputArgs extends undefined | z.ZodRawShape = undef
|
|
|
45
40
|
outputSchema?: OutputSchema;
|
|
46
41
|
handler: InputArgs extends z.ZodRawShape ? (args: z.objectOutputType<InputArgs, z.ZodTypeAny>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => ExpectedOutput | Promise<ExpectedOutput> : (args: unknown, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => ExpectedOutput | Promise<ExpectedOutput>;
|
|
47
42
|
isDestrcutive?: boolean;
|
|
48
|
-
|
|
43
|
+
requiredResources?: ResourceList;
|
|
49
44
|
};
|
|
50
45
|
|
|
51
46
|
type Server = RequestHandlerExtra<ServerRequest, ServerNotification>;
|
|
@@ -64,6 +59,9 @@ type SamplingOpts = {
|
|
|
64
59
|
text: string;
|
|
65
60
|
};
|
|
66
61
|
}[];
|
|
62
|
+
requestParams?: {
|
|
63
|
+
[key: string]: string;
|
|
64
|
+
};
|
|
67
65
|
};
|
|
68
66
|
declare const createSampler: (server: Server, opts?: Opts) => (payload: SamplingOpts) => Promise<any>;
|
|
69
67
|
|
package/dist/index.d.ts
CHANGED
|
@@ -30,13 +30,8 @@ interface MCPRegistryEntry {
|
|
|
30
30
|
mcpServer: McpServer;
|
|
31
31
|
}
|
|
32
32
|
type ResourceList = {
|
|
33
|
-
type: 'resource_link';
|
|
34
33
|
uri: string;
|
|
35
|
-
name: string;
|
|
36
34
|
description: string;
|
|
37
|
-
_meta: Record<string, string>;
|
|
38
|
-
mimeType?: string;
|
|
39
|
-
annotations?: Record<string, unknown>;
|
|
40
35
|
}[];
|
|
41
36
|
type ToolRegistrationOptions<InputArgs extends undefined | z.ZodRawShape = undefined, OutputSchema extends undefined | z.ZodRawShape = undefined, ExpectedOutput = OutputSchema extends z.ZodRawShape ? z.objectOutputType<OutputSchema, z.ZodTypeAny> : string> = {
|
|
42
37
|
name: string;
|
|
@@ -45,7 +40,7 @@ type ToolRegistrationOptions<InputArgs extends undefined | z.ZodRawShape = undef
|
|
|
45
40
|
outputSchema?: OutputSchema;
|
|
46
41
|
handler: InputArgs extends z.ZodRawShape ? (args: z.objectOutputType<InputArgs, z.ZodTypeAny>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => ExpectedOutput | Promise<ExpectedOutput> : (args: unknown, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => ExpectedOutput | Promise<ExpectedOutput>;
|
|
47
42
|
isDestrcutive?: boolean;
|
|
48
|
-
|
|
43
|
+
requiredResources?: ResourceList;
|
|
49
44
|
};
|
|
50
45
|
|
|
51
46
|
type Server = RequestHandlerExtra<ServerRequest, ServerNotification>;
|
|
@@ -64,6 +59,9 @@ type SamplingOpts = {
|
|
|
64
59
|
text: string;
|
|
65
60
|
};
|
|
66
61
|
}[];
|
|
62
|
+
requestParams?: {
|
|
63
|
+
[key: string]: string;
|
|
64
|
+
};
|
|
67
65
|
};
|
|
68
66
|
declare const createSampler: (server: Server, opts?: Opts) => (payload: SamplingOpts) => Promise<any>;
|
|
69
67
|
|
package/dist/index.js
CHANGED
|
@@ -69,9 +69,6 @@ var mcpRegistry = {};
|
|
|
69
69
|
var mcpDescriptions = {};
|
|
70
70
|
var isMcpRegistrationActivated = typeof globalThis.jest !== "undefined";
|
|
71
71
|
var registerMcp = (mcp, name) => {
|
|
72
|
-
if (isMcpRegistrationActivated) {
|
|
73
|
-
throw new Error("MCP Registration is already activated. Cannot register new MCP servers.");
|
|
74
|
-
}
|
|
75
72
|
const mcpName = isAlphabet(name);
|
|
76
73
|
mcpRegistry[mcpName] = mcp;
|
|
77
74
|
};
|
|
@@ -83,7 +80,7 @@ async function activateMcpRegistration(sdk2) {
|
|
|
83
80
|
const mcpServerList = Object.entries(mcpRegistry);
|
|
84
81
|
for await (const entry of mcpServerList) {
|
|
85
82
|
const [key, mcpServer] = entry;
|
|
86
|
-
await sdk2.
|
|
83
|
+
await sdk2.registerLocalServer({
|
|
87
84
|
name: `editor-${key}`,
|
|
88
85
|
server: mcpServer,
|
|
89
86
|
version: "1.0.0",
|
|
@@ -142,9 +139,6 @@ function createToolRegistrator(server) {
|
|
|
142
139
|
function addTool(opts) {
|
|
143
140
|
const outputSchema = opts.outputSchema;
|
|
144
141
|
const inputSchema = opts.schema ? opts.schema : {};
|
|
145
|
-
if (isMcpRegistrationActivated) {
|
|
146
|
-
throw new Error("MCP Registration is already activated. Cannot add new tools.");
|
|
147
|
-
}
|
|
148
142
|
const toolCallback = async function(args, extra) {
|
|
149
143
|
try {
|
|
150
144
|
const invocationResult = await opts.handler(opts.schema ? args : {}, extra);
|
|
@@ -154,8 +148,7 @@ function createToolRegistrator(server) {
|
|
|
154
148
|
{
|
|
155
149
|
type: "text",
|
|
156
150
|
text: typeof invocationResult === "string" ? invocationResult : JSON.stringify(invocationResult)
|
|
157
|
-
}
|
|
158
|
-
...opts.resourceList || []
|
|
151
|
+
}
|
|
159
152
|
]
|
|
160
153
|
};
|
|
161
154
|
} catch (error) {
|
|
@@ -170,6 +163,14 @@ function createToolRegistrator(server) {
|
|
|
170
163
|
};
|
|
171
164
|
}
|
|
172
165
|
};
|
|
166
|
+
const annotations = {
|
|
167
|
+
destructiveHint: opts.isDestrcutive,
|
|
168
|
+
readOnlyHint: opts.isDestrcutive ? false : void 0,
|
|
169
|
+
title: opts.name
|
|
170
|
+
};
|
|
171
|
+
if (opts.requiredResources) {
|
|
172
|
+
annotations["angie/requiredResources"] = opts.requiredResources;
|
|
173
|
+
}
|
|
173
174
|
server.registerTool(
|
|
174
175
|
opts.name,
|
|
175
176
|
{
|
|
@@ -177,14 +178,13 @@ function createToolRegistrator(server) {
|
|
|
177
178
|
inputSchema,
|
|
178
179
|
outputSchema,
|
|
179
180
|
title: opts.name,
|
|
180
|
-
annotations
|
|
181
|
-
destructiveHint: opts.isDestrcutive,
|
|
182
|
-
readOnlyHint: opts.isDestrcutive ? false : void 0,
|
|
183
|
-
title: opts.name
|
|
184
|
-
}
|
|
181
|
+
annotations
|
|
185
182
|
},
|
|
186
183
|
toolCallback
|
|
187
184
|
);
|
|
185
|
+
if (isMcpRegistrationActivated) {
|
|
186
|
+
server.sendToolListChanged();
|
|
187
|
+
}
|
|
188
188
|
}
|
|
189
189
|
return {
|
|
190
190
|
addTool
|
|
@@ -251,10 +251,12 @@ var createSampler = (server, opts = DEFAULT_OPTS) => {
|
|
|
251
251
|
const { maxTokens = 1e3, modelPreferences = "openai", model = "gpt-4o" } = opts;
|
|
252
252
|
const exec = async (payload) => {
|
|
253
253
|
const systemPromptObject = { ...payload.systemPrompt ? { systemPrompt: payload.systemPrompt } : {} };
|
|
254
|
+
const requestParams = payload.requestParams || {};
|
|
254
255
|
const result = await server.sendRequest(
|
|
255
256
|
{
|
|
256
257
|
method: "sampling/createMessage",
|
|
257
258
|
params: {
|
|
259
|
+
...requestParams,
|
|
258
260
|
maxTokens,
|
|
259
261
|
modelPreferences: {
|
|
260
262
|
hints: [{ name: modelPreferences }]
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/init.ts","../src/mcp-registry.ts","../src/test-utils/mock-mcp-registry.ts","../src/sampler.ts","../src/utils/prompt-builder.ts"],"sourcesContent":["import { getSDK } from './init';\n\nexport {\n\tMcpServer,\n\tResourceTemplate,\n\ttype RegisteredResource,\n\ttype ToolCallback,\n} from '@modelcontextprotocol/sdk/server/mcp.js';\nexport { SamplingMessageSchema } from '@modelcontextprotocol/sdk/types.js';\nexport { init } from './init';\nexport * from './mcp-registry';\nexport { createSampler } from './sampler';\nexport { toolPrompts } from './utils/prompt-builder';\nexport const getAngieSdk = () => getSDK();\n","import { isExperimentActive } from '@elementor/editor-v1-adapters';\nimport { AngieMcpSdk } from '@elementor-external/angie-sdk';\n\nimport { activateMcpRegistration } from './mcp-registry';\n\nlet sdk: AngieMcpSdk;\n\nexport const getSDK = () => {\n\t// @ts-ignore - QUnit fails this\n\tconst isMCPDisabled = !! ( globalThis as Record< string, unknown > ).__ELEMENTOR_MCP_DISABLED__;\n\tif ( isMCPDisabled ) {\n\t\treturn {} as unknown as AngieMcpSdk;\n\t}\n\tif ( ! sdk ) {\n\t\tsdk = new AngieMcpSdk();\n\t}\n\treturn sdk;\n};\n\nexport function init() {\n\tif ( isExperimentActive( 'editor_mcp' ) ) {\n\t\treturn getSDK().waitForReady();\n\t}\n\treturn Promise.resolve();\n}\n\nexport function startMCPServer() {\n\tif ( isExperimentActive( 'editor_mcp' ) ) {\n\t\treturn getSDK()\n\t\t\t.waitForReady()\n\t\t\t.then( () => activateMcpRegistration( sdk ) );\n\t}\n\treturn Promise.resolve();\n}\n\ndocument.addEventListener(\n\t'DOMContentLoaded',\n\t() => {\n\t\tstartMCPServer();\n\t},\n\t{\n\t\tonce: true,\n\t}\n);\n","import { type z, type z3 } from '@elementor/schema';\nimport { type AngieMcpSdk } from '@elementor-external/angie-sdk';\nimport { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\nimport { mockMcpRegistry } from './test-utils/mock-mcp-registry';\n\ntype ZodRawShape = z3.ZodRawShape;\n\nconst mcpRegistry: { [ namespace: string ]: McpServer } = {};\nconst mcpDescriptions: { [ namespace: string ]: string } = {};\n// @ts-ignore - QUnit fails this\nlet isMcpRegistrationActivated = false || typeof globalThis.jest !== 'undefined';\n\nexport const registerMcp = ( mcp: McpServer, name: string ) => {\n\tif ( isMcpRegistrationActivated ) {\n\t\tthrow new Error( 'MCP Registration is already activated. Cannot register new MCP servers.' );\n\t}\n\tconst mcpName = isAlphabet( name );\n\tmcpRegistry[ mcpName ] = mcp;\n};\n\nexport async function activateMcpRegistration( sdk: AngieMcpSdk ) {\n\tif ( isMcpRegistrationActivated ) {\n\t\treturn;\n\t}\n\tisMcpRegistrationActivated = true;\n\tconst mcpServerList = Object.entries( mcpRegistry );\n\tfor await ( const entry of mcpServerList ) {\n\t\tconst [ key, mcpServer ] = entry;\n\t\tawait sdk.registerServer( {\n\t\t\tname: `editor-${ key }`,\n\t\t\tserver: mcpServer,\n\t\t\tversion: '1.0.0',\n\t\t\tdescription: mcpDescriptions[ key ] || key,\n\t\t} );\n\t}\n}\n\nconst isAlphabet = ( str: string ): string | never => {\n\tconst passes = !! str && /^[a-z_]+$/.test( str );\n\tif ( ! passes ) {\n\t\tthrow new Error( 'Not alphabet' );\n\t}\n\treturn str;\n};\n\n/**\n *\n * @param namespace The namespace of the MCP server. It should contain only lowercase alphabetic characters.\n * @param options\n * @param options.instructions\n */\nexport const getMCPByDomain = ( namespace: string, options?: { instructions?: string } ): MCPRegistryEntry => {\n\tconst mcpName = `editor-${ isAlphabet( namespace ) }`;\n\t// @ts-ignore - QUnit fails this\n\tif ( typeof globalThis.jest !== 'undefined' ) {\n\t\treturn mockMcpRegistry();\n\t}\n\tif ( ! mcpRegistry[ namespace ] ) {\n\t\tmcpRegistry[ namespace ] = new McpServer(\n\t\t\t{\n\t\t\t\tname: mcpName,\n\t\t\t\tversion: '1.0.0',\n\t\t\t},\n\t\t\t{\n\t\t\t\tinstructions: options?.instructions,\n\t\t\t}\n\t\t);\n\t}\n\tconst mcpServer = mcpRegistry[ namespace ];\n\tconst { addTool } = createToolRegistrator( mcpServer );\n\treturn {\n\t\tmcpServer,\n\t\taddTool,\n\t\tsetMCPDescription: ( description: string ) => {\n\t\t\tmcpDescriptions[ namespace ] = description;\n\t\t},\n\t\tgetActiveChatInfo: () => {\n\t\t\tconst info = localStorage.getItem( 'angie_active_chat_id' );\n\t\t\tif ( ! info ) {\n\t\t\t\treturn {\n\t\t\t\t\texpiresAt: 0,\n\t\t\t\t\tsessionId: '',\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst rawData = JSON.parse( info );\n\t\t\treturn {\n\t\t\t\texpiresAt: rawData.expiresAt as number,\n\t\t\t\tsessionId: rawData.sessionId as string,\n\t\t\t};\n\t\t},\n\t};\n};\n\nexport interface MCPRegistryEntry {\n\taddTool: < T extends undefined | z.ZodRawShape = undefined, O extends undefined | z.ZodRawShape = undefined >(\n\t\topts: ToolRegistrationOptions< T, O >\n\t) => void;\n\tsetMCPDescription: ( description: string ) => void;\n\tgetActiveChatInfo: () => { sessionId: string; expiresAt: number };\n\tmcpServer: McpServer;\n}\n\ntype ResourceList = {\n\ttype: 'resource_link';\n\turi: string;\n\tname: string;\n\tdescription: string;\n\t_meta: Record< string, string >;\n\tmimeType?: string;\n\tannotations?: Record< string, unknown >;\n}[];\n\ntype ToolRegistrationOptions<\n\tInputArgs extends undefined | z.ZodRawShape = undefined,\n\tOutputSchema extends undefined | z.ZodRawShape = undefined,\n\tExpectedOutput = OutputSchema extends z.ZodRawShape ? z.objectOutputType< OutputSchema, z.ZodTypeAny > : string,\n> = {\n\tname: string;\n\tdescription: string;\n\tschema?: InputArgs;\n\toutputSchema?: OutputSchema;\n\thandler: InputArgs extends z.ZodRawShape\n\t\t? (\n\t\t\t\targs: z.objectOutputType< InputArgs, z.ZodTypeAny >,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >\n\t\t: (\n\t\t\t\targs: unknown,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >;\n\tisDestrcutive?: boolean;\n\tresourceList?: ResourceList;\n};\n\nfunction createToolRegistrator( server: McpServer ) {\n\tfunction addTool<\n\t\tT extends undefined | z.ZodRawShape = undefined,\n\t\tO extends undefined | z.ZodRawShape = undefined,\n\t>( opts: ToolRegistrationOptions< T, O > ) {\n\t\tconst outputSchema = opts.outputSchema as ZodRawShape | undefined;\n\t\t// @ts-ignore: TS is unable to infer the type here\n\t\tconst inputSchema: ZodRawShape = opts.schema ? opts.schema : {};\n\t\tif ( isMcpRegistrationActivated ) {\n\t\t\tthrow new Error( 'MCP Registration is already activated. Cannot add new tools.' );\n\t\t}\n\t\tconst toolCallback: ToolCallback< ZodRawShape > = async function ( args, extra ) {\n\t\t\ttry {\n\t\t\t\tconst invocationResult = await opts.handler( opts.schema ? args : {}, extra );\n\t\t\t\treturn {\n\t\t\t\t\tstructuredContent: typeof invocationResult === 'string' ? undefined : invocationResult,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\t\ttypeof invocationResult === 'string'\n\t\t\t\t\t\t\t\t\t? invocationResult\n\t\t\t\t\t\t\t\t\t: JSON.stringify( invocationResult ),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...( opts.resourceList || [] ),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t} catch ( error ) {\n\t\t\t\treturn {\n\t\t\t\t\tisError: true,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext: ( error as Error ).message || 'Unknown error',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\t\tserver.registerTool(\n\t\t\topts.name,\n\t\t\t{\n\t\t\t\tdescription: opts.description,\n\t\t\t\tinputSchema,\n\t\t\t\toutputSchema,\n\t\t\t\ttitle: opts.name,\n\t\t\t\tannotations: {\n\t\t\t\t\tdestructiveHint: opts.isDestrcutive,\n\t\t\t\t\treadOnlyHint: opts.isDestrcutive ? false : undefined,\n\t\t\t\t\ttitle: opts.name,\n\t\t\t\t},\n\t\t\t},\n\t\t\ttoolCallback\n\t\t);\n\t}\n\treturn {\n\t\taddTool,\n\t};\n}\n","import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n\nimport { type MCPRegistryEntry } from '../mcp-registry';\n\nconst mock = new Proxy(\n\t{},\n\t{\n\t\tget: () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\tfunction mockedFn( ..._: unknown[] ) {}\n\t\t\treturn mockedFn;\n\t\t},\n\t}\n);\n\nexport const mockMcpRegistry = (): MCPRegistryEntry => {\n\treturn {\n\t\taddTool: () => {},\n\t\tsetMCPDescription: () => {},\n\t\tgetActiveChatInfo() {\n\t\t\treturn { sessionId: 'mock-session-id', expiresAt: Date.now() + 3600000 };\n\t\t},\n\t\tmcpServer: mock as McpServer,\n\t};\n};\n","import { type z } from '@elementor/schema';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { SamplingMessageSchema, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\ntype Server = RequestHandlerExtra< ServerRequest, ServerNotification >;\ntype Opts = {\n\tmaxTokens?: number;\n\tmodelPreferences?: string;\n\tmodel?: string;\n};\n\nconst DEFAULT_OPTS: Opts = {\n\tmaxTokens: 10000,\n\tmodelPreferences: 'openai',\n\tmodel: 'gpt-4o',\n};\n\ntype SamplingOpts = {\n\tsystemPrompt?: string;\n\tstructuredOutput?: z.ZodTypeAny;\n\tmessages: { role: 'user' | 'assistant'; content: { type: 'text'; text: string } }[];\n};\n\nconst DEFAULT_STRUCTURED_OUTPUT = {\n\ttype: 'object',\n\tproperties: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tdescription: 'Result',\n\t\t},\n\t},\n\trequired: [ 'content' ],\n\tadditionalProperties: false,\n};\n\nexport const createSampler = ( server: Server, opts: Opts = DEFAULT_OPTS ) => {\n\tconst { maxTokens = 1000, modelPreferences = 'openai', model = 'gpt-4o' } = opts;\n\tconst exec = async ( payload: SamplingOpts ) => {\n\t\tconst systemPromptObject = { ...( payload.systemPrompt ? { systemPrompt: payload.systemPrompt } : {} ) };\n\t\tconst result = await server.sendRequest(\n\t\t\t{\n\t\t\t\tmethod: 'sampling/createMessage',\n\t\t\t\tparams: {\n\t\t\t\t\tmaxTokens,\n\t\t\t\t\tmodelPreferences: {\n\t\t\t\t\t\thints: [ { name: modelPreferences } ],\n\t\t\t\t\t},\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t...systemPromptObject,\n\t\t\t\t\t\t...{ structured_output: payload.structuredOutput || DEFAULT_STRUCTURED_OUTPUT },\n\t\t\t\t\t},\n\t\t\t\t\tmessages: payload.messages,\n\t\t\t\t},\n\t\t\t\t// ...systemPromptObject,\n\t\t\t},\n\t\t\tSamplingMessageSchema\n\t\t);\n\t\ttry {\n\t\t\treturn JSON.parse( result.content.text as string );\n\t\t} catch {\n\t\t\treturn result.content;\n\t\t}\n\t};\n\treturn exec;\n};\n","class ToolPrompts {\n\tpublic _description = '';\n\tpublic _parameters: Record< string, string > = {};\n\tpublic _examples: string[] = [];\n\tpublic _furtherInstructions: string[] = [];\n\n\tconstructor( public name: string ) {}\n\n\tdescription(): string;\n\tdescription( desc: string ): this;\n\tdescription( desc?: string | undefined ) {\n\t\tif ( typeof desc === 'undefined' ) {\n\t\t\treturn this._description;\n\t\t}\n\t\tthis._description = desc;\n\t\treturn this;\n\t}\n\n\tparameter( key: string ): string;\n\tparameter( key: string, description: string ): this;\n\tparameter( key: string, description?: string ) {\n\t\tif ( typeof description === 'undefined' ) {\n\t\t\treturn this._parameters[ key ];\n\t\t}\n\t\tthis._parameters[ key ] = `**${ key }**:\\n${ description }`;\n\t\treturn this;\n\t}\n\n\tinstruction( instruction: string ): this {\n\t\tthis._furtherInstructions.push( instruction );\n\t\treturn this;\n\t}\n\n\texample( example: string ): this {\n\t\tthis._examples.push( example );\n\t\treturn this;\n\t}\n\n\tpublic get examples() {\n\t\treturn this._examples.join( '\\n\\n' );\n\t}\n\n\tprompt(): string {\n\t\treturn `# ${ this.name }\n# Description\n${ this._description }\n\n${ this._parameters.length ? '# Parameters' : '' }\n${ Object.values( this._parameters ).join( '\\n\\n' ) }\n\n${ this._examples.length ? '# Examples' : '' }\n${ this.examples }\n\n${ this._furtherInstructions.length ? '# Further Instructions' : '' }\n${ this._furtherInstructions.join( '\\n\\n' ) }\n`.trim();\n\t}\n}\n\nexport const toolPrompts = ( name: string ) => {\n\treturn new ToolPrompts( name );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gCAAmC;AACnC,uBAA4B;;;ACC5B,iBAA6C;;;ACE7C,IAAM,OAAO,IAAI;AAAA,EAChB,CAAC;AAAA,EACD;AAAA,IACC,KAAK,MAAM;AAEV,eAAS,YAAa,GAAe;AAAA,MAAC;AACtC,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEO,IAAM,kBAAkB,MAAwB;AACtD,SAAO;A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I,IAAI,KAAM,GAAI;AAAA,EAAS,WAAY;AACzD,WAAO;AAAA,EACR;AAAA,EAEA,YAAa,aAA4B;AACxC,SAAK,qBAAqB,KAAM,WAAY;AAC5C,WAAO;AAAA,EACR;AAAA,EAEA,QAAS,SAAwB;AAChC,SAAK,UAAU,KAAM,OAAQ;AAC7B,WAAO;AAAA,EACR;AAAA,EAEA,IAAW,WAAW;AACrB,WAAO,KAAK,UAAU,KAAM,MAAO;AAAA,EACpC;AAAA,EAEA,SAAiB;AAChB,WAAO,KAAM,KAAK,IAAK;AAAA;AAAA,EAEtB,KAAK,YAAa;AAAA;AAAA,EAElB,KAAK,YAAY,SAAS,iBAAiB,EAAG;AAAA,EAC9C,OAAO,OAAQ,KAAK,WAAY,EAAE,KAAM,MAAO,CAAE;AAAA;AAAA,EAEjD,KAAK,UAAU,SAAS,eAAe,EAAG;AAAA,EAC1C,KAAK,QAAS;AAAA;AAAA,EAEd,KAAK,qBAAqB,SAAS,2BAA2B,EAAG;AAAA,EACjE,KAAK,qBAAqB,KAAM,MAAO,CAAE;AAAA,EAC1C,KAAK;AAAA,EACN;AACD;AAEO,IAAM,cAAc,CAAE,SAAkB;AAC9C,SAAO,IAAI,YAAa,IAAK;AAC9B;;;ALhDO,IAAM,cAAc,MAAM,OAAO;","names":["sdk","import_mcp","import_types"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/init.ts","../src/mcp-registry.ts","../src/test-utils/mock-mcp-registry.ts","../src/sampler.ts","../src/utils/prompt-builder.ts"],"sourcesContent":["import { getSDK } from './init';\n\nexport {\n\tMcpServer,\n\tResourceTemplate,\n\ttype RegisteredResource,\n\ttype ToolCallback,\n} from '@modelcontextprotocol/sdk/server/mcp.js';\nexport { SamplingMessageSchema } from '@modelcontextprotocol/sdk/types.js';\nexport { init } from './init';\nexport * from './mcp-registry';\nexport { createSampler } from './sampler';\nexport { toolPrompts } from './utils/prompt-builder';\nexport const getAngieSdk = () => getSDK();\n","import { isExperimentActive } from '@elementor/editor-v1-adapters';\nimport { AngieMcpSdk } from '@elementor-external/angie-sdk';\n\nimport { activateMcpRegistration } from './mcp-registry';\n\nlet sdk: AngieMcpSdk;\n\nexport const getSDK = () => {\n\t// @ts-ignore - QUnit fails this\n\tconst isMCPDisabled = !! ( globalThis as Record< string, unknown > ).__ELEMENTOR_MCP_DISABLED__;\n\tif ( isMCPDisabled ) {\n\t\treturn {} as unknown as AngieMcpSdk;\n\t}\n\tif ( ! sdk ) {\n\t\tsdk = new AngieMcpSdk();\n\t}\n\treturn sdk;\n};\n\nexport function init() {\n\tif ( isExperimentActive( 'editor_mcp' ) ) {\n\t\treturn getSDK().waitForReady();\n\t}\n\treturn Promise.resolve();\n}\n\nexport function startMCPServer() {\n\tif ( isExperimentActive( 'editor_mcp' ) ) {\n\t\treturn getSDK()\n\t\t\t.waitForReady()\n\t\t\t.then( () => activateMcpRegistration( sdk ) );\n\t}\n\treturn Promise.resolve();\n}\n\ndocument.addEventListener(\n\t'DOMContentLoaded',\n\t() => {\n\t\tstartMCPServer();\n\t},\n\t{\n\t\tonce: true,\n\t}\n);\n","import { type z, type z3 } from '@elementor/schema';\nimport { type AngieMcpSdk } from '@elementor-external/angie-sdk';\nimport { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\nimport { mockMcpRegistry } from './test-utils/mock-mcp-registry';\n\ntype ZodRawShape = z3.ZodRawShape;\n\nconst mcpRegistry: { [ namespace: string ]: McpServer } = {};\nconst mcpDescriptions: { [ namespace: string ]: string } = {};\n// @ts-ignore - QUnit fails this\nlet isMcpRegistrationActivated = false || typeof globalThis.jest !== 'undefined';\n\nexport const registerMcp = ( mcp: McpServer, name: string ) => {\n\tconst mcpName = isAlphabet( name );\n\tmcpRegistry[ mcpName ] = mcp;\n};\n\nexport async function activateMcpRegistration( sdk: AngieMcpSdk ) {\n\tif ( isMcpRegistrationActivated ) {\n\t\treturn;\n\t}\n\tisMcpRegistrationActivated = true;\n\tconst mcpServerList = Object.entries( mcpRegistry );\n\tfor await ( const entry of mcpServerList ) {\n\t\tconst [ key, mcpServer ] = entry;\n\t\tawait sdk.registerLocalServer( {\n\t\t\tname: `editor-${ key }`,\n\t\t\tserver: mcpServer,\n\t\t\tversion: '1.0.0',\n\t\t\tdescription: mcpDescriptions[ key ] || key,\n\t\t} );\n\t}\n}\n\nconst isAlphabet = ( str: string ): string | never => {\n\tconst passes = !! str && /^[a-z_]+$/.test( str );\n\tif ( ! passes ) {\n\t\tthrow new Error( 'Not alphabet' );\n\t}\n\treturn str;\n};\n\n/**\n *\n * @param namespace The namespace of the MCP server. It should contain only lowercase alphabetic characters.\n * @param options\n * @param options.instructions\n */\nexport const getMCPByDomain = ( namespace: string, options?: { instructions?: string } ): MCPRegistryEntry => {\n\tconst mcpName = `editor-${ isAlphabet( namespace ) }`;\n\t// @ts-ignore - QUnit fails this\n\tif ( typeof globalThis.jest !== 'undefined' ) {\n\t\treturn mockMcpRegistry();\n\t}\n\tif ( ! mcpRegistry[ namespace ] ) {\n\t\tmcpRegistry[ namespace ] = new McpServer(\n\t\t\t{\n\t\t\t\tname: mcpName,\n\t\t\t\tversion: '1.0.0',\n\t\t\t},\n\t\t\t{\n\t\t\t\tinstructions: options?.instructions,\n\t\t\t}\n\t\t);\n\t}\n\tconst mcpServer = mcpRegistry[ namespace ];\n\tconst { addTool } = createToolRegistrator( mcpServer );\n\treturn {\n\t\tmcpServer,\n\t\taddTool,\n\t\tsetMCPDescription: ( description: string ) => {\n\t\t\tmcpDescriptions[ namespace ] = description;\n\t\t},\n\t\tgetActiveChatInfo: () => {\n\t\t\tconst info = localStorage.getItem( 'angie_active_chat_id' );\n\t\t\tif ( ! info ) {\n\t\t\t\treturn {\n\t\t\t\t\texpiresAt: 0,\n\t\t\t\t\tsessionId: '',\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst rawData = JSON.parse( info );\n\t\t\treturn {\n\t\t\t\texpiresAt: rawData.expiresAt as number,\n\t\t\t\tsessionId: rawData.sessionId as string,\n\t\t\t};\n\t\t},\n\t};\n};\n\nexport interface MCPRegistryEntry {\n\taddTool: < T extends undefined | z.ZodRawShape = undefined, O extends undefined | z.ZodRawShape = undefined >(\n\t\topts: ToolRegistrationOptions< T, O >\n\t) => void;\n\tsetMCPDescription: ( description: string ) => void;\n\tgetActiveChatInfo: () => { sessionId: string; expiresAt: number };\n\tmcpServer: McpServer;\n}\n\ntype ResourceList = {\n\turi: string;\n\tdescription: string;\n}[];\n\ntype ToolRegistrationOptions<\n\tInputArgs extends undefined | z.ZodRawShape = undefined,\n\tOutputSchema extends undefined | z.ZodRawShape = undefined,\n\tExpectedOutput = OutputSchema extends z.ZodRawShape ? z.objectOutputType< OutputSchema, z.ZodTypeAny > : string,\n> = {\n\tname: string;\n\tdescription: string;\n\tschema?: InputArgs;\n\toutputSchema?: OutputSchema;\n\thandler: InputArgs extends z.ZodRawShape\n\t\t? (\n\t\t\t\targs: z.objectOutputType< InputArgs, z.ZodTypeAny >,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >\n\t\t: (\n\t\t\t\targs: unknown,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >;\n\tisDestrcutive?: boolean;\n\trequiredResources?: ResourceList;\n};\n\nfunction createToolRegistrator( server: McpServer ) {\n\tfunction addTool<\n\t\tT extends undefined | z.ZodRawShape = undefined,\n\t\tO extends undefined | z.ZodRawShape = undefined,\n\t>( opts: ToolRegistrationOptions< T, O > ) {\n\t\tconst outputSchema = opts.outputSchema as ZodRawShape | undefined;\n\t\t// @ts-ignore: TS is unable to infer the type here\n\t\tconst inputSchema: ZodRawShape = opts.schema ? opts.schema : {};\n\t\tconst toolCallback: ToolCallback< ZodRawShape > = async function ( args, extra ) {\n\t\t\ttry {\n\t\t\t\tconst invocationResult = await opts.handler( opts.schema ? args : {}, extra );\n\t\t\t\treturn {\n\t\t\t\t\tstructuredContent: typeof invocationResult === 'string' ? undefined : invocationResult,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\t\ttypeof invocationResult === 'string'\n\t\t\t\t\t\t\t\t\t? invocationResult\n\t\t\t\t\t\t\t\t\t: JSON.stringify( invocationResult ),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t} catch ( error ) {\n\t\t\t\treturn {\n\t\t\t\t\tisError: true,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext: ( error as Error ).message || 'Unknown error',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\t\tconst annotations: Record< string, unknown > = {\n\t\t\tdestructiveHint: opts.isDestrcutive,\n\t\t\treadOnlyHint: opts.isDestrcutive ? false : undefined,\n\t\t\ttitle: opts.name,\n\t\t};\n\t\tif ( opts.requiredResources ) {\n\t\t\tannotations[ 'angie/requiredResources' ] = opts.requiredResources;\n\t\t}\n\t\tserver.registerTool(\n\t\t\topts.name,\n\t\t\t{\n\t\t\t\tdescription: opts.description,\n\t\t\t\tinputSchema,\n\t\t\t\toutputSchema,\n\t\t\t\ttitle: opts.name,\n\t\t\t\tannotations,\n\t\t\t},\n\t\t\ttoolCallback\n\t\t);\n\t\tif ( isMcpRegistrationActivated ) {\n\t\t\tserver.sendToolListChanged();\n\t\t}\n\t}\n\treturn {\n\t\taddTool,\n\t};\n}\n","import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n\nimport { type MCPRegistryEntry } from '../mcp-registry';\n\nconst mock = new Proxy(\n\t{},\n\t{\n\t\tget: () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\tfunction mockedFn( ..._: unknown[] ) {}\n\t\t\treturn mockedFn;\n\t\t},\n\t}\n);\n\nexport const mockMcpRegistry = (): MCPRegistryEntry => {\n\treturn {\n\t\taddTool: () => {},\n\t\tsetMCPDescription: () => {},\n\t\tgetActiveChatInfo() {\n\t\t\treturn { sessionId: 'mock-session-id', expiresAt: Date.now() + 3600000 };\n\t\t},\n\t\tmcpServer: mock as McpServer,\n\t};\n};\n","import { type z } from '@elementor/schema';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { SamplingMessageSchema, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\ntype Server = RequestHandlerExtra< ServerRequest, ServerNotification >;\ntype Opts = {\n\tmaxTokens?: number;\n\tmodelPreferences?: string;\n\tmodel?: string;\n};\n\nconst DEFAULT_OPTS: Opts = {\n\tmaxTokens: 10000,\n\tmodelPreferences: 'openai',\n\tmodel: 'gpt-4o',\n};\n\ntype SamplingOpts = {\n\tsystemPrompt?: string;\n\tstructuredOutput?: z.ZodTypeAny;\n\tmessages: { role: 'user' | 'assistant'; content: { type: 'text'; text: string } }[];\n\trequestParams?: { [ key: string ]: string };\n};\n\nconst DEFAULT_STRUCTURED_OUTPUT = {\n\ttype: 'object',\n\tproperties: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tdescription: 'Result',\n\t\t},\n\t},\n\trequired: [ 'content' ],\n\tadditionalProperties: false,\n};\n\nexport const createSampler = ( server: Server, opts: Opts = DEFAULT_OPTS ) => {\n\tconst { maxTokens = 1000, modelPreferences = 'openai', model = 'gpt-4o' } = opts;\n\tconst exec = async ( payload: SamplingOpts ) => {\n\t\tconst systemPromptObject = { ...( payload.systemPrompt ? { systemPrompt: payload.systemPrompt } : {} ) };\n\t\tconst requestParams = payload.requestParams || {};\n\t\tconst result = await server.sendRequest(\n\t\t\t{\n\t\t\t\tmethod: 'sampling/createMessage',\n\t\t\t\tparams: {\n\t\t\t\t\t...requestParams,\n\t\t\t\t\tmaxTokens,\n\t\t\t\t\tmodelPreferences: {\n\t\t\t\t\t\thints: [ { name: modelPreferences } ],\n\t\t\t\t\t},\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t...systemPromptObject,\n\t\t\t\t\t\t...{ structured_output: payload.structuredOutput || DEFAULT_STRUCTURED_OUTPUT },\n\t\t\t\t\t},\n\t\t\t\t\tmessages: payload.messages,\n\t\t\t\t},\n\t\t\t\t// ...systemPromptObject,\n\t\t\t},\n\t\t\tSamplingMessageSchema\n\t\t);\n\t\ttry {\n\t\t\treturn JSON.parse( result.content.text as string );\n\t\t} catch {\n\t\t\treturn result.content;\n\t\t}\n\t};\n\treturn exec;\n};\n","class ToolPrompts {\n\tpublic _description = '';\n\tpublic _parameters: Record< string, string > = {};\n\tpublic _examples: string[] = [];\n\tpublic _furtherInstructions: string[] = [];\n\n\tconstructor( public name: string ) {}\n\n\tdescription(): string;\n\tdescription( desc: string ): this;\n\tdescription( desc?: string | undefined ) {\n\t\tif ( typeof desc === 'undefined' ) {\n\t\t\treturn this._description;\n\t\t}\n\t\tthis._description = desc;\n\t\treturn this;\n\t}\n\n\tparameter( key: string ): string;\n\tparameter( key: string, description: string ): this;\n\tparameter( key: string, description?: string ) {\n\t\tif ( typeof description === 'undefined' ) {\n\t\t\treturn this._parameters[ key ];\n\t\t}\n\t\tthis._parameters[ key ] = `**${ key }**:\\n${ description }`;\n\t\treturn this;\n\t}\n\n\tinstruction( instruction: string ): this {\n\t\tthis._furtherInstructions.push( instruction );\n\t\treturn this;\n\t}\n\n\texample( example: string ): this {\n\t\tthis._examples.push( example );\n\t\treturn this;\n\t}\n\n\tpublic get examples() {\n\t\treturn this._examples.join( '\\n\\n' );\n\t}\n\n\tprompt(): string {\n\t\treturn `# ${ this.name }\n# Description\n${ this._description }\n\n${ this._parameters.length ? '# Parameters' : '' }\n${ Object.values( this._parameters ).join( '\\n\\n' ) }\n\n${ this._examples.length ? '# Examples' : '' }\n${ this.examples }\n\n${ this._furtherInstructions.length ? '# Further Instructions' : '' }\n${ this._furtherInstructions.join( '\\n\\n' ) }\n`.trim();\n\t}\n}\n\nexport const toolPrompts = ( name: string ) => {\n\treturn new ToolPrompts( name );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gCAAmC;AACnC,uBAA4B;;;ACC5B,iBAA6C;;;ACE7C,IAAM,OAAO,IAAI;AAAA,EAChB,CAAC;AAAA,EACD;AAAA,IACC,KAAK,MAAM;AAEV,eAAS,YAAa,GAAe;AAAA,MAAC;AACtC,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEO,IAAM,kBAAkB,MAAwB;AACtD,SAAO;AAAA,IACN,SAAS,MAAM;AAAA,IAAC;AAAA,IAChB,mBAAmB,MAAM;AAAA,IAAC;AAAA,IAC1B,oBAAoB;AACnB,aAAO,EAAE,WAAW,mBAAmB,WAAW,KAAK,IAAI,IAAI,KAAQ;AAAA,IACxE;AAAA,IACA,WAAW;AAAA,EACZ;AACD;;;ADdA,IAAM,cAAoD,CAAC;AAC3D,IAAM,kBAAqD,CAAC;AAE5D,IAAI,6BAAsC,OAAO,WAAW,SAAS;AAE9D,IAAM,cAAc,CAAE,KAAgB,SAAkB;AAC9D,QAAM,UAAU,WAAY,IAAK;AACjC,cAAa,OAAQ,IAAI;AAC1B;AAEA,eAAsB,wBAAyBA,MAAmB;AACjE,MAAK,4BAA6B;AACjC;AAAA,EACD;AACA,+BAA6B;AAC7B,QAAM,gBAAgB,OAAO,QAAS,WAAY;AAClD,mBAAkB,SAAS,eAAgB;AAC1C,UAAM,CAAE,KAAK,SAAU,IAAI;AAC3B,UAAMA,KAAI,oBAAqB;AAAA,MAC9B,MAAM,UAAW,GAAI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;AAAA,EACjE,KAAK,qBAAqB,KAAM,MAAO,CAAE;AAAA,EAC1C,KAAK;AAAA,EACN;AACD;AAEO,IAAM,cAAc,CAAE,SAAkB;AAC9C,SAAO,IAAI,YAAa,IAAK;AAC9B;;;ALhDO,IAAM,cAAc,MAAM,OAAO;","names":["sdk","import_mcp","import_types"]}
|
package/dist/index.mjs
CHANGED
|
@@ -34,9 +34,6 @@ var mcpRegistry = {};
|
|
|
34
34
|
var mcpDescriptions = {};
|
|
35
35
|
var isMcpRegistrationActivated = typeof globalThis.jest !== "undefined";
|
|
36
36
|
var registerMcp = (mcp, name) => {
|
|
37
|
-
if (isMcpRegistrationActivated) {
|
|
38
|
-
throw new Error("MCP Registration is already activated. Cannot register new MCP servers.");
|
|
39
|
-
}
|
|
40
37
|
const mcpName = isAlphabet(name);
|
|
41
38
|
mcpRegistry[mcpName] = mcp;
|
|
42
39
|
};
|
|
@@ -48,7 +45,7 @@ async function activateMcpRegistration(sdk2) {
|
|
|
48
45
|
const mcpServerList = Object.entries(mcpRegistry);
|
|
49
46
|
for await (const entry of mcpServerList) {
|
|
50
47
|
const [key, mcpServer] = entry;
|
|
51
|
-
await sdk2.
|
|
48
|
+
await sdk2.registerLocalServer({
|
|
52
49
|
name: `editor-${key}`,
|
|
53
50
|
server: mcpServer,
|
|
54
51
|
version: "1.0.0",
|
|
@@ -107,9 +104,6 @@ function createToolRegistrator(server) {
|
|
|
107
104
|
function addTool(opts) {
|
|
108
105
|
const outputSchema = opts.outputSchema;
|
|
109
106
|
const inputSchema = opts.schema ? opts.schema : {};
|
|
110
|
-
if (isMcpRegistrationActivated) {
|
|
111
|
-
throw new Error("MCP Registration is already activated. Cannot add new tools.");
|
|
112
|
-
}
|
|
113
107
|
const toolCallback = async function(args, extra) {
|
|
114
108
|
try {
|
|
115
109
|
const invocationResult = await opts.handler(opts.schema ? args : {}, extra);
|
|
@@ -119,8 +113,7 @@ function createToolRegistrator(server) {
|
|
|
119
113
|
{
|
|
120
114
|
type: "text",
|
|
121
115
|
text: typeof invocationResult === "string" ? invocationResult : JSON.stringify(invocationResult)
|
|
122
|
-
}
|
|
123
|
-
...opts.resourceList || []
|
|
116
|
+
}
|
|
124
117
|
]
|
|
125
118
|
};
|
|
126
119
|
} catch (error) {
|
|
@@ -135,6 +128,14 @@ function createToolRegistrator(server) {
|
|
|
135
128
|
};
|
|
136
129
|
}
|
|
137
130
|
};
|
|
131
|
+
const annotations = {
|
|
132
|
+
destructiveHint: opts.isDestrcutive,
|
|
133
|
+
readOnlyHint: opts.isDestrcutive ? false : void 0,
|
|
134
|
+
title: opts.name
|
|
135
|
+
};
|
|
136
|
+
if (opts.requiredResources) {
|
|
137
|
+
annotations["angie/requiredResources"] = opts.requiredResources;
|
|
138
|
+
}
|
|
138
139
|
server.registerTool(
|
|
139
140
|
opts.name,
|
|
140
141
|
{
|
|
@@ -142,14 +143,13 @@ function createToolRegistrator(server) {
|
|
|
142
143
|
inputSchema,
|
|
143
144
|
outputSchema,
|
|
144
145
|
title: opts.name,
|
|
145
|
-
annotations
|
|
146
|
-
destructiveHint: opts.isDestrcutive,
|
|
147
|
-
readOnlyHint: opts.isDestrcutive ? false : void 0,
|
|
148
|
-
title: opts.name
|
|
149
|
-
}
|
|
146
|
+
annotations
|
|
150
147
|
},
|
|
151
148
|
toolCallback
|
|
152
149
|
);
|
|
150
|
+
if (isMcpRegistrationActivated) {
|
|
151
|
+
server.sendToolListChanged();
|
|
152
|
+
}
|
|
153
153
|
}
|
|
154
154
|
return {
|
|
155
155
|
addTool
|
|
@@ -219,10 +219,12 @@ var createSampler = (server, opts = DEFAULT_OPTS) => {
|
|
|
219
219
|
const { maxTokens = 1e3, modelPreferences = "openai", model = "gpt-4o" } = opts;
|
|
220
220
|
const exec = async (payload) => {
|
|
221
221
|
const systemPromptObject = { ...payload.systemPrompt ? { systemPrompt: payload.systemPrompt } : {} };
|
|
222
|
+
const requestParams = payload.requestParams || {};
|
|
222
223
|
const result = await server.sendRequest(
|
|
223
224
|
{
|
|
224
225
|
method: "sampling/createMessage",
|
|
225
226
|
params: {
|
|
227
|
+
...requestParams,
|
|
226
228
|
maxTokens,
|
|
227
229
|
modelPreferences: {
|
|
228
230
|
hints: [{ name: modelPreferences }]
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/init.ts","../src/mcp-registry.ts","../src/test-utils/mock-mcp-registry.ts","../src/index.ts","../src/sampler.ts","../src/utils/prompt-builder.ts"],"sourcesContent":["import { isExperimentActive } from '@elementor/editor-v1-adapters';\nimport { AngieMcpSdk } from '@elementor-external/angie-sdk';\n\nimport { activateMcpRegistration } from './mcp-registry';\n\nlet sdk: AngieMcpSdk;\n\nexport const getSDK = () => {\n\t// @ts-ignore - QUnit fails this\n\tconst isMCPDisabled = !! ( globalThis as Record< string, unknown > ).__ELEMENTOR_MCP_DISABLED__;\n\tif ( isMCPDisabled ) {\n\t\treturn {} as unknown as AngieMcpSdk;\n\t}\n\tif ( ! sdk ) {\n\t\tsdk = new AngieMcpSdk();\n\t}\n\treturn sdk;\n};\n\nexport function init() {\n\tif ( isExperimentActive( 'editor_mcp' ) ) {\n\t\treturn getSDK().waitForReady();\n\t}\n\treturn Promise.resolve();\n}\n\nexport function startMCPServer() {\n\tif ( isExperimentActive( 'editor_mcp' ) ) {\n\t\treturn getSDK()\n\t\t\t.waitForReady()\n\t\t\t.then( () => activateMcpRegistration( sdk ) );\n\t}\n\treturn Promise.resolve();\n}\n\ndocument.addEventListener(\n\t'DOMContentLoaded',\n\t() => {\n\t\tstartMCPServer();\n\t},\n\t{\n\t\tonce: true,\n\t}\n);\n","import { type z, type z3 } from '@elementor/schema';\nimport { type AngieMcpSdk } from '@elementor-external/angie-sdk';\nimport { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\nimport { mockMcpRegistry } from './test-utils/mock-mcp-registry';\n\ntype ZodRawShape = z3.ZodRawShape;\n\nconst mcpRegistry: { [ namespace: string ]: McpServer } = {};\nconst mcpDescriptions: { [ namespace: string ]: string } = {};\n// @ts-ignore - QUnit fails this\nlet isMcpRegistrationActivated = false || typeof globalThis.jest !== 'undefined';\n\nexport const registerMcp = ( mcp: McpServer, name: string ) => {\n\tif ( isMcpRegistrationActivated ) {\n\t\tthrow new Error( 'MCP Registration is already activated. Cannot register new MCP servers.' );\n\t}\n\tconst mcpName = isAlphabet( name );\n\tmcpRegistry[ mcpName ] = mcp;\n};\n\nexport async function activateMcpRegistration( sdk: AngieMcpSdk ) {\n\tif ( isMcpRegistrationActivated ) {\n\t\treturn;\n\t}\n\tisMcpRegistrationActivated = true;\n\tconst mcpServerList = Object.entries( mcpRegistry );\n\tfor await ( const entry of mcpServerList ) {\n\t\tconst [ key, mcpServer ] = entry;\n\t\tawait sdk.registerServer( {\n\t\t\tname: `editor-${ key }`,\n\t\t\tserver: mcpServer,\n\t\t\tversion: '1.0.0',\n\t\t\tdescription: mcpDescriptions[ key ] || key,\n\t\t} );\n\t}\n}\n\nconst isAlphabet = ( str: string ): string | never => {\n\tconst passes = !! str && /^[a-z_]+$/.test( str );\n\tif ( ! passes ) {\n\t\tthrow new Error( 'Not alphabet' );\n\t}\n\treturn str;\n};\n\n/**\n *\n * @param namespace The namespace of the MCP server. It should contain only lowercase alphabetic characters.\n * @param options\n * @param options.instructions\n */\nexport const getMCPByDomain = ( namespace: string, options?: { instructions?: string } ): MCPRegistryEntry => {\n\tconst mcpName = `editor-${ isAlphabet( namespace ) }`;\n\t// @ts-ignore - QUnit fails this\n\tif ( typeof globalThis.jest !== 'undefined' ) {\n\t\treturn mockMcpRegistry();\n\t}\n\tif ( ! mcpRegistry[ namespace ] ) {\n\t\tmcpRegistry[ namespace ] = new McpServer(\n\t\t\t{\n\t\t\t\tname: mcpName,\n\t\t\t\tversion: '1.0.0',\n\t\t\t},\n\t\t\t{\n\t\t\t\tinstructions: options?.instructions,\n\t\t\t}\n\t\t);\n\t}\n\tconst mcpServer = mcpRegistry[ namespace ];\n\tconst { addTool } = createToolRegistrator( mcpServer );\n\treturn {\n\t\tmcpServer,\n\t\taddTool,\n\t\tsetMCPDescription: ( description: string ) => {\n\t\t\tmcpDescriptions[ namespace ] = description;\n\t\t},\n\t\tgetActiveChatInfo: () => {\n\t\t\tconst info = localStorage.getItem( 'angie_active_chat_id' );\n\t\t\tif ( ! info ) {\n\t\t\t\treturn {\n\t\t\t\t\texpiresAt: 0,\n\t\t\t\t\tsessionId: '',\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst rawData = JSON.parse( info );\n\t\t\treturn {\n\t\t\t\texpiresAt: rawData.expiresAt as number,\n\t\t\t\tsessionId: rawData.sessionId as string,\n\t\t\t};\n\t\t},\n\t};\n};\n\nexport interface MCPRegistryEntry {\n\taddTool: < T extends undefined | z.ZodRawShape = undefined, O extends undefined | z.ZodRawShape = undefined >(\n\t\topts: ToolRegistrationOptions< T, O >\n\t) => void;\n\tsetMCPDescription: ( description: string ) => void;\n\tgetActiveChatInfo: () => { sessionId: string; expiresAt: number };\n\tmcpServer: McpServer;\n}\n\ntype ResourceList = {\n\ttype: 'resource_link';\n\turi: string;\n\tname: string;\n\tdescription: string;\n\t_meta: Record< string, string >;\n\tmimeType?: string;\n\tannotations?: Record< string, unknown >;\n}[];\n\ntype ToolRegistrationOptions<\n\tInputArgs extends undefined | z.ZodRawShape = undefined,\n\tOutputSchema extends undefined | z.ZodRawShape = undefined,\n\tExpectedOutput = OutputSchema extends z.ZodRawShape ? z.objectOutputType< OutputSchema, z.ZodTypeAny > : string,\n> = {\n\tname: string;\n\tdescription: string;\n\tschema?: InputArgs;\n\toutputSchema?: OutputSchema;\n\thandler: InputArgs extends z.ZodRawShape\n\t\t? (\n\t\t\t\targs: z.objectOutputType< InputArgs, z.ZodTypeAny >,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >\n\t\t: (\n\t\t\t\targs: unknown,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >;\n\tisDestrcutive?: boolean;\n\tresourceList?: ResourceList;\n};\n\nfunction createToolRegistrator( server: McpServer ) {\n\tfunction addTool<\n\t\tT extends undefined | z.ZodRawShape = undefined,\n\t\tO extends undefined | z.ZodRawShape = undefined,\n\t>( opts: ToolRegistrationOptions< T, O > ) {\n\t\tconst outputSchema = opts.outputSchema as ZodRawShape | undefined;\n\t\t// @ts-ignore: TS is unable to infer the type here\n\t\tconst inputSchema: ZodRawShape = opts.schema ? opts.schema : {};\n\t\tif ( isMcpRegistrationActivated ) {\n\t\t\tthrow new Error( 'MCP Registration is already activated. Cannot add new tools.' );\n\t\t}\n\t\tconst toolCallback: ToolCallback< ZodRawShape > = async function ( args, extra ) {\n\t\t\ttry {\n\t\t\t\tconst invocationResult = await opts.handler( opts.schema ? args : {}, extra );\n\t\t\t\treturn {\n\t\t\t\t\tstructuredContent: typeof invocationResult === 'string' ? undefined : invocationResult,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\t\ttypeof invocationResult === 'string'\n\t\t\t\t\t\t\t\t\t? invocationResult\n\t\t\t\t\t\t\t\t\t: JSON.stringify( invocationResult ),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...( opts.resourceList || [] ),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t} catch ( error ) {\n\t\t\t\treturn {\n\t\t\t\t\tisError: true,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext: ( error as Error ).message || 'Unknown error',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\t\tserver.registerTool(\n\t\t\topts.name,\n\t\t\t{\n\t\t\t\tdescription: opts.description,\n\t\t\t\tinputSchema,\n\t\t\t\toutputSchema,\n\t\t\t\ttitle: opts.name,\n\t\t\t\tannotations: {\n\t\t\t\t\tdestructiveHint: opts.isDestrcutive,\n\t\t\t\t\treadOnlyHint: opts.isDestrcutive ? false : undefined,\n\t\t\t\t\ttitle: opts.name,\n\t\t\t\t},\n\t\t\t},\n\t\t\ttoolCallback\n\t\t);\n\t}\n\treturn {\n\t\taddTool,\n\t};\n}\n","import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n\nimport { type MCPRegistryEntry } from '../mcp-registry';\n\nconst mock = new Proxy(\n\t{},\n\t{\n\t\tget: () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\tfunction mockedFn( ..._: unknown[] ) {}\n\t\t\treturn mockedFn;\n\t\t},\n\t}\n);\n\nexport const mockMcpRegistry = (): MCPRegistryEntry => {\n\treturn {\n\t\taddTool: () => {},\n\t\tsetMCPDescription: () => {},\n\t\tgetActiveChatInfo() {\n\t\t\treturn { sessionId: 'mock-session-id', expiresAt: Date.now() + 3600000 };\n\t\t},\n\t\tmcpServer: mock as McpServer,\n\t};\n};\n","import { getSDK } from './init';\n\nexport {\n\tMcpServer,\n\tResourceTemplate,\n\ttype RegisteredResource,\n\ttype ToolCallback,\n} from '@modelcontextprotocol/sdk/server/mcp.js';\nexport { SamplingMessageSchema } from '@modelcontextprotocol/sdk/types.js';\nexport { init } from './init';\nexport * from './mcp-registry';\nexport { createSampler } from './sampler';\nexport { toolPrompts } from './utils/prompt-builder';\nexport const getAngieSdk = () => getSDK();\n","import { type z } from '@elementor/schema';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { SamplingMessageSchema, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\ntype Server = RequestHandlerExtra< ServerRequest, ServerNotification >;\ntype Opts = {\n\tmaxTokens?: number;\n\tmodelPreferences?: string;\n\tmodel?: string;\n};\n\nconst DEFAULT_OPTS: Opts = {\n\tmaxTokens: 10000,\n\tmodelPreferences: 'openai',\n\tmodel: 'gpt-4o',\n};\n\ntype SamplingOpts = {\n\tsystemPrompt?: string;\n\tstructuredOutput?: z.ZodTypeAny;\n\tmessages: { role: 'user' | 'assistant'; content: { type: 'text'; text: string } }[];\n};\n\nconst DEFAULT_STRUCTURED_OUTPUT = {\n\ttype: 'object',\n\tproperties: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tdescription: 'Result',\n\t\t},\n\t},\n\trequired: [ 'content' ],\n\tadditionalProperties: false,\n};\n\nexport const createSampler = ( server: Server, opts: Opts = DEFAULT_OPTS ) => {\n\tconst { maxTokens = 1000, modelPreferences = 'openai', model = 'gpt-4o' } = opts;\n\tconst exec = async ( payload: SamplingOpts ) => {\n\t\tconst systemPromptObject = { ...( payload.systemPrompt ? { systemPrompt: payload.systemPrompt } : {} ) };\n\t\tconst result = await server.sendRequest(\n\t\t\t{\n\t\t\t\tmethod: 'sampling/createMessage',\n\t\t\t\tparams: {\n\t\t\t\t\tmaxTokens,\n\t\t\t\t\tmodelPreferences: {\n\t\t\t\t\t\thints: [ { name: modelPreferences } ],\n\t\t\t\t\t},\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t...systemPromptObject,\n\t\t\t\t\t\t...{ structured_output: payload.structuredOutput || DEFAULT_STRUCTURED_OUTPUT },\n\t\t\t\t\t},\n\t\t\t\t\tmessages: payload.messages,\n\t\t\t\t},\n\t\t\t\t// ...systemPromptObject,\n\t\t\t},\n\t\t\tSamplingMessageSchema\n\t\t);\n\t\ttry {\n\t\t\treturn JSON.parse( result.content.text as string );\n\t\t} catch {\n\t\t\treturn result.content;\n\t\t}\n\t};\n\treturn exec;\n};\n","class ToolPrompts {\n\tpublic _description = '';\n\tpublic _parameters: Record< string, string > = {};\n\tpublic _examples: string[] = [];\n\tpublic _furtherInstructions: string[] = [];\n\n\tconstructor( public name: string ) {}\n\n\tdescription(): string;\n\tdescription( desc: string ): this;\n\tdescription( desc?: string | undefined ) {\n\t\tif ( typeof desc === 'undefined' ) {\n\t\t\treturn this._description;\n\t\t}\n\t\tthis._description = desc;\n\t\treturn this;\n\t}\n\n\tparameter( key: string ): string;\n\tparameter( key: string, description: string ): this;\n\tparameter( key: string, description?: string ) {\n\t\tif ( typeof description === 'undefined' ) {\n\t\t\treturn this._parameters[ key ];\n\t\t}\n\t\tthis._parameters[ key ] = `**${ key }**:\\n${ description }`;\n\t\treturn this;\n\t}\n\n\tinstruction( instruction: string ): this {\n\t\tthis._furtherInstructions.push( instruction );\n\t\treturn this;\n\t}\n\n\texample( example: string ): this {\n\t\tthis._examples.push( example );\n\t\treturn this;\n\t}\n\n\tpublic get examples() {\n\t\treturn this._examples.join( '\\n\\n' );\n\t}\n\n\tprompt(): string {\n\t\treturn `# ${ this.name }\n# Description\n${ this._description }\n\n${ this._parameters.length ? '# Parameters' : '' }\n${ Object.values( this._parameters ).join( '\\n\\n' ) }\n\n${ this._examples.length ? '# Examples' : '' }\n${ this.examples }\n\n${ this._furtherInstructions.length ? '# Further Instructions' : '' }\n${ this._furtherInstructions.join( '\\n\\n' ) }\n`.trim();\n\t}\n}\n\nexport const toolPrompts = ( name: string ) => {\n\treturn new ToolPrompts( name );\n};\n"],"mappings":";AAAA,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;;;ACC5B,SAAS,iBAAoC;;;ACE7C,IAAM,OAAO,IAAI;AAAA,EAChB,CAAC;AAAA,EACD;AAAA,IACC,KAAK,MAAM;AAEV,eAAS,YAAa,GAAe;AAAA,MAAC;AACtC,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEO,IAAM,kBAAkB,MAAwB;AACtD,SAAO;AAAA,IACN,SAAS,MAAM;AAAA,IAAC;AAAA,IAChB,mBAAmB,MAAM;AAAA,IAAC;AAAA,IAC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zD,WAAO;AAAA,EACR;AAAA,EAEA,YAAa,aAA4B;AACxC,SAAK,qBAAqB,KAAM,WAAY;AAC5C,WAAO;AAAA,EACR;AAAA,EAEA,QAAS,SAAwB;AAChC,SAAK,UAAU,KAAM,OAAQ;AAC7B,WAAO;AAAA,EACR;AAAA,EAEA,IAAW,WAAW;AACrB,WAAO,KAAK,UAAU,KAAM,MAAO;AAAA,EACpC;AAAA,EAEA,SAAiB;AAChB,WAAO,KAAM,KAAK,IAAK;AAAA;AAAA,EAEtB,KAAK,YAAa;AAAA;AAAA,EAElB,KAAK,YAAY,SAAS,iBAAiB,EAAG;AAAA,EAC9C,OAAO,OAAQ,KAAK,WAAY,EAAE,KAAM,MAAO,CAAE;AAAA;AAAA,EAEjD,KAAK,UAAU,SAAS,eAAe,EAAG;AAAA,EAC1C,KAAK,QAAS;AAAA;AAAA,EAEd,KAAK,qBAAqB,SAAS,2BAA2B,EAAG;AAAA,EACjE,KAAK,qBAAqB,KAAM,MAAO,CAAE;AAAA,EAC1C,KAAK;AAAA,EACN;AACD;AAEO,IAAM,cAAc,CAAE,SAAkB;AAC9C,SAAO,IAAI,YAAa,IAAK;AAC9B;;;AFhDO,IAAM,cAAc,MAAM,OAAO;","names":["sdk","McpServer","SamplingMessageSchema"]}
|
|
1
|
+
{"version":3,"sources":["../src/init.ts","../src/mcp-registry.ts","../src/test-utils/mock-mcp-registry.ts","../src/index.ts","../src/sampler.ts","../src/utils/prompt-builder.ts"],"sourcesContent":["import { isExperimentActive } from '@elementor/editor-v1-adapters';\nimport { AngieMcpSdk } from '@elementor-external/angie-sdk';\n\nimport { activateMcpRegistration } from './mcp-registry';\n\nlet sdk: AngieMcpSdk;\n\nexport const getSDK = () => {\n\t// @ts-ignore - QUnit fails this\n\tconst isMCPDisabled = !! ( globalThis as Record< string, unknown > ).__ELEMENTOR_MCP_DISABLED__;\n\tif ( isMCPDisabled ) {\n\t\treturn {} as unknown as AngieMcpSdk;\n\t}\n\tif ( ! sdk ) {\n\t\tsdk = new AngieMcpSdk();\n\t}\n\treturn sdk;\n};\n\nexport function init() {\n\tif ( isExperimentActive( 'editor_mcp' ) ) {\n\t\treturn getSDK().waitForReady();\n\t}\n\treturn Promise.resolve();\n}\n\nexport function startMCPServer() {\n\tif ( isExperimentActive( 'editor_mcp' ) ) {\n\t\treturn getSDK()\n\t\t\t.waitForReady()\n\t\t\t.then( () => activateMcpRegistration( sdk ) );\n\t}\n\treturn Promise.resolve();\n}\n\ndocument.addEventListener(\n\t'DOMContentLoaded',\n\t() => {\n\t\tstartMCPServer();\n\t},\n\t{\n\t\tonce: true,\n\t}\n);\n","import { type z, type z3 } from '@elementor/schema';\nimport { type AngieMcpSdk } from '@elementor-external/angie-sdk';\nimport { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\nimport { mockMcpRegistry } from './test-utils/mock-mcp-registry';\n\ntype ZodRawShape = z3.ZodRawShape;\n\nconst mcpRegistry: { [ namespace: string ]: McpServer } = {};\nconst mcpDescriptions: { [ namespace: string ]: string } = {};\n// @ts-ignore - QUnit fails this\nlet isMcpRegistrationActivated = false || typeof globalThis.jest !== 'undefined';\n\nexport const registerMcp = ( mcp: McpServer, name: string ) => {\n\tconst mcpName = isAlphabet( name );\n\tmcpRegistry[ mcpName ] = mcp;\n};\n\nexport async function activateMcpRegistration( sdk: AngieMcpSdk ) {\n\tif ( isMcpRegistrationActivated ) {\n\t\treturn;\n\t}\n\tisMcpRegistrationActivated = true;\n\tconst mcpServerList = Object.entries( mcpRegistry );\n\tfor await ( const entry of mcpServerList ) {\n\t\tconst [ key, mcpServer ] = entry;\n\t\tawait sdk.registerLocalServer( {\n\t\t\tname: `editor-${ key }`,\n\t\t\tserver: mcpServer,\n\t\t\tversion: '1.0.0',\n\t\t\tdescription: mcpDescriptions[ key ] || key,\n\t\t} );\n\t}\n}\n\nconst isAlphabet = ( str: string ): string | never => {\n\tconst passes = !! str && /^[a-z_]+$/.test( str );\n\tif ( ! passes ) {\n\t\tthrow new Error( 'Not alphabet' );\n\t}\n\treturn str;\n};\n\n/**\n *\n * @param namespace The namespace of the MCP server. It should contain only lowercase alphabetic characters.\n * @param options\n * @param options.instructions\n */\nexport const getMCPByDomain = ( namespace: string, options?: { instructions?: string } ): MCPRegistryEntry => {\n\tconst mcpName = `editor-${ isAlphabet( namespace ) }`;\n\t// @ts-ignore - QUnit fails this\n\tif ( typeof globalThis.jest !== 'undefined' ) {\n\t\treturn mockMcpRegistry();\n\t}\n\tif ( ! mcpRegistry[ namespace ] ) {\n\t\tmcpRegistry[ namespace ] = new McpServer(\n\t\t\t{\n\t\t\t\tname: mcpName,\n\t\t\t\tversion: '1.0.0',\n\t\t\t},\n\t\t\t{\n\t\t\t\tinstructions: options?.instructions,\n\t\t\t}\n\t\t);\n\t}\n\tconst mcpServer = mcpRegistry[ namespace ];\n\tconst { addTool } = createToolRegistrator( mcpServer );\n\treturn {\n\t\tmcpServer,\n\t\taddTool,\n\t\tsetMCPDescription: ( description: string ) => {\n\t\t\tmcpDescriptions[ namespace ] = description;\n\t\t},\n\t\tgetActiveChatInfo: () => {\n\t\t\tconst info = localStorage.getItem( 'angie_active_chat_id' );\n\t\t\tif ( ! info ) {\n\t\t\t\treturn {\n\t\t\t\t\texpiresAt: 0,\n\t\t\t\t\tsessionId: '',\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst rawData = JSON.parse( info );\n\t\t\treturn {\n\t\t\t\texpiresAt: rawData.expiresAt as number,\n\t\t\t\tsessionId: rawData.sessionId as string,\n\t\t\t};\n\t\t},\n\t};\n};\n\nexport interface MCPRegistryEntry {\n\taddTool: < T extends undefined | z.ZodRawShape = undefined, O extends undefined | z.ZodRawShape = undefined >(\n\t\topts: ToolRegistrationOptions< T, O >\n\t) => void;\n\tsetMCPDescription: ( description: string ) => void;\n\tgetActiveChatInfo: () => { sessionId: string; expiresAt: number };\n\tmcpServer: McpServer;\n}\n\ntype ResourceList = {\n\turi: string;\n\tdescription: string;\n}[];\n\ntype ToolRegistrationOptions<\n\tInputArgs extends undefined | z.ZodRawShape = undefined,\n\tOutputSchema extends undefined | z.ZodRawShape = undefined,\n\tExpectedOutput = OutputSchema extends z.ZodRawShape ? z.objectOutputType< OutputSchema, z.ZodTypeAny > : string,\n> = {\n\tname: string;\n\tdescription: string;\n\tschema?: InputArgs;\n\toutputSchema?: OutputSchema;\n\thandler: InputArgs extends z.ZodRawShape\n\t\t? (\n\t\t\t\targs: z.objectOutputType< InputArgs, z.ZodTypeAny >,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >\n\t\t: (\n\t\t\t\targs: unknown,\n\t\t\t\textra: RequestHandlerExtra< ServerRequest, ServerNotification >\n\t\t ) => ExpectedOutput | Promise< ExpectedOutput >;\n\tisDestrcutive?: boolean;\n\trequiredResources?: ResourceList;\n};\n\nfunction createToolRegistrator( server: McpServer ) {\n\tfunction addTool<\n\t\tT extends undefined | z.ZodRawShape = undefined,\n\t\tO extends undefined | z.ZodRawShape = undefined,\n\t>( opts: ToolRegistrationOptions< T, O > ) {\n\t\tconst outputSchema = opts.outputSchema as ZodRawShape | undefined;\n\t\t// @ts-ignore: TS is unable to infer the type here\n\t\tconst inputSchema: ZodRawShape = opts.schema ? opts.schema : {};\n\t\tconst toolCallback: ToolCallback< ZodRawShape > = async function ( args, extra ) {\n\t\t\ttry {\n\t\t\t\tconst invocationResult = await opts.handler( opts.schema ? args : {}, extra );\n\t\t\t\treturn {\n\t\t\t\t\tstructuredContent: typeof invocationResult === 'string' ? undefined : invocationResult,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\t\ttypeof invocationResult === 'string'\n\t\t\t\t\t\t\t\t\t? invocationResult\n\t\t\t\t\t\t\t\t\t: JSON.stringify( invocationResult ),\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t} catch ( error ) {\n\t\t\t\treturn {\n\t\t\t\t\tisError: true,\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext: ( error as Error ).message || 'Unknown error',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t};\n\t\tconst annotations: Record< string, unknown > = {\n\t\t\tdestructiveHint: opts.isDestrcutive,\n\t\t\treadOnlyHint: opts.isDestrcutive ? false : undefined,\n\t\t\ttitle: opts.name,\n\t\t};\n\t\tif ( opts.requiredResources ) {\n\t\t\tannotations[ 'angie/requiredResources' ] = opts.requiredResources;\n\t\t}\n\t\tserver.registerTool(\n\t\t\topts.name,\n\t\t\t{\n\t\t\t\tdescription: opts.description,\n\t\t\t\tinputSchema,\n\t\t\t\toutputSchema,\n\t\t\t\ttitle: opts.name,\n\t\t\t\tannotations,\n\t\t\t},\n\t\t\ttoolCallback\n\t\t);\n\t\tif ( isMcpRegistrationActivated ) {\n\t\t\tserver.sendToolListChanged();\n\t\t}\n\t}\n\treturn {\n\t\taddTool,\n\t};\n}\n","import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\n\nimport { type MCPRegistryEntry } from '../mcp-registry';\n\nconst mock = new Proxy(\n\t{},\n\t{\n\t\tget: () => {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\tfunction mockedFn( ..._: unknown[] ) {}\n\t\t\treturn mockedFn;\n\t\t},\n\t}\n);\n\nexport const mockMcpRegistry = (): MCPRegistryEntry => {\n\treturn {\n\t\taddTool: () => {},\n\t\tsetMCPDescription: () => {},\n\t\tgetActiveChatInfo() {\n\t\t\treturn { sessionId: 'mock-session-id', expiresAt: Date.now() + 3600000 };\n\t\t},\n\t\tmcpServer: mock as McpServer,\n\t};\n};\n","import { getSDK } from './init';\n\nexport {\n\tMcpServer,\n\tResourceTemplate,\n\ttype RegisteredResource,\n\ttype ToolCallback,\n} from '@modelcontextprotocol/sdk/server/mcp.js';\nexport { SamplingMessageSchema } from '@modelcontextprotocol/sdk/types.js';\nexport { init } from './init';\nexport * from './mcp-registry';\nexport { createSampler } from './sampler';\nexport { toolPrompts } from './utils/prompt-builder';\nexport const getAngieSdk = () => getSDK();\n","import { type z } from '@elementor/schema';\nimport { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { SamplingMessageSchema, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\ntype Server = RequestHandlerExtra< ServerRequest, ServerNotification >;\ntype Opts = {\n\tmaxTokens?: number;\n\tmodelPreferences?: string;\n\tmodel?: string;\n};\n\nconst DEFAULT_OPTS: Opts = {\n\tmaxTokens: 10000,\n\tmodelPreferences: 'openai',\n\tmodel: 'gpt-4o',\n};\n\ntype SamplingOpts = {\n\tsystemPrompt?: string;\n\tstructuredOutput?: z.ZodTypeAny;\n\tmessages: { role: 'user' | 'assistant'; content: { type: 'text'; text: string } }[];\n\trequestParams?: { [ key: string ]: string };\n};\n\nconst DEFAULT_STRUCTURED_OUTPUT = {\n\ttype: 'object',\n\tproperties: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tdescription: 'Result',\n\t\t},\n\t},\n\trequired: [ 'content' ],\n\tadditionalProperties: false,\n};\n\nexport const createSampler = ( server: Server, opts: Opts = DEFAULT_OPTS ) => {\n\tconst { maxTokens = 1000, modelPreferences = 'openai', model = 'gpt-4o' } = opts;\n\tconst exec = async ( payload: SamplingOpts ) => {\n\t\tconst systemPromptObject = { ...( payload.systemPrompt ? { systemPrompt: payload.systemPrompt } : {} ) };\n\t\tconst requestParams = payload.requestParams || {};\n\t\tconst result = await server.sendRequest(\n\t\t\t{\n\t\t\t\tmethod: 'sampling/createMessage',\n\t\t\t\tparams: {\n\t\t\t\t\t...requestParams,\n\t\t\t\t\tmaxTokens,\n\t\t\t\t\tmodelPreferences: {\n\t\t\t\t\t\thints: [ { name: modelPreferences } ],\n\t\t\t\t\t},\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t...systemPromptObject,\n\t\t\t\t\t\t...{ structured_output: payload.structuredOutput || DEFAULT_STRUCTURED_OUTPUT },\n\t\t\t\t\t},\n\t\t\t\t\tmessages: payload.messages,\n\t\t\t\t},\n\t\t\t\t// ...systemPromptObject,\n\t\t\t},\n\t\t\tSamplingMessageSchema\n\t\t);\n\t\ttry {\n\t\t\treturn JSON.parse( result.content.text as string );\n\t\t} catch {\n\t\t\treturn result.content;\n\t\t}\n\t};\n\treturn exec;\n};\n","class ToolPrompts {\n\tpublic _description = '';\n\tpublic _parameters: Record< string, string > = {};\n\tpublic _examples: string[] = [];\n\tpublic _furtherInstructions: string[] = [];\n\n\tconstructor( public name: string ) {}\n\n\tdescription(): string;\n\tdescription( desc: string ): this;\n\tdescription( desc?: string | undefined ) {\n\t\tif ( typeof desc === 'undefined' ) {\n\t\t\treturn this._description;\n\t\t}\n\t\tthis._description = desc;\n\t\treturn this;\n\t}\n\n\tparameter( key: string ): string;\n\tparameter( key: string, description: string ): this;\n\tparameter( key: string, description?: string ) {\n\t\tif ( typeof description === 'undefined' ) {\n\t\t\treturn this._parameters[ key ];\n\t\t}\n\t\tthis._parameters[ key ] = `**${ key }**:\\n${ description }`;\n\t\treturn this;\n\t}\n\n\tinstruction( instruction: string ): this {\n\t\tthis._furtherInstructions.push( instruction );\n\t\treturn this;\n\t}\n\n\texample( example: string ): this {\n\t\tthis._examples.push( example );\n\t\treturn this;\n\t}\n\n\tpublic get examples() {\n\t\treturn this._examples.join( '\\n\\n' );\n\t}\n\n\tprompt(): string {\n\t\treturn `# ${ this.name }\n# Description\n${ this._description }\n\n${ this._parameters.length ? '# Parameters' : '' }\n${ Object.values( this._parameters ).join( '\\n\\n' ) }\n\n${ this._examples.length ? '# Examples' : '' }\n${ this.examples }\n\n${ this._furtherInstructions.length ? '# Further Instructions' : '' }\n${ this._furtherInstructions.join( '\\n\\n' ) }\n`.trim();\n\t}\n}\n\nexport const toolPrompts = ( name: string ) => {\n\treturn new ToolPrompts( name );\n};\n"],"mappings":";AAAA,SAAS,0BAA0B;AACnC,SAAS,mBAAmB;;;ACC5B,SAAS,iBAAoC;;;ACE7C,IAAM,OAAO,IAAI;AAAA,EAChB,CAAC;AAAA,EACD;AAAA,IACC,KAAK,MAAM;AAEV,eAAS,YAAa,GAAe;AAAA,MAAC;AACtC,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEO,IAAM,kBAAkB,MAAwB;AACtD,SAAO;AAAA,IACN,SAAS,MAAM;AAAA,IAAC;AAAA,IAChB,mBAAmB,MAAM;AAAA,IAAC;AAAA,IAC1B,oBAAoB;AACnB,aAAO,EAAE,WAAW,mBAAmB,WAAW,KAAK,IAAI,IAAI,KAAQ;AAAA,IACxE;AAAA,IACA,WAAW;AAAA,EACZ;AACD;;;ADdA,IAAM,cAAoD,CAAC;AAC3D,IAAM,kBAAqD,CAAC;AAE5D,IAAI,6BAAsC,OAAO,WAAW,SAAS;AAE9D,IAAM,cAAc,CAAE,KAAgB,SAAkB;AAC9D,QAAM,UAAU,WAAY,IAAK;AACjC,cAAa,OAAQ,IAAI;AAC1B;AAEA,eAAsB,wBAAyBA,MAAmB;AACjE,MAAK,4BAA6B;AACjC;AAAA,EACD;AACA,+BAA6B;AAC7B,QAAM,gBAAgB,OAAO,QAAS,WAAY;AAClD,mBAAkB,SAAS,eAAgB;AAC1C,UAAM,CAAE,KAAK,SAAU,IAAI;AAC3B,UAAMA,KAAI,oBAAqB;AAAA,MAC9B,MAAM,UAAW,GAAI;AAAA,MACrB,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,aAAa,gBAAiB,GAAI,KAAK;AAAA,IACxC,CAAE;AAAA,EACH;AACD;AAEA,IAAM,aAAa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O,IAAM,cAAc,CAAE,SAAkB;AAC9C,SAAO,IAAI,YAAa,IAAK;AAC9B;;;AFhDO,IAAM,cAAc,MAAM,OAAO;","names":["sdk","McpServer","SamplingMessageSchema"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-mcp",
|
|
3
|
-
"version": "3.35.0-
|
|
3
|
+
"version": "3.35.0-341",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -43,9 +43,10 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@elementor-external/angie-sdk": "npm:@elementor/angie-sdk@1.0.3",
|
|
46
|
-
"@elementor/schema": "3.35.0-
|
|
46
|
+
"@elementor/schema": "3.35.0-341",
|
|
47
47
|
"@modelcontextprotocol/sdk": "1.17.4",
|
|
48
|
-
"@elementor/store": "3.35.0-
|
|
49
|
-
"@elementor/editor-v1-adapters": "3.35.0-
|
|
48
|
+
"@elementor/store": "3.35.0-341",
|
|
49
|
+
"@elementor/editor-v1-adapters": "3.35.0-341",
|
|
50
|
+
"zod-to-json-schema": "3.24.6"
|
|
50
51
|
}
|
|
51
52
|
}
|
package/src/mcp-registry.ts
CHANGED
|
@@ -14,9 +14,6 @@ const mcpDescriptions: { [ namespace: string ]: string } = {};
|
|
|
14
14
|
let isMcpRegistrationActivated = false || typeof globalThis.jest !== 'undefined';
|
|
15
15
|
|
|
16
16
|
export const registerMcp = ( mcp: McpServer, name: string ) => {
|
|
17
|
-
if ( isMcpRegistrationActivated ) {
|
|
18
|
-
throw new Error( 'MCP Registration is already activated. Cannot register new MCP servers.' );
|
|
19
|
-
}
|
|
20
17
|
const mcpName = isAlphabet( name );
|
|
21
18
|
mcpRegistry[ mcpName ] = mcp;
|
|
22
19
|
};
|
|
@@ -29,7 +26,7 @@ export async function activateMcpRegistration( sdk: AngieMcpSdk ) {
|
|
|
29
26
|
const mcpServerList = Object.entries( mcpRegistry );
|
|
30
27
|
for await ( const entry of mcpServerList ) {
|
|
31
28
|
const [ key, mcpServer ] = entry;
|
|
32
|
-
await sdk.
|
|
29
|
+
await sdk.registerLocalServer( {
|
|
33
30
|
name: `editor-${ key }`,
|
|
34
31
|
server: mcpServer,
|
|
35
32
|
version: '1.0.0',
|
|
@@ -104,13 +101,8 @@ export interface MCPRegistryEntry {
|
|
|
104
101
|
}
|
|
105
102
|
|
|
106
103
|
type ResourceList = {
|
|
107
|
-
type: 'resource_link';
|
|
108
104
|
uri: string;
|
|
109
|
-
name: string;
|
|
110
105
|
description: string;
|
|
111
|
-
_meta: Record< string, string >;
|
|
112
|
-
mimeType?: string;
|
|
113
|
-
annotations?: Record< string, unknown >;
|
|
114
106
|
}[];
|
|
115
107
|
|
|
116
108
|
type ToolRegistrationOptions<
|
|
@@ -132,7 +124,7 @@ type ToolRegistrationOptions<
|
|
|
132
124
|
extra: RequestHandlerExtra< ServerRequest, ServerNotification >
|
|
133
125
|
) => ExpectedOutput | Promise< ExpectedOutput >;
|
|
134
126
|
isDestrcutive?: boolean;
|
|
135
|
-
|
|
127
|
+
requiredResources?: ResourceList;
|
|
136
128
|
};
|
|
137
129
|
|
|
138
130
|
function createToolRegistrator( server: McpServer ) {
|
|
@@ -143,9 +135,6 @@ function createToolRegistrator( server: McpServer ) {
|
|
|
143
135
|
const outputSchema = opts.outputSchema as ZodRawShape | undefined;
|
|
144
136
|
// @ts-ignore: TS is unable to infer the type here
|
|
145
137
|
const inputSchema: ZodRawShape = opts.schema ? opts.schema : {};
|
|
146
|
-
if ( isMcpRegistrationActivated ) {
|
|
147
|
-
throw new Error( 'MCP Registration is already activated. Cannot add new tools.' );
|
|
148
|
-
}
|
|
149
138
|
const toolCallback: ToolCallback< ZodRawShape > = async function ( args, extra ) {
|
|
150
139
|
try {
|
|
151
140
|
const invocationResult = await opts.handler( opts.schema ? args : {}, extra );
|
|
@@ -159,7 +148,6 @@ function createToolRegistrator( server: McpServer ) {
|
|
|
159
148
|
? invocationResult
|
|
160
149
|
: JSON.stringify( invocationResult ),
|
|
161
150
|
},
|
|
162
|
-
...( opts.resourceList || [] ),
|
|
163
151
|
],
|
|
164
152
|
};
|
|
165
153
|
} catch ( error ) {
|
|
@@ -174,6 +162,14 @@ function createToolRegistrator( server: McpServer ) {
|
|
|
174
162
|
};
|
|
175
163
|
}
|
|
176
164
|
};
|
|
165
|
+
const annotations: Record< string, unknown > = {
|
|
166
|
+
destructiveHint: opts.isDestrcutive,
|
|
167
|
+
readOnlyHint: opts.isDestrcutive ? false : undefined,
|
|
168
|
+
title: opts.name,
|
|
169
|
+
};
|
|
170
|
+
if ( opts.requiredResources ) {
|
|
171
|
+
annotations[ 'angie/requiredResources' ] = opts.requiredResources;
|
|
172
|
+
}
|
|
177
173
|
server.registerTool(
|
|
178
174
|
opts.name,
|
|
179
175
|
{
|
|
@@ -181,14 +177,13 @@ function createToolRegistrator( server: McpServer ) {
|
|
|
181
177
|
inputSchema,
|
|
182
178
|
outputSchema,
|
|
183
179
|
title: opts.name,
|
|
184
|
-
annotations
|
|
185
|
-
destructiveHint: opts.isDestrcutive,
|
|
186
|
-
readOnlyHint: opts.isDestrcutive ? false : undefined,
|
|
187
|
-
title: opts.name,
|
|
188
|
-
},
|
|
180
|
+
annotations,
|
|
189
181
|
},
|
|
190
182
|
toolCallback
|
|
191
183
|
);
|
|
184
|
+
if ( isMcpRegistrationActivated ) {
|
|
185
|
+
server.sendToolListChanged();
|
|
186
|
+
}
|
|
192
187
|
}
|
|
193
188
|
return {
|
|
194
189
|
addTool,
|
package/src/sampler.ts
CHANGED
|
@@ -19,6 +19,7 @@ type SamplingOpts = {
|
|
|
19
19
|
systemPrompt?: string;
|
|
20
20
|
structuredOutput?: z.ZodTypeAny;
|
|
21
21
|
messages: { role: 'user' | 'assistant'; content: { type: 'text'; text: string } }[];
|
|
22
|
+
requestParams?: { [ key: string ]: string };
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
const DEFAULT_STRUCTURED_OUTPUT = {
|
|
@@ -37,10 +38,12 @@ export const createSampler = ( server: Server, opts: Opts = DEFAULT_OPTS ) => {
|
|
|
37
38
|
const { maxTokens = 1000, modelPreferences = 'openai', model = 'gpt-4o' } = opts;
|
|
38
39
|
const exec = async ( payload: SamplingOpts ) => {
|
|
39
40
|
const systemPromptObject = { ...( payload.systemPrompt ? { systemPrompt: payload.systemPrompt } : {} ) };
|
|
41
|
+
const requestParams = payload.requestParams || {};
|
|
40
42
|
const result = await server.sendRequest(
|
|
41
43
|
{
|
|
42
44
|
method: 'sampling/createMessage',
|
|
43
45
|
params: {
|
|
46
|
+
...requestParams,
|
|
44
47
|
maxTokens,
|
|
45
48
|
modelPreferences: {
|
|
46
49
|
hints: [ { name: modelPreferences } ],
|