@agentvault/agentvault 0.17.3 → 0.17.5

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.
Files changed (62) hide show
  1. package/dist/cli.js +141 -4
  2. package/dist/cli.js.map +4 -4
  3. package/dist/index.js +159 -16
  4. package/dist/index.js.map +4 -4
  5. package/dist/openclaw-entry.js +598 -142
  6. package/dist/openclaw-entry.js.map +4 -4
  7. package/openclaw.plugin.json +1 -1
  8. package/package.json +1 -1
  9. package/dist/_cp.d.ts +0 -10
  10. package/dist/_cp.d.ts.map +0 -1
  11. package/dist/account-config.d.ts +0 -20
  12. package/dist/account-config.d.ts.map +0 -1
  13. package/dist/channel.d.ts +0 -350
  14. package/dist/channel.d.ts.map +0 -1
  15. package/dist/cli.d.ts +0 -2
  16. package/dist/cli.d.ts.map +0 -1
  17. package/dist/create-agent.d.ts +0 -28
  18. package/dist/create-agent.d.ts.map +0 -1
  19. package/dist/crypto-helpers.d.ts +0 -2
  20. package/dist/crypto-helpers.d.ts.map +0 -1
  21. package/dist/doctor.d.ts +0 -41
  22. package/dist/doctor.d.ts.map +0 -1
  23. package/dist/fetch-interceptor.d.ts +0 -32
  24. package/dist/fetch-interceptor.d.ts.map +0 -1
  25. package/dist/gateway-send.d.ts +0 -98
  26. package/dist/gateway-send.d.ts.map +0 -1
  27. package/dist/http-handlers.d.ts +0 -42
  28. package/dist/http-handlers.d.ts.map +0 -1
  29. package/dist/index.d.ts +0 -25
  30. package/dist/index.d.ts.map +0 -1
  31. package/dist/mcp-handlers.d.ts +0 -26
  32. package/dist/mcp-handlers.d.ts.map +0 -1
  33. package/dist/mcp-server.d.ts +0 -88
  34. package/dist/mcp-server.d.ts.map +0 -1
  35. package/dist/openclaw-compat.d.ts +0 -33
  36. package/dist/openclaw-compat.d.ts.map +0 -1
  37. package/dist/openclaw-entry.d.ts +0 -27
  38. package/dist/openclaw-entry.d.ts.map +0 -1
  39. package/dist/openclaw-plugin.d.ts +0 -102
  40. package/dist/openclaw-plugin.d.ts.map +0 -1
  41. package/dist/openclaw-types.d.ts +0 -155
  42. package/dist/openclaw-types.d.ts.map +0 -1
  43. package/dist/policy-enforcer.d.ts +0 -78
  44. package/dist/policy-enforcer.d.ts.map +0 -1
  45. package/dist/setup.d.ts +0 -27
  46. package/dist/setup.d.ts.map +0 -1
  47. package/dist/skill-invoker.d.ts +0 -30
  48. package/dist/skill-invoker.d.ts.map +0 -1
  49. package/dist/skill-manifest.d.ts +0 -25
  50. package/dist/skill-manifest.d.ts.map +0 -1
  51. package/dist/skill-telemetry.d.ts +0 -36
  52. package/dist/skill-telemetry.d.ts.map +0 -1
  53. package/dist/skills-publish.d.ts +0 -8
  54. package/dist/skills-publish.d.ts.map +0 -1
  55. package/dist/state.d.ts +0 -32
  56. package/dist/state.d.ts.map +0 -1
  57. package/dist/transport.d.ts +0 -24
  58. package/dist/transport.d.ts.map +0 -1
  59. package/dist/types.d.ts +0 -379
  60. package/dist/types.d.ts.map +0 -1
  61. package/dist/workspace-handlers.d.ts +0 -62
  62. package/dist/workspace-handlers.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -46538,6 +46538,7 @@ var http_handlers_exports = {};
