@muxoai/sdk 1.2.3 → 1.3.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.
Files changed (183) hide show
  1. package/.agents/plugins/marketplace.json +22 -0
  2. package/.claude-plugin/marketplace.json +17 -0
  3. package/.codex/config.toml +5 -0
  4. package/ARCHITECTURE.md +111 -0
  5. package/README.md +21 -12
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +894 -0
  8. package/dist/config.d.ts +20 -0
  9. package/dist/config.js +89 -0
  10. package/dist/engine.d.ts +156 -0
  11. package/dist/engine.js +876 -0
  12. package/dist/index.d.ts +7 -0
  13. package/dist/index.js +7 -0
  14. package/dist/mcp.d.ts +45 -0
  15. package/dist/mcp.js +914 -0
  16. package/dist/nl.d.ts +34 -0
  17. package/dist/nl.js +577 -0
  18. package/dist/providers/composio-instant.d.ts +14 -0
  19. package/dist/providers/composio-instant.js +814 -0
  20. package/dist/providers/composio-sdk.d.ts +41 -0
  21. package/dist/providers/composio-sdk.js +572 -0
  22. package/dist/providers/microsoft-governance.d.ts +66 -0
  23. package/dist/providers/microsoft-governance.js +415 -0
  24. package/dist/providers/stripe-billing.d.ts +41 -0
  25. package/dist/providers/stripe-billing.js +372 -0
  26. package/dist/providers/stripe-projects.d.ts +53 -0
  27. package/dist/providers/stripe-projects.js +636 -0
  28. package/dist/providers/supermemory.d.ts +64 -0
  29. package/dist/providers/supermemory.js +224 -0
  30. package/{index.d.ts → dist/sdk.d.ts} +77 -1
  31. package/dist/sdk.js +270 -0
  32. package/dist/server.d.ts +10 -0
  33. package/dist/server.js +1277 -0
  34. package/dist/store.d.ts +216 -0
  35. package/dist/store.js +1449 -0
  36. package/dist/types.d.ts +285 -0
  37. package/dist/types.js +1 -0
  38. package/dist/ui/console-html.d.ts +2 -0
  39. package/dist/ui/console-html.js +2343 -0
  40. package/package.json +66 -6
  41. package/plugins/muxo/.app.json +8 -0
  42. package/plugins/muxo/.claude-plugin/plugin.json +16 -0
  43. package/plugins/muxo/.codex-plugin/plugin.json +55 -0
  44. package/plugins/muxo/.mcp.json +40 -0
  45. package/plugins/muxo/assets/logo.png +0 -0
  46. package/plugins/muxo/assets/logo.svg +6 -0
  47. package/plugins/muxo/hooks/hooks.json +27 -0
  48. package/plugins/muxo/hooks/session-start.sh +85 -0
  49. package/plugins/muxo/hooks/user-prompt-submit.sh +45 -0
  50. package/plugins/muxo/mcp.json +38 -0
  51. package/plugins/muxo/plugin.json +59 -0
  52. package/plugins/muxo/skills/muxo/SKILL.md +25 -0
  53. package/plugins/muxo/skills/muxo/references/cli.md +57 -0
  54. package/plugins/muxo/skills/muxo/references/mcp.md +25 -0
  55. package/plugins/muxo/skills/setup/SKILL.md +28 -0
  56. package/src/catalogues/stripe-projects-catalog.json +9832 -0
  57. package/vendor/microsoft-governance/README.md +363 -0
  58. package/vendor/microsoft-governance/dist/audit.d.ts +26 -0
  59. package/vendor/microsoft-governance/dist/audit.d.ts.map +1 -0
  60. package/vendor/microsoft-governance/dist/audit.js +107 -0
  61. package/vendor/microsoft-governance/dist/audit.js.map +1 -0
  62. package/vendor/microsoft-governance/dist/cascade-containment.d.ts +84 -0
  63. package/vendor/microsoft-governance/dist/cascade-containment.d.ts.map +1 -0
  64. package/vendor/microsoft-governance/dist/cascade-containment.js +387 -0
  65. package/vendor/microsoft-governance/dist/cascade-containment.js.map +1 -0
  66. package/vendor/microsoft-governance/dist/client.d.ts +34 -0
  67. package/vendor/microsoft-governance/dist/client.d.ts.map +1 -0
  68. package/vendor/microsoft-governance/dist/client.js +112 -0
  69. package/vendor/microsoft-governance/dist/client.js.map +1 -0
  70. package/vendor/microsoft-governance/dist/context-poisoning.d.ts +58 -0
  71. package/vendor/microsoft-governance/dist/context-poisoning.d.ts.map +1 -0
  72. package/vendor/microsoft-governance/dist/context-poisoning.js +410 -0
  73. package/vendor/microsoft-governance/dist/context-poisoning.js.map +1 -0
  74. package/vendor/microsoft-governance/dist/credential-vault.d.ts +213 -0
  75. package/vendor/microsoft-governance/dist/credential-vault.d.ts.map +1 -0
  76. package/vendor/microsoft-governance/dist/credential-vault.js +567 -0
  77. package/vendor/microsoft-governance/dist/credential-vault.js.map +1 -0
  78. package/vendor/microsoft-governance/dist/discovery.d.ts +80 -0
  79. package/vendor/microsoft-governance/dist/discovery.d.ts.map +1 -0
  80. package/vendor/microsoft-governance/dist/discovery.js +404 -0
  81. package/vendor/microsoft-governance/dist/discovery.js.map +1 -0
  82. package/vendor/microsoft-governance/dist/encryption/channel.d.ts +29 -0
  83. package/vendor/microsoft-governance/dist/encryption/channel.d.ts.map +1 -0
  84. package/vendor/microsoft-governance/dist/encryption/channel.js +78 -0
  85. package/vendor/microsoft-governance/dist/encryption/channel.js.map +1 -0
  86. package/vendor/microsoft-governance/dist/encryption/index.d.ts +9 -0
  87. package/vendor/microsoft-governance/dist/encryption/index.d.ts.map +1 -0
  88. package/vendor/microsoft-governance/dist/encryption/index.js +23 -0
  89. package/vendor/microsoft-governance/dist/encryption/index.js.map +1 -0
  90. package/vendor/microsoft-governance/dist/encryption/mesh-client.d.ts +267 -0
  91. package/vendor/microsoft-governance/dist/encryption/mesh-client.d.ts.map +1 -0
  92. package/vendor/microsoft-governance/dist/encryption/mesh-client.js +1001 -0
  93. package/vendor/microsoft-governance/dist/encryption/mesh-client.js.map +1 -0
  94. package/vendor/microsoft-governance/dist/encryption/ratchet.d.ts +38 -0
  95. package/vendor/microsoft-governance/dist/encryption/ratchet.d.ts.map +1 -0
  96. package/vendor/microsoft-governance/dist/encryption/ratchet.js +223 -0
  97. package/vendor/microsoft-governance/dist/encryption/ratchet.js.map +1 -0
  98. package/vendor/microsoft-governance/dist/encryption/registry-client.d.ts +136 -0
  99. package/vendor/microsoft-governance/dist/encryption/registry-client.d.ts.map +1 -0
  100. package/vendor/microsoft-governance/dist/encryption/registry-client.js +369 -0
  101. package/vendor/microsoft-governance/dist/encryption/registry-client.js.map +1 -0
  102. package/vendor/microsoft-governance/dist/encryption/x3dh.d.ts +80 -0
  103. package/vendor/microsoft-governance/dist/encryption/x3dh.d.ts.map +1 -0
  104. package/vendor/microsoft-governance/dist/encryption/x3dh.js +238 -0
  105. package/vendor/microsoft-governance/dist/encryption/x3dh.js.map +1 -0
  106. package/vendor/microsoft-governance/dist/framework-adapter.d.ts +63 -0
  107. package/vendor/microsoft-governance/dist/framework-adapter.d.ts.map +1 -0
  108. package/vendor/microsoft-governance/dist/framework-adapter.js +253 -0
  109. package/vendor/microsoft-governance/dist/framework-adapter.js.map +1 -0
  110. package/vendor/microsoft-governance/dist/identity.d.ts +124 -0
  111. package/vendor/microsoft-governance/dist/identity.d.ts.map +1 -0
  112. package/vendor/microsoft-governance/dist/identity.js +446 -0
  113. package/vendor/microsoft-governance/dist/identity.js.map +1 -0
  114. package/vendor/microsoft-governance/dist/index.d.ts +39 -0
  115. package/vendor/microsoft-governance/dist/index.d.ts.map +1 -0
  116. package/vendor/microsoft-governance/dist/index.js +95 -0
  117. package/vendor/microsoft-governance/dist/index.js.map +1 -0
  118. package/vendor/microsoft-governance/dist/kill-switch.d.ts +22 -0
  119. package/vendor/microsoft-governance/dist/kill-switch.d.ts.map +1 -0
  120. package/vendor/microsoft-governance/dist/kill-switch.js +60 -0
  121. package/vendor/microsoft-governance/dist/kill-switch.js.map +1 -0
  122. package/vendor/microsoft-governance/dist/lifecycle.d.ts +50 -0
  123. package/vendor/microsoft-governance/dist/lifecycle.d.ts.map +1 -0
  124. package/vendor/microsoft-governance/dist/lifecycle.js +113 -0
  125. package/vendor/microsoft-governance/dist/lifecycle.js.map +1 -0
  126. package/vendor/microsoft-governance/dist/mcp.d.ts +41 -0
  127. package/vendor/microsoft-governance/dist/mcp.d.ts.map +1 -0
  128. package/vendor/microsoft-governance/dist/mcp.js +233 -0
  129. package/vendor/microsoft-governance/dist/mcp.js.map +1 -0
  130. package/vendor/microsoft-governance/dist/metrics.d.ts +123 -0
  131. package/vendor/microsoft-governance/dist/metrics.d.ts.map +1 -0
  132. package/vendor/microsoft-governance/dist/metrics.js +289 -0
  133. package/vendor/microsoft-governance/dist/metrics.js.map +1 -0
  134. package/vendor/microsoft-governance/dist/oci-manifest.d.ts +49 -0
  135. package/vendor/microsoft-governance/dist/oci-manifest.d.ts.map +1 -0
  136. package/vendor/microsoft-governance/dist/oci-manifest.js +182 -0
  137. package/vendor/microsoft-governance/dist/oci-manifest.js.map +1 -0
  138. package/vendor/microsoft-governance/dist/policy-backends/cedar.d.ts +15 -0
  139. package/vendor/microsoft-governance/dist/policy-backends/cedar.d.ts.map +1 -0
  140. package/vendor/microsoft-governance/dist/policy-backends/cedar.js +88 -0
  141. package/vendor/microsoft-governance/dist/policy-backends/cedar.js.map +1 -0
  142. package/vendor/microsoft-governance/dist/policy-backends/opa.d.ts +17 -0
  143. package/vendor/microsoft-governance/dist/policy-backends/opa.d.ts.map +1 -0
  144. package/vendor/microsoft-governance/dist/policy-backends/opa.js +74 -0
  145. package/vendor/microsoft-governance/dist/policy-backends/opa.js.map +1 -0
  146. package/vendor/microsoft-governance/dist/policy.d.ts +77 -0
  147. package/vendor/microsoft-governance/dist/policy.d.ts.map +1 -0
  148. package/vendor/microsoft-governance/dist/policy.js +760 -0
  149. package/vendor/microsoft-governance/dist/policy.js.map +1 -0
  150. package/vendor/microsoft-governance/dist/prompt-defense.d.ts +37 -0
  151. package/vendor/microsoft-governance/dist/prompt-defense.d.ts.map +1 -0
  152. package/vendor/microsoft-governance/dist/prompt-defense.js +229 -0
  153. package/vendor/microsoft-governance/dist/prompt-defense.js.map +1 -0
  154. package/vendor/microsoft-governance/dist/protocol-facets.d.ts +87 -0
  155. package/vendor/microsoft-governance/dist/protocol-facets.d.ts.map +1 -0
  156. package/vendor/microsoft-governance/dist/protocol-facets.js +728 -0
  157. package/vendor/microsoft-governance/dist/protocol-facets.js.map +1 -0
  158. package/vendor/microsoft-governance/dist/rings.d.ts +17 -0
  159. package/vendor/microsoft-governance/dist/rings.d.ts.map +1 -0
  160. package/vendor/microsoft-governance/dist/rings.js +61 -0
  161. package/vendor/microsoft-governance/dist/rings.js.map +1 -0
  162. package/vendor/microsoft-governance/dist/sandbox.d.ts +61 -0
  163. package/vendor/microsoft-governance/dist/sandbox.d.ts.map +1 -0
  164. package/vendor/microsoft-governance/dist/sandbox.js +199 -0
  165. package/vendor/microsoft-governance/dist/sandbox.js.map +1 -0
  166. package/vendor/microsoft-governance/dist/surface-parity.d.ts +45 -0
  167. package/vendor/microsoft-governance/dist/surface-parity.d.ts.map +1 -0
  168. package/vendor/microsoft-governance/dist/surface-parity.js +216 -0
  169. package/vendor/microsoft-governance/dist/surface-parity.js.map +1 -0
  170. package/vendor/microsoft-governance/dist/trust.d.ts +28 -0
  171. package/vendor/microsoft-governance/dist/trust.d.ts.map +1 -0
  172. package/vendor/microsoft-governance/dist/trust.js +209 -0
  173. package/vendor/microsoft-governance/dist/trust.js.map +1 -0
  174. package/vendor/microsoft-governance/dist/types.d.ts +422 -0
  175. package/vendor/microsoft-governance/dist/types.d.ts.map +1 -0
  176. package/vendor/microsoft-governance/dist/types.js +29 -0
  177. package/vendor/microsoft-governance/dist/types.js.map +1 -0
  178. package/vendor/microsoft-governance/dist/verify.d.ts +135 -0
  179. package/vendor/microsoft-governance/dist/verify.d.ts.map +1 -0
  180. package/vendor/microsoft-governance/dist/verify.js +356 -0
  181. package/vendor/microsoft-governance/dist/verify.js.map +1 -0
  182. package/vendor/microsoft-governance/package.json +64 -0
  183. package/index.js +0 -1
