@muhaven/mcp 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,54 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.9] — 2026-05-23
11
+
12
+ ### Added
13
+
14
+ - **`pathDDecodedCall` in the position.buy echo on Path D fallback.**
15
+ When the bundler trace contains a `zd_sponsorUserOperation` event,
16
+ the handler now decodes the userOp.callData inline and surfaces:
17
+
18
+ pathDDecodedCall: {
19
+ sender: '0x<kernel>',
20
+ kernelExecuteMode: '0x<32 bytes>',
21
+ kernelExecuteTarget: '0x<addr>', // should == MuHavenSubscription
22
+ kernelExecuteValue: '0',
23
+ innerSelector: '0xd29b624b', // purchase(...)
24
+ innerPurchaseTokenArg: '0x<addr>', // the RWA token (MuHavenToken)
25
+ innerPurchaseMaxSharesHint: '14',
26
+ innerPurchaseEphemeralEOA: '0x<addr>',
27
+ expectedSubscriptionAddress: '0x<addr>', // MCP env wiring
28
+ kernelExecuteTargetMatchesSubscription: true|false,
29
+ interpretation: 'kernel.execute target matches MuHavenSubscription. ...',
30
+ }
31
+
32
+ Lets the LLM read at-a-glance which contract the kernel was about
33
+ to call (kernel.execute target) vs which RWA token the inner
34
+ purchase() carries — the two are commonly confused (the inner
35
+ purchase's first arg IS the token address, but the kernel.execute
36
+ target should be the subscription).
37
+
38
+ The `interpretation` field branches on three cases:
39
+ 1. target == expected subscription → "shape is correct; AA23 is
40
+ downstream of validator signature decode; check
41
+ muhaven.policy.session_key_status."
42
+ 2. target == inner purchase.token → "kernel is dispatching to
43
+ the token instead of the subscription — code bug."
44
+ 3. Anything else → "unexpected third-address dispatch."
45
+
46
+ - **`decodeKernelExecuteSingleCall` exported from
47
+ `clients/kernel-encoder.ts`.** Sibling to the existing encoder;
48
+ reuses the same KERNEL_EXECUTE_ABI + single-call default mode.
49
+ Returns `null` on unsupported modes (batch / delegate / try) so
50
+ the diagnostic emits a clear gap instead of garbage.
51
+
52
+ - **`scripts/decode-userop-trace.ts`** — standalone CLI that takes
53
+ the raw `pathDBundlerTrace` JSON via stdin and prints the same
54
+ decode + cross-check. Useful when triaging against an older MCP
55
+ version that doesn't ship `pathDDecodedCall`, or for offline
56
+ analysis from a saved trace.
57
+
10
58
  ## [0.2.8] — 2026-05-23
11
59
 
12
60
  ### Added
package/dist/broker.cjs CHANGED
@@ -2783,7 +2783,7 @@ function printUsage() {
2783
2783
  }
2784
2784
  function getBrokerPackageVersion() {
2785
2785
  {
2786
- return "0.2.8";
2786
+ return "0.2.9";
2787
2787
  }
2788
2788
  }
2789
2789
  function printVersion() {
package/dist/broker.js CHANGED
@@ -2785,7 +2785,7 @@ function printUsage() {
2785
2785
  }
2786
2786
  function getBrokerPackageVersion() {
2787
2787
  {
2788
- return "0.2.8";
2788
+ return "0.2.9";
2789
2789
  }
2790
2790
  }
2791
2791
  function printVersion() {
package/dist/index.cjs CHANGED
@@ -1968,6 +1968,26 @@ function encodeKernelExecuteSingleCall(input) {
1968
1968
  args: [KERNEL_V3_SINGLE_CALL_MODE_DEFAULT, executionCalldata]
1969
1969
  });
1970
1970
  }
