Skip to content

feat: per-request network override + 12 clause-builder intent tools#128

Draft
davidecarpini wants to merge 10 commits into
mainfrom
feat/per-request-network-and-clause-builders
Draft

feat: per-request network override + 12 clause-builder intent tools#128
davidecarpini wants to merge 10 commits into
mainfrom
feat/per-request-network-and-clause-builders

Conversation

@davidecarpini
Copy link
Copy Markdown
Member

Summary

Make the MCP server per-request network aware and add 12 new build*Clauses intent tools so external agent loops (e.g. veworld-b3mo-backend) can stop carrying ABIs and clause encoding locally and delegate everything to this server.

This is a breaking change (bumped to 2.0.0-alpha.0):

  • every tool input shape now exposes an optional network field
  • new public tool surface: getStargateLevels, resolveVnsName, resolveToken, getCuratedStargateValidators, plus 12 build*Clauses tools

Per-request network awareness (Fase 1)

  • services/thor/request-context.tsrunWithRequestNetwork + getRequestNetwork backed by AsyncLocalStorage
  • services/thor/config.ts — replaces the singleton ThorClient with a Map<ThorNetworkType, ThorClient> cache; getThorClient / getThorNetworkType / getThorNodeUrl now resolve in order: explicit override → request context → env default
  • server.ts — every registered tool gets network injected into its input shape and runs inside runWithRequestNetwork(network), so existing tools keep working with the env default while clients that pass network get a per-request override (no leak across concurrent requests, see parity tests)

Registry primitives (Fase 2)

  • contracts-registry/addresses.ts — add vechainSwapRouter, wvet, vtho for mainnet/testnet
  • contracts-registry/abis.ts — add UNISWAP_V2_ROUTER_ABI
  • contracts-registry/index.ts — new swap category, three new entries (vechainSwapRouter, wvet, vtho)
  • new services/stargate-levels/STARGATE_LEVELS + findStargateLevelById/ByTier/ByVet + resolveStargateLevel
  • new tools: getStargateLevels, resolveVnsName, resolveToken

Curated read tool (Fase 3)

  • getCuratedStargateValidators — wraps getValidators, applies the offline% filter and sorts by nftYieldsIfDelegatedNextCycle[tier]

Clause builders (Fase 4)

New services/clause-builder/ shared module (types, units, encoders, on-chain reads, token resolution) + 12 new MCP tools, all with annotations.destructiveHint: true and readOnlyHint: false so downstream agents can route them onto an exec_clauses event:

  • buildSendTokenClauses, buildSwapClauses
  • buildStargateStakeAndDelegateClauses, buildStargateDelegateClauses, buildStargateUndelegateClauses, buildStargateClaimRewardsClauses
  • buildB3trConvertToVot3Clauses, buildB3trConvertToB3trClauses, buildB3trCastAllocationVotesClauses, buildB3trClaimVoterRewardsClauses, buildB3trCastProposalVoteClauses, buildB3trDelegateVot3Clauses

Each tool returns the canonical { ok, network, data: { clauses, summary, gasHint }, error? } shape. The server NEVER signs or broadcasts.

Parity tests

tests/clause-parity/clause-parity.unit.test.ts — 27 unit tests asserting byte-equal parity with the legacy veworld-b3mo-backend/src/services/clauseBuilder/* output (transfer/approve selectors, exact stake amounts, allowance-conditional approve, tier-vs-amount validation, X-tier rejection, etc.).

Test plan

  • npx tsup builds clean
  • npx jest tests/clause-parity/ — 27/27 green
  • Smoke test against a running MCP: tools/list returns the new tools and the network field appears in every input schema
  • Smoke test: call buildSendTokenClauses with network: "testnet" and verify the recipient/value/data match a known fixture
  • Smoke test: parallel calls with different network overrides do not leak the Thor client (mainnet/testnet caches stay independent)
  • Verify downstream veworld-b3mo-backend agent loop works against this branch end-to-end

davidecarpini and others added 10 commits May 12, 2026 23:03
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…dd category filter

- Extract VeBetterDAO addresses and IPFS gateway URL into src/constants
- Split ABIs into src/services/abis (ERC20, ERC721 Enumerable, X-Allocation-Voting, X2EarnApps)
- Move fetchJson and mapWithConcurrency into src/utils
- Replace viem encode/decode and raw fetch with VeChain SDK Contract + executeMultipleClausesCall
- Add categories filter to getVeBetterDaoApps (IPFS-backed, case-insensitive, OR semantics)
- Add .cursor/rules/code-organization.mdc documenting src/ folder conventions

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…rDaoApps

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Introduces a central registry covering VeBetterDAO, Stargate and standard
ERC20/721 contracts, plus four MCP tools to discover, inspect and interact
with them: listKnownContracts, getContractAbi, callContract (multicall
reads) and buildContractTransaction (multi-clause tx for wallet signing).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…cts-registry

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…apps-tool

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	src/constants/index.ts
#	src/services/vebetterdao-contracts.ts
#	src/tools/get-gm-nft-status.ts
#	src/tools/index.ts
The file was reintroduced by the merge with origin/main, but it is
dead code: all consumers were migrated to `contracts-registry` in
cffb561. Restoring the post-refactor state.

Co-authored-by: Cursor <cursoragent@cursor.com>
Drop the @vechain/stargate-contracts-artifacts dependency in favor of
four hand-vendored JSON files under src/services/contracts-registry/
stargate/. The upstream package buries the V4 contracts under
deprecated/ and ships a broken ESM dist on Node 22, so vendoring just
the abi[] is the cleanest path until they publish a flat artifacts
layout. Shrinks the prod bundle from 2.19 MB to 414 KB (the package
included bytecode + metadata we don't need) and removes the stargate
entry from tsup `noExternal`.

Co-authored-by: Cursor <cursoragent@cursor.com>
Make the server per-request network aware via AsyncLocalStorage so a single
process can serve mainnet, testnet and solo at the same time, and add the
12 build*Clauses intent tools that own the previously backend-side clause
encoding for token transfers, swaps, Stargate staking/delegation/rewards,
and VeBetterDAO governance.

- thor/config.ts: per-network ThorClient cache; getThorClient/Network/Url
  resolve from explicit override > request context > env default
- thor/request-context.ts: AsyncLocalStorage with runWithRequestNetwork
- server.ts: every registered tool gets `network` injected into its input
  shape and runs inside runWithRequestNetwork so env-default callers are
  unaffected and clients that pass `network` get a live override
- contracts-registry: add vechainSwapRouter, wvet, vtho addresses and
  UNISWAP_V2_ROUTER_ABI; new "swap" category
- new services/stargate-levels: STARGATE_LEVELS + resolveStargateLevel
- new clause-builder service: types, units, encoders, onchain-reads,
  token-resolution shared by every build*Clauses tool
- new tools: getStargateLevels, resolveVnsName, resolveToken,
  getCuratedStargateValidators, plus the 12 build*Clauses tools (all
  destructiveHint=true so the agent loop routes them to the SSE
  exec_clauses event)
- tests/clause-parity: 27 unit tests asserting byte-equal parity with
  the legacy veworld-b3mo-backend clauseBuilder/* output
- bump version to 2.0.0-alpha.0 (breaking: tool input shapes now expose
  `network`, intent tools are new public surface)
Comment thread package-lock.json
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 Open source vulnerabilities detected - critical severity
Aikido detected 8 vulnerabilities across 4 packages, it includes 1 critical and 7 high vulnerabilities.

Details

Remediation Aikido suggests bumping the vulnerable packages to a safe version.

Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant