@muxoai/sdk 1.2.3 → 1.4.2

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 (208) hide show
  1. package/.agents/plugins/marketplace.json +22 -0
  2. package/.claude-plugin/marketplace.json +32 -0
  3. package/.codex/config.toml +12 -0
  4. package/ARCHITECTURE.md +121 -0
  5. package/README.md +85 -31
  6. package/dist/clerk.d.ts +35 -0
  7. package/dist/clerk.js +201 -0
  8. package/dist/cli.d.ts +2 -0
  9. package/dist/cli.js +2380 -0
  10. package/dist/composio-catalog.d.ts +234 -0
  11. package/dist/composio-catalog.js +1894 -0
  12. package/dist/config.d.ts +36 -0
  13. package/dist/config.js +115 -0
  14. package/dist/durable-workflow.d.ts +45 -0
  15. package/dist/durable-workflow.js +90 -0
  16. package/dist/engine.d.ts +465 -0
  17. package/dist/engine.js +2560 -0
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.js +7 -0
  20. package/dist/mcp-schema.d.ts +286 -0
  21. package/dist/mcp-schema.js +2559 -0
  22. package/dist/mcp.d.ts +22 -0
  23. package/dist/mcp.js +1356 -0
  24. package/dist/memory-graph.d.ts +21 -0
  25. package/dist/memory-graph.js +173 -0
  26. package/dist/nl.d.ts +34 -0
  27. package/dist/nl.js +756 -0
  28. package/dist/oauth.d.ts +32 -0
  29. package/dist/oauth.js +134 -0
  30. package/dist/policy.d.ts +190 -0
  31. package/dist/policy.js +1597 -0
  32. package/dist/providers/composio-instant.d.ts +18 -0
  33. package/dist/providers/composio-instant.js +1169 -0
  34. package/dist/providers/composio-sdk.d.ts +162 -0
  35. package/dist/providers/composio-sdk.js +1395 -0
  36. package/dist/providers/microsoft-governance.d.ts +152 -0
  37. package/dist/providers/microsoft-governance.js +1062 -0
  38. package/dist/providers/stripe-billing.d.ts +83 -0
  39. package/dist/providers/stripe-billing.js +611 -0
  40. package/dist/providers/stripe-projects.d.ts +508 -0
  41. package/dist/providers/stripe-projects.js +3188 -0
  42. package/dist/providers/supermemory.d.ts +160 -0
  43. package/dist/providers/supermemory.js +778 -0
  44. package/dist/provisioning-managed.d.ts +50 -0
  45. package/dist/provisioning-managed.js +155 -0
  46. package/dist/sdk.d.ts +951 -0
  47. package/dist/sdk.js +748 -0
  48. package/dist/server.d.ts +10 -0
  49. package/dist/server.js +3575 -0
  50. package/dist/store.d.ts +348 -0
  51. package/dist/store.js +2323 -0
  52. package/dist/types.d.ts +593 -0
  53. package/dist/types.js +1 -0
  54. package/dist/ui/console-html.d.ts +64 -0
  55. package/dist/ui/console-html.js +3857 -0
  56. package/dist/ui/design-tokens.d.ts +177 -0
  57. package/dist/ui/design-tokens.js +210 -0
  58. package/dist/version.d.ts +1 -0
  59. package/dist/version.js +1 -0
  60. package/package.json +68 -7
  61. package/plugins/muxo/.app.json +8 -0
  62. package/plugins/muxo/.claude-plugin/plugin.json +16 -0
  63. package/plugins/muxo/.codex-plugin/plugin.json +64 -0
  64. package/plugins/muxo/.cursor-plugin/plugin.json +30 -0
  65. package/plugins/muxo/.mcp.json +8 -0
  66. package/plugins/muxo/assets/logo.png +0 -0
  67. package/plugins/muxo/assets/logo.svg +6 -0
  68. package/plugins/muxo/hooks/hooks.json +27 -0
  69. package/plugins/muxo/hooks/session-start.sh +97 -0
  70. package/plugins/muxo/hooks/user-prompt-submit.sh +58 -0
  71. package/plugins/muxo/mcp.json +28 -0
  72. package/plugins/muxo/plugin.json +116 -0
  73. package/plugins/muxo/skills/muxo/SKILL.md +153 -0
  74. package/plugins/muxo/skills/muxo/agents/openai.yaml +12 -0
  75. package/plugins/muxo/skills/muxo/references/cli.md +63 -0
  76. package/plugins/muxo/skills/muxo/references/mcp.md +37 -0
  77. package/plugins/muxo/skills/muxo-activity-summary/SKILL.md +81 -0
  78. package/plugins/muxo/skills/setup/SKILL.md +42 -0
  79. package/plugins/muxo/skills/setup/agents/openai.yaml +12 -0
  80. package/src/catalogues/stripe-projects-catalog.json +9972 -0
  81. package/vendor/microsoft-governance/README.md +363 -0
  82. package/vendor/microsoft-governance/dist/audit.d.ts +26 -0
  83. package/vendor/microsoft-governance/dist/audit.d.ts.map +1 -0
  84. package/vendor/microsoft-governance/dist/audit.js +107 -0
  85. package/vendor/microsoft-governance/dist/audit.js.map +1 -0
  86. package/vendor/microsoft-governance/dist/cascade-containment.d.ts +84 -0
  87. package/vendor/microsoft-governance/dist/cascade-containment.d.ts.map +1 -0
  88. package/vendor/microsoft-governance/dist/cascade-containment.js +387 -0
  89. package/vendor/microsoft-governance/dist/cascade-containment.js.map +1 -0
  90. package/vendor/microsoft-governance/dist/client.d.ts +34 -0
  91. package/vendor/microsoft-governance/dist/client.d.ts.map +1 -0
  92. package/vendor/microsoft-governance/dist/client.js +112 -0
  93. package/vendor/microsoft-governance/dist/client.js.map +1 -0
  94. package/vendor/microsoft-governance/dist/context-poisoning.d.ts +58 -0
  95. package/vendor/microsoft-governance/dist/context-poisoning.d.ts.map +1 -0
  96. package/vendor/microsoft-governance/dist/context-poisoning.js +410 -0
  97. package/vendor/microsoft-governance/dist/context-poisoning.js.map +1 -0
  98. package/vendor/microsoft-governance/dist/credential-vault.d.ts +213 -0
  99. package/vendor/microsoft-governance/dist/credential-vault.d.ts.map +1 -0
  100. package/vendor/microsoft-governance/dist/credential-vault.js +567 -0
  101. package/vendor/microsoft-governance/dist/credential-vault.js.map +1 -0
  102. package/vendor/microsoft-governance/dist/discovery.d.ts +80 -0
  103. package/vendor/microsoft-governance/dist/discovery.d.ts.map +1 -0
  104. package/vendor/microsoft-governance/dist/discovery.js +404 -0
  105. package/vendor/microsoft-governance/dist/discovery.js.map +1 -0
  106. package/vendor/microsoft-governance/dist/encryption/channel.d.ts +29 -0
  107. package/vendor/microsoft-governance/dist/encryption/channel.d.ts.map +1 -0
  108. package/vendor/microsoft-governance/dist/encryption/channel.js +78 -0
  109. package/vendor/microsoft-governance/dist/encryption/channel.js.map +1 -0
  110. package/vendor/microsoft-governance/dist/encryption/index.d.ts +9 -0
  111. package/vendor/microsoft-governance/dist/encryption/index.d.ts.map +1 -0
  112. package/vendor/microsoft-governance/dist/encryption/index.js +23 -0
  113. package/vendor/microsoft-governance/dist/encryption/index.js.map +1 -0
  114. package/vendor/microsoft-governance/dist/encryption/mesh-client.d.ts +267 -0
  115. package/vendor/microsoft-governance/dist/encryption/mesh-client.d.ts.map +1 -0
  116. package/vendor/microsoft-governance/dist/encryption/mesh-client.js +1001 -0
  117. package/vendor/microsoft-governance/dist/encryption/mesh-client.js.map +1 -0
  118. package/vendor/microsoft-governance/dist/encryption/ratchet.d.ts +38 -0
  119. package/vendor/microsoft-governance/dist/encryption/ratchet.d.ts.map +1 -0
  120. package/vendor/microsoft-governance/dist/encryption/ratchet.js +223 -0
  121. package/vendor/microsoft-governance/dist/encryption/ratchet.js.map +1 -0
  122. package/vendor/microsoft-governance/dist/encryption/registry-client.d.ts +136 -0
  123. package/vendor/microsoft-governance/dist/encryption/registry-client.d.ts.map +1 -0
  124. package/vendor/microsoft-governance/dist/encryption/registry-client.js +369 -0
  125. package/vendor/microsoft-governance/dist/encryption/registry-client.js.map +1 -0
  126. package/vendor/microsoft-governance/dist/encryption/x3dh.d.ts +80 -0
  127. package/vendor/microsoft-governance/dist/encryption/x3dh.d.ts.map +1 -0
  128. package/vendor/microsoft-governance/dist/encryption/x3dh.js +238 -0
  129. package/vendor/microsoft-governance/dist/encryption/x3dh.js.map +1 -0
  130. package/vendor/microsoft-governance/dist/framework-adapter.d.ts +63 -0
  131. package/vendor/microsoft-governance/dist/framework-adapter.d.ts.map +1 -0
  132. package/vendor/microsoft-governance/dist/framework-adapter.js +253 -0
  133. package/vendor/microsoft-governance/dist/framework-adapter.js.map +1 -0
  134. package/vendor/microsoft-governance/dist/identity.d.ts +124 -0
  135. package/vendor/microsoft-governance/dist/identity.d.ts.map +1 -0
  136. package/vendor/microsoft-governance/dist/identity.js +446 -0
  137. package/vendor/microsoft-governance/dist/identity.js.map +1 -0
  138. package/vendor/microsoft-governance/dist/index.d.ts +39 -0
  139. package/vendor/microsoft-governance/dist/index.d.ts.map +1 -0
  140. package/vendor/microsoft-governance/dist/index.js +95 -0
  141. package/vendor/microsoft-governance/dist/index.js.map +1 -0
  142. package/vendor/microsoft-governance/dist/kill-switch.d.ts +22 -0
  143. package/vendor/microsoft-governance/dist/kill-switch.d.ts.map +1 -0
  144. package/vendor/microsoft-governance/dist/kill-switch.js +60 -0
  145. package/vendor/microsoft-governance/dist/kill-switch.js.map +1 -0
  146. package/vendor/microsoft-governance/dist/lifecycle.d.ts +50 -0
  147. package/vendor/microsoft-governance/dist/lifecycle.d.ts.map +1 -0
  148. package/vendor/microsoft-governance/dist/lifecycle.js +113 -0
  149. package/vendor/microsoft-governance/dist/lifecycle.js.map +1 -0
  150. package/vendor/microsoft-governance/dist/mcp.d.ts +41 -0
  151. package/vendor/microsoft-governance/dist/mcp.d.ts.map +1 -0
  152. package/vendor/microsoft-governance/dist/mcp.js +233 -0
  153. package/vendor/microsoft-governance/dist/mcp.js.map +1 -0
  154. package/vendor/microsoft-governance/dist/metrics.d.ts +123 -0
  155. package/vendor/microsoft-governance/dist/metrics.d.ts.map +1 -0
  156. package/vendor/microsoft-governance/dist/metrics.js +289 -0
  157. package/vendor/microsoft-governance/dist/metrics.js.map +1 -0
  158. package/vendor/microsoft-governance/dist/oci-manifest.d.ts +49 -0
  159. package/vendor/microsoft-governance/dist/oci-manifest.d.ts.map +1 -0
  160. package/vendor/microsoft-governance/dist/oci-manifest.js +182 -0
  161. package/vendor/microsoft-governance/dist/oci-manifest.js.map +1 -0
  162. package/vendor/microsoft-governance/dist/policy-backends/cedar.d.ts +15 -0
  163. package/vendor/microsoft-governance/dist/policy-backends/cedar.d.ts.map +1 -0
  164. package/vendor/microsoft-governance/dist/policy-backends/cedar.js +88 -0
  165. package/vendor/microsoft-governance/dist/policy-backends/cedar.js.map +1 -0
  166. package/vendor/microsoft-governance/dist/policy-backends/opa.d.ts +17 -0
  167. package/vendor/microsoft-governance/dist/policy-backends/opa.d.ts.map +1 -0
  168. package/vendor/microsoft-governance/dist/policy-backends/opa.js +74 -0
  169. package/vendor/microsoft-governance/dist/policy-backends/opa.js.map +1 -0
  170. package/vendor/microsoft-governance/dist/policy.d.ts +77 -0
  171. package/vendor/microsoft-governance/dist/policy.d.ts.map +1 -0
  172. package/vendor/microsoft-governance/dist/policy.js +760 -0
  173. package/vendor/microsoft-governance/dist/policy.js.map +1 -0
  174. package/vendor/microsoft-governance/dist/prompt-defense.d.ts +37 -0
  175. package/vendor/microsoft-governance/dist/prompt-defense.d.ts.map +1 -0
  176. package/vendor/microsoft-governance/dist/prompt-defense.js +229 -0
  177. package/vendor/microsoft-governance/dist/prompt-defense.js.map +1 -0
  178. package/vendor/microsoft-governance/dist/protocol-facets.d.ts +87 -0
  179. package/vendor/microsoft-governance/dist/protocol-facets.d.ts.map +1 -0
  180. package/vendor/microsoft-governance/dist/protocol-facets.js +728 -0
  181. package/vendor/microsoft-governance/dist/protocol-facets.js.map +1 -0
  182. package/vendor/microsoft-governance/dist/rings.d.ts +17 -0
  183. package/vendor/microsoft-governance/dist/rings.d.ts.map +1 -0
  184. package/vendor/microsoft-governance/dist/rings.js +61 -0
  185. package/vendor/microsoft-governance/dist/rings.js.map +1 -0
  186. package/vendor/microsoft-governance/dist/sandbox.d.ts +61 -0
  187. package/vendor/microsoft-governance/dist/sandbox.d.ts.map +1 -0
  188. package/vendor/microsoft-governance/dist/sandbox.js +199 -0
  189. package/vendor/microsoft-governance/dist/sandbox.js.map +1 -0
  190. package/vendor/microsoft-governance/dist/surface-parity.d.ts +45 -0
  191. package/vendor/microsoft-governance/dist/surface-parity.d.ts.map +1 -0
  192. package/vendor/microsoft-governance/dist/surface-parity.js +216 -0
  193. package/vendor/microsoft-governance/dist/surface-parity.js.map +1 -0
  194. package/vendor/microsoft-governance/dist/trust.d.ts +28 -0
  195. package/vendor/microsoft-governance/dist/trust.d.ts.map +1 -0
  196. package/vendor/microsoft-governance/dist/trust.js +209 -0
  197. package/vendor/microsoft-governance/dist/trust.js.map +1 -0
  198. package/vendor/microsoft-governance/dist/types.d.ts +422 -0
  199. package/vendor/microsoft-governance/dist/types.d.ts.map +1 -0
  200. package/vendor/microsoft-governance/dist/types.js +29 -0
  201. package/vendor/microsoft-governance/dist/types.js.map +1 -0
  202. package/vendor/microsoft-governance/dist/verify.d.ts +135 -0
  203. package/vendor/microsoft-governance/dist/verify.d.ts.map +1 -0
  204. package/vendor/microsoft-governance/dist/verify.js +356 -0
  205. package/vendor/microsoft-governance/dist/verify.js.map +1 -0
  206. package/vendor/microsoft-governance/package.json +64 -0
  207. package/index.d.ts +0 -177
  208. package/index.js +0 -1