package/dist/mcp.js ADDED
@@ -0,0 +1,914 @@
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
+ /**
6
+ * Concise server instructions (<512 chars) per OpenAI Plugin MCP Server specification:
7
+ * https://developers.openai.com/plugins/build/mcp-server
8
+ */
9
+ export const MUXO_MCP_SERVER_INSTRUCTIONS = "Muxo governs SaaS actions (Composio app.*), Instant tools (instant.*), Cloud Infrastructure (Stripe Projects resource.*), Supermemory v5 recall, and Microsoft Agent Governance Ed25519 receipts. Workflow: 1) search_tools & inspect_tool. 2) plan_action to get a plan_*. 3) If authHandoff.required is true, show redirectUrl and call wait_for_connection. 4) Execute via the matching risk tool (execute_read/write/admin/financial/provisioning/destructive). 5) Verify via get_receipt.";
10
+ export const MUXO_MCP_TOOLS = [
11
+ {
12
+ name: "get_profile",
13
+ title: "Get Authenticated Profile",
14
+ description: "Get the authenticated actor profile, user ID, email, workspace ID, and subscription tier.",
15
+ inputSchema: {
16
+ type: "object",
17
+ properties: {},
18
+ additionalProperties: false,
19
+ },
20
+ outputSchema: {
21
+ type: "object",
22
+ properties: {
23
+ id: { type: "string", description: "Unique user identifier" },
24
+ name: { type: "string", description: "Display name" },
25
+ email: { type: "string", description: "Email address" },
26
+ workspaceId: { type: "string", description: "Active workspace ID" },
27
+ workspaceName: { type: "string", description: "Active workspace name" },
28
+ tier: { type: "string", description: "Workspace subscription tier" },
29
+ },
30
+ required: ["id"],
31
+ },
32
+ annotations: {
33
+ readOnlyHint: true,
34
+ destructiveHint: false,
35
+ openWorldHint: false,
36
+ },
37
+ _meta: {
38
+ "openai/profile": true,
39
+ },
40
+ },
41
+ {
42
+ name: "get_organization",
43
+ title: "Get Organization & Billing Summary",
44
+ description: "Get workspace governance policy, monthly action usage, credit balance, Merchant-of-Record supplier settlement summary, and active connection/resource counts.",
45
+ inputSchema: {
46
+ type: "object",
47
+ properties: {},
48
+ additionalProperties: false,
49
+ },
50
+ annotations: {
51
+ readOnlyHint: true,
52
+ destructiveHint: false,
53
+ openWorldHint: false,
54
+ },
55
+ },
56
+ {
57
+ name: "search_tools",
58
+ title: "Search Unified Tool Catalog",
59
+ description: "Search the unified Muxo catalog across Connected Apps (Composio SDK: app.*), Instant Tools (Composio Instant: instant.*), and Cloud Infrastructure (Stripe Projects: resource.*).",
60
+ inputSchema: {
61
+ type: "object",
62
+ properties: {
63
+ query: {
64
+ type: "string",
65
+ description: "Search keywords (e.g. 'postgres', 'github issue', 'web search', 'seo audit', 'redis')",
66
+ },
67
+ lane: {
68
+ type: "string",
69
+ enum: ["all", "composio_sdk", "composio_instant", "stripe_projects"],
70
+ default: "all",
71
+ },
72
+ risk_level: {
73
+ type: "string",
74
+ enum: [
75
+ "read",
76
+ "write",
77
+ "admin",
78
+ "financial",
79
+ "provisioning",
80
+ "destructive",
81
+ ],
82
+ },
83
+ limit: { type: "number", default: 20 },
84
+ },
85
+ additionalProperties: false,
86
+ },
87
+ annotations: {
88
+ readOnlyHint: true,
89
+ destructiveHint: false,
90
+ openWorldHint: true,
91
+ },
92
+ },
93
+ {
94
+ name: "inspect_tool",
95
+ title: "Inspect Tool Schema & Risk",
96
+ description: "Inspect a tool's full input JSON schema, risk classification, provider lane, LLM context URL, and credit cost before planning.",
97
+ inputSchema: {
98
+ type: "object",
99
+ required: ["tool_slug"],
100
+ properties: {
101
+ tool_slug: {
102
+ type: "string",
103
+ description: "Canonical Muxo tool slug (e.g. 'instant.seo.audit', 'app.gmail.send_email', or 'resource.turso.database')",
104
+ },
105
+ },
106
+ additionalProperties: false,
107
+ },
108
+ annotations: {
109
+ readOnlyHint: true,
110
+ destructiveHint: false,
111
+ openWorldHint: false,
112
+ },
113
+ },
114
+ {
115
+ name: "connection_status",
116
+ title: "Check Connection Status",
117
+ description: "Check connection status across Composio OAuth apps, Instant wallet, and linked Stripe Projects cloud providers.",
118
+ inputSchema: {
119
+ type: "object",
120
+ properties: {
121
+ provider: {
122
+ type: "string",
123
+ description: "Optional provider filter (e.g. 'github', 'gmail', 'slack', 'neon', 'turso')",
124
+ },
125
+ sync_live: {
126
+ type: "boolean",
127
+ default: true,
128
+ description: "Whether to sync live status from upstream Composio and Stripe Projects",
129
+ },
130
+ },
131
+ additionalProperties: false,
132
+ },
133
+ annotations: {
134
+ readOnlyHint: true,
135
+ destructiveHint: false,
136
+ openWorldHint: true,
137
+ },
138
+ },
139
+ {
140
+ name: "start_connection",
141
+ title: "Start OAuth Connection Handoff",
142
+ description: "Initiate a managed OAuth connection handoff for a Connected App (Composio) or link a cloud provider (Stripe Projects).",
143
+ inputSchema: {
144
+ type: "object",
145
+ required: ["provider"],
146
+ properties: {
147
+ provider: {
148
+ type: "string",
149
+ description: "Provider or toolkit slug (e.g. 'github', 'gmail', 'slack', 'neon')",
150
+ },
151
+ lane: {
152
+ type: "string",
153
+ enum: ["composio_sdk", "stripe_projects"],
154
+ description: "Provider lane (defaults to composio_sdk unless prefixed with resource.)",
155
+ },
156
+ callback_url: {
157
+ type: "string",
158
+ description: "Optional OAuth callback URL",
159
+ },
160
+ },
161
+ additionalProperties: false,
162
+ },
163
+ annotations: {
164
+ readOnlyHint: false,
165
+ destructiveHint: false,
166
+ openWorldHint: true,
167
+ },
168
+ },
169
+ {
170
+ name: "wait_for_connection",
171
+ title: "Wait for OAuth Connection Handoff",
172
+ description: "Poll and wait for an external user's pending OAuth connection handoff to become active before resuming a planned operation.",
173
+ inputSchema: {
174
+ type: "object",
175
+ required: ["provider"],
176
+ properties: {
177
+ provider: {
178
+ type: "string",
179
+ description: "Provider or toolkit slug (e.g. 'github', 'gmail', 'slack', 'notion', 'linear')",
180
+ },
181
+ timeout_seconds: {
182
+ type: "number",
183
+ default: 15,
184
+ description: "Maximum seconds to poll for OAuth completion (0-120, default 15)",
185
+ },
186
+ },
187
+ additionalProperties: false,
188
+ },
189
+ annotations: {
190
+ readOnlyHint: true,
191
+ destructiveHint: false,
192
+ openWorldHint: true,
193
+ },
194
+ },
195
+ {
196
+ name: "plan_action",
197
+ title: "Create Governed Action Plan",
198
+ description: "Create a governed execution plan (plan_*) for any tool, billing operation, or infrastructure provisioning operation. Accepts either an exact tool_slug (e.g. 'instant.seo.audit', 'billing.credits.topup', 'resource.turso.database') or a natural-language instruction (e.g. 'audit seo for https://muxo.ai'). Evaluates workspace policy, risk level, Supermemory v5 recall, Ed25519 signature, BYOK vs Muxo-funded mode, and credit balance.",
199
+ inputSchema: {
200
+ type: "object",
201
+ required: ["tool_slug"],
202
+ properties: {
203
+ tool_slug: {
204
+ type: "string",
205
+ description: "Muxo tool slug (e.g. 'instant.seo.audit', 'billing.credits.topup') or natural-language request",
206
+ },
207
+ input: {
208
+ type: "object",
209
+ description: "Arguments matching the tool's inputSchema (auto-extracted when tool_slug is natural language)",
210
+ },
211
+ reason: {
212
+ type: "string",
213
+ description: "Audit reason explaining why this action is being planned",
214
+ },
215
+ },
216
+ additionalProperties: false,
217
+ },
218
+ annotations: {
219
+ readOnlyHint: false,
220
+ destructiveHint: false,
221
+ openWorldHint: false,
222
+ },
223
+ },
224
+ {
225
+ name: "get_plan",
226
+ title: "Get Action Plan",
227
+ description: "Inspect the status, risk level, governance decision record, and approval state of a planned action.",
228
+ inputSchema: {
229
+ type: "object",
230
+ required: ["plan_id"],
231
+ properties: {
232
+ plan_id: { type: "string", description: "Plan ID (plan_*)" },
233
+ },
234
+ additionalProperties: false,
235
+ },
236
+ annotations: {
237
+ readOnlyHint: true,
238
+ destructiveHint: false,
239
+ openWorldHint: false,
240
+ },
241
+ },
242
+ {
243
+ name: "get_run_context",
244
+ title: "Get Workspace Context & Memory",
245
+ description: "Get the workspace runtime context, Supermemory v5 contextual brain (static/dynamic profile + hybrid search recall), Microsoft Agent Governance status, active provisioned Stripe Projects resources, and redacted environment variable keys.",
246
+ inputSchema: {
247
+ type: "object",
248
+ properties: {
249
+ query: {
250
+ type: "string",
251
+ description: "Optional semantic search query to recall relevant workspace memories from Supermemory v5",
252
+ },
253
+ },
254
+ additionalProperties: false,
255
+ },
256
+ annotations: {
257
+ readOnlyHint: true,
258
+ destructiveHint: false,
259
+ openWorldHint: false,
260
+ },
261
+ },
262
+ {
263
+ name: "execute_read",
264
+ title: "Execute Read Plan",
265
+ description: "Execute an approved plan with riskLevel = 'read'.",
266
+ inputSchema: {
267
+ type: "object",
268
+ required: ["plan_id"],
269
+ properties: {
270
+ plan_id: { type: "string", description: "Plan ID (plan_*)" },
271
+ },
272
+ additionalProperties: false,
273
+ },
274
+ annotations: {
275
+ readOnlyHint: true,
276
+ destructiveHint: false,
277
+ openWorldHint: true,
278
+ },
279
+ },
280
+ {
281
+ name: "execute_write",
282
+ title: "Execute Write Plan",
283
+ description: "Execute an approved plan with riskLevel = 'write'.",
284
+ inputSchema: {
285
+ type: "object",
286
+ required: ["plan_id"],
287
+ properties: {
288
+ plan_id: { type: "string", description: "Plan ID (plan_*)" },
289
+ },
290
+ additionalProperties: false,
291
+ },
292
+ annotations: {
293
+ readOnlyHint: false,
294
+ destructiveHint: false,
295
+ openWorldHint: true,
296
+ },
297
+ },
298
+ {
299
+ name: "execute_admin",
300
+ title: "Execute Admin Plan",
301
+ description: "Execute an approved plan with riskLevel = 'admin'.",
302
+ inputSchema: {
303
+ type: "object",
304
+ required: ["plan_id"],
305
+ properties: {
306
+ plan_id: { type: "string", description: "Plan ID (plan_*)" },
307
+ },
308
+ additionalProperties: false,
309
+ },
310
+ annotations: {
311
+ readOnlyHint: false,
312
+ destructiveHint: false,
313
+ openWorldHint: true,
314
+ },
315
+ },
316
+ {
317
+ name: "execute_financial",
318
+ title: "Execute Financial Plan",
319
+ description: "Execute an approved plan with riskLevel = 'financial'.",
320
+ inputSchema: {
321
+ type: "object",
322
+ required: ["plan_id"],
323
+ properties: {
324
+ plan_id: { type: "string", description: "Plan ID (plan_*)" },
325
+ },
326
+ additionalProperties: false,
327
+ },
328
+ annotations: {
329
+ readOnlyHint: false,
330
+ destructiveHint: false,
331
+ openWorldHint: true,
332
+ },
333
+ },
334
+ {
335
+ name: "execute_provisioning",
336
+ title: "Execute Infrastructure Provisioning Plan",
337
+ description: "Execute an approved infrastructure provisioning plan with riskLevel = 'provisioning' via Stripe Projects.",
338
+ inputSchema: {
339
+ type: "object",
340
+ required: ["plan_id"],
341
+ properties: {
342
+ plan_id: { type: "string", description: "Plan ID (plan_*)" },
343
+ },
344
+ additionalProperties: false,
345
+ },
346
+ annotations: {
347
+ readOnlyHint: false,
348
+ destructiveHint: false,
349
+ openWorldHint: true,
350
+ },
351
+ },
352
+ {
353
+ name: "execute_destructive",
354
+ title: "Execute Destructive Plan",
355
+ description: "Execute an approved plan with riskLevel = 'destructive'.",
356
+ inputSchema: {
357
+ type: "object",
358
+ required: ["plan_id"],
359
+ properties: {
360
+ plan_id: { type: "string", description: "Plan ID (plan_*)" },
361
+ },
362
+ additionalProperties: false,
363
+ },
364
+ annotations: {
365
+ readOnlyHint: false,
366
+ destructiveHint: true,
367
+ openWorldHint: true,
368
+ },
369
+ },
370
+ {
371
+ name: "get_run",
372
+ title: "Get Execution Run",
373
+ description: "Get the execution status, output, duration, and metered cost of a run (run_*).",
374
+ inputSchema: {
375
+ type: "object",
376
+ required: ["run_id"],
377
+ properties: {
378
+ run_id: { type: "string", description: "Run ID (run_*)" },
379
+ },
380
+ additionalProperties: false,
381
+ },
382
+ annotations: {
383
+ readOnlyHint: true,
384
+ destructiveHint: false,
385
+ openWorldHint: false,
386
+ },
387
+ },
388
+ {
389
+ name: "cancel_run",
390
+ title: "Cancel Execution Run",
391
+ description: "Cancel an in-progress run and issue a cancellation receipt.",
392
+ inputSchema: {
393
+ type: "object",
394
+ required: ["run_id"],
395
+ properties: {
396
+ run_id: { type: "string", description: "Run ID (run_*)" },
397
+ },
398
+ additionalProperties: false,
399
+ },
400
+ annotations: {
401
+ readOnlyHint: false,
402
+ destructiveHint: true,
403
+ openWorldHint: false,
404
+ },
405
+ },
406
+ {
407
+ name: "get_receipt",
408
+ title: "Verify Execution Receipt",
409
+ description: "Fetch and cryptographically verify the HMAC-SHA256 + Ed25519 chained execution receipt (rcpt_*) for a run.",
410
+ inputSchema: {
411
+ type: "object",
412
+ required: ["receipt_id"],
413
+ properties: {
414
+ receipt_id: {
415
+ type: "string",
416
+ description: "Receipt ID (rcpt_*) or Run ID (run_*)",
417
+ },
418
+ },
419
+ additionalProperties: false,
420
+ },
421
+ annotations: {
422
+ readOnlyHint: true,
423
+ destructiveHint: false,
424
+ openWorldHint: false,
425
+ },
426
+ },
427
+ ];
428
+ /**
429
+ * OpenAI Company Knowledge standard `search` and `fetch` tool definitions
430
+ * per https://developers.openai.com/plugins/build/mcp-server#company-knowledge-compatibility
431
+ */
432
+ export const OPENAI_COMPANY_KNOWLEDGE_TOOLS = [
433
+ {
434
+ name: "search",
435
+ title: "Search Muxo Tools & Workspace Memory",
436
+ description: "Search across Muxo tools, provisioned cloud resources, and Supermemory v5 workspace knowledge.",
437
+ inputSchema: {
438
+ type: "object",
439
+ required: ["query"],
440
+ properties: {
441
+ query: { type: "string", description: "Search query string." },
442
+ },
443
+ additionalProperties: false,
444
+ },
445
+ annotations: {
446
+ readOnlyHint: true,
447
+ destructiveHint: false,
448
+ openWorldHint: false,
449
+ },
450
+ },
451
+ {
452
+ name: "fetch",
453
+ title: "Fetch Muxo Tool or Memory Record",
454
+ description: "Retrieve complete details for a Muxo tool, resource, or workspace memory record by ID.",
455
+ inputSchema: {
456
+ type: "object",
457
+ required: ["id"],
458
+ properties: {
459
+ id: {
460
+ type: "string",
461
+ description: "Identifier returned by search (e.g. 'tool:instant.seo.audit' or 'memory:mem_123').",
462
+ },
463
+ },
464
+ additionalProperties: false,
465
+ },
466
+ annotations: {
467
+ readOnlyHint: true,
468
+ destructiveHint: false,
469
+ openWorldHint: false,
470
+ },
471
+ },
472
+ ];
473
+ function sha256Digest(content) {
474
+ const hash = crypto
475
+ .createHash("sha256")
476
+ .update(Buffer.from(content, "utf8"))
477
+ .digest("hex");
478
+ return `sha256:${hash}`;
479
+ }
480
+ function parseFrontmatter(markdown) {
481
+ const match = markdown.match(/^---\r?\n([\s\S]*?)\r?\n---/);
482
+ if (!match)
483
+ return {};
484
+ const result = {};
485
+ for (const line of match[1].split(/\r?\n/)) {
486
+ const idx = line.indexOf(":");
487
+ if (idx > 0) {
488
+ const k = line.slice(0, idx).trim();
489
+ const v = line.slice(idx + 1).trim();
490
+ if (k && v)
491
+ result[k] = v;
492
+ }
493
+ }
494
+ return result;
495
+ }
496
+ function readSkillFileOrDefault(relPath, fallback) {
497
+ try {
498
+ const absPath = path.join(ROOT_DIR, "plugins", "muxo", "skills", relPath);
499
+ if (fs.existsSync(absPath)) {
500
+ return fs.readFileSync(absPath, "utf8");
501
+ }
502
+ }
503
+ catch {
504
+ // Fallback to embedded markdown
505
+ }
506
+ return fallback;
507
+ }
508
+ export function getMuxoMcpSkills() {
509
+ const muxoSkillMd = readSkillFileOrDefault("muxo/SKILL.md", `---
510
+ name: muxo
511
+ description: Route governed Muxo work between the hosted MCP-backed app and the local Muxo CLI across Connected Apps (Composio), Instant Tools, Cloud Infrastructure (Stripe Projects), Supermemory v5, and Microsoft Agent Governance.
512
+ ---
513
+
514
+ # Muxo
515
+
516
+ 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.*\`).
517
+ `);
518
+ 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\`.`);
519
+ 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\`.`);
520
+ const setupSkillMd = readSkillFileOrDefault("setup/SKILL.md", `---
521
+ name: setup
522
+ 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.
523
+ ---
524
+
525
+ # Muxo Onboarding & Setup
526
+
527
+ Call \`get_profile\` and \`get_organization\` to verify your workspace connection, or run \`npx -y @muxoai/cli@latest login --signup\` in a terminal.
528
+ `);
529
+ const muxoFm = parseFrontmatter(muxoSkillMd);
530
+ const setupFm = parseFrontmatter(setupSkillMd);
531
+ const muxoFiles = [
532
+ {
533
+ path: "SKILL.md",
534
+ uri: "skill://muxo/muxo/SKILL.md",
535
+ size: Buffer.byteLength(muxoSkillMd, "utf8"),
536
+ digest: sha256Digest(muxoSkillMd),
537
+ mimeType: "text/markdown",
538
+ content: muxoSkillMd,
539
+ },
540
+ {
541
+ path: "references/cli.md",
542
+ uri: "skill://muxo/muxo/references/cli.md",
543
+ size: Buffer.byteLength(muxoCliMd, "utf8"),
544
+ digest: sha256Digest(muxoCliMd),
545
+ mimeType: "text/markdown",
546
+ content: muxoCliMd,
547
+ },
548
+ {
549
+ path: "references/mcp.md",
550
+ uri: "skill://muxo/muxo/references/mcp.md",
551
+ size: Buffer.byteLength(muxoMcpMd, "utf8"),
552
+ digest: sha256Digest(muxoMcpMd),
553
+ mimeType: "text/markdown",
554
+ content: muxoMcpMd,
555
+ },
556
+ ];
557
+ const setupFiles = [
558
+ {
559
+ path: "SKILL.md",
560
+ uri: "skill://muxo/setup/SKILL.md",
561
+ size: Buffer.byteLength(setupSkillMd, "utf8"),
562
+ digest: sha256Digest(setupSkillMd),
563
+ mimeType: "text/markdown",
564
+ content: setupSkillMd,
565
+ },
566
+ ];
567
+ const muxoName = muxoFm.name || "muxo";
568
+ const muxoDesc = muxoFm.description ||
569
+ "Route governed Muxo work between the hosted MCP-backed app and the local Muxo CLI.";
570
+ const setupName = setupFm.name || "setup";
571
+ const setupDesc = setupFm.description ||
572
+ "Guided onboarding skill for setting up the Muxo plugin in OpenAI ChatGPT and Codex.";
573
+ return [
574
+ {
575
+ name: muxoName,
576
+ description: muxoDesc,
577
+ uri: "skill://muxo/muxo/SKILL.md",
578
+ version: muxoFiles[0].digest,
579
+ frontmatter: {
580
+ name: muxoName,
581
+ description: muxoDesc,
582
+ },
583
+ files: muxoFiles,
584
+ },
585
+ {
586
+ name: setupName,
587
+ description: setupDesc,
588
+ uri: "skill://muxo/setup/SKILL.md",
589
+ version: setupFiles[0].digest,
590
+ frontmatter: {
591
+ name: setupName,
592
+ description: setupDesc,
593
+ },
594
+ files: setupFiles,
595
+ },
596
+ ];
597
+ }
598
+ export async function dispatchMcpToolCall(engine, ctx, toolName, args = {}) {
599
+ switch (toolName) {
600
+ case "get_profile":
601
+ return engine.getProfile(ctx);
602
+ case "get_organization":
603
+ return engine.getOrganization(ctx);
604
+ case "search_tools":
605
+ return engine.searchTools({
606
+ query: args.query ? String(args.query) : undefined,
607
+ lane: args.lane || "all",
608
+ riskLevel: args.risk_level,
609
+ limit: args.limit ? Number(args.limit) : 20,
610
+ });
611
+ case "inspect_tool":
612
+ return engine.inspectTool(String(args.tool_slug || args.slug || ""));
613
+ case "connection_status":
614
+ return engine.connectionStatus(ctx, {
615
+ provider: args.provider ? String(args.provider) : undefined,
616
+ syncLive: args.sync_live !== false,
617
+ });
618
+ case "start_connection":
619
+ return engine.startConnection(ctx, {
620
+ provider: String(args.provider || ""),
621
+ lane: args.lane,
622
+ callbackUrl: args.callback_url ? String(args.callback_url) : undefined,
623
+ });
624
+ case "wait_for_connection":
625
+ return engine.waitForConnection(ctx, {
626
+ provider: String(args.provider || ""),
627
+ timeoutSeconds: args.timeout_seconds !== undefined
628
+ ? Number(args.timeout_seconds)
629
+ : 15,
630
+ });
631
+ case "plan_action":
632
+ return engine.planAction(ctx, {
633
+ toolSlug: String(args.tool_slug ||
634
+ args.slug ||
635
+ args.tool_id ||
636
+ args.prompt ||
637
+ args.instruction ||
638
+ ""),
639
+ input: (args.input || args.arguments) || {},
640
+ reason: args.reason ? String(args.reason) : undefined,
641
+ });
642
+ case "get_plan":
643
+ return engine.getPlan(ctx, String(args.plan_id || ""));
644
+ case "get_run_context":
645
+ return engine.getRunContext(ctx, args.query ? String(args.query) : undefined);
646
+ case "execute_read":
647
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "read");
648
+ case "execute_write":
649
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "write");
650
+ case "execute_admin":
651
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "admin");
652
+ case "execute_financial":
653
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "financial");
654
+ case "execute_provisioning":
655
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "provisioning");
656
+ case "execute_destructive":
657
+ return engine.executePlanForRisk(ctx, String(args.plan_id || ""), "destructive");
658
+ case "get_run":
659
+ return engine.getRun(ctx, String(args.run_id || ""));
660
+ case "cancel_run":
661
+ return engine.cancelRun(ctx, String(args.run_id || ""));
662
+ case "get_receipt":
663
+ return engine.getReceipt(ctx, String(args.receipt_id || args.run_id || ""));
664
+ // OpenAI Company Knowledge standard `search` and `fetch` tool support
665
+ case "search": {
666
+ const q = String(args.query || "").trim();
667
+ const [toolsRes, memRes] = await Promise.all([
668
+ engine.searchTools({ query: q, limit: 10 }),
669
+ engine.getMemoryOverview(ctx, q),
670
+ ]);
671
+ const toolHits = toolsRes.tools.map((t) => ({
672
+ id: `tool:${t.slug}`,
673
+ title: `${t.name} (${t.slug})`,
674
+ url: t.providerUrl || `https://docs.muxo.ai/tools/${encodeURIComponent(t.slug)}`,
675
+ snippet: `${t.description} [lane=${t.lane}, risk=${t.riskLevel}, cost=${t.creditCost}cr]`,
676
+ }));
677
+ const memHits = (memRes.memories || []).slice(0, 5).map((m) => ({
678
+ id: `memory:${m.id}`,
679
+ title: m.title,
680
+ url: `https://app.muxo.ai/?memory=${encodeURIComponent(m.id)}`,
681
+ snippet: m.content.slice(0, 240),
682
+ }));
683
+ return {
684
+ results: [...toolHits, ...memHits],
685
+ };
686
+ }
687
+ case "fetch": {
688
+ const rawId = String(args.id || "").trim();
689
+ const slug = rawId.startsWith("tool:") ? rawId.slice(5) : rawId;
690
+ if (rawId.startsWith("memory:")) {
691
+ const memId = rawId.slice(7);
692
+ const memRes = await engine.getMemoryOverview(ctx);
693
+ const found = (memRes.memories || []).find((m) => m.id === memId);
694
+ if (!found)
695
+ throw new Error(`Memory record not found: ${rawId}`);
696
+ return {
697
+ id: rawId,
698
+ title: found.title,
699
+ text: found.content,
700
+ url: `https://app.muxo.ai/?memory=${encodeURIComponent(found.id)}`,
701
+ metadata: {
702
+ namespace: found.namespace,
703
+ kind: found.kind,
704
+ createdAt: found.createdAt,
705
+ },
706
+ };
707
+ }
708
+ const tool = await engine.inspectTool(slug);
709
+ return {
710
+ id: `tool:${tool.slug}`,
711
+ title: tool.name,
712
+ text: JSON.stringify(tool, null, 2),
713
+ url: tool.providerUrl ||
714
+ `https://docs.muxo.ai/tools/${encodeURIComponent(tool.slug)}`,
715
+ metadata: {
716
+ slug: tool.slug,
717
+ lane: tool.lane,
718
+ riskLevel: tool.riskLevel,
719
+ creditCost: String(tool.creditCost),
720
+ },
721
+ };
722
+ }
723
+ default:
724
+ throw new Error(`Unknown MCP tool: ${toolName}`);
725
+ }
726
+ }
727
+ export async function handleJsonRpcMcpRequest(engine, ctx, rpc) {
728
+ const id = rpc.id ?? null;
729
+ const method = String(rpc.method || "");
730
+ const params = (rpc.params || {});
731
+ if (method === "notifications/initialized" ||
732
+ method.startsWith("notifications/")) {
733
+ return null;
734
+ }
735
+ try {
736
+ if (method === "initialize") {
737
+ const requestedProtocol = typeof params.protocolVersion === "string" &&
738
+ params.protocolVersion.trim()
739
+ ? params.protocolVersion.trim()
740
+ : "2025-06-18";
741
+ return {
742
+ jsonrpc: "2.0",
743
+ id,
744
+ result: {
745
+ protocolVersion: requestedProtocol,
746
+ instructions: MUXO_MCP_SERVER_INSTRUCTIONS,
747
+ serverInfo: {
748
+ name: "muxo-mcp-server",
749
+ version: "1.3.0",
750
+ },
751
+ capabilities: {
752
+ tools: { listChanged: false },
753
+ resources: { listChanged: false },
754
+ extensions: {
755
+ "io.modelcontextprotocol/skills": {},
756
+ },
757
+ },
758
+ },
759
+ };
760
+ }
761
+ if (method === "ping") {
762
+ return { jsonrpc: "2.0", id, result: {} };
763
+ }
764
+ if (method === "tools/list") {
765
+ return {
766
+ jsonrpc: "2.0",
767
+ id,
768
+ result: {
769
+ tools: MUXO_MCP_TOOLS,
770
+ },
771
+ };
772
+ }
773
+ if (method === "tools/call") {
774
+ const toolName = String(params.name || "");
775
+ const toolArgs = (params.arguments || {});
776
+ const output = await dispatchMcpToolCall(engine, ctx, toolName, toolArgs);
777
+ const structuredContent = output && typeof output === "object" && !Array.isArray(output)
778
+ ? output
779
+ : { data: output };
780
+ return {
781
+ jsonrpc: "2.0",
782
+ id,
783
+ result: {
784
+ structuredContent,
785
+ content: [
786
+ {
787
+ type: "text",
788
+ text: JSON.stringify(output, null, 2),
789
+ },
790
+ ],
791
+ isError: false,
792
+ },
793
+ };
794
+ }
795
+ // SEP-2640 Skills Import Extension (`io.modelcontextprotocol/skills`)
796
+ if (method === "skills/list") {
797
+ const skills = getMuxoMcpSkills().map((s) => ({
798
+ name: s.name,
799
+ description: s.description,
800
+ uri: s.uri,
801
+ version: s.version,
802
+ digest: s.files[0]?.digest || "",
803
+ files: s.files.length,
804
+ }));
805
+ return {
806
+ jsonrpc: "2.0",
807
+ id,
808
+ result: { skills },
809
+ };
810
+ }
811
+ if (method === "skills/get") {
812
+ const requestedName = String(params.name || "muxo").trim();
813
+ const skill = getMuxoMcpSkills().find((s) => s.name === requestedName);
814
+ if (!skill) {
815
+ return {
816
+ jsonrpc: "2.0",
817
+ id,
818
+ error: {
819
+ code: -32602,
820
+ message: `Skill not found: ${requestedName}`,
821
+ },
822
+ };
823
+ }
824
+ return {
825
+ jsonrpc: "2.0",
826
+ id,
827
+ result: {
828
+ skill: {
829
+ name: skill.name,
830
+ description: skill.description,
831
+ uri: skill.uri,
832
+ version: skill.version,
833
+ digest: skill.files[0]?.digest || "",
834
+ },
835
+ frontmatter: skill.frontmatter,
836
+ files: skill.files.map((f) => ({
837
+ path: f.path,
838
+ uri: f.uri,
839
+ size: f.size,
840
+ digest: f.digest,
841
+ mimeType: f.mimeType,
842
+ })),
843
+ },
844
+ };
845
+ }
846
+ if (method === "resources/list") {
847
+ const resources = getMuxoMcpSkills().flatMap((s) => s.files.map((f) => ({
848
+ uri: f.uri,
849
+ name: `${s.name}/${f.path}`,
850
+ description: s.description,
851
+ mimeType: f.mimeType,
852
+ })));
853
+ return {
854
+ jsonrpc: "2.0",
855
+ id,
856
+ result: { resources },
857
+ };
858
+ }
859
+ if (method === "resources/read") {
860
+ const uri = String(params.uri || "").trim();
861
+ const allFiles = getMuxoMcpSkills().flatMap((s) => s.files);
862
+ const found = allFiles.find((f) => f.uri === uri);
863
+ if (!found) {
864
+ return {
865
+ jsonrpc: "2.0",
866
+ id,
867
+ error: {
868
+ code: -32602,
869
+ message: `Resource not found: ${uri}`,
870
+ },
871
+ };
872
+ }
873
+ return {
874
+ jsonrpc: "2.0",
875
+ id,
876
+ result: {
877
+ contents: [
878
+ {
879
+ uri: found.uri,
880
+ mimeType: found.mimeType,
881
+ text: found.content,
882
+ },
883
+ ],
884
+ },
885
+ };
886
+ }
887
+ return {
888
+ jsonrpc: "2.0",
889
+ id,
890
+ error: {
891
+ code: -32601,
892
+ message: `Method not found: ${method}`,
893
+ },
894
+ };
895
+ }
896
+ catch (err) {
897
+ return {
898
+ jsonrpc: "2.0",
899
+ id,
900
+ result: {
901
+ content: [
902
+ {
903
+ type: "text",
904
+ text: JSON.stringify({
905
+ ok: false,
906
+ error: String(err?.message || err || "MCP tool execution failed"),
907
+ }, null, 2),
908
+ },
909
+ ],
910
+ isError: true,
911
+ },
912
+ };
913
+ }
914
+ }