@elementor/editor-mcp 3.35.0-362 → 3.35.0-364
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 +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/angie-annotations.ts +8 -0
- package/src/index.ts +1 -0
- package/src/mcp-registry.ts +5 -0
package/dist/index.d.mts
CHANGED
|
@@ -9,6 +9,16 @@ import { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.j
|
|
|
9
9
|
|
|
10
10
|
declare function init(): Promise<void>;
|
|
11
11
|
|
|
12
|
+
declare const ANGIE_MODEL_PREFERENCES: "angie/modelPreferences";
|
|
13
|
+
interface AngieModelPreferences {
|
|
14
|
+
hints?: Array<{
|
|
15
|
+
name: string;
|
|
16
|
+
}>;
|
|
17
|
+
costPriority?: number;
|
|
18
|
+
speedPriority?: number;
|
|
19
|
+
intelligencePriority?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
declare const registerMcp: (mcp: McpServer, name: string) => void;
|
|
13
23
|
declare function activateMcpRegistration(sdk: AngieMcpSdk): Promise<void>;
|
|
14
24
|
/**
|
|
@@ -46,6 +56,7 @@ type ToolRegistrationOptions<InputArgs extends undefined | z.ZodRawShape = undef
|
|
|
46
56
|
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
57
|
isDestrcutive?: boolean;
|
|
48
58
|
requiredResources?: ResourceList;
|
|
59
|
+
modelPreferences?: AngieModelPreferences;
|
|
49
60
|
};
|
|
50
61
|
|
|
51
62
|
type Server = RequestHandlerExtra<ServerRequest, ServerNotification>;
|
|
@@ -90,4 +101,4 @@ declare const toolPrompts: (name: string) => ToolPrompts;
|
|
|
90
101
|
|
|
91
102
|
declare const getAngieSdk: () => _elementor_external_angie_sdk.AngieMcpSdk;
|
|
92
103
|
|
|
93
|
-
export { type MCPRegistryEntry, activateMcpRegistration, createSampler, getAngieSdk, getMCPByDomain, init, registerMcp, toolPrompts };
|
|
104
|
+
export { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences, type MCPRegistryEntry, activateMcpRegistration, createSampler, getAngieSdk, getMCPByDomain, init, registerMcp, toolPrompts };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,16 @@ import { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.j
|
|
|
9
9
|
|
|
10
10
|
declare function init(): Promise<void>;
|
|
11
11
|
|
|
12
|
+
declare const ANGIE_MODEL_PREFERENCES: "angie/modelPreferences";
|
|
13
|
+
interface AngieModelPreferences {
|
|
14
|
+
hints?: Array<{
|
|
15
|
+
name: string;
|
|
16
|
+
}>;
|
|
17
|
+
costPriority?: number;
|
|
18
|
+
speedPriority?: number;
|
|
19
|
+
intelligencePriority?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
declare const registerMcp: (mcp: McpServer, name: string) => void;
|
|
13
23
|
declare function activateMcpRegistration(sdk: AngieMcpSdk): Promise<void>;
|
|
14
24
|
/**
|
|
@@ -46,6 +56,7 @@ type ToolRegistrationOptions<InputArgs extends undefined | z.ZodRawShape = undef
|
|
|
46
56
|
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
57
|
isDestrcutive?: boolean;
|
|
48
58
|
requiredResources?: ResourceList;
|
|
59
|
+
modelPreferences?: AngieModelPreferences;
|
|
49
60
|
};
|
|
50
61
|
|
|
51
62
|
type Server = RequestHandlerExtra<ServerRequest, ServerNotification>;
|
|
@@ -90,4 +101,4 @@ declare const toolPrompts: (name: string) => ToolPrompts;
|
|
|
90
101
|
|
|
91
102
|
declare const getAngieSdk: () => _elementor_external_angie_sdk.AngieMcpSdk;
|
|
92
103
|
|
|
93
|
-
export { type MCPRegistryEntry, activateMcpRegistration, createSampler, getAngieSdk, getMCPByDomain, init, registerMcp, toolPrompts };
|
|
104
|
+
export { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences, type MCPRegistryEntry, activateMcpRegistration, createSampler, getAngieSdk, getMCPByDomain, init, registerMcp, toolPrompts };
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
ANGIE_MODEL_PREFERENCES: () => ANGIE_MODEL_PREFERENCES,
|
|
23
24
|
McpServer: () => import_mcp2.McpServer,
|
|
24
25
|
ResourceTemplate: () => import_mcp2.ResourceTemplate,
|
|
25
26
|
SamplingMessageSchema: () => import_types2.SamplingMessageSchema,
|
|
@@ -58,6 +59,9 @@ var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
|
58
59
|
var import_schema = require("@elementor/schema");
|
|
59
60
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
60
61
|
|
|
62
|
+
// src/angie-annotations.ts
|
|
63
|
+
var ANGIE_MODEL_PREFERENCES = "angie/modelPreferences";
|
|
64
|
+
|
|
61
65
|
// src/test-utils/mock-mcp-registry.ts
|
|
62
66
|
var mock = new Proxy(
|
|
63
67
|
{},
|
|
@@ -212,6 +216,9 @@ function createToolRegistrator(server) {
|
|
|
212
216
|
if (opts.requiredResources) {
|
|
213
217
|
annotations["angie/requiredResources"] = opts.requiredResources;
|
|
214
218
|
}
|
|
219
|
+
if (opts.modelPreferences) {
|
|
220
|
+
annotations[ANGIE_MODEL_PREFERENCES] = opts.modelPreferences;
|
|
221
|
+
}
|
|
215
222
|
server.registerTool(
|
|
216
223
|
opts.name,
|
|
217
224
|
{
|
|
@@ -367,6 +374,7 @@ var toolPrompts = (name) => {
|
|
|
367
374
|
var getAngieSdk = () => getSDK();
|
|
368
375
|
// Annotate the CommonJS export names for ESM import in node:
|
|
369
376
|
0 && (module.exports = {
|
|
377
|
+
ANGIE_MODEL_PREFERENCES,
|
|
370
378
|
McpServer,
|
|
371
379
|
ResourceTemplate,
|
|
372
380
|
SamplingMessageSchema,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/get-sdk.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 './get-sdk';\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 { AngieMcpSdk } from '@elementor-external/angie-sdk';\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","import { isExperimentActive } from '@elementor/editor-v1-adapters';\n\nimport { getSDK } from './get-sdk';\nimport { activateMcpRegistration } from './mcp-registry';\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\tconst sdk = getSDK();\n\t\tsdk.waitForReady().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 { 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 { getSDK } from './get-sdk';\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\twaitForReady: () => getSDK().waitForReady(),\n\t\t// @ts-expect-error: TS is unable to infer the type here\n\t\tresource: async ( ...args: Parameters< McpServer[ 'resource' ] > ) => {\n\t\t\tawait getSDK().waitForReady();\n\t\t\treturn mcpServer.resource( ...args );\n\t\t},\n\t\tsendResourceUpdated: ( ...args: Parameters< McpServer[ 'server' ][ 'sendResourceUpdated' ] > ) => {\n\t\t\treturn new Promise( async () => {\n\t\t\t\tawait getSDK().waitForReady();\n\t\t\t\tmcpServer.server.sendResourceUpdated( ...args );\n\t\t\t} );\n\t\t},\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\tsendResourceUpdated: McpServer[ 'server' ][ 'sendResourceUpdated' ];\n\tresource: McpServer[ 'resource' ];\n\tmcpServer: McpServer;\n\twaitForReady: () => Promise< void >;\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\n\t\t? z.objectOutputType< OutputSchema & { llm_instructions?: string }, z.ZodTypeAny >\n\t\t: 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\tif ( outputSchema && ! ( 'llm_instructions' in outputSchema ) ) {\n\t\t\tObject.assign( outputSchema, {\n\t\t\t\tllm_instruction: z.string().optional().describe( 'Instructions for what to do next' ),\n\t\t\t} );\n\t\t}\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\t// @ts-ignore\n\t\tresource: async () => {},\n\t\t// @ts-ignore\n\t\tsendResourceUpdated: () => {},\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,uBAA4B;AAE5B,IAAI;AAEG,IAAM,SAAS,MAAM;AAE3B,QAAM,gBAAgB,CAAC,CAAI,WAA0C;AACrE,MAAK,eAAgB;AACpB,WAAO,CAAC;AAAA,EACT;AACA,MAAK,CAAE,KAAM;AACZ,UAAM,IAAI,6BAAY;AAAA,EACvB;AACA,SAAO;AACR;;;ADZA,IAAAA,cAKO;AACP,IAAAC,gBAAsC;;;AERtC,gCAAmC;;;ACAnC,oBAA2B;AAE3B,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;AAC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
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/get-sdk.ts","../src/init.ts","../src/mcp-registry.ts","../src/angie-annotations.ts","../src/test-utils/mock-mcp-registry.ts","../src/sampler.ts","../src/utils/prompt-builder.ts"],"sourcesContent":["import { getSDK } from './get-sdk';\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 { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';\nexport const getAngieSdk = () => getSDK();\n","import { AngieMcpSdk } from '@elementor-external/angie-sdk';\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","import { isExperimentActive } from '@elementor/editor-v1-adapters';\n\nimport { getSDK } from './get-sdk';\nimport { activateMcpRegistration } from './mcp-registry';\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\tconst sdk = getSDK();\n\t\tsdk.waitForReady().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 { 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 { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';\nimport { getSDK } from './get-sdk';\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\twaitForReady: () => getSDK().waitForReady(),\n\t\t// @ts-expect-error: TS is unable to infer the type here\n\t\tresource: async ( ...args: Parameters< McpServer[ 'resource' ] > ) => {\n\t\t\tawait getSDK().waitForReady();\n\t\t\treturn mcpServer.resource( ...args );\n\t\t},\n\t\tsendResourceUpdated: ( ...args: Parameters< McpServer[ 'server' ][ 'sendResourceUpdated' ] > ) => {\n\t\t\treturn new Promise( async () => {\n\t\t\t\tawait getSDK().waitForReady();\n\t\t\t\tmcpServer.server.sendResourceUpdated( ...args );\n\t\t\t} );\n\t\t},\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\tsendResourceUpdated: McpServer[ 'server' ][ 'sendResourceUpdated' ];\n\tresource: McpServer[ 'resource' ];\n\tmcpServer: McpServer;\n\twaitForReady: () => Promise< void >;\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\n\t\t? z.objectOutputType< OutputSchema & { llm_instructions?: string }, z.ZodTypeAny >\n\t\t: 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\tmodelPreferences?: AngieModelPreferences;\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\tif ( outputSchema && ! ( 'llm_instructions' in outputSchema ) ) {\n\t\t\tObject.assign( outputSchema, {\n\t\t\t\tllm_instruction: z.string().optional().describe( 'Instructions for what to do next' ),\n\t\t\t} );\n\t\t}\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\tif ( opts.modelPreferences ) {\n\t\t\tannotations[ ANGIE_MODEL_PREFERENCES ] = opts.modelPreferences;\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","export const ANGIE_MODEL_PREFERENCES = 'angie/modelPreferences' as const;\n\nexport interface AngieModelPreferences {\n\thints?: Array< { name: string } >;\n\tcostPriority?: number; // 0-1 (future use)\n\tspeedPriority?: number; // 0-1 (future use)\n\tintelligencePriority?: number; // 0-1 (future use)\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\t// @ts-ignore\n\t\tresource: async () => {},\n\t\t// @ts-ignore\n\t\tsendResourceUpdated: () => {},\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;AAAA;;;ACAA,uBAA4B;AAE5B,IAAI;AAEG,IAAM,SAAS,MAAM;AAE3B,QAAM,gBAAgB,CAAC,CAAI,WAA0C;AACrE,MAAK,eAAgB;AACpB,WAAO,CAAC;AAAA,EACT;AACA,MAAK,CAAE,KAAM;AACZ,UAAM,IAAI,6BAAY;AAAA,EACvB;AACA,SAAO;AACR;;;ADZA,IAAAA,cAKO;AACP,IAAAC,gBAAsC;;;AERtC,gCAAmC;;;ACAnC,oBAA2B;AAE3B,iBAA6C;;;ACFtC,IAAM,0BAA0B;;;ACIvC,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;AAAA,IAEN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Ac,MAAM,OAAO;","names":["import_mcp","import_types","sdk","sdk"]}
|
package/dist/index.mjs
CHANGED
|
@@ -26,6 +26,9 @@ import { isExperimentActive } from "@elementor/editor-v1-adapters";
|
|
|
26
26
|
import { z } from "@elementor/schema";
|
|
27
27
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
28
28
|
|
|
29
|
+
// src/angie-annotations.ts
|
|
30
|
+
var ANGIE_MODEL_PREFERENCES = "angie/modelPreferences";
|
|
31
|
+
|
|
29
32
|
// src/test-utils/mock-mcp-registry.ts
|
|
30
33
|
var mock = new Proxy(
|
|
31
34
|
{},
|
|
@@ -180,6 +183,9 @@ function createToolRegistrator(server) {
|
|
|
180
183
|
if (opts.requiredResources) {
|
|
181
184
|
annotations["angie/requiredResources"] = opts.requiredResources;
|
|
182
185
|
}
|
|
186
|
+
if (opts.modelPreferences) {
|
|
187
|
+
annotations[ANGIE_MODEL_PREFERENCES] = opts.modelPreferences;
|
|
188
|
+
}
|
|
183
189
|
server.registerTool(
|
|
184
190
|
opts.name,
|
|
185
191
|
{
|
|
@@ -334,6 +340,7 @@ var toolPrompts = (name) => {
|
|
|
334
340
|
// src/index.ts
|
|
335
341
|
var getAngieSdk = () => getSDK();
|
|
336
342
|
export {
|
|
343
|
+
ANGIE_MODEL_PREFERENCES,
|
|
337
344
|
McpServer2 as McpServer,
|
|
338
345
|
ResourceTemplate,
|
|
339
346
|
SamplingMessageSchema2 as SamplingMessageSchema,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/get-sdk.ts","../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 { AngieMcpSdk } from '@elementor-external/angie-sdk';\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","import { getSDK } from './get-sdk';\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';\n\nimport { getSDK } from './get-sdk';\nimport { activateMcpRegistration } from './mcp-registry';\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\tconst sdk = getSDK();\n\t\tsdk.waitForReady().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 { 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 { getSDK } from './get-sdk';\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\twaitForReady: () => getSDK().waitForReady(),\n\t\t// @ts-expect-error: TS is unable to infer the type here\n\t\tresource: async ( ...args: Parameters< McpServer[ 'resource' ] > ) => {\n\t\t\tawait getSDK().waitForReady();\n\t\t\treturn mcpServer.resource( ...args );\n\t\t},\n\t\tsendResourceUpdated: ( ...args: Parameters< McpServer[ 'server' ][ 'sendResourceUpdated' ] > ) => {\n\t\t\treturn new Promise( async () => {\n\t\t\t\tawait getSDK().waitForReady();\n\t\t\t\tmcpServer.server.sendResourceUpdated( ...args );\n\t\t\t} );\n\t\t},\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\tsendResourceUpdated: McpServer[ 'server' ][ 'sendResourceUpdated' ];\n\tresource: McpServer[ 'resource' ];\n\tmcpServer: McpServer;\n\twaitForReady: () => Promise< void >;\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\n\t\t? z.objectOutputType< OutputSchema & { llm_instructions?: string }, z.ZodTypeAny >\n\t\t: 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\tif ( outputSchema && ! ( 'llm_instructions' in outputSchema ) ) {\n\t\t\tObject.assign( outputSchema, {\n\t\t\t\tllm_instruction: z.string().optional().describe( 'Instructions for what to do next' ),\n\t\t\t} );\n\t\t}\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\t// @ts-ignore\n\t\tresource: async () => {},\n\t\t// @ts-ignore\n\t\tsendResourceUpdated: () => {},\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,SAAS,mBAAmB;AAE5B,IAAI;AAEG,IAAM,SAAS,MAAM;AAE3B,QAAM,gBAAgB,CAAC,CAAI,WAA0C;AACrE,MAAK,eAAgB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B,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":["McpServer","SamplingMessageSchema","sdk","sdk"]}
|
|
1
|
+
{"version":3,"sources":["../src/get-sdk.ts","../src/index.ts","../src/init.ts","../src/mcp-registry.ts","../src/angie-annotations.ts","../src/test-utils/mock-mcp-registry.ts","../src/sampler.ts","../src/utils/prompt-builder.ts"],"sourcesContent":["import { AngieMcpSdk } from '@elementor-external/angie-sdk';\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","import { getSDK } from './get-sdk';\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 { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';\nexport const getAngieSdk = () => getSDK();\n","import { isExperimentActive } from '@elementor/editor-v1-adapters';\n\nimport { getSDK } from './get-sdk';\nimport { activateMcpRegistration } from './mcp-registry';\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\tconst sdk = getSDK();\n\t\tsdk.waitForReady().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 { 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 { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';\nimport { getSDK } from './get-sdk';\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\twaitForReady: () => getSDK().waitForReady(),\n\t\t// @ts-expect-error: TS is unable to infer the type here\n\t\tresource: async ( ...args: Parameters< McpServer[ 'resource' ] > ) => {\n\t\t\tawait getSDK().waitForReady();\n\t\t\treturn mcpServer.resource( ...args );\n\t\t},\n\t\tsendResourceUpdated: ( ...args: Parameters< McpServer[ 'server' ][ 'sendResourceUpdated' ] > ) => {\n\t\t\treturn new Promise( async () => {\n\t\t\t\tawait getSDK().waitForReady();\n\t\t\t\tmcpServer.server.sendResourceUpdated( ...args );\n\t\t\t} );\n\t\t},\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\tsendResourceUpdated: McpServer[ 'server' ][ 'sendResourceUpdated' ];\n\tresource: McpServer[ 'resource' ];\n\tmcpServer: McpServer;\n\twaitForReady: () => Promise< void >;\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\n\t\t? z.objectOutputType< OutputSchema & { llm_instructions?: string }, z.ZodTypeAny >\n\t\t: 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\tmodelPreferences?: AngieModelPreferences;\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\tif ( outputSchema && ! ( 'llm_instructions' in outputSchema ) ) {\n\t\t\tObject.assign( outputSchema, {\n\t\t\t\tllm_instruction: z.string().optional().describe( 'Instructions for what to do next' ),\n\t\t\t} );\n\t\t}\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\tif ( opts.modelPreferences ) {\n\t\t\tannotations[ ANGIE_MODEL_PREFERENCES ] = opts.modelPreferences;\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","export const ANGIE_MODEL_PREFERENCES = 'angie/modelPreferences' as const;\n\nexport interface AngieModelPreferences {\n\thints?: Array< { name: string } >;\n\tcostPriority?: number; // 0-1 (future use)\n\tspeedPriority?: number; // 0-1 (future use)\n\tintelligencePriority?: number; // 0-1 (future use)\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\t// @ts-ignore\n\t\tresource: async () => {},\n\t\t// @ts-ignore\n\t\tsendResourceUpdated: () => {},\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,SAAS,mBAAmB;AAE5B,IAAI;AAEG,IAAM,SAAS,MAAM;AAE3B,QAAM,gBAAgB,CAAC,CAAI,WAA0C;AACrE,MAAK,eAAgB;AACpB,WAAO,CAAC;AAAA,EACT;AACA,MAAK,CAAE,KAAM;AACZ,UAAM,IAAI,YAAY;AAAA,EACvB;AACA,SA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ElB,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;;;AN/CO,IAAM,cAAc,MAAM,OAAO;","names":["McpServer","SamplingMessageSchema","sdk","sdk"]}
|
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-364",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -43,10 +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-364",
|
|
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-364",
|
|
49
|
+
"@elementor/editor-v1-adapters": "3.35.0-364",
|
|
50
50
|
"zod-to-json-schema": "3.24.6"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const ANGIE_MODEL_PREFERENCES = 'angie/modelPreferences' as const;
|
|
2
|
+
|
|
3
|
+
export interface AngieModelPreferences {
|
|
4
|
+
hints?: Array< { name: string } >;
|
|
5
|
+
costPriority?: number; // 0-1 (future use)
|
|
6
|
+
speedPriority?: number; // 0-1 (future use)
|
|
7
|
+
intelligencePriority?: number; // 0-1 (future use)
|
|
8
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -11,4 +11,5 @@ export { init } from './init';
|
|
|
11
11
|
export * from './mcp-registry';
|
|
12
12
|
export { createSampler } from './sampler';
|
|
13
13
|
export { toolPrompts } from './utils/prompt-builder';
|
|
14
|
+
export { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';
|
|
14
15
|
export const getAngieSdk = () => getSDK();
|
package/src/mcp-registry.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/m
|
|
|
4
4
|
import { type RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
5
5
|
import { type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
|
|
7
|
+
import { ANGIE_MODEL_PREFERENCES, type AngieModelPreferences } from './angie-annotations';
|
|
7
8
|
import { getSDK } from './get-sdk';
|
|
8
9
|
import { mockMcpRegistry } from './test-utils/mock-mcp-registry';
|
|
9
10
|
|
|
@@ -143,6 +144,7 @@ type ToolRegistrationOptions<
|
|
|
143
144
|
) => ExpectedOutput | Promise< ExpectedOutput >;
|
|
144
145
|
isDestrcutive?: boolean;
|
|
145
146
|
requiredResources?: ResourceList;
|
|
147
|
+
modelPreferences?: AngieModelPreferences;
|
|
146
148
|
};
|
|
147
149
|
|
|
148
150
|
function createToolRegistrator( server: McpServer ) {
|
|
@@ -193,6 +195,9 @@ function createToolRegistrator( server: McpServer ) {
|
|
|
193
195
|
if ( opts.requiredResources ) {
|
|
194
196
|
annotations[ 'angie/requiredResources' ] = opts.requiredResources;
|
|
195
197
|
}
|
|
198
|
+
if ( opts.modelPreferences ) {
|
|
199
|
+
annotations[ ANGIE_MODEL_PREFERENCES ] = opts.modelPreferences;
|
|
200
|
+
}
|
|
196
201
|
server.registerTool(
|
|
197
202
|
opts.name,
|
|
198
203
|
{
|