package/dist/mcp.js ADDED
@@ -0,0 +1,1356 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { ROOT_DIR } from "./config.js";
5
+ import { APPROVED_PLAN_STATUSES, DEFAULT_LEGACY_MCP_PROTOCOL_VERSION, DEFAULT_TOOL_SECURITY_SCHEMES, LATEST_MCP_PROTOCOL_VERSION, MCP_ERR_HEADER_MISMATCH, MCP_ERR_MISSING_REQUIRED_CLIENT_CAPABILITY, MCP_ERR_UNSUPPORTED_PROTOCOL_VERSION, MUXO_MCP_RESOURCE_TEMPLATES, MUXO_MCP_SERVER_INSTRUCTIONS, MUXO_MCP_TOOLS, MUXO_UI_MCP_APP_URI, MUXO_UI_RESOURCES, MUXO_UI_WIDGET_URI, OPENAI_COMPANY_KNOWLEDGE_TOOLS, PUBLIC_MCP_TOOL_NAMES, PUBLIC_TOOL_SECURITY_SCHEMES, SUPPORTED_MCP_PROTOCOL_VERSIONS, UI_RENDERED_MCP_TOOL_NAMES, attachMcpHarnessGuidance, MuxoToolError, buildApprovalUrl, buildMcpDiscoverResult, buildMcpErrorResultMeta, buildMcpToolDescriptor, buildMcpToolResultMeta, buildOnboardTeamGuide, clampWaitSeconds, completeMcpArgument, decodeMcpHeaderValue, errorPayloadFrom, extractOpenAiClientMeta, findMcpSkill, isSupportedMcpProtocolVersion, renderMuxoUiWidgetHtml, securitySchemesForTool, validateMcpHttpHeadersAndMeta, } from "./mcp-schema.js";
6
+ import { MUXO_VERSION } from "./version.js";
7
+ export { DEFAULT_LEGACY_MCP_PROTOCOL_VERSION, DEFAULT_TOOL_SECURITY_SCHEMES, LATEST_MCP_PROTOCOL_VERSION, MCP_ERR_HEADER_MISMATCH, MCP_ERR_MISSING_REQUIRED_CLIENT_CAPABILITY, MCP_ERR_UNSUPPORTED_PROTOCOL_VERSION, MUXO_MCP_RESOURCE_TEMPLATES, MUXO_MCP_SERVER_INSTRUCTIONS, MUXO_MCP_TOOLS, MUXO_UI_MCP_APP_URI, MUXO_UI_RESOURCES, MUXO_UI_WIDGET_URI, OPENAI_COMPANY_KNOWLEDGE_TOOLS, PUBLIC_MCP_TOOL_NAMES, PUBLIC_TOOL_SECURITY_SCHEMES, SUPPORTED_MCP_PROTOCOL_VERSIONS, UI_RENDERED_MCP_TOOL_NAMES, attachMcpHarnessGuidance, buildMcpDiscoverResult, buildMcpErrorResultMeta, buildMcpToolDescriptor, buildMcpToolResultMeta, completeMcpArgument, decodeMcpHeaderValue, extractOpenAiClientMeta, isSupportedMcpProtocolVersion, renderMuxoUiWidgetHtml, securitySchemesForTool, validateMcpHttpHeadersAndMeta, };
8
+ function sha256Digest(content) {
9
+ const hash = crypto
10
+ .createHash("sha256")
11
+ .update(Buffer.from(content, "utf8"))
12
+ .digest("hex");
13
+ return `sha256:${hash}`;
14
+ }
15
+ function parseFrontmatter(markdown) {
16
+ const match = markdown.match(/^---\r?\n([\s\S]*?)\r?\n---/);
17
+ if (!match)
18
+ return {};
19
+ const result = {};
20
+ for (const line of match[1].split(/\r?\n/)) {
21
+ const idx = line.indexOf(":");
22
+ if (idx > 0) {
23
+ const k = line.slice(0, idx).trim();
24
+ const v = line.slice(idx + 1).trim();
25
+ if (k && v)
26
+ result[k] = v;
27
+ }
28
+ }
29
+ return result;
30
+ }
31
+ function readSkillFileOrDefault(relPath, fallback) {
32
+ try {
33
+ const absPath = path.join(ROOT_DIR, "plugins", "muxo", "skills", relPath);
34
+ if (fs.existsSync(absPath)) {
35
+ return fs.readFileSync(absPath, "utf8");
36
+ }
37
+ }
38
+ catch {
39
+ // Fallback to embedded markdown
40
+ }
41
+ return fallback;
42
+ }
43
+ export function getMuxoMcpSkills() {
44
+ const muxoSkillMd = readSkillFileOrDefault("muxo/SKILL.md", `---
45
+ name: muxo
46
+ description: Route governed Muxo work between the hosted MCP-backed app and the local Muxo CLI across Muxo Connected Apps, Instant Tools, Cloud Infrastructure (Stripe Projects), Supermemory v5, and Microsoft Agent Governance.
47
+ ---
48
+
49
+ # Muxo
50
+
51
+ Use \`search_tools\`, \`inspect_tool\`, \`plan_action\`, \`wait_for_connection\`, and \`execute_<risk>\` to run governed actions across Connected Apps (\`app.*\`), Instant Tools (\`instant.*\`), and Cloud Infrastructure (\`resource.*\`).
52
+ `);
53
+ const muxoCliMd = readSkillFileOrDefault("muxo/references/cli.md", `# Local Muxo CLI\n\nRun \`muxo login --signup\`, \`muxo search\`, \`muxo link <provider> --wait\`, \`muxo exec\`, and \`muxo env pull\`.`);
54
+ const muxoMcpMd = readSkillFileOrDefault("muxo/references/mcp.md", `# Hosted Muxo MCP App\n\nFollow \`search_tools\` -> \`inspect_tool\` -> \`plan_action\` -> \`wait_for_connection\` -> \`execute_<risk>\` -> \`get_receipt\`.`);
55
+ const setupSkillMd = readSkillFileOrDefault("setup/SKILL.md", `---
56
+ name: setup
57
+ description: Guided onboarding skill for setting up the Muxo plugin in OpenAI ChatGPT and Codex. Helps users verify workspace authorization, connect external SaaS apps via OAuth handoff, provision cloud infrastructure, or install the local Muxo CLI.
58
+ ---
59
+
60
+ # Muxo Onboarding & Setup
61
+
62
+ Call \`get_profile\` and \`get_organization\` to verify your workspace connection, or run \`npx -y @muxoai/cli@latest login --signup\` in a terminal.
63
+ `);
64
+ const muxoOpenaiYaml = readSkillFileOrDefault("muxo/agents/openai.yaml", `interface:\n display_name: "Muxo"\n short_description: "Governed SaaS, Instant Web/SEO tools, Cloud Infrastructure, and Workspace Memory"\n default_prompt: "Audit https://muxo.ai for technical SEO and crawl its top pages."\n\ndependencies:\n tools:\n - type: "mcp"\n value: "muxo"\n description: "Muxo Governed Execution, Instant Web/SEO Tools, Connected Apps, and Cloud Infrastructure MCP Server"\n transport: "streamable_http"\n url: "https://api.muxo.ai/mcp"\n`);
65
+ const setupOpenaiYaml = readSkillFileOrDefault("setup/agents/openai.yaml", `interface:\n display_name: "Muxo Setup"\n short_description: "Guided onboarding and connection verification for Muxo in ChatGPT and Codex"\n default_prompt: "Check my Muxo profile and organization status."\n\ndependencies:\n tools:\n - type: "mcp"\n value: "muxo"\n description: "Muxo Governed Execution, Instant Web/SEO Tools, Connected Apps, and Cloud Infrastructure MCP Server"\n transport: "streamable_http"\n url: "https://api.muxo.ai/mcp"\n`);
66
+ const muxoFm = parseFrontmatter(muxoSkillMd);
67
+ const setupFm = parseFrontmatter(setupSkillMd);
68
+ const muxoFiles = [
69
+ {
70
+ path: "SKILL.md",
71
+ uri: "skill://muxo/muxo/SKILL.md",
72
+ size: Buffer.byteLength(muxoSkillMd, "utf8"),
73
+ digest: sha256Digest(muxoSkillMd),
74
+ mimeType: "text/markdown",
75
+ content: muxoSkillMd,
76
+ },
77
+ {
78
+ path: "agents/openai.yaml",
79
+ uri: "skill://muxo/muxo/agents/openai.yaml",
80
+ size: Buffer.byteLength(muxoOpenaiYaml, "utf8"),
81
+ digest: sha256Digest(muxoOpenaiYaml),
82
+ mimeType: "application/yaml",
83
+ content: muxoOpenaiYaml,
84
+ },
85
+ {
86
+ path: "references/cli.md",
87
+ uri: "skill://muxo/muxo/references/cli.md",
88
+ size: Buffer.byteLength(muxoCliMd, "utf8"),
89
+ digest: sha256Digest(muxoCliMd),
90
+ mimeType: "text/markdown",
91
+ content: muxoCliMd,
92
+ },
93
+ {
94
+ path: "references/mcp.md",
95
+ uri: "skill://muxo/muxo/references/mcp.md",
96
+ size: Buffer.byteLength(muxoMcpMd, "utf8"),
97
+ digest: sha256Digest(muxoMcpMd),
98
+ mimeType: "text/markdown",
99
+ content: muxoMcpMd,
100
+ },
101
+ ];
102
+ const setupFiles = [
103
+ {
104
+ path: "SKILL.md",
105
+ uri: "skill://muxo/setup/SKILL.md",
106
+ size: Buffer.byteLength(setupSkillMd, "utf8"),
107
+ digest: sha256Digest(setupSkillMd),
108
+ mimeType: "text/markdown",
109
+ content: setupSkillMd,
110
+ },
111
+ {
112
+ path: "agents/openai.yaml",
113
+ uri: "skill://muxo/setup/agents/openai.yaml",
114
+ size: Buffer.byteLength(setupOpenaiYaml, "utf8"),
115
+ digest: sha256Digest(setupOpenaiYaml),
116
+ mimeType: "application/yaml",
117
+ content: setupOpenaiYaml,
118
+ },
119
+ ];
120
+ const muxoName = muxoFm.name || "muxo";
121
+ const muxoDesc = muxoFm.description ||
122
+ "Route governed Muxo work between the hosted MCP-backed app and the local Muxo CLI.";
123
+ const setupName = setupFm.name || "setup";
124
+ const setupDesc = setupFm.description ||
125
+ "Guided onboarding skill for setting up the Muxo plugin in OpenAI ChatGPT and Codex.";
126
+ return [
127
+ {
128
+ name: muxoName,
129
+ description: muxoDesc,
130
+ uri: "skill://muxo/muxo/SKILL.md",
131
+ version: muxoFiles[0].digest,
132
+ frontmatter: {
133
+ name: muxoName,
134
+ description: muxoDesc,
135
+ },
136
+ files: muxoFiles,
137
+ },
138
+ {
139
+ name: setupName,
140
+ description: setupDesc,
141
+ uri: "skill://muxo/setup/SKILL.md",
142
+ version: setupFiles[0].digest,
143
+ frontmatter: {
144
+ name: setupName,
145
+ description: setupDesc,
146
+ },
147
+ files: setupFiles,
148
+ },
149
+ ];
150
+ }
151
+ export async function dispatchMcpToolCall(engine, ctx, toolName, args = {}) {
152
+ switch (toolName) {
153
+ case "get_profile":
154
+ return engine.getProfile(ctx);
155
+ case "get_organization":
156
+ return engine.getOrganization(ctx);
157
+ case "search_tools":
158
+ return engine.searchTools({
159
+ query: args.query ? String(args.query) : undefined,
160
+ lane: args.lane || "all",
161
+ riskLevel: args.risk_level,
162
+ limit: args.limit ? Number(args.limit) : 20,
163
+ });
164
+ case "inspect_tool":
165
+ return engine.inspectTool(String(args.tool_slug || args.slug || ""));
166
+ case "connection_status":
167
+ return engine.connectionStatus(ctx, {
168
+ provider: args.provider ? String(args.provider) : undefined,
169
+ syncLive: args.sync_live !== false,
170
+ });
171
+ case "start_connection": {
172
+ const conn = await engine.startConnection(ctx, {
173
+ provider: String(args.provider || ""),
174
+ lane: args.lane,
175
+ callbackUrl: args.callback_url ? String(args.callback_url) : undefined,
176
+ });
177
+ return {
178
+ ok: true,
179
+ ...conn,
180
+ connection: conn,
181
+ };
182
+ }
183
+ case "wait_for_connection":
184
+ return engine.waitForConnection(ctx, {
185
+ provider: String(args.provider || ""),
186
+ timeoutSeconds: clampWaitSeconds(args.timeout_seconds),
187
+ });
188
+ case "plan_action":
189
+ return engine.planAction(ctx, {
190
+ toolSlug: String(args.tool_slug ||
191
+ args.slug ||
192
+ args.tool_id ||
193
+ args.prompt ||
194
+ args.instruction ||
195
+ ""),
196
+ input: (args.input || args.arguments) || {},
197
+ reason: args.reason ? String(args.reason) : undefined,
198
+ });
199
+ case "get_plan":
200
+ if (args.wait_for_approval === true || args.wait === true) {
201
+ return engine.waitForPlanApproval(ctx, {
202
+ planId: String(args.plan_id || ""),
203
+ timeoutSeconds: clampWaitSeconds(args.timeout_seconds, 15, 60),
204
+ });
205
+ }
206
+ {
207
+ const plan = engine.getPlan(ctx, String(args.plan_id || ""));
208
+ return {
209
+ ok: true,
210
+ approved: APPROVED_PLAN_STATUSES.has(plan.approvalStatus),
211
+ timedOut: false,
212
+ plan,
213
+ approvalStatus: plan.approvalStatus,
214
+ approvalUrl: buildApprovalUrl(engine.config.baseUrl, plan.id),
215
+ };
216
+ }
217
+ case "get_run_context": {
218
+ const action = String(args.action || "").trim().toLowerCase();
219
+ const prompt = String(args.prompt || "").trim();
220
+ const query = args.query ? String(args.query) : undefined;
221
+ const rawParamRules = Array.isArray(args.parameter_rules)
222
+ ? args.parameter_rules
223
+ : Array.isArray(args.parameterRules)
224
+ ? args.parameterRules
225
+ : undefined;
226
+ if (action === "memory_graph") {
227
+ return engine.getMemoryGraph(ctx, query);
228
+ }
229
+ if (action === "governance_status") {
230
+ return engine.getGovernanceOverview(ctx);
231
+ }
232
+ if (action === "list_workspaces") {
233
+ const workspaces = engine.store.listUserWorkspaces(ctx.user.id, ctx.workspace.id);
234
+ return {
235
+ ok: true,
236
+ action,
237
+ currentWorkspaceId: ctx.workspace.id,
238
+ activeWorkspace: workspaces.find((w) => w.id === ctx.workspace.id) || {
239
+ id: ctx.workspace.id,
240
+ name: ctx.workspace.name,
241
+ slug: ctx.workspace.slug,
242
+ tier: ctx.workspace.tier,
243
+ },
244
+ workspaces,
245
+ };
246
+ }
247
+ if (action === "switch_workspace") {
248
+ const targetWsId = String(args.workspace_id || query || prompt || "").trim();
249
+ if (!targetWsId) {
250
+ throw new Error("workspace_id is required when action='switch_workspace'");
251
+ }
252
+ const switched = engine.store.switchUserWorkspace(ctx.user.id, targetWsId);
253
+ if (!switched) {
254
+ throw new Error(`Workspace ${targetWsId} not found or not linked to your account. Call get_run_context with action='list_workspaces' to see accessible workspaces.`);
255
+ }
256
+ return {
257
+ ok: true,
258
+ action,
259
+ switched: true,
260
+ workspaceId: switched.workspace.id,
261
+ workspace: switched.workspace,
262
+ workspaces: engine.store.listUserWorkspaces(ctx.user.id, switched.workspace.id),
263
+ message: `Active workspace for your session is now ${switched.workspace.name} (${switched.workspace.id}). API keys stay bound to their own workspace; use a key minted for ${switched.workspace.id} to target it over MCP.`,
264
+ };
265
+ }
266
+ if (action === "onboard_team") {
267
+ return buildOnboardTeamGuide({
268
+ baseUrl: engine.config.baseUrl,
269
+ workspaceId: ctx.workspace.id,
270
+ workspaceName: ctx.workspace.name,
271
+ teamName: String(args.team_name || args.teamName || query || prompt || "").trim(),
272
+ workspaces: engine.store.listUserWorkspaces(ctx.user.id, ctx.workspace.id),
273
+ });
274
+ }
275
+ if (action === "set_guardrail" &&
276
+ (prompt || (rawParamRules && rawParamRules.length > 0))) {
277
+ return engine.applyNaturalLanguageGuardrail(ctx, prompt, {
278
+ parameterRules: rawParamRules,
279
+ source: rawParamRules ? "mcp_harness" : "deterministic",
280
+ });
281
+ }
282
+ if (action === "reset_guardrails") {
283
+ return engine.resetWorkspaceGuardrails(ctx);
284
+ }
285
+ if (action === "check_policy" || action === "simulate_policy") {
286
+ const toolSlug = String(args.tool_slug || args.slug || args.tool_id || query || prompt || "instant.web.search").trim();
287
+ const input = (args.input || args.arguments) || {};
288
+ return engine.checkToolPolicy(ctx, { toolSlug, input });
289
+ }
290
+ if (action === "kill_switch") {
291
+ const enabled = typeof args.enabled === "boolean"
292
+ ? args.enabled
293
+ : typeof args.active === "boolean"
294
+ ? args.active
295
+ : !/\b(resume|unpause|disable|off|false)\b/i.test(prompt || query || "");
296
+ const reason = prompt ||
297
+ query ||
298
+ (enabled ? "Paused via MCP get_run_context" : undefined);
299
+ const updated = engine.setKillSwitch(ctx, enabled, reason);
300
+ const govOverview = engine.getGovernanceOverview(ctx);
301
+ return {
302
+ ok: true,
303
+ action: "kill_switch",
304
+ killSwitchActive: Boolean(updated.policy.killSwitchActive),
305
+ killSwitchReason: updated.policy.killSwitchReason || null,
306
+ policy: updated.policy,
307
+ llmPolicyBrief: govOverview.llmPolicyBrief,
308
+ explanation: govOverview.explanation,
309
+ };
310
+ }
311
+ if (action === "scan_context") {
312
+ const textToScan = String(args.content || prompt || query || "");
313
+ return engine.scanForContextPoisoning(ctx.workspace.id, textToScan);
314
+ }
315
+ if (action === "forget") {
316
+ if (!(query || prompt)) {
317
+ throw new Error("query is required when action='forget'");
318
+ }
319
+ return engine.forgetWorkspaceMemoryMatching(ctx, query || prompt);
320
+ }
321
+ if (action === "recall") {
322
+ return engine.getMemoryOverview(ctx, query);
323
+ }
324
+ if (action === "remember") {
325
+ if (prompt && !args.content) {
326
+ return engine.doNaturalLanguage(ctx, { prompt });
327
+ }
328
+ const record = await engine.addWorkspaceMemory(ctx, {
329
+ title: String(args.title || prompt.slice(0, 60) || "Workspace Fact"),
330
+ content: String(args.content || prompt || query || ""),
331
+ kind: "fact",
332
+ });
333
+ const overview = await engine.getMemoryOverview(ctx);
334
+ return {
335
+ ok: true,
336
+ memory: record,
337
+ activeDefaults: overview.activeDefaults,
338
+ explanation: overview.explanation,
339
+ };
340
+ }
341
+ if (prompt && !action) {
342
+ return engine.doNaturalLanguage(ctx, { prompt });
343
+ }
344
+ const runCtx = await engine.getRunContext(ctx, query);
345
+ if (args.include_graph === true) {
346
+ const memoryGraph = await engine.getMemoryGraph(ctx, query);
347
+ return { ...runCtx, memoryGraph };
348
+ }
349
+ return runCtx;
350
+ }
351
+ case "execute_read":
352
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "read");
353
+ case "execute_write":
354
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "write");
355
+ case "execute_admin":
356
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "admin");
357
+ case "execute_financial":
358
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "financial");
359
+ case "execute_provisioning":
360
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "provisioning");
361
+ case "execute_destructive":
362
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "destructive");
363
+ case "get_run":
364
+ return engine.getRun(ctx, String(args.run_id || ""));
365
+ case "cancel_run":
366
+ return engine.cancelRun(ctx, String(args.run_id || ""), args.reason ? String(args.reason) : undefined);
367
+ case "get_receipt": {
368
+ const targetId = String(args.receipt_id || args.run_id || "latest").trim();
369
+ if (targetId === "chain") {
370
+ return engine.verifyReceiptChain(ctx);
371
+ }
372
+ const verified = engine.getReceipt(ctx, targetId);
373
+ if (args.verify_chain === true) {
374
+ const receiptChain = engine.verifyReceiptChain(ctx);
375
+ return { ...verified, receiptChain };
376
+ }
377
+ return verified;
378
+ }
379
+ // Supermemory MCP & Governance direct tool aliases for agent harness interoperability
380
+ case "who_am_i":
381
+ return engine.getProfile(ctx);
382
+ case "list_spaces": {
383
+ const overview = await engine.getMemoryOverview(ctx);
384
+ return {
385
+ activeSpace: overview.namespace,
386
+ spaces: [
387
+ {
388
+ id: overview.namespace,
389
+ containerTag: overview.namespace,
390
+ workspaceId: ctx.workspace.id,
391
+ workspaceName: ctx.workspace.name,
392
+ active: true,
393
+ },
394
+ ],
395
+ };
396
+ }
397
+ case "search_memory":
398
+ case "list_memories":
399
+ return engine.getMemoryOverview(ctx, args.query ? String(args.query) : undefined);
400
+ case "add_memory":
401
+ case "remember": {
402
+ const prompt = String(args.prompt || "").trim();
403
+ if (prompt && !args.content) {
404
+ return engine.doNaturalLanguage(ctx, { prompt });
405
+ }
406
+ const content = String(args.content || args.memory || prompt || "");
407
+ const title = String(args.title || content.slice(0, 60) || "Workspace Memory");
408
+ const record = await engine.addWorkspaceMemory(ctx, {
409
+ title,
410
+ content,
411
+ kind: args.kind || "fact",
412
+ });
413
+ const overview = await engine.getMemoryOverview(ctx);
414
+ return {
415
+ ok: true,
416
+ memory: record,
417
+ activeDefaults: overview.activeDefaults,
418
+ explanation: overview.explanation,
419
+ };
420
+ }
421
+ case "forget_memory": {
422
+ const query = String(args.query || args.id || args.memory || "").trim();
423
+ if (!query)
424
+ throw new Error("query is required to forget a memory");
425
+ return engine.forgetWorkspaceMemoryMatching(ctx, query);
426
+ }
427
+ case "memory_graph":
428
+ return engine.getMemoryGraph(ctx, args.query ? String(args.query) : undefined);
429
+ case "set_guardrail":
430
+ case "configure_guardrails": {
431
+ const rawParamRules = Array.isArray(args.parameter_rules)
432
+ ? args.parameter_rules
433
+ : Array.isArray(args.parameterRules)
434
+ ? args.parameterRules
435
+ : undefined;
436
+ return engine.applyNaturalLanguageGuardrail(ctx, String(args.prompt || args.rule || args.instruction || ""), {
437
+ parameterRules: rawParamRules,
438
+ source: rawParamRules ? "mcp_harness" : "deterministic",
439
+ });
440
+ }
441
+ case "reset_guardrails":
442
+ return engine.resetWorkspaceGuardrails(ctx);
443
+ case "check_policy":
444
+ case "simulate_policy":
445
+ return engine.checkToolPolicy(ctx, {
446
+ toolSlug: String(args.tool_slug || args.slug || args.tool_id || args.query || "instant.web.search"),
447
+ input: (args.input || args.arguments) || {},
448
+ });
449
+ case "kill_switch": {
450
+ const enabled = typeof args.enabled === "boolean"
451
+ ? args.enabled
452
+ : typeof args.active === "boolean"
453
+ ? args.active
454
+ : true;
455
+ const reason = args.reason
456
+ ? String(args.reason)
457
+ : args.prompt
458
+ ? String(args.prompt)
459
+ : undefined;
460
+ const updated = engine.setKillSwitch(ctx, enabled, reason);
461
+ const govOverview = engine.getGovernanceOverview(ctx);
462
+ return {
463
+ ok: true,
464
+ action: "kill_switch",
465
+ killSwitchActive: Boolean(updated.policy.killSwitchActive),
466
+ killSwitchReason: updated.policy.killSwitchReason || null,
467
+ policy: updated.policy,
468
+ llmPolicyBrief: govOverview.llmPolicyBrief,
469
+ explanation: govOverview.explanation,
470
+ };
471
+ }
472
+ case "scan_context":
473
+ return engine.scanForContextPoisoning(ctx.workspace.id, String(args.content || args.prompt || args.query || ""));
474
+ case "governance_status":
475
+ return engine.getGovernanceOverview(ctx);
476
+ case "verify_receipt_chain":
477
+ return engine.verifyReceiptChain(ctx, args.limit ? Number(args.limit) : 100);
478
+ case "do":
479
+ return engine.doNaturalLanguage(ctx, {
480
+ prompt: String(args.prompt || args.instruction || args.query || ""),
481
+ input: args.input || undefined,
482
+ dryRun: Boolean(args.dry_run || args.dryRun),
483
+ autoApprove: args.auto_approve !== false && args.autoApprove !== false,
484
+ });
485
+ // OpenAI Company Knowledge standard `search` and `fetch` tool support
486
+ case "search": {
487
+ const q = String(args.query || "").trim();
488
+ const [toolsRes, memRes] = await Promise.all([
489
+ engine.searchTools({ query: q, limit: 10 }),
490
+ engine.getMemoryOverview(ctx, q),
491
+ ]);
492
+ const toolHits = toolsRes.tools.map((t) => ({
493
+ id: `tool:${t.slug}`,
494
+ title: `${t.name} (${t.slug})`,
495
+ url: t.providerUrl || `https://docs.muxo.ai/catalogue#${encodeURIComponent(t.providerSlug || t.slug)}`,
496
+ snippet: `${t.description} [lane=${t.lane}, risk=${t.riskLevel}, cost=${t.creditCost}cr]`,
497
+ }));
498
+ const memHits = (memRes.memories || []).slice(0, 5).map((m) => ({
499
+ id: `memory:${m.id}`,
500
+ title: m.title,
501
+ url: `https://app.muxo.ai/?memory=${encodeURIComponent(m.id)}`,
502
+ snippet: m.content.slice(0, 240),
503
+ }));
504
+ return {
505
+ results: [...toolHits, ...memHits],
506
+ };
507
+ }
508
+ case "fetch": {
509
+ const rawId = String(args.id || "").trim();
510
+ const slug = rawId.startsWith("tool:") ? rawId.slice(5) : rawId;
511
+ if (rawId.startsWith("memory:")) {
512
+ const memId = rawId.slice(7);
513
+ const memRes = await engine.getMemoryOverview(ctx);
514
+ const found = (memRes.memories || []).find((m) => m.id === memId);
515
+ if (!found)
516
+ throw new Error(`Memory record not found: ${rawId}`);
517
+ return {
518
+ id: rawId,
519
+ title: found.title,
520
+ text: found.content,
521
+ url: `https://app.muxo.ai/?memory=${encodeURIComponent(found.id)}`,
522
+ metadata: {
523
+ namespace: found.namespace,
524
+ kind: found.kind,
525
+ createdAt: found.createdAt,
526
+ },
527
+ };
528
+ }
529
+ const tool = await engine.inspectTool(slug);
530
+ return {
531
+ id: `tool:${tool.slug}`,
532
+ title: tool.name,
533
+ text: JSON.stringify(tool, null, 2),
534
+ url: tool.providerUrl ||
535
+ `https://docs.muxo.ai/catalogue#${encodeURIComponent(tool.providerSlug || tool.slug)}`,
536
+ metadata: {
537
+ slug: tool.slug,
538
+ lane: tool.lane,
539
+ riskLevel: tool.riskLevel,
540
+ creditCost: String(tool.creditCost),
541
+ },
542
+ };
543
+ }
544
+ default:
545
+ throw new MuxoToolError(`Unknown MCP tool: '${toolName}'. Call tools/list for the canonical Muxo MCP tools.`, { code: "unknown_mcp_tool", statusCode: 404, payload: { toolName } });
546
+ }
547
+ }
548
+ export async function handleJsonRpcMcpRequest(engine, ctx, rpc) {
549
+ const id = rpc.id ?? null;
550
+ const method = String(rpc.method || "");
551
+ const params = (rpc.params || {});
552
+ if (method === "notifications/initialized" ||
553
+ method.startsWith("notifications/")) {
554
+ return null;
555
+ }
556
+ const headerAndMetaCheck = validateMcpHttpHeadersAndMeta({}, rpc);
557
+ if (!headerAndMetaCheck.ok) {
558
+ return {
559
+ jsonrpc: "2.0",
560
+ id,
561
+ error: headerAndMetaCheck.error,
562
+ };
563
+ }
564
+ try {
565
+ if (method === "server/discover") {
566
+ return {
567
+ jsonrpc: "2.0",
568
+ id,
569
+ result: buildMcpDiscoverResult(MUXO_VERSION),
570
+ };
571
+ }
572
+ if (method === "initialize") {
573
+ const requestedProtocol = headerAndMetaCheck.protocolVersion;
574
+ const serverInfo = {
575
+ name: "muxo-mcp-server",
576
+ title: "Muxo Unified Agent Runtime & Governance MCP Server",
577
+ version: MUXO_VERSION,
578
+ };
579
+ return {
580
+ jsonrpc: "2.0",
581
+ id,
582
+ result: {
583
+ resultType: "complete",
584
+ protocolVersion: requestedProtocol,
585
+ supportedVersions: [...SUPPORTED_MCP_PROTOCOL_VERSIONS],
586
+ instructions: MUXO_MCP_SERVER_INSTRUCTIONS,
587
+ serverInfo,
588
+ capabilities: {
589
+ tools: { listChanged: false },
590
+ resources: { listChanged: false, subscribe: false },
591
+ prompts: { listChanged: false },
592
+ completions: {},
593
+ extensions: {
594
+ "io.modelcontextprotocol/skills": {},
595
+ "io.modelcontextprotocol/apps": {},
596
+ },
597
+ },
598
+ _meta: {
599
+ "io.modelcontextprotocol/serverInfo": serverInfo,
600
+ "io.modelcontextprotocol/instructions": MUXO_MCP_SERVER_INSTRUCTIONS,
601
+ },
602
+ },
603
+ };
604
+ }
605
+ if (method === "ping") {
606
+ return { jsonrpc: "2.0", id, result: { resultType: "complete" } };
607
+ }
608
+ if (method === "completion/complete") {
609
+ const catalogTools = await engine.searchTools({ lane: "all", limit: 100 });
610
+ const completion = completeMcpArgument(params, catalogTools.tools.map((t) => t.slug));
611
+ return {
612
+ jsonrpc: "2.0",
613
+ id,
614
+ result: {
615
+ resultType: "complete",
616
+ completion,
617
+ },
618
+ };
619
+ }
620
+ if (method === "subscriptions/listen") {
621
+ return {
622
+ jsonrpc: "2.0",
623
+ id,
624
+ result: {
625
+ resultType: "complete",
626
+ events: [],
627
+ ttlMs: 30_000,
628
+ cacheScope: "private",
629
+ },
630
+ };
631
+ }
632
+ if (method === "prompts/list") {
633
+ return {
634
+ jsonrpc: "2.0",
635
+ id,
636
+ result: {
637
+ resultType: "complete",
638
+ ttlMs: 300_000,
639
+ cacheScope: "public",
640
+ prompts: [
641
+ {
642
+ name: "context",
643
+ title: "Workspace Memory & Governance Context",
644
+ description: "Ready-to-attach workspace context (Supermemory v5 profile, bi-temporal facts, learned parameter defaults, and active Microsoft Governance guardrails).",
645
+ arguments: [
646
+ {
647
+ name: "query",
648
+ description: "Optional topic or task query to focus memory recall",
649
+ required: false,
650
+ },
651
+ ],
652
+ },
653
+ {
654
+ name: "governed_execution",
655
+ title: "Governed Tool Execution Workflow",
656
+ description: "Step-by-step assistant prompt for discovering, planning, approving, executing, and verifying a governed Muxo action.",
657
+ arguments: [
658
+ {
659
+ name: "task",
660
+ description: "Natural-language task to plan and execute",
661
+ required: false,
662
+ },
663
+ ],
664
+ },
665
+ {
666
+ name: "security_audit",
667
+ title: "Workspace Governance, Memory Graph & Receipt Chain Audit",
668
+ description: "Inspect the workspace's 9-module Microsoft Agent Governance posture, Bi-Temporal Knowledge Graph, and Ed25519 AgenticReceipt hash chain.",
669
+ arguments: [],
670
+ },
671
+ {
672
+ name: "policy_guardrails",
673
+ title: "Workspace Policy, Parameter Guardrails & Risk Matrix",
674
+ description: "Load the structured LLM Policy & Governance Brief (riskLaneMatrix, conditional parameterRules with compliance guidance, budget caps, kill switch status, and control-plane commands).",
675
+ arguments: [],
676
+ },
677
+ ],
678
+ },
679
+ };
680
+ }
681
+ if (method === "prompts/get") {
682
+ const promptName = String(params.name || "context").trim();
683
+ const promptArgs = (params.arguments || {});
684
+ if (promptName === "context") {
685
+ const query = promptArgs.query ? String(promptArgs.query) : undefined;
686
+ const runCtx = await engine.getRunContext(ctx, query);
687
+ return {
688
+ jsonrpc: "2.0",
689
+ id,
690
+ result: {
691
+ resultType: "complete",
692
+ description: "Ready-to-attach Muxo workspace memory, active defaults, and safety guardrails.",
693
+ messages: [
694
+ {
695
+ role: "user",
696
+ content: {
697
+ type: "text",
698
+ text: String(runCtx.llmSystemPrompt || runCtx.explanation.preferred),
699
+ },
700
+ },
701
+ ],
702
+ },
703
+ };
704
+ }
705
+ if (promptName === "policy_guardrails") {
706
+ const gov = engine.getGovernanceOverview(ctx);
707
+ const sections = [
708
+ gov.llmPolicyBrief.llmSystemDirective,
709
+ `### Structured LLM Policy Brief (JSON)\n\`\`\`json\n${JSON.stringify(gov.llmPolicyBrief, null, 2)}\n\`\`\``,
710
+ ];
711
+ if (promptArgs.tool_slug) {
712
+ const sim = await engine.checkToolPolicy(ctx, {
713
+ toolSlug: String(promptArgs.tool_slug),
714
+ });
715
+ sections.push(`### Dry-Run Policy Check for \`${sim.toolSlug}\`\n\`\`\`json\n${JSON.stringify(sim, null, 2)}\n\`\`\``);
716
+ }
717
+ return {
718
+ jsonrpc: "2.0",
719
+ id,
720
+ result: {
721
+ resultType: "complete",
722
+ description: "Workspace policy, conditional parameter guardrails, and risk-lane matrix for AI agents",
723
+ messages: [
724
+ {
725
+ role: "user",
726
+ content: {
727
+ type: "text",
728
+ text: sections.join("\n\n"),
729
+ },
730
+ },
731
+ ],
732
+ },
733
+ };
734
+ }
735
+ if (promptName === "governed_execution") {
736
+ const task = String(promptArgs.task || "the user's requested operation");
737
+ const runCtx = await engine.getRunContext(ctx);
738
+ return {
739
+ jsonrpc: "2.0",
740
+ id,
741
+ result: {
742
+ resultType: "complete",
743
+ description: "Governed Muxo execution workflow prompt",
744
+ messages: [
745
+ {
746
+ role: "user",
747
+ content: {
748
+ type: "text",
749
+ text: `${runCtx.llmSystemPrompt}\n\n## Task\nExecute "${task}" safely using Muxo:\n1. Call \`search_tools\` and \`inspect_tool\` (or pass a natural-language request to \`plan_action\`).\n2. Call \`plan_action\` and inspect \`plan.approvalStatus\`, \`authHandoff\`, and \`llmGuidance.nextToolCalls\`.\n3. If \`authHandoff.required\` is true, present \`humanHandoff.markdownForUser\` and call \`wait_for_connection\`.\n4. If \`approvalStatus === "pending_approval"\`, present \`humanHandoff.markdownForUser\` and call \`get_plan\` with \`wait_for_approval: true\`.\n5. Execute with \`execute_<riskLevel>\` and verify the cryptographic receipt with \`get_receipt\`.`,
750
+ },
751
+ },
752
+ ],
753
+ },
754
+ };
755
+ }
756
+ if (promptName === "security_audit") {
757
+ const [gov, graph, chain] = await Promise.all([
758
+ Promise.resolve(engine.getGovernanceOverview(ctx)),
759
+ engine.getMemoryGraph(ctx),
760
+ Promise.resolve(engine.verifyReceiptChain(ctx)),
761
+ ]);
762
+ return {
763
+ jsonrpc: "2.0",
764
+ id,
765
+ result: {
766
+ resultType: "complete",
767
+ description: "Workspace governance, bi-temporal graph, and receipt chain audit",
768
+ messages: [
769
+ {
770
+ role: "user",
771
+ content: {
772
+ type: "text",
773
+ text: [
774
+ `# Muxo Security, Memory & Cryptographic Audit`,
775
+ `## 1. Microsoft Agent Governance (9 Modules)\n${gov.explanation.preferred}`,
776
+ `## 2. Bi-Temporal Knowledge Graph\n${graph.explanation.preferred}\n\`\`\`mermaid\n${graph.mermaid}\n\`\`\``,
777
+ `## 3. Portable Ed25519 AgenticReceipt Chain\n${chain.explanation.preferred}`,
778
+ ].join("\n\n"),
779
+ },
780
+ },
781
+ ],
782
+ },
783
+ };
784
+ }
785
+ return {
786
+ jsonrpc: "2.0",
787
+ id,
788
+ error: {
789
+ code: -32602,
790
+ message: `Prompt not found: ${promptName}`,
791
+ },
792
+ };
793
+ }
794
+ if (method === "tools/list") {
795
+ return {
796
+ jsonrpc: "2.0",
797
+ id,
798
+ result: {
799
+ resultType: "complete",
800
+ ttlMs: 300_000,
801
+ cacheScope: "public",
802
+ tools: MUXO_MCP_TOOLS.map((t) => buildMcpToolDescriptor(t)),
803
+ },
804
+ };
805
+ }
806
+ if (method === "tools/call") {
807
+ const toolName = String(params.name || "");
808
+ const toolArgs = (params.arguments || {});
809
+ const rawOutput = await dispatchMcpToolCall(engine, ctx, toolName, toolArgs);
810
+ const output = attachMcpHarnessGuidance(toolName, toolArgs, rawOutput);
811
+ const structuredContent = output && typeof output === "object" && !Array.isArray(output)
812
+ ? output
813
+ : { data: output };
814
+ const resultMeta = buildMcpToolResultMeta(toolName, params);
815
+ return {
816
+ jsonrpc: "2.0",
817
+ id,
818
+ result: {
819
+ resultType: "complete",
820
+ structuredContent,
821
+ content: [
822
+ {
823
+ type: "text",
824
+ text: JSON.stringify(output, null, 2),
825
+ },
826
+ ],
827
+ ...(resultMeta ? { _meta: resultMeta } : {}),
828
+ isError: false,
829
+ },
830
+ };
831
+ }
832
+ // SEP-2640 Skills Import Extension (`io.modelcontextprotocol/skills`)
833
+ if (method === "skills/list") {
834
+ const skills = getMuxoMcpSkills().map((s) => ({
835
+ uri: s.uri,
836
+ frontmatter: s.frontmatter,
837
+ resources: s.files.map((f) => ({
838
+ uri: f.uri,
839
+ digest: f.digest,
840
+ })),
841
+ name: s.name,
842
+ description: s.description,
843
+ version: s.version,
844
+ digest: s.files[0]?.digest || "",
845
+ files: s.files.length,
846
+ }));
847
+ return {
848
+ jsonrpc: "2.0",
849
+ id,
850
+ result: {
851
+ resultType: "complete",
852
+ ttlMs: 300_000,
853
+ cacheScope: "public",
854
+ skills,
855
+ },
856
+ };
857
+ }
858
+ if (method === "skills/get") {
859
+ const { skill, requested } = findMcpSkill(getMuxoMcpSkills(), params);
860
+ if (!skill) {
861
+ return {
862
+ jsonrpc: "2.0",
863
+ id,
864
+ error: {
865
+ code: -32602,
866
+ message: `Skill not found: ${requested}`,
867
+ },
868
+ };
869
+ }
870
+ const resources = skill.files.map((f) => ({
871
+ uri: f.uri,
872
+ digest: f.digest,
873
+ }));
874
+ return {
875
+ jsonrpc: "2.0",
876
+ id,
877
+ result: {
878
+ resultType: "complete",
879
+ ttlMs: 300_000,
880
+ cacheScope: "public",
881
+ skill: {
882
+ uri: skill.uri,
883
+ frontmatter: skill.frontmatter,
884
+ resources,
885
+ name: skill.name,
886
+ description: skill.description,
887
+ version: skill.version,
888
+ digest: skill.files[0]?.digest || "",
889
+ },
890
+ uri: skill.uri,
891
+ frontmatter: skill.frontmatter,
892
+ resources,
893
+ files: skill.files.map((f) => ({
894
+ path: f.path,
895
+ uri: f.uri,
896
+ size: f.size,
897
+ digest: f.digest,
898
+ mimeType: f.mimeType,
899
+ })),
900
+ },
901
+ };
902
+ }
903
+ if (method === "resources/templates/list") {
904
+ return {
905
+ jsonrpc: "2.0",
906
+ id,
907
+ result: {
908
+ resultType: "complete",
909
+ ttlMs: 300_000,
910
+ cacheScope: "public",
911
+ resourceTemplates: MUXO_MCP_RESOURCE_TEMPLATES,
912
+ },
913
+ };
914
+ }
915
+ if (method === "resources/list") {
916
+ const skillResources = getMuxoMcpSkills().flatMap((s) => s.files.map((f) => ({
917
+ uri: f.uri,
918
+ name: `${s.name}/${f.path}`,
919
+ description: s.description,
920
+ mimeType: f.mimeType,
921
+ })));
922
+ const dynamicResources = [
923
+ {
924
+ uri: "muxo://profile",
925
+ name: "Workspace Profile & Active Memory Defaults",
926
+ description: "Stable and recent Supermemory v5 profile context, active auto-fill defaults, and Ed25519 Agent DID for the active workspace.",
927
+ mimeType: "application/json",
928
+ },
929
+ {
930
+ uri: "supermemory://profile",
931
+ name: "Supermemory Active Space Profile",
932
+ description: "Supermemory MCP compatible profile resource (static + dynamic facts and preferences) for the active workspace.",
933
+ mimeType: "application/json",
934
+ },
935
+ {
936
+ uri: "supermemory://spaces",
937
+ name: "Supermemory Accessible Spaces",
938
+ description: "Compact list of accessible workspace memory spaces with the active containerTag marked.",
939
+ mimeType: "application/json",
940
+ },
941
+ {
942
+ uri: "muxo://context",
943
+ name: "Governed Workspace Run Context",
944
+ description: "Ready-to-inject workspace context including guardrails, learned defaults, provisioned cloud resources, and Supermemory recall.",
945
+ mimeType: "application/json",
946
+ },
947
+ {
948
+ uri: "muxo://memory/graph",
949
+ name: "Bi-Temporal Knowledge Graph",
950
+ description: "Entity & relationship graph with active facts, superseded historical facts (validFrom/validTo), and Mermaid topology.",
951
+ mimeType: "application/json",
952
+ },
953
+ {
954
+ uri: "muxo://governance/policy",
955
+ name: "Microsoft Agent Governance & Guardrails",
956
+ description: "9-module Microsoft Agent Governance status, plain-English guardrails, Bayesian trust score, and OWASP ASI-06 scan status.",
957
+ mimeType: "application/json",
958
+ },
959
+ {
960
+ uri: "muxo://policy/brief",
961
+ name: "LLM Policy, Risk Matrix & Parameter Guardrails Brief",
962
+ description: "Structured LLM policy digest with riskLaneMatrix, conditional parameterRules compliance guidance, learned memory defaults, and control-plane commands.",
963
+ mimeType: "application/json",
964
+ },
965
+ {
966
+ uri: "muxo://receipts/chain",
967
+ name: "Cryptographic AgenticReceipt Hash Chain",
968
+ description: "Tamper-evident SHA-256 + portable Ed25519 AgenticReceipt chain verification report.",
969
+ mimeType: "application/json",
970
+ },
971
+ ];
972
+ return {
973
+ jsonrpc: "2.0",
974
+ id,
975
+ result: {
976
+ resultType: "complete",
977
+ ttlMs: 60_000,
978
+ cacheScope: "private",
979
+ resources: [...MUXO_UI_RESOURCES, ...skillResources, ...dynamicResources],
980
+ },
981
+ };
982
+ }
983
+ if (method === "resources/read") {
984
+ const uri = String(params.uri || "").trim();
985
+ const uiResource = MUXO_UI_RESOURCES.find((r) => r.uri === uri);
986
+ if (uiResource) {
987
+ return {
988
+ jsonrpc: "2.0",
989
+ id,
990
+ result: {
991
+ resultType: "complete",
992
+ ttlMs: 300_000,
993
+ cacheScope: "public",
994
+ contents: [
995
+ {
996
+ uri: uiResource.uri,
997
+ mimeType: uiResource.mimeType,
998
+ text: renderMuxoUiWidgetHtml(),
999
+ _meta: uiResource._meta,
1000
+ },
1001
+ ],
1002
+ },
1003
+ };
1004
+ }
1005
+ if (uri === "muxo://profile" || uri === "supermemory://profile") {
1006
+ const overview = await engine.getMemoryOverview(ctx);
1007
+ const profile = engine.getProfile(ctx);
1008
+ const payload = {
1009
+ uri,
1010
+ workspaceId: ctx.workspace.id,
1011
+ workspaceSlug: ctx.workspace.slug,
1012
+ namespace: overview.namespace,
1013
+ profile: overview.context.profile,
1014
+ activeDefaults: overview.activeDefaults,
1015
+ activeGuardrails: overview.activeGuardrails,
1016
+ actor: profile,
1017
+ explanation: overview.explanation,
1018
+ };
1019
+ return {
1020
+ jsonrpc: "2.0",
1021
+ id,
1022
+ result: {
1023
+ resultType: "complete",
1024
+ ttlMs: 60_000,
1025
+ cacheScope: "private",
1026
+ contents: [
1027
+ {
1028
+ uri,
1029
+ mimeType: "application/json",
1030
+ text: JSON.stringify(payload, null, 2),
1031
+ },
1032
+ ],
1033
+ },
1034
+ };
1035
+ }
1036
+ if (uri === "muxo://spaces" || uri === "supermemory://spaces") {
1037
+ const overview = await engine.getMemoryOverview(ctx);
1038
+ const payload = {
1039
+ activeSpace: overview.namespace,
1040
+ spaces: [
1041
+ {
1042
+ id: overview.namespace,
1043
+ containerTag: overview.namespace,
1044
+ workspaceId: ctx.workspace.id,
1045
+ workspaceName: ctx.workspace.name,
1046
+ active: true,
1047
+ },
1048
+ ],
1049
+ };
1050
+ return {
1051
+ jsonrpc: "2.0",
1052
+ id,
1053
+ result: {
1054
+ resultType: "complete",
1055
+ ttlMs: 60_000,
1056
+ cacheScope: "private",
1057
+ contents: [
1058
+ {
1059
+ uri,
1060
+ mimeType: "application/json",
1061
+ text: JSON.stringify(payload, null, 2),
1062
+ },
1063
+ ],
1064
+ },
1065
+ };
1066
+ }
1067
+ if (uri === "muxo://context") {
1068
+ const runCtx = await engine.getRunContext(ctx);
1069
+ return {
1070
+ jsonrpc: "2.0",
1071
+ id,
1072
+ result: {
1073
+ resultType: "complete",
1074
+ ttlMs: 60_000,
1075
+ cacheScope: "private",
1076
+ contents: [
1077
+ {
1078
+ uri,
1079
+ mimeType: "application/json",
1080
+ text: JSON.stringify(runCtx, null, 2),
1081
+ },
1082
+ ],
1083
+ },
1084
+ };
1085
+ }
1086
+ if (uri === "muxo://memory/graph") {
1087
+ const graph = await engine.getMemoryGraph(ctx);
1088
+ return {
1089
+ jsonrpc: "2.0",
1090
+ id,
1091
+ result: {
1092
+ resultType: "complete",
1093
+ ttlMs: 60_000,
1094
+ cacheScope: "private",
1095
+ contents: [
1096
+ {
1097
+ uri,
1098
+ mimeType: "application/json",
1099
+ text: JSON.stringify(graph, null, 2),
1100
+ },
1101
+ ],
1102
+ },
1103
+ };
1104
+ }
1105
+ if (uri === "muxo://governance/policy") {
1106
+ const gov = engine.getGovernanceOverview(ctx);
1107
+ return {
1108
+ jsonrpc: "2.0",
1109
+ id,
1110
+ result: {
1111
+ resultType: "complete",
1112
+ ttlMs: 60_000,
1113
+ cacheScope: "private",
1114
+ contents: [
1115
+ {
1116
+ uri,
1117
+ mimeType: "application/json",
1118
+ text: JSON.stringify(gov, null, 2),
1119
+ },
1120
+ ],
1121
+ },
1122
+ };
1123
+ }
1124
+ if (uri === "muxo://policy/brief") {
1125
+ const gov = engine.getGovernanceOverview(ctx);
1126
+ return {
1127
+ jsonrpc: "2.0",
1128
+ id,
1129
+ result: {
1130
+ resultType: "complete",
1131
+ ttlMs: 60_000,
1132
+ cacheScope: "private",
1133
+ contents: [
1134
+ {
1135
+ uri,
1136
+ mimeType: "application/json",
1137
+ text: JSON.stringify(gov.llmPolicyBrief, null, 2),
1138
+ },
1139
+ ],
1140
+ },
1141
+ };
1142
+ }
1143
+ if (uri === "muxo://receipts/chain") {
1144
+ const chain = engine.verifyReceiptChain(ctx);
1145
+ return {
1146
+ jsonrpc: "2.0",
1147
+ id,
1148
+ result: {
1149
+ resultType: "complete",
1150
+ ttlMs: 60_000,
1151
+ cacheScope: "private",
1152
+ contents: [
1153
+ {
1154
+ uri,
1155
+ mimeType: "application/json",
1156
+ text: JSON.stringify(chain, null, 2),
1157
+ },
1158
+ ],
1159
+ },
1160
+ };
1161
+ }
1162
+ if (uri.startsWith("muxo://tools/")) {
1163
+ const slug = decodeURIComponent(uri.slice("muxo://tools/".length)).trim();
1164
+ try {
1165
+ const inspected = await dispatchMcpToolCall(engine, ctx, "inspect_tool", {
1166
+ tool_slug: slug,
1167
+ });
1168
+ return {
1169
+ jsonrpc: "2.0",
1170
+ id,
1171
+ result: {
1172
+ resultType: "complete",
1173
+ ttlMs: 300_000,
1174
+ cacheScope: "public",
1175
+ contents: [
1176
+ {
1177
+ uri,
1178
+ mimeType: "application/json",
1179
+ text: JSON.stringify(inspected, null, 2),
1180
+ },
1181
+ ],
1182
+ },
1183
+ };
1184
+ }
1185
+ catch {
1186
+ return {
1187
+ jsonrpc: "2.0",
1188
+ id,
1189
+ error: {
1190
+ code: -32602,
1191
+ message: `Resource not found: ${uri}`,
1192
+ },
1193
+ };
1194
+ }
1195
+ }
1196
+ if (uri.startsWith("muxo://plans/")) {
1197
+ const planId = decodeURIComponent(uri.slice("muxo://plans/".length)).trim();
1198
+ try {
1199
+ const planRecord = await dispatchMcpToolCall(engine, ctx, "get_plan", {
1200
+ plan_id: planId,
1201
+ });
1202
+ return {
1203
+ jsonrpc: "2.0",
1204
+ id,
1205
+ result: {
1206
+ resultType: "complete",
1207
+ ttlMs: 30_000,
1208
+ cacheScope: "private",
1209
+ contents: [
1210
+ {
1211
+ uri,
1212
+ mimeType: "application/json",
1213
+ text: JSON.stringify(planRecord, null, 2),
1214
+ },
1215
+ ],
1216
+ },
1217
+ };
1218
+ }
1219
+ catch {
1220
+ return {
1221
+ jsonrpc: "2.0",
1222
+ id,
1223
+ error: {
1224
+ code: -32602,
1225
+ message: `Resource not found: ${uri}`,
1226
+ },
1227
+ };
1228
+ }
1229
+ }
1230
+ if (uri.startsWith("muxo://runs/")) {
1231
+ const runId = decodeURIComponent(uri.slice("muxo://runs/".length)).trim();
1232
+ try {
1233
+ const runRecord = await dispatchMcpToolCall(engine, ctx, "get_run", {
1234
+ run_id: runId,
1235
+ });
1236
+ return {
1237
+ jsonrpc: "2.0",
1238
+ id,
1239
+ result: {
1240
+ resultType: "complete",
1241
+ ttlMs: 30_000,
1242
+ cacheScope: "private",
1243
+ contents: [
1244
+ {
1245
+ uri,
1246
+ mimeType: "application/json",
1247
+ text: JSON.stringify(runRecord, null, 2),
1248
+ },
1249
+ ],
1250
+ },
1251
+ };
1252
+ }
1253
+ catch {
1254
+ return {
1255
+ jsonrpc: "2.0",
1256
+ id,
1257
+ error: {
1258
+ code: -32602,
1259
+ message: `Resource not found: ${uri}`,
1260
+ },
1261
+ };
1262
+ }
1263
+ }
1264
+ if (uri.startsWith("muxo://receipts/")) {
1265
+ const receiptId = decodeURIComponent(uri.slice("muxo://receipts/".length)).trim();
1266
+ try {
1267
+ const receiptRecord = await dispatchMcpToolCall(engine, ctx, "get_receipt", {
1268
+ receipt_id: receiptId,
1269
+ });
1270
+ return {
1271
+ jsonrpc: "2.0",
1272
+ id,
1273
+ result: {
1274
+ resultType: "complete",
1275
+ ttlMs: 60_000,
1276
+ cacheScope: "private",
1277
+ contents: [
1278
+ {
1279
+ uri,
1280
+ mimeType: "application/json",
1281
+ text: JSON.stringify(receiptRecord, null, 2),
1282
+ },
1283
+ ],
1284
+ },
1285
+ };
1286
+ }
1287
+ catch {
1288
+ return {
1289
+ jsonrpc: "2.0",
1290
+ id,
1291
+ error: {
1292
+ code: -32602,
1293
+ message: `Resource not found: ${uri}`,
1294
+ },
1295
+ };
1296
+ }
1297
+ }
1298
+ const allFiles = getMuxoMcpSkills().flatMap((s) => s.files);
1299
+ const found = allFiles.find((f) => f.uri === uri);
1300
+ if (!found) {
1301
+ return {
1302
+ jsonrpc: "2.0",
1303
+ id,
1304
+ error: {
1305
+ code: -32602,
1306
+ message: `Resource not found: ${uri}`,
1307
+ },
1308
+ };
1309
+ }
1310
+ return {
1311
+ jsonrpc: "2.0",
1312
+ id,
1313
+ result: {
1314
+ resultType: "complete",
1315
+ ttlMs: 300_000,
1316
+ cacheScope: "public",
1317
+ contents: [
1318
+ {
1319
+ uri: found.uri,
1320
+ mimeType: found.mimeType,
1321
+ text: found.content,
1322
+ },
1323
+ ],
1324
+ },
1325
+ };
1326
+ }
1327
+ return {
1328
+ jsonrpc: "2.0",
1329
+ id,
1330
+ error: {
1331
+ code: -32601,
1332
+ message: `Method not found: ${method}`,
1333
+ },
1334
+ };
1335
+ }
1336
+ catch (err) {
1337
+ const errPayload = errorPayloadFrom(err, "MCP tool execution failed");
1338
+ const errMeta = buildMcpErrorResultMeta(err, engine?.config?.baseUrl || "https://api.muxo.ai");
1339
+ return {
1340
+ jsonrpc: "2.0",
1341
+ id,
1342
+ result: {
1343
+ resultType: "complete",
1344
+ structuredContent: errPayload,
1345
+ content: [
1346
+ {
1347
+ type: "text",
1348
+ text: JSON.stringify(errPayload, null, 2),
1349
+ },
1350
+ ],
1351
+ ...(errMeta ? { _meta: errMeta } : {}),
1352
+ isError: true,
1353
+ },
1354
+ };
1355
+ }
1356
+ }