@eclipse-lyra/extension-webmcp 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/webmcp-extension-DuWWRVUQ.js +84 -0
- package/dist/webmcp-extension-DuWWRVUQ.js.map +1 -0
- package/dist/webmcp-extension.d.ts +3 -0
- package/dist/webmcp-extension.d.ts.map +1 -0
- package/dist/webmcp-service.d.ts +13 -0
- package/dist/webmcp-service.d.ts.map +1 -0
- package/package.json +31 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { extensionRegistry } from "@eclipse-lyra/core";
|
|
2
|
+
import pkg from "../package.json";
|
|
3
|
+
extensionRegistry.registerExtension({
|
|
4
|
+
id: pkg.name,
|
|
5
|
+
name: "WebMCP",
|
|
6
|
+
description: "Exposes app commands as WebMCP tools for browser agents and MCP clients",
|
|
7
|
+
loader: () => import("./webmcp-extension-DuWWRVUQ.js"),
|
|
8
|
+
icon: "plug",
|
|
9
|
+
dependencies: ["@eclipse-lyra/extension-ai-system"]
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { extensionRegistry } from \"@eclipse-lyra/core\";\nimport pkg from \"../package.json\";\n\nextensionRegistry.registerExtension({\n id: pkg.name,\n name: \"WebMCP\",\n description: \"Exposes app commands as WebMCP tools for browser agents and MCP clients\",\n loader: () => import(\"./webmcp-extension\"),\n icon: \"plug\",\n dependencies: [\"@eclipse-lyra/extension-ai-system\"],\n});\n"],"names":[],"mappings":";;AAGA,kBAAkB,kBAAkB;AAAA,EAClC,IAAI,IAAI;AAAA,EACR,MAAM;AAAA,EACN,aAAa;AAAA,EACb,QAAQ,MAAM,OAAO,gCAAoB;AAAA,EACzC,MAAM;AAAA,EACN,cAAc,CAAC,mCAAmC;AACpD,CAAC;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { commandRegistry, subscribe, TOPIC_COMMAND_REGISTERED, unsubscribe } from "@eclipse-lyra/core";
|
|
2
|
+
import { ToolRegistry } from "@eclipse-lyra/extension-ai-system/api";
|
|
3
|
+
class WebMCPService {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.toolRegistry = new ToolRegistry();
|
|
6
|
+
this.registeredNames = /* @__PURE__ */ new Set();
|
|
7
|
+
this.registeredIds = /* @__PURE__ */ new Set();
|
|
8
|
+
this.commandSubscriptionToken = null;
|
|
9
|
+
}
|
|
10
|
+
async start() {
|
|
11
|
+
await this.ensureModelContext();
|
|
12
|
+
if (!navigator.modelContext) return;
|
|
13
|
+
const initialCommands = Object.values(commandRegistry.listCommands());
|
|
14
|
+
for (const command of initialCommands) {
|
|
15
|
+
this.registerCommand(command);
|
|
16
|
+
}
|
|
17
|
+
this.commandSubscriptionToken = subscribe(TOPIC_COMMAND_REGISTERED, (command) => {
|
|
18
|
+
this.registerCommand(command);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
stop() {
|
|
22
|
+
if (this.commandSubscriptionToken !== null) {
|
|
23
|
+
unsubscribe(this.commandSubscriptionToken);
|
|
24
|
+
this.commandSubscriptionToken = null;
|
|
25
|
+
}
|
|
26
|
+
if (typeof navigator !== "undefined" && navigator.modelContext) {
|
|
27
|
+
this.registeredNames.forEach((name) => navigator.modelContext.unregisterTool(name));
|
|
28
|
+
}
|
|
29
|
+
this.registeredNames.clear();
|
|
30
|
+
this.registeredIds.clear();
|
|
31
|
+
}
|
|
32
|
+
async ensureModelContext() {
|
|
33
|
+
if (typeof navigator === "undefined") return;
|
|
34
|
+
if (navigator.modelContext) return;
|
|
35
|
+
await import("@mcp-b/global");
|
|
36
|
+
}
|
|
37
|
+
toolDefToInputSchema(params) {
|
|
38
|
+
return {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: params.properties,
|
|
41
|
+
required: params.required
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
textContent(text) {
|
|
45
|
+
return { content: [{ type: "text", text }] };
|
|
46
|
+
}
|
|
47
|
+
registerCommand(command) {
|
|
48
|
+
if (this.registeredIds.has(command.id)) return;
|
|
49
|
+
if (!navigator.modelContext) return;
|
|
50
|
+
const schemaContext = commandRegistry.createExecutionContext?.() ?? {};
|
|
51
|
+
const toolDef = this.toolRegistry.commandToTool(command, schemaContext);
|
|
52
|
+
const commandId = command.id;
|
|
53
|
+
const toolName = toolDef.function.name;
|
|
54
|
+
const toTextContent = (t) => this.textContent(t);
|
|
55
|
+
navigator.modelContext.registerTool({
|
|
56
|
+
name: toolName,
|
|
57
|
+
description: toolDef.function.description,
|
|
58
|
+
inputSchema: this.toolDefToInputSchema(toolDef.function.parameters),
|
|
59
|
+
async execute(args) {
|
|
60
|
+
try {
|
|
61
|
+
const execContext = commandRegistry.createExecutionContext?.(args) ?? {
|
|
62
|
+
params: args ?? {}
|
|
63
|
+
};
|
|
64
|
+
const result = await commandRegistry.execute(commandId, execContext);
|
|
65
|
+
const text = result === void 0 || result === null ? "Done" : typeof result === "object" ? JSON.stringify(result) : String(result);
|
|
66
|
+
return toTextContent(text);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
69
|
+
return toTextContent(`Error: ${message}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
this.registeredNames.add(toolName);
|
|
74
|
+
this.registeredIds.add(command.id);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const webmcpExtension = async (_uiContext) => {
|
|
78
|
+
const service = new WebMCPService();
|
|
79
|
+
await service.start();
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
webmcpExtension as default
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=webmcp-extension-DuWWRVUQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webmcp-extension-DuWWRVUQ.js","sources":["../src/webmcp-service.ts","../src/webmcp-extension.ts"],"sourcesContent":["import {\n commandRegistry,\n subscribe,\n unsubscribe,\n TOPIC_COMMAND_REGISTERED,\n} from \"@eclipse-lyra/core\";\nimport { ToolRegistry, type ToolDefinition } from \"@eclipse-lyra/extension-ai-system/api\";\nimport type { Command } from \"@eclipse-lyra/core\";\nimport type { InputSchema } from \"@mcp-b/webmcp-types\";\n\nexport class WebMCPService {\n private readonly toolRegistry = new ToolRegistry();\n private readonly registeredNames = new Set<string>();\n private readonly registeredIds = new Set<string>();\n private commandSubscriptionToken: ReturnType<typeof subscribe> | null = null;\n\n async start(): Promise<void> {\n await this.ensureModelContext();\n if (!navigator.modelContext) return;\n\n const initialCommands = Object.values(commandRegistry.listCommands()) as Command[];\n for (const command of initialCommands) {\n this.registerCommand(command);\n }\n\n this.commandSubscriptionToken = subscribe(TOPIC_COMMAND_REGISTERED, (command: Command) => {\n this.registerCommand(command);\n });\n }\n\n stop(): void {\n if (this.commandSubscriptionToken !== null) {\n unsubscribe(this.commandSubscriptionToken);\n this.commandSubscriptionToken = null;\n }\n if (typeof navigator !== \"undefined\" && navigator.modelContext) {\n this.registeredNames.forEach((name) => navigator.modelContext!.unregisterTool(name));\n }\n this.registeredNames.clear();\n this.registeredIds.clear();\n }\n\n private async ensureModelContext(): Promise<void> {\n if (typeof navigator === \"undefined\") return;\n if (navigator.modelContext) return;\n await import(\"@mcp-b/global\");\n }\n\n private toolDefToInputSchema(\n params: ToolDefinition[\"function\"][\"parameters\"]\n ): InputSchema {\n return {\n type: \"object\",\n properties: params.properties as InputSchema[\"properties\"],\n required: params.required,\n };\n }\n\n private textContent(\n text: string\n ): { content: Array<{ type: \"text\"; text: string }> } {\n return { content: [{ type: \"text\", text }] };\n }\n\n private registerCommand(command: Command): void {\n if (this.registeredIds.has(command.id)) return;\n if (!navigator.modelContext) return;\n\n const schemaContext = commandRegistry.createExecutionContext?.() ?? {};\n const toolDef = this.toolRegistry.commandToTool(command, schemaContext) as ToolDefinition;\n const commandId = command.id;\n const toolName = toolDef.function.name;\n const toTextContent = (t: string) => this.textContent(t);\n\n navigator.modelContext.registerTool({\n name: toolName,\n description: toolDef.function.description,\n inputSchema: this.toolDefToInputSchema(toolDef.function.parameters),\n async execute(args: Record<string, unknown>) {\n try {\n const execContext =\n commandRegistry.createExecutionContext?.(args as Record<string, unknown>) ?? {\n params: args ?? {},\n };\n const result = await commandRegistry.execute(commandId, execContext);\n const text =\n result === undefined || result === null\n ? \"Done\"\n : typeof result === \"object\"\n ? JSON.stringify(result)\n : String(result);\n return toTextContent(text);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return toTextContent(`Error: ${message}`);\n }\n },\n });\n this.registeredNames.add(toolName);\n this.registeredIds.add(command.id);\n }\n}\n","import { WebMCPService } from \"./webmcp-service\";\n\nexport default async (_uiContext: unknown): Promise<void> => {\n const service = new WebMCPService();\n await service.start();\n};\n"],"names":[],"mappings":";;AAUO,MAAM,cAAc;AAAA,EAApB,cAAA;AACL,SAAiB,eAAe,IAAI,aAAA;AACpC,SAAiB,sCAAsB,IAAA;AACvC,SAAiB,oCAAoB,IAAA;AACrC,SAAQ,2BAAgE;AAAA,EAAA;AAAA,EAExE,MAAM,QAAuB;AAC3B,UAAM,KAAK,mBAAA;AACX,QAAI,CAAC,UAAU,aAAc;AAE7B,UAAM,kBAAkB,OAAO,OAAO,gBAAgB,cAAc;AACpE,eAAW,WAAW,iBAAiB;AACrC,WAAK,gBAAgB,OAAO;AAAA,IAC9B;AAEA,SAAK,2BAA2B,UAAU,0BAA0B,CAAC,YAAqB;AACxF,WAAK,gBAAgB,OAAO;AAAA,IAC9B,CAAC;AAA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AAErB,gBAAM,SAAS,MAAM,gBAAgB,QAAQ,WAAW,WAAW;AACnE,gBAAM,OACJ,WAAW,UAAa,WAAW,OAC/B,SACA,OAAO,WAAW,WAChB,KAAK,UAAU,MAAM,IACrB,OAAO,MAAM;AACrB,iBAAO,cAAc,IAAI;AAAA,QAC3B,SAAS,KAAK;AACZ,gBAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC/D,iBAAO,cAAc,UAAU,OAAO,EAAE;AAAA,QAC1C;AAAA,MACF;AAAA,IAAA,CACD;AACD,SAAK,gBAAgB,IAAI,QAAQ;AACjC,SAAK,cAAc,IAAI,QAAQ,EAAE;AAAA,EACnC;AACF;ACnGA,MAAA,kBAAe,OAAO,eAAuC;AAC3D,QAAM,UAAU,IAAI,cAAA;AACpB,QAAM,QAAQ,MAAA;AAChB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webmcp-extension.d.ts","sourceRoot":"","sources":["../src/webmcp-extension.ts"],"names":[],"mappings":"yBAEsB,YAAY,OAAO,KAAG,OAAO,CAAC,IAAI,CAAC;AAAzD,wBAGE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class WebMCPService {
|
|
2
|
+
private readonly toolRegistry;
|
|
3
|
+
private readonly registeredNames;
|
|
4
|
+
private readonly registeredIds;
|
|
5
|
+
private commandSubscriptionToken;
|
|
6
|
+
start(): Promise<void>;
|
|
7
|
+
stop(): void;
|
|
8
|
+
private ensureModelContext;
|
|
9
|
+
private toolDefToInputSchema;
|
|
10
|
+
private textContent;
|
|
11
|
+
private registerCommand;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=webmcp-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webmcp-service.d.ts","sourceRoot":"","sources":["../src/webmcp-service.ts"],"names":[],"mappings":"AAUA,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IACnD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqB;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IACnD,OAAO,CAAC,wBAAwB,CAA6C;IAEvE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAc5B,IAAI,IAAI,IAAI;YAYE,kBAAkB;IAMhC,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,eAAe;CAqCxB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eclipse-lyra/extension-webmcp",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@eclipse-lyra/core": "*",
|
|
14
|
+
"@eclipse-lyra/extension-ai-system": "*",
|
|
15
|
+
"@mcp-b/global": "^1.5.0",
|
|
16
|
+
"zod-to-json-schema": "^3.25.1"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"typescript": "^5.9.3",
|
|
20
|
+
"vite": "^7.1.12",
|
|
21
|
+
"vite-plugin-dts": "^4.5.4"
|
|
22
|
+
},
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "vite build"
|
|
30
|
+
}
|
|
31
|
+
}
|