1971
+ function decodeKernelExecuteSingleCall(data) {
1972
+ let decoded;
1973
+ try {
1974
+ decoded = viem.decodeFunctionData({ abi: KERNEL_EXECUTE_ABI, data });
1975
+ } catch {
1976
+ return null;
1977
+ }
1978
+ const [mode, executionCalldata] = decoded.args;
1979
+ if (mode !== KERNEL_V3_SINGLE_CALL_MODE_DEFAULT) {
1980
+ return null;
1981
+ }
1982
+ const ec = executionCalldata.slice(2);
1983
+ if (ec.length < 20 * 2 + 32 * 2) {
1984
+ return null;
1985
+ }
1986
+ const target = `0x${ec.slice(0, 40)}`;
1987
+ const value = BigInt(`0x${ec.slice(40, 40 + 64)}`);
1988
+ const innerCallData = `0x${ec.slice(40 + 64)}`;
1989
+ return { mode, target, value, innerCallData };
1990
+ }
1971
1991
  var ECDSA_SIG_HEX_RE = /^0x[0-9a-fA-F]{130}$/;
1972
1992
  var PERMISSION_USE_PREFIX = "0xff";
1973
1993
  function buildKernelSessionKeySignature(input) {
@@ -2357,6 +2377,79 @@ async function syncSnapshotFromMirror(deps, brokerSignerAddress) {
2357
2377
  }
2358
2378
  return { kind: "ok", sessionId: activeId };
2359
2379
  }
