@eclipse-docks/extension-webmcp 0.7.68
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 +21 -0
- package/dist/index.js.map +1 -0
- package/dist/webmcp-extension-vZl42m8K.js +76 -0
- package/dist/webmcp-extension-vZl42m8K.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 +12 -0
- package/dist/webmcp-service.d.ts.map +1 -0
- package/package.json +33 -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,21 @@
|
|
|
1
|
+
import { extensionRegistry } from "@eclipse-docks/core";
|
|
2
|
+
import pkg from "../package.json";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
function isModelContextAvailable() {
|
|
5
|
+
return typeof navigator !== "undefined" && "modelContext" in navigator && navigator.modelContext != null;
|
|
6
|
+
}
|
|
7
|
+
extensionRegistry.registerExtension({
|
|
8
|
+
id: pkg.name,
|
|
9
|
+
name: "WebMCP",
|
|
10
|
+
description: "Exposes app commands as WebMCP tools for browser agents and MCP clients",
|
|
11
|
+
loader: async () => {
|
|
12
|
+
if (!isModelContextAvailable()) throw new Error("WebMCP extension requires navigator.modelContext (Web Model Context API).");
|
|
13
|
+
return import("./webmcp-extension-vZl42m8K.js");
|
|
14
|
+
},
|
|
15
|
+
icon: "plug",
|
|
16
|
+
dependencies: ["@eclipse-docks/extension-ai-system"],
|
|
17
|
+
experimental: true
|
|
18
|
+
});
|
|
19
|
+
//#endregion
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { extensionRegistry } from \"@eclipse-docks/core\";\nimport pkg from \"../package.json\";\n\nfunction isModelContextAvailable(): boolean {\n return typeof navigator !== \"undefined\" && \"modelContext\" in navigator && navigator.modelContext != null;\n}\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: async () => {\n if (!isModelContextAvailable()) {\n throw new Error(\"WebMCP extension requires navigator.modelContext (Web Model Context API).\");\n }\n return import(\"./webmcp-extension\");\n },\n icon: \"plug\",\n dependencies: [\"@eclipse-docks/extension-ai-system\"],\n experimental: true,\n});\n"],"mappings":";;;AAGA,SAAS,0BAAmC;AAC1C,QAAO,OAAO,cAAc,eAAe,kBAAkB,aAAa,UAAU,gBAAgB;;AAGtG,kBAAkB,kBAAkB;CAClC,IAAI,IAAI;CACR,MAAM;CACN,aAAa;CACb,QAAQ,YAAY;AAClB,MAAI,CAAC,yBAAyB,CAC5B,OAAM,IAAI,MAAM,4EAA4E;AAE9F,SAAO,OAAO;;CAEhB,MAAM;CACN,cAAc,CAAC,qCAAqC;CACpD,cAAc;CACf,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { TOPIC_COMMAND_REGISTERED, commandRegistry, subscribe, unsubscribe } from "@eclipse-docks/core";
|
|
2
|
+
import { ToolRegistry } from "@eclipse-docks/extension-ai-system/api";
|
|
3
|
+
//#region src/webmcp-service.ts
|
|
4
|
+
var WebMCPService = class {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.toolRegistry = new ToolRegistry();
|
|
7
|
+
this.registeredNames = /* @__PURE__ */ new Set();
|
|
8
|
+
this.registeredIds = /* @__PURE__ */ new Set();
|
|
9
|
+
this.commandSubscriptionToken = null;
|
|
10
|
+
}
|
|
11
|
+
async start() {
|
|
12
|
+
const initialCommands = Object.values(commandRegistry.listCommands());
|
|
13
|
+
for (const command of initialCommands) this.registerCommand(command);
|
|
14
|
+
this.commandSubscriptionToken = subscribe(TOPIC_COMMAND_REGISTERED, (command) => {
|
|
15
|
+
this.registerCommand(command);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
stop() {
|
|
19
|
+
if (this.commandSubscriptionToken !== null) {
|
|
20
|
+
unsubscribe(this.commandSubscriptionToken);
|
|
21
|
+
this.commandSubscriptionToken = null;
|
|
22
|
+
}
|
|
23
|
+
const modelContext = navigator.modelContext;
|
|
24
|
+
if (modelContext) this.registeredNames.forEach((name) => modelContext.unregisterTool(name));
|
|
25
|
+
this.registeredNames.clear();
|
|
26
|
+
this.registeredIds.clear();
|
|
27
|
+
}
|
|
28
|
+
toolDefToInputSchema(params) {
|
|
29
|
+
return {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: params.properties,
|
|
32
|
+
required: params.required
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
textContent(text) {
|
|
36
|
+
return { content: [{
|
|
37
|
+
type: "text",
|
|
38
|
+
text
|
|
39
|
+
}] };
|
|
40
|
+
}
|
|
41
|
+
registerCommand(command) {
|
|
42
|
+
if (this.registeredIds.has(command.id)) return;
|
|
43
|
+
const modelContext = navigator.modelContext;
|
|
44
|
+
if (!modelContext) return;
|
|
45
|
+
const schemaContext = commandRegistry.createExecutionContext?.() ?? {};
|
|
46
|
+
const toolDef = this.toolRegistry.commandToTool(command, schemaContext);
|
|
47
|
+
const commandId = command.id;
|
|
48
|
+
const toolName = toolDef.function.name;
|
|
49
|
+
const toTextContent = (t) => this.textContent(t);
|
|
50
|
+
modelContext.registerTool({
|
|
51
|
+
name: toolName,
|
|
52
|
+
description: toolDef.function.description,
|
|
53
|
+
inputSchema: this.toolDefToInputSchema(toolDef.function.parameters),
|
|
54
|
+
async execute(args) {
|
|
55
|
+
try {
|
|
56
|
+
const execContext = commandRegistry.createExecutionContext?.(args) ?? { params: args ?? {} };
|
|
57
|
+
const result = await commandRegistry.execute(commandId, execContext);
|
|
58
|
+
return toTextContent(result === void 0 || result === null ? "Done" : typeof result === "object" ? JSON.stringify(result) : String(result));
|
|
59
|
+
} catch (err) {
|
|
60
|
+
return toTextContent(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
this.registeredNames.add(toolName);
|
|
65
|
+
this.registeredIds.add(command.id);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/webmcp-extension.ts
|
|
70
|
+
var webmcp_extension_default = async (_uiContext) => {
|
|
71
|
+
await new WebMCPService().start();
|
|
72
|
+
};
|
|
73
|
+
//#endregion
|
|
74
|
+
export { webmcp_extension_default as default };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=webmcp-extension-vZl42m8K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webmcp-extension-vZl42m8K.js","names":[],"sources":["../src/webmcp-service.ts","../src/webmcp-extension.ts"],"sourcesContent":["import {\n commandRegistry,\n subscribe,\n unsubscribe,\n TOPIC_COMMAND_REGISTERED,\n} from \"@eclipse-docks/core\";\nimport { ToolRegistry, type ToolDefinition } from \"@eclipse-docks/extension-ai-system/api\";\nimport type { Command } from \"@eclipse-docks/core\";\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 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 const modelContext = navigator.modelContext;\n if (modelContext) {\n this.registeredNames.forEach((name) => modelContext.unregisterTool(name));\n }\n this.registeredNames.clear();\n this.registeredIds.clear();\n }\n\n private toolDefToInputSchema(\n params: ToolDefinition[\"function\"][\"parameters\"]\n ): { type: \"object\"; properties?: Record<string, unknown>; required?: string[] } {\n return {\n type: \"object\",\n properties: params.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 const modelContext = navigator.modelContext;\n if (!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 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"],"mappings":";;;AASA,IAAa,gBAAb,MAA2B;;sBACO,IAAI,cAAc;yCACf,IAAI,KAAa;uCACnB,IAAI,KAAa;kCACsB;;CAExE,MAAM,QAAuB;EAC3B,MAAM,kBAAkB,OAAO,OAAO,gBAAgB,cAAc,CAAC;AACrE,OAAK,MAAM,WAAW,gBACpB,MAAK,gBAAgB,QAAQ;AAG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L,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,GACvB;;;GAG9C,CAAC;AACF,OAAK,gBAAgB,IAAI,SAAS;AAClC,OAAK,cAAc,IAAI,QAAQ,GAAG;;;;;ACzFtC,IAAA,2BAAe,OAAO,eAAuC;AAE3D,OADgB,IAAI,eAAe,CACrB,OAAO"}
|
|
@@ -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,12 @@
|
|
|
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 toolDefToInputSchema;
|
|
9
|
+
private textContent;
|
|
10
|
+
private registerCommand;
|
|
11
|
+
}
|
|
12
|
+
//# 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":"AASA,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;IAW5B,IAAI,IAAI,IAAI;IAaZ,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,eAAe;CAsCxB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eclipse-docks/extension-webmcp",
|
|
3
|
+
"version": "0.7.68",
|
|
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-docks/core": "*",
|
|
14
|
+
"@eclipse-docks/extension-ai-system": "*"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "^6.0.0",
|
|
18
|
+
"vite": "^8.0.0",
|
|
19
|
+
"vite-plugin-dts": "^4.5.4"
|
|
20
|
+
},
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "vite build"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/eclipse-docks/core"
|
|
32
|
+
}
|
|
33
|
+
}
|