dexe-mcp 0.1.3 → 0.2.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 (100) hide show
  1. package/.mcp.example.json +12 -2
  2. package/CHANGELOG.md +48 -0
  3. package/FUTURE.md +26 -5
  4. package/README.md +80 -195
  5. package/dist/bootstrap.d.ts.map +1 -1
  6. package/dist/bootstrap.js +10 -1
  7. package/dist/bootstrap.js.map +1 -1
  8. package/dist/config.d.ts +10 -0
  9. package/dist/config.d.ts.map +1 -1
  10. package/dist/config.js +24 -1
  11. package/dist/config.js.map +1 -1
  12. package/dist/hardhat.d.ts.map +1 -1
  13. package/dist/hardhat.js +10 -5
  14. package/dist/hardhat.js.map +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/lib/addresses.d.ts +57 -0
  17. package/dist/lib/addresses.d.ts.map +1 -0
  18. package/dist/lib/addresses.js +83 -0
  19. package/dist/lib/addresses.js.map +1 -0
  20. package/dist/lib/calldata.d.ts +32 -0
  21. package/dist/lib/calldata.d.ts.map +1 -0
  22. package/dist/lib/calldata.js +28 -0
  23. package/dist/lib/calldata.js.map +1 -0
  24. package/dist/lib/govEnums.d.ts +12 -0
  25. package/dist/lib/govEnums.d.ts.map +1 -0
  26. package/dist/lib/govEnums.js +35 -0
  27. package/dist/lib/govEnums.js.map +1 -0
  28. package/dist/lib/ipfs.d.ts +60 -0
  29. package/dist/lib/ipfs.d.ts.map +1 -0
  30. package/dist/lib/ipfs.js +167 -0
  31. package/dist/lib/ipfs.js.map +1 -0
  32. package/dist/lib/multicall.d.ts +33 -0
  33. package/dist/lib/multicall.d.ts.map +1 -0
  34. package/dist/lib/multicall.js +46 -0
  35. package/dist/lib/multicall.js.map +1 -0
  36. package/dist/lib/proposalCatalog.d.ts +45 -0
  37. package/dist/lib/proposalCatalog.d.ts.map +1 -0
  38. package/dist/lib/proposalCatalog.js +416 -0
  39. package/dist/lib/proposalCatalog.js.map +1 -0
  40. package/dist/lib/subgraph.d.ts +15 -0
  41. package/dist/lib/subgraph.d.ts.map +1 -0
  42. package/dist/lib/subgraph.js +37 -0
  43. package/dist/lib/subgraph.js.map +1 -0
  44. package/dist/runtime.d.ts +51 -13
  45. package/dist/runtime.d.ts.map +1 -1
  46. package/dist/runtime.js +149 -26
  47. package/dist/runtime.js.map +1 -1
  48. package/dist/tools/dao.d.ts +4 -0
  49. package/dist/tools/dao.d.ts.map +1 -0
  50. package/dist/tools/dao.js +242 -0
  51. package/dist/tools/dao.js.map +1 -0
  52. package/dist/tools/daoDeploy.d.ts +4 -0
  53. package/dist/tools/daoDeploy.d.ts.map +1 -0
  54. package/dist/tools/daoDeploy.js +323 -0
  55. package/dist/tools/daoDeploy.js.map +1 -0
  56. package/dist/tools/index.d.ts.map +1 -1
  57. package/dist/tools/index.js +24 -0
  58. package/dist/tools/index.js.map +1 -1
  59. package/dist/tools/ipfs.d.ts +6 -0
  60. package/dist/tools/ipfs.d.ts.map +1 -0
  61. package/dist/tools/ipfs.js +310 -0
  62. package/dist/tools/ipfs.js.map +1 -0
  63. package/dist/tools/proposal.d.ts +4 -0
  64. package/dist/tools/proposal.d.ts.map +1 -0
  65. package/dist/tools/proposal.js +199 -0
  66. package/dist/tools/proposal.js.map +1 -0
  67. package/dist/tools/proposalBuild.d.ts +4 -0
  68. package/dist/tools/proposalBuild.d.ts.map +1 -0
  69. package/dist/tools/proposalBuild.js +357 -0
  70. package/dist/tools/proposalBuild.js.map +1 -0
  71. package/dist/tools/proposalBuildComplex.d.ts +4 -0
  72. package/dist/tools/proposalBuildComplex.d.ts.map +1 -0
  73. package/dist/tools/proposalBuildComplex.js +700 -0
  74. package/dist/tools/proposalBuildComplex.js.map +1 -0
  75. package/dist/tools/proposalBuildInternal.d.ts +4 -0
  76. package/dist/tools/proposalBuildInternal.d.ts.map +1 -0
  77. package/dist/tools/proposalBuildInternal.js +211 -0
  78. package/dist/tools/proposalBuildInternal.js.map +1 -0
  79. package/dist/tools/proposalBuildMore.d.ts +4 -0
  80. package/dist/tools/proposalBuildMore.d.ts.map +1 -0
  81. package/dist/tools/proposalBuildMore.js +436 -0
  82. package/dist/tools/proposalBuildMore.js.map +1 -0
  83. package/dist/tools/proposalBuildOffchain.d.ts +4 -0
  84. package/dist/tools/proposalBuildOffchain.d.ts.map +1 -0
  85. package/dist/tools/proposalBuildOffchain.js +386 -0
  86. package/dist/tools/proposalBuildOffchain.js.map +1 -0
  87. package/dist/tools/read.d.ts +4 -0
  88. package/dist/tools/read.d.ts.map +1 -0
  89. package/dist/tools/read.js +353 -0
  90. package/dist/tools/read.js.map +1 -0
  91. package/dist/tools/vote.d.ts +4 -0
  92. package/dist/tools/vote.d.ts.map +1 -0
  93. package/dist/tools/vote.js +196 -0
  94. package/dist/tools/vote.js.map +1 -0
  95. package/dist/tools/voteBuild.d.ts +4 -0
  96. package/dist/tools/voteBuild.d.ts.map +1 -0
  97. package/dist/tools/voteBuild.js +563 -0
  98. package/dist/tools/voteBuild.js.map +1 -0
  99. package/package.json +9 -4
  100. package/PLAN.md +0 -132