2380
+ var PURCHASE_SELECTOR_LOWER = SUBSCRIPTION_PURCHASE_SELECTOR.toLowerCase();
2381
+ function buildPathDDecodedCall(trace, deps) {
2382
+ const sponsorEvent = trace.find((e) => e.method === "zd_sponsorUserOperation");
2383
+ if (!sponsorEvent) return void 0;
2384
+ let req;
2385
+ try {
2386
+ req = JSON.parse(sponsorEvent.requestBody);
2387
+ } catch {
2388
+ return void 0;
2389
+ }
2390
+ const userOp = req.params?.[0]?.userOp;
2391
+ if (!userOp || typeof userOp.callData !== "string" || !userOp.callData.startsWith("0x")) {
2392
+ return void 0;
2393
+ }
2394
+ const sender = userOp.sender ?? "<missing>";
2395
+ const decoded = decodeKernelExecuteSingleCall(userOp.callData);
2396
+ if (!decoded) {
2397
+ return {
2398
+ sender,
2399
+ kernelExecuteMode: "<undecodable>",
2400
+ kernelExecuteTarget: "<undecodable>",
2401
+ kernelExecuteValue: "<undecodable>",
2402
+ innerSelector: "<undecodable>",
2403
+ interpretation: "kernel.execute callData could not be decoded as single-call default mode. The mode word is non-zero or the executionCalldata layout is unexpected. Manual decode required."
2404
+ };
2405
+ }
2406
+ const innerSelector = decoded.innerCallData.slice(0, 10).toLowerCase();
2407
+ let innerPurchaseTokenArg;
2408
+ let innerPurchaseMaxSharesHint;
2409
+ let innerPurchaseEphemeralEOA;
2410
+ if (innerSelector === PURCHASE_SELECTOR_LOWER) {
2411
+ try {
2412
+ const inner = viem.decodeFunctionData({
2413
+ abi: SUBSCRIPTION_PURCHASE_ABI,
2414
+ data: decoded.innerCallData
2415
+ });
2416
+ const [tokenArg, , maxSharesHint, ephemeralEOA] = inner.args;
2417
+ innerPurchaseTokenArg = tokenArg;
2418
+ innerPurchaseMaxSharesHint = maxSharesHint.toString();
2419
+ innerPurchaseEphemeralEOA = ephemeralEOA;
2420
+ } catch {
2421
+ }
2422
+ }
2423
+ const expectedSubscriptionAddress = deps.subscriptionAddress?.toLowerCase();
2424
+ const kernelTargetLower = decoded.target.toLowerCase();
2425
+ let kernelExecuteTargetMatchesSubscription;
2426
+ let interpretation;
2427
+ if (expectedSubscriptionAddress === void 0) {
2428
+ interpretation = `kernel.execute target=${decoded.target}; inner purchase token=${innerPurchaseTokenArg ?? "<unknown>"}; MUHAVEN_SUBSCRIPTION_ADDRESS not wired on this MCP server \u2014 cannot cross-check.`;
2429
+ } else if (kernelTargetLower === expectedSubscriptionAddress) {
2430
+ kernelExecuteTargetMatchesSubscription = true;
2431
+ interpretation = `kernel.execute target matches MuHavenSubscription (${decoded.target}). Inner purchase token = ${innerPurchaseTokenArg ?? "<unknown>"}. The shape is correct; the AA23 revert is downstream of the validator's signature decode \u2014 likely either an on-chain signer-vs-installed-permission mismatch, a target/selector not in the on-chain policy, or a cap-arg breach. Check muhaven.policy.session_key_status for the installed permission state.`;
2432
+ } else if (innerPurchaseTokenArg !== void 0 && kernelTargetLower === innerPurchaseTokenArg.toLowerCase()) {
2433
+ kernelExecuteTargetMatchesSubscription = false;
2434
+ interpretation = `kernel.execute target = ${decoded.target} = the RWA MuHavenToken (purchase.token arg0). Expected MuHavenSubscription (${deps.subscriptionAddress}). The kernel is dispatching purchase() to the token contract instead of the subscription \u2014 token doesn't have a purchase() selector, so fallback returns empty revert data (= AA23 reverted 0x). This is a code-side bug in the kernel.execute target wiring.`;
2435
+ } else {
2436
+ kernelExecuteTargetMatchesSubscription = false;
2437
+ interpretation = `kernel.execute target = ${decoded.target} \u2014 NEITHER the expected MuHavenSubscription (${deps.subscriptionAddress}) NOR the inner purchase.token arg (${innerPurchaseTokenArg ?? "<none>"}). This is an unexpected third-address dispatch; inspect deps.subscriptionAddress env wiring.`;
2438
+ }
2439
+ return {
2440
+ sender,
2441
+ kernelExecuteMode: decoded.mode,
2442
+ kernelExecuteTarget: decoded.target,
2443
+ kernelExecuteValue: decoded.value.toString(),
2444
+ innerSelector,
2445
+ innerPurchaseTokenArg,
2446
+ innerPurchaseMaxSharesHint,
2447
+ innerPurchaseEphemeralEOA,
2448
+ expectedSubscriptionAddress: deps.subscriptionAddress,
2449
+ kernelExecuteTargetMatchesSubscription,
2450
+ interpretation
2451
+ };
2452
+ }
2360
2453
  async function attemptPathD(args, deps) {
2361
2454
  const { shares, tokenAddress, tokenSymbol } = args;
2362
2455
  if (!deps.broker || !deps.bundler) {
@@ -2804,6 +2897,7 @@ async function positionBuy(input, deps) {
2804
2897
  let pathDFallbackDetail;
2805
2898
  let pathDSubmittedUserOpHash;
2806
2899
  let pathDBundlerTrace;
2900
+ let pathDDecodedCall;
2807
2901
  const pathD = await attemptPathD(
2808
2902
  { shares, tokenAddress: token.address, tokenSymbol: token.symbol },
2809
2903
  deps
@@ -2821,6 +2915,7 @@ async function positionBuy(input, deps) {
2821
2915
  const trace = deps.bundler.drainTrace();
2822
2916
  if (trace.length > 0) {
2823
2917
  pathDBundlerTrace = trace;
2918
+ pathDDecodedCall = buildPathDDecodedCall(trace, deps);
2824
2919
  }
2825
2920
  }
2826
2921
  }
@@ -2847,7 +2942,8 @@ ${dashboardUrl}`,
2847
2942
  ...pathDFallbackReason ? { pathDFallbackReason } : {},
2848
2943
  ...pathDFallbackDetail ? { pathDFallbackDetail } : {},
2849
2944
  ...pathDSubmittedUserOpHash ? { pathDSubmittedUserOpHash } : {},
2850
- ...pathDBundlerTrace ? { pathDBundlerTrace } : {}
2945
+ ...pathDBundlerTrace ? { pathDBundlerTrace } : {},
2946
+ ...pathDDecodedCall ? { pathDDecodedCall } : {}
2851
2947
  }
2852
2948
  });
2853
2949
  }
@@ -3198,7 +3294,7 @@ var SERVER_NAME = "@muhaven/mcp";
3198
3294
  var SERVER_VERSION = resolveServerVersion();
3199
3295
  function resolveServerVersion() {
3200
3296
  {
3201
- return "0.2.8";
3297
+ return "0.2.9";
3202
3298
  }
3203
3299
  }
3204
3300
  function toJsonInputSchema(schema) {
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
10
10
  import { platform, homedir } from 'os';
11
11
  import { connect, createServer } from 'net';
12
12
  import { setTimeout as setTimeout$1 } from 'timers/promises';
13
- import { parseAbi, toFunctionSelector, encodeFunctionData, encodePacked, pad, concatHex, decodeAbiParameters } from 'viem';
13
+ import { parseAbi, toFunctionSelector, encodeFunctionData, decodeFunctionData, encodePacked, pad, concatHex, decodeAbiParameters } from 'viem';
14
14
  import { createHash, randomBytes } from 'crypto';
15
15
  import { getUserOperationHash } from 'viem/account-abstraction';
16
16
  import { privateKeyToAccount } from 'viem/accounts';
@@ -1964,6 +1964,26 @@ function encodeKernelExecuteSingleCall(input) {
1964
1964
  args: [KERNEL_V3_SINGLE_CALL_MODE_DEFAULT, executionCalldata]
1965
1965
  });
1966
1966
  }
1967
+ function decodeKernelExecuteSingleCall(data) {
1968
+ let decoded;
1969
+ try {
1970
+ decoded = decodeFunctionData({ abi: KERNEL_EXECUTE_ABI, data });
1971
+ } catch {
1972
+ return null;
1973
+ }
1974
+ const [mode, executionCalldata] = decoded.args;
1975
+ if (mode !== KERNEL_V3_SINGLE_CALL_MODE_DEFAULT) {
1976
+ return null;
1977
+ }
1978
+ const ec = executionCalldata.slice(2);
1979
+ if (ec.length < 20 * 2 + 32 * 2) {
1980
+ return null;
1981
+ }
1982
+ const target = `0x${ec.slice(0, 40)}`;
1983
+ const value = BigInt(`0x${ec.slice(40, 40 + 64)}`);
1984
+ const innerCallData = `0x${ec.slice(40 + 64)}`;
1985
+ return { mode, target, value, innerCallData };
1986
+ }
1967
1987
  var ECDSA_SIG_HEX_RE = /^0x[0-9a-fA-F]{130}$/;
1968
1988
  var PERMISSION_USE_PREFIX = "0xff";
1969
1989
  function buildKernelSessionKeySignature(input) {
@@ -2353,6 +2373,79 @@ async function syncSnapshotFromMirror(deps, brokerSignerAddress) {
2353
2373
  }
2354
2374
  return { kind: "ok", sessionId: activeId };
2355
2375
  }
2376
+ var PURCHASE_SELECTOR_LOWER = SUBSCRIPTION_PURCHASE_SELECTOR.toLowerCase();
2377
+ function buildPathDDecodedCall(trace, deps) {
2378
+ const sponsorEvent = trace.find((e) => e.method === "zd_sponsorUserOperation");
2379
+ if (!sponsorEvent) return void 0;
2380
+ let req;
2381
+ try {
2382
+ req = JSON.parse(sponsorEvent.requestBody);
2383
+ } catch {
2384
+ return void 0;
2385
+ }
2386
+ const userOp = req.params?.[0]?.userOp;
2387
+ if (!userOp || typeof userOp.callData !== "string" || !userOp.callData.startsWith("0x")) {
2388
+ return void 0;
2389
+ }
2390
+ const sender = userOp.sender ?? "<missing>";
2391
+ const decoded = decodeKernelExecuteSingleCall(userOp.callData);
2392
+ if (!decoded) {
2393
+ return {
2394
+ sender,
2395
+ kernelExecuteMode: "<undecodable>",
2396
+ kernelExecuteTarget: "<undecodable>",
2397
+ kernelExecuteValue: "<undecodable>",
2398
+ innerSelector: "<undecodable>",
2399
+ interpretation: "kernel.execute callData could not be decoded as single-call default mode. The mode word is non-zero or the executionCalldata layout is unexpected. Manual decode required."
2400
+ };
2401
+ }
2402
+ const innerSelector = decoded.innerCallData.slice(0, 10).toLowerCase();
2403
+ let innerPurchaseTokenArg;
2404
+ let innerPurchaseMaxSharesHint;
2405
+ let innerPurchaseEphemeralEOA;
2406
+ if (innerSelector === PURCHASE_SELECTOR_LOWER) {
2407
+ try {
2408
+ const inner = decodeFunctionData({
2409
+ abi: SUBSCRIPTION_PURCHASE_ABI,
2410
+ data: decoded.innerCallData
2411
+ });
2412
+ const [tokenArg, , maxSharesHint, ephemeralEOA] = inner.args;
2413
+ innerPurchaseTokenArg = tokenArg;
2414
+ innerPurchaseMaxSharesHint = maxSharesHint.toString();
2415
+ innerPurchaseEphemeralEOA = ephemeralEOA;
2416
+ } catch {
2417
+ }
2418
+ }
2419
+ const expectedSubscriptionAddress = deps.subscriptionAddress?.toLowerCase();
2420
+ const kernelTargetLower = decoded.target.toLowerCase();
2421
+ let kernelExecuteTargetMatchesSubscription;
2422
+ let interpretation;
2423
+ if (expectedSubscriptionAddress === void 0) {
2424
+ interpretation = `kernel.execute target=${decoded.target}; inner purchase token=${innerPurchaseTokenArg ?? "<unknown>"}; MUHAVEN_SUBSCRIPTION_ADDRESS not wired on this MCP server \u2014 cannot cross-check.`;
2425
+ } else if (kernelTargetLower === expectedSubscriptionAddress) {
2426
+ kernelExecuteTargetMatchesSubscription = true;
2427
+ interpretation = `kernel.execute target matches MuHavenSubscription (${decoded.target}). Inner purchase token = ${innerPurchaseTokenArg ?? "<unknown>"}. The shape is correct; the AA23 revert is downstream of the validator's signature decode \u2014 likely either an on-chain signer-vs-installed-permission mismatch, a target/selector not in the on-chain policy, or a cap-arg breach. Check muhaven.policy.session_key_status for the installed permission state.`;
2428
+ } else if (innerPurchaseTokenArg !== void 0 && kernelTargetLower === innerPurchaseTokenArg.toLowerCase()) {
2429
+ kernelExecuteTargetMatchesSubscription = false;
2430
+ interpretation = `kernel.execute target = ${decoded.target} = the RWA MuHavenToken (purchase.token arg0). Expected MuHavenSubscription (${deps.subscriptionAddress}). The kernel is dispatching purchase() to the token contract instead of the subscription \u2014 token doesn't have a purchase() selector, so fallback returns empty revert data (= AA23 reverted 0x). This is a code-side bug in the kernel.execute target wiring.`;
2431
+ } else {
2432
+ kernelExecuteTargetMatchesSubscription = false;
2433
+ interpretation = `kernel.execute target = ${decoded.target} \u2014 NEITHER the expected MuHavenSubscription (${deps.subscriptionAddress}) NOR the inner purchase.token arg (${innerPurchaseTokenArg ?? "<none>"}). This is an unexpected third-address dispatch; inspect deps.subscriptionAddress env wiring.`;
2434
+ }
2435
+ return {
2436
+ sender,
2437
+ kernelExecuteMode: decoded.mode,
2438
+ kernelExecuteTarget: decoded.target,
2439
+ kernelExecuteValue: decoded.value.toString(),
2440
+ innerSelector,
2441
+ innerPurchaseTokenArg,
2442
+ innerPurchaseMaxSharesHint,
2443
+ innerPurchaseEphemeralEOA,
2444
+ expectedSubscriptionAddress: deps.subscriptionAddress,
2445
+ kernelExecuteTargetMatchesSubscription,
2446
+ interpretation
2447
+ };
2448
+ }
2356
2449
  async function attemptPathD(args, deps) {
2357
2450
  const { shares, tokenAddress, tokenSymbol } = args;
2358
2451
  if (!deps.broker || !deps.bundler) {
@@ -2800,6 +2893,7 @@ async function positionBuy(input, deps) {
2800
2893
  let pathDFallbackDetail;
2801
2894
  let pathDSubmittedUserOpHash;
2802
2895
  let pathDBundlerTrace;
2896
+ let pathDDecodedCall;
2803
2897
  const pathD = await attemptPathD(
2804
2898
  { shares, tokenAddress: token.address, tokenSymbol: token.symbol },
2805
2899
  deps
@@ -2817,6 +2911,7 @@ async function positionBuy(input, deps) {
2817
2911
  const trace = deps.bundler.drainTrace();
2818
2912
  if (trace.length > 0) {
2819
2913
  pathDBundlerTrace = trace;
2914
+ pathDDecodedCall = buildPathDDecodedCall(trace, deps);
2820
2915
  }
2821
2916
  }
2822
2917
  }
@@ -2843,7 +2938,8 @@ ${dashboardUrl}`,
2843
2938
  ...pathDFallbackReason ? { pathDFallbackReason } : {},
2844
2939
  ...pathDFallbackDetail ? { pathDFallbackDetail } : {},
2845
2940
  ...pathDSubmittedUserOpHash ? { pathDSubmittedUserOpHash } : {},
2846
- ...pathDBundlerTrace ? { pathDBundlerTrace } : {}
2941
+ ...pathDBundlerTrace ? { pathDBundlerTrace } : {},
2942
+ ...pathDDecodedCall ? { pathDDecodedCall } : {}
2847
2943
  }
2848
2944
  });
2849
2945
  }
@@ -3194,7 +3290,7 @@ var SERVER_NAME = "@muhaven/mcp";
3194
3290
  var SERVER_VERSION = resolveServerVersion();
3195
3291
  function resolveServerVersion() {
3196
3292
  {
3197
- return "0.2.8";
3293
+ return "0.2.9";
3198
3294
  }
3199
3295
  }
3200
3296
  function toJsonInputSchema(schema) {
package/manifest.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifest_version": "0.2",
4
4
  "name": "muhaven-mcp",
5
5
  "display_name": "MuHaven (RWA portfolio)",
6
- "version": "0.2.8",
6
+ "version": "0.2.9",
7
7
  "description": "Confidential RWA portfolio management on Fhenix CoFHE. Read your encrypted balances, propose yield claims and policy changes — all signing happens in a sibling broker daemon, the LLM never sees your private key.",
8
8
  "long_description": "MuHaven MCP exposes 24 tools across read.* / position.* / policy.* / issuer.* / governance.* groups for managing real-world asset (RWA) tokens with FHE-encrypted balances. Authentication uses a one-time device-code ceremony (run `muhaven-broker login`); subsequent tool calls fetch the JWT from the broker over a Unix socket. Position / governance tools deep-link to the dashboard for passkey signing — they NEVER auto-submit to a bundler. The companion `muhaven-broker` daemon must be running before tools can be invoked. See README for setup.",
9
9
  "author": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muhaven/mcp",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "MuHaven MCP server — read/position/policy toolsets bridging Claude Desktop / Cursor / Claude Code to the MuHaven backend, with a sibling muhaven-broker daemon holding the session-key private half over a local IPC socket",
5
5
  "type": "module",
6
6
  "repository": {