46538
46538
  __export(http_handlers_exports, {
46539
46539
  handleActionRequest: () => handleActionRequest,
46540
46540
  handleDecisionRequest: () => handleDecisionRequest,
46541
+ handleMcpConfigRequest: () => handleMcpConfigRequest,
46541
46542
  handleSendRequest: () => handleSendRequest,
46542
46543
  handleStatusRequest: () => handleStatusRequest,
46543
46544
  handleTargetsRequest: () => handleTargetsRequest
@@ -46679,12 +46680,90 @@ function handleTargetsRequest(channel) {
46679
46680
  }
46680
46681
  };
46681
46682
  }
46683
+ function handleMcpConfigRequest(agentName, port, mcpSkillCount) {
46684
+ return {
46685
+ status: 200,
46686
+ body: {
46687
+ mcpServers: {
46688
+ [`agentvault-${agentName}`]: {
46689
+ url: `http://127.0.0.1:${port}/mcp`
46690
+ }
46691
+ },
46692
+ _meta: {
46693
+ agent: agentName,
46694
+ skills_count: mcpSkillCount,
46695
+ transport: "streamable-http",
46696
+ auth: "none (localhost)",
46697
+ instructions: "Add the mcpServers block to your MCP configuration file (e.g., .mcp.json or mcp_config.json)"
46698
+ }
46699
+ }
46700
+ };
46701
+ }
46682
46702
  var init_http_handlers = __esm({
46683
46703
  "src/http-handlers.ts"() {
46684
46704
  "use strict";
46685
46705
  }
46686
46706
  });
46687
46707
 
46708
+ // src/mcp-proxy-helpers.ts
46709
+ var mcp_proxy_helpers_exports = {};
46710
+ __export(mcp_proxy_helpers_exports, {
46711
+ createMcpProxyRequest: () => createMcpProxyRequest
46712
+ });
46713
+ import { Readable } from "node:stream";
46714
+ async function createMcpProxyRequest(mcpServer, payload) {
46715
+ const bodyStr = JSON.stringify(payload);
46716
+ const req = Object.assign(new Readable({ read() {
46717
+ } }), {
46718
+ method: "POST",
46719
+ url: "/mcp",
46720
+ headers: {
46721
+ "content-type": "application/json",
46722
+ "content-length": String(Buffer.byteLength(bodyStr)),
46723
+ // Use localhost to bypass SPT validation (WS already authenticated)
46724
+ host: "localhost"
46725
+ },
46726
+ socket: { remoteAddress: "127.0.0.1" }
46727
+ });
46728
+ req.push(bodyStr);
46729
+ req.push(null);
46730
+ let responseStatus = 200;
46731
+ let responseBody = "";
46732
+ const chunks = [];
46733
+ const res = {
46734
+ writeHead: (status) => {
46735
+ responseStatus = status;
46736
+ },
46737
+ write: (chunk) => {
46738
+ chunks.push(typeof chunk === "string" ? chunk : chunk.toString());
46739
+ return true;
46740
+ },
46741
+ end: (data) => {
46742
+ if (data) chunks.push(typeof data === "string" ? data : data.toString());
46743
+ responseBody = chunks.join("");
46744
+ },
46745
+ setHeader: () => {
46746
+ },
46747
+ getHeader: () => void 0,
46748
+ statusCode: 200,
46749
+ headersSent: false
46750
+ };
46751
+ await mcpServer.handleRequest(req, res);
46752
+ if (responseBody) {
46753
+ try {
46754
+ return JSON.parse(responseBody);
46755
+ } catch {
46756
+ return { jsonrpc: "2.0", error: { code: -32603, message: responseBody } };
46757
+ }
46758
+ }
46759
+ return null;
46760
+ }
46761
+ var init_mcp_proxy_helpers = __esm({
46762
+ "src/mcp-proxy-helpers.ts"() {
46763
+ "use strict";
46764
+ }
46765
+ });
46766
+
46688
46767
  // src/workspace-handlers.ts
46689
46768
  var workspace_handlers_exports = {};