package/PLAN.md DELETED
@@ -1,132 +0,0 @@
1
- # Plan: `dexe-mcp` — MCP Server for DeXe Protocol Dev Tooling
2
-
3
- ## Context
4
-
5
- DeXe Protocol (`D:\dev\DeXe-Protocol`) is a governance DAO protocol: 129 Solidity contracts (OpenZeppelin v4.9.2, Solidity 0.8.20, Hardhat 2.20.1), organized around `GovPool`, `GovSettings`, `GovUserKeeper`, `GovValidators`, proposal contracts (`DistributionProposal`, `StakingProposal`, `TokenSaleProposal`), voting-power libs (`LinearPower`, `PolynomialPower`), and a `ContractsRegistry` service locator.
6
-
7
- Day-to-day dev work on this repo currently means jumping between `npm run compile`, `hardhat test --grep`, reading TypeChain output, and hand-decoding proposal calldata against ABIs. We want an MCP server Claude Code can drive directly so an agent can compile, introspect contracts, and answer governance-domain questions (decode a proposal, read on-chain gov state, simulate a vote on a fork) without the human babysitting each shell command.
8
-
9
- **Decisions already made (from user):**
10
- - TypeScript / Node, `@modelcontextprotocol/sdk` v1.x, stdio transport
11
- - Separate repo (`dexe-mcp`) — not nested inside DeXe-Protocol
12
- - Scope: **build/test**, **contract introspection**, **governance domain**. Explicitly **out of scope**: deployment/migration tooling
13
- - Consumer: Claude Code (stdio)
14
-
15
- The server points at a DeXe-Protocol checkout via `DEXE_PROTOCOL_PATH`; it reads Hardhat artifacts off disk and shells out to `npm run <script>` in that directory. On-chain / fork interactions go through an injected RPC URL.
16
-
17
- ## Repository Layout
18
-
19
- ```
20
- dexe-mcp/
21
- ├── package.json # "bin": { "dexe-mcp": "dist/index.js" }
22
- ├── tsconfig.json
23
- ├── README.md # how to wire into Claude Code .mcp.json
24
- ├── .mcp.example.json # copy-paste snippet for users
25
- ├── src/
26
- │ ├── index.ts # McpServer + StdioServerTransport entrypoint
27
- │ ├── config.ts # env: DEXE_PROTOCOL_PATH, RPC_URL, FORK_BLOCK
28
- │ ├── artifacts.ts # load hardhat artifacts + build-info + storage layout
29
- │ ├── hardhat.ts # spawn `npm run …` in DEXE_PROTOCOL_PATH, stream + cap output
30
- │ ├── rpc.ts # ethers v6 Provider factory
31
- │ ├── fork.ts # on-demand `hardhat node --fork` child process mgmt
32
- │ ├── lib/
33
- │ │ ├── selectors.ts # 4byte index built from all compiled ABIs
34
- │ │ ├── decoders.ts # proposal-executor decoders (Distribution/Staking/TokenSale)
35
- │ │ └── govAddresses.ts # resolve GovPool ecosystem via ContractsRegistry
36
- │ └── tools/
37
- │ ├── index.ts # registerAll(server)
38
- │ ├── build.ts # compile / test / coverage / lint
39
- │ ├── introspect.ts # abi / selectors / storage / natspec / source
40
- │ └── gov.ts # decode_calldata / decode_proposal / read_gov_state / simulate_vote
41
- └── test/
42
- └── tools.test.ts # vitest; uses a tiny fixture hardhat project
43
- ```
44
-
45
- ## Dependencies
46
-
47
- - `@modelcontextprotocol/sdk` (v1.x) — `McpServer`, `StdioServerTransport`, `registerTool`
48
- - `zod` — input/output schemas (Standard Schema, per current MCP SDK docs)
49
- - `ethers` v6 — ABI parsing, `Interface.parseTransaction`, providers, impersonation
50
- - `execa` — child_process wrapper for hardhat shell-outs (timeout + stdout capping)
51
- - `p-limit` — guard concurrent hardhat invocations
52
- - Dev: `typescript`, `tsx`, `vitest`, `@types/node`
53
-
54
- ## Tool Catalog
55
-
56
- All tools use `registerTool(name, {title, description, inputSchema, outputSchema}, handler)` with Zod schemas and return both `content` (text) and `structuredContent` (machine-readable).
57
-
58
- ### Build / test (wraps `npm run …` in `DEXE_PROTOCOL_PATH`)
59
-
60
- | Tool | Input | Behavior |
61
- |---|---|---|
62
- | `dexe_compile` | `{ force?: boolean }` | Runs `npm run compile`. Parses solc errors/warnings; returns counts + first N diagnostics with file/line. |
63
- | `dexe_test` | `{ grep?: string, file?: string, bail?: boolean }` | Runs `npx hardhat test` (with `--grep` / file arg). Parses mocha output; returns pass/fail counts and up to 20 failures with stack traces. |
64
- | `dexe_coverage` | `{ grep?: string }` | Runs `npm run coverage`. Returns per-contract line/branch % summary parsed from `coverage/coverage-summary.json`. |
65
- | `dexe_lint` | `{ fix?: boolean }` | Runs `npm run lint-fix` (or dry-run). Returns changed-file list. |
66
-
67
- All build/test tools cap stdout at ~200 lines and write full logs to a tmp file, surfacing the path in `structuredContent.logFile`.
68
-
69
- ### Contract introspection (reads artifacts, no network)
70
-
71
- `artifacts.ts` loads `${DEXE_PROTOCOL_PATH}/artifacts/contracts/**/*.json` and the matching `build-info/*.json` for storage layout + metadata.
72
-
73
- | Tool | Input | Behavior |
74
- |---|---|---|
75
- | `dexe_list_contracts` | `{ filter?: string, kind?: "contract"\|"interface"\|"library" }` | Enumerates compiled contracts, returning `{name, path, kind}`. |
76
- | `dexe_get_abi` | `{ contract: string }` | Returns ABI JSON for named contract. |
77
- | `dexe_get_selectors` | `{ contract: string }` | Returns list of `{signature, selector, type: "function"\|"event"\|"error"}` using `ethers.Interface.getFunction().selector`. |
78
- | `dexe_find_selector` | `{ selector: "0xXXXXXXXX" }` | Reverse-lookup against the prebuilt index in `lib/selectors.ts`; returns all matching signatures + contracts. |
79
- | `dexe_get_storage_layout` | `{ contract: string }` | Extracts storage layout from build-info `output.contracts[file][name].storageLayout`. |
80
- | `dexe_get_natspec` | `{ contract: string, member?: string }` | Returns `devdoc`/`userdoc` from artifact metadata, optionally scoped to one function. |
81
- | `dexe_get_source` | `{ contract: string, symbol?: string }` | Returns source path; if `symbol`, returns a slice around its definition using AST from build-info. |
82
-
83
- ### Governance domain (the reason this MCP exists)
84
-
85
- | Tool | Input | Behavior |
86
- |---|---|---|
87
- | `dexe_decode_calldata` | `{ data: "0x...", contract?: string }` | Tries to decode calldata. Without `contract`, iterates all loaded ABIs by selector match. Returns decoded function + args (recursively decoding nested proposal executor calldata for `GovPool.createProposal` / `execute`). |
88
- | `dexe_decode_proposal` | `{ govPool: address, proposalId: number }` | Calls `GovPool.getProposals` via RPC, decodes every action's `data` against the matching executor (`DistributionProposal`, `TokenSaleProposal`, `StakingProposal`, or generic) using `lib/decoders.ts`. |
89
- | `dexe_read_gov_state` | `{ govPool: address, fields?: string[] }` | Aggregate read: `GovSettings` params, `GovUserKeeper` totals, `GovValidators` set, active proposal count. Resolved via `ContractsRegistry` (`lib/govAddresses.ts`). |
90
- | `dexe_simulate_vote` | `{ govPool: address, proposalId: number, voter: address, voteAmount: string, support: boolean }` | Starts/reuses a `hardhat node --fork $RPC_URL` child (managed by `fork.ts`), impersonates `voter`, calls `GovPool.vote`, returns the new proposal state + gas used. Fork is torn down on server shutdown. |
91
- | `dexe_list_gov_contract_types` | `{}` | Static catalog: names, roles, ABI pointers for the governance subsystem. Cheap orientation tool for agents new to the repo. |
92
-
93
- ## Key Implementation Notes
94
-
95
- - **Single source of truth for artifacts.** `artifacts.ts` memoizes a `Map<contractName, {abi, bytecode, buildInfoPath}>` built once per `DEXE_PROTOCOL_PATH` mtime. Invalidated after `dexe_compile` completes.
96
- - **Selector index.** Built lazily on first introspection call by walking the artifact map and calling `new ethers.Interface(abi)` on each. Stored as `Map<selector, Array<{contract, signature}>>` — supports collisions.
97
- - **Proposal decoding is the crown jewel.** `lib/decoders.ts` must handle `GovPool`'s `ProposalAction[]` shape (`executor`, `value`, `data`), dispatching by `executor` address class to the proposal-specific ABIs. Fall back to generic ABI decode when executor is unknown. Unit-test this against real calldata captured from mainnet proposals.
98
- - **Fork lifecycle.** `fork.ts` owns at most one `hardhat node` child process. Tools that need fork state (`simulate_vote`) start it lazily; `server.onclose` kills it. No persistent state between tool calls beyond the running fork.
99
- - **Shell-out safety.** All child_process calls use `execa` with `cwd: DEXE_PROTOCOL_PATH`, fixed arg arrays (no shell interpolation), 10-minute timeout, and `maxBuffer` protection.
100
- - **Config.** `config.ts` reads `DEXE_PROTOCOL_PATH` (required), `DEXE_RPC_URL` (optional; needed for gov state / simulate), `DEXE_FORK_BLOCK` (optional). Fails fast on startup with a clear error if `DEXE_PROTOCOL_PATH` is missing or not a Hardhat project (no `hardhat.config.js`).
101
- - **Logging.** Per MCP convention, **all logs to stderr** (stdout is the protocol channel). Use `console.error` or a thin `pino` stderr stream.
102
-
103
- ## Verification
104
-
105
- 1. **Unit tests** (`vitest`): each tool handler tested against a tiny fixture Hardhat project committed under `test/fixtures/`. Covers ABI loading, selector index, calldata decoding (including nested proposal executors), stdout parsing for compile/test.
106
- 2. **Smoke against the real repo.** With `DEXE_PROTOCOL_PATH=D:\dev\DeXe-Protocol` set, run the server under the official MCP Inspector: `npx @modelcontextprotocol/inspector node dist/index.js`. Manually exercise:
107
- - `dexe_compile` → expect clean build
108
- - `dexe_test { grep: "GovPool" }` → expect real pass/fail summary
109
- - `dexe_list_contracts { filter: "Gov" }` → expect `GovPool`, `GovSettings`, etc.
110
- - `dexe_get_abi { contract: "GovPool" }`
111
- - `dexe_find_selector { selector: "<known GovPool selector>" }`
112
- - `dexe_decode_calldata` against a captured real-world proposal createProposal calldata
113
- 3. **End-to-end in Claude Code.** Add to `.mcp.json`:
114
- ```json
115
- {
116
- "mcpServers": {
117
- "dexe": {
118
- "command": "node",
119
- "args": ["D:/dev/dexe-mcp/dist/index.js"],
120
- "env": { "DEXE_PROTOCOL_PATH": "D:/dev/DeXe-Protocol" }
121
- }
122
- }
123
- }
124
- ```
125
- Restart Claude Code, confirm tools appear, ask it "compile the protocol and summarize any warnings" and "decode proposal 42 on GovPool 0x…".
126
- 4. **Fork simulation test** (optional, needs RPC): set `DEXE_RPC_URL` to an Ethereum archive node, run `dexe_simulate_vote` against a real active proposal, verify no orphaned `hardhat node` processes after server shutdown.
127
-
128
- ## Out of Scope (explicit, per user)
129
-
130
- - Deployment / migration tooling (`hardhat-migrate` wrappers, network configs under `deploy/config/configs/`, verification) — deliberately excluded.
131
- - TypeChain codegen orchestration, Go bindings, markup doc generation.
132
- - Remote / HTTP transport, auth, multi-tenant hosting.