46690
46769
  __export(workspace_handlers_exports, {
@@ -46900,6 +46979,7 @@ var init_channel = __esm({
46900
46979
  _stopped = false;
46901
46980
  _persisted = null;
46902
46981
  _httpServer = null;
46982
+ _mcpServer = null;
46903
46983
  _pollFallbackTimer = null;
46904
46984
  _heartbeatTimer = null;
46905
46985
  _heartbeatCallback = null;
@@ -47951,9 +48031,28 @@ var init_channel = __esm({
47951
48031
  const result = handlers.handleTargetsRequest(this);
47952
48032
  res.writeHead(result.status, { "Content-Type": "application/json" });
47953
48033
  res.end(JSON.stringify(result.body));
48034
+ } else if (req.url === "/mcp" && (req.method === "POST" || req.method === "GET" || req.method === "DELETE")) {
48035
+ if (!this._mcpServer) {
48036
+ res.writeHead(503, { "Content-Type": "application/json" });
48037
+ res.end(JSON.stringify({ ok: false, error: "MCP server not initialized" }));
48038
+ return;
48039
+ }
48040
+ this._mcpServer.handleRequest(req, res).catch((err) => {
48041
+ console.error("[MCP] Request handling error:", err);
48042
+ if (!res.headersSent) {
48043
+ res.writeHead(500, { "Content-Type": "application/json" });
48044
+ res.end(JSON.stringify({ ok: false, error: "Internal MCP error" }));
48045
+ }
48046
+ });
48047
+ } else if (req.method === "GET" && req.url === "/mcp-config") {
48048
+ const agentName = this.config.agentName ?? "agent";
48049
+ const mcpSkillCount = this._mcpServer?.skillCount ?? 0;
48050
+ const result = handlers.handleMcpConfigRequest(agentName, port, mcpSkillCount);
48051
+ res.writeHead(result.status, { "Content-Type": "application/json" });
48052
+ res.end(JSON.stringify(result.body));
47954
48053
  } else {
47955
48054
  res.writeHead(404, { "Content-Type": "application/json" });
47956
- res.end(JSON.stringify({ ok: false, error: "Not found. Use POST /send, POST /decision, POST /action, GET /status, or GET /targets" }));
48055
+ res.end(JSON.stringify({ ok: false, error: "Not found. Use POST /send, POST /decision, POST /action, GET /status, GET /targets, or /mcp" }));
47957
48056
  }
47958
48057
  });
47959
48058
  this._httpServer.listen(port, "127.0.0.1", () => {
@@ -47966,6 +48065,17 @@ var init_channel = __esm({
47966
48065
  this._httpServer = null;
47967
48066
  }
47968
48067
  }
48068
+ /**
48069
+ * Attach an MCP server instance to this channel.
48070
+ * The MCP server will be served at /mcp on the local HTTP server.
48071
+ */
48072
+ setMcpServer(mcpServer) {
48073
+ this._mcpServer = mcpServer;
48074
+ }
48075
+ /** The attached MCP server, if any. */
48076
+ get mcpServer() {
48077
+ return this._mcpServer;
48078
+ }
47969
48079
  // --- Topic management ---
47970
48080
  /**
47971
48081
  * Create a new topic within the conversation group.
@@ -48560,6 +48670,33 @@ var init_channel = __esm({
48560
48670
  await this._fetchScanRules();
48561
48671
  return;
48562
48672
  }
48673
+ if (data.event === "mcp_request") {
48674
+ const requestId = data.data?.request_id;
48675
+ const mcpPayload = data.data?.mcp_payload;
48676
+ if (requestId && mcpPayload && this._mcpServer) {
48677
+ try {
48678
+ const { createMcpProxyRequest: createMcpProxyRequest2 } = await Promise.resolve().then(() => (init_mcp_proxy_helpers(), mcp_proxy_helpers_exports));
48679
+ const mcpResponse = await createMcpProxyRequest2(this._mcpServer, mcpPayload);
48680
+ ws.send(JSON.stringify({
48681
+ event: "mcp_response",
48682
+ data: { request_id: requestId, mcp_payload: mcpResponse }
48683
+ }));
48684
+ } catch (err) {
48685
+ ws.send(JSON.stringify({
48686
+ event: "mcp_response",
48687
+ data: {
48688
+ request_id: requestId,
48689
+ mcp_payload: {
48690
+ jsonrpc: "2.0",
48691
+ id: mcpPayload?.id ?? null,
48692
+ error: { code: -32603, message: String(err) }
48693
+ }
48694
+ }
48695
+ }));
48696
+ }
48697
+ }
48698
+ return;
48699
+ }
48563
48700
  if (data.event === "hub_identity_sync") {
48564
48701
  if (this._persisted && data.data?.hub_id) {
48565
48702
  const changed = this._persisted.hubId !== data.data.hub_id || this._persisted.agentRole !== (data.data.agent_role ?? "peer");
@@ -74952,7 +75089,7 @@ var init_mcp = __esm({
74952
75089
  // ../../node_modules/@hono/node-server/dist/index.mjs
74953
75090
  import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
74954
75091
  import { Http2ServerRequest } from "http2";
74955
- import { Readable } from "stream";
75092
+ import { Readable as Readable2 } from "stream";
74956
75093
  import crypto2 from "crypto";
74957
75094
  async function readWithoutBlocking(readPromise) {
74958
75095
  return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]);
@@ -75069,7 +75206,7 @@ var init_dist2 = __esm({
75069
75206
  init.body = new ReadableStream({
75070
75207
  async pull(controller) {
75071
75208
  try {
75072
- reader ||= Readable.toWeb(incoming).getReader();
75209
+ reader ||= Readable2.toWeb(incoming).getReader();
75073
75210
  const { done, value } = await reader.read();
75074
75211
  if (done) {
75075
75212
  controller.close();
@@ -75082,7 +75219,7 @@ var init_dist2 = __esm({
75082
75219
  }
75083
75220
  });
75084
75221
  } else {
75085
- init.body = Readable.toWeb(incoming);
75222
+ init.body = Readable2.toWeb(incoming);
75086
75223
  }
75087
75224
  }
75088
75225
  return new Request2(url2, init);
@@ -76278,23 +76415,29 @@ var init_mcp_server2 = __esm({
76278
76415
  * Each request gets a fresh stateless transport; after the response is
76279
76416
  * flushed the transport + underlying protocol connection are torn down
76280
76417
  * so the single McpServer instance is ready for the next caller.
76418
+ *
76419
+ * Local requests from 127.0.0.1/::1 bypass SPT validation (owner access).
76281
76420
  */
76282
76421
  async handleRequest(req, res) {
76283
76422
  if (!this.initialized) {
76284
76423
  this.initialize();
76285
76424
  }
76286
- const authHeader = req.headers.authorization;
76287
- if (!authHeader?.startsWith("Bearer ")) {
76288
- res.writeHead(401, { "Content-Type": "application/json" });
76289
- res.end(JSON.stringify({ error: "Missing or invalid Authorization header" }));
76290
- return;
76291
- }
76292
- const token = authHeader.slice(7);
76293
- const valid = await this.validateSpt(token);
76294
- if (!valid) {
76295
- res.writeHead(403, { "Content-Type": "application/json" });
76296
- res.end(JSON.stringify({ error: "Invalid or expired SPT token" }));
76297
- return;
76425
+ const remote = req.socket?.remoteAddress;
76426
+ const isLocal = remote === "127.0.0.1" || remote === "::1" || remote === "::ffff:127.0.0.1";
76427
+ if (!isLocal) {
76428
+ const authHeader = req.headers.authorization;
76429
+ if (!authHeader?.startsWith("Bearer ")) {
76430
+ res.writeHead(401, { "Content-Type": "application/json" });
76431
+ res.end(JSON.stringify({ error: "Missing or invalid Authorization header" }));
76432
+ return;
76433
+ }
76434
+ const token = authHeader.slice(7);
76435
+ const valid = await this.validateSpt(token);
76436
+ if (!valid) {
76437
+ res.writeHead(403, { "Content-Type": "application/json" });
76438
+ res.end(JSON.stringify({ error: "Invalid or expired SPT token" }));
76439
+ return;
76440
+ }
76298
76441
  }
76299
76442
  const transport = new StreamableHTTPServerTransport({
76300
76443
  sessionIdGenerator: void 0