streamable-httpupdated 8d ago
The composition authority + read API for Spiral Stake strategy data. It ports the app's client-side data composition server-side and serves it back as JSON, so three consumers run off one core:
What can you do with leverage?
Spiral Stake β mcp read-data backbone (Step 1a)
The composition authority + read API for Spiral Stake strategy data. It ports the app's client-side data composition server-side and serves it back as JSON, so three consumers run off one core:
- The app β the complete read surface it currently fetches, for a like-for-like Step-2 swap.
- Agents β the frozen
/strategiescontract. - Partners (later) β a clean, versioned, self-documenting REST surface (OpenAPI).
Read-only. No contract writes, no tx building, no signing, no private keys. It composes
numbers and serves JSON. The MCP tool layer, execution/build_*, and partner auth are later
steps β the seams are pre-cut (core + http) but not built.
Architecture
src/
core/ pure composition β no I/O, unit-testable
leverage.ts β VERBATIM copy of v2-client/src/utils/leverage.ts (byte-diff gated)
apy.ts collateral-APY resolution (Pendle/DeFiLlama/Royco/StableWatch/on-chain)
leverageApy.ts 30/60/90d leveraged-APY windows + lumpy-token smoothing
compose.ts Market assembly from warm raw (port of FlashLeverage.createInstance)
strategy.ts Market β frozen /strategies contract (ladder, freshness, spiralHints)
exitLiquidity.ts exit-liquidity tier (the single verdict) + thresholds
sources/ one adapter per upstream (fetch + parse). native fetch + viem; no axios/wagmi
cache/ two-layer cache β RAW store (last-good) + warming policy (CONTRACT cadences)
warmer/ background scheduler (stale-while-revalidate); reads NEVER fetch
http/ thin hono REST layer (the only thing that knows about requests)
data/ static market config (copied from the app) + readMarkets port
config/ env (validated) + structured logger with correlation ids
Data flow: warmer fetches upstreams on the CONTRACT cadence β writes raw to the cache
(last-good on failure) β core composes strategies from warm raw only β http serves them.
A stale/failed upstream serves last-good with a visible stale age per field-group β never
dropped, never coerced to 0.
Run
cp .env.example .env # fill in RPC + API keys (secrets via env only)
npm install
npm run dev # tsx watch; serves on :$PORT (default 8787)
npm test # golden + parity gates
npm run typecheck # tsc --noEmit
npm run openapi # (re)emit openapi.json
node --import tsx scripts/smoke.ts # live: prime + print one composed strategy
/health (liveness + cache diagnostics) and /ready (503 until the warmer primes the required
data) are available immediately on boot.
Endpoints β app-read inventory β endpoint mapping
Every data read the app performs in v2-client/src/api-services/* maps to an endpoint here
(positions stay on the dashboard backend and are not reimplemented):
App read (api-services/*) |
mcp endpoint |
|---|---|
getTokenApy, getAllMorphoMarketsData, fetchMerklSpotIncentives, prices, on-chain value β composed markets |
GET /v1/strategies, GET /v1/strategies/:id |
FlashLeverage.createInstance β the app's full client-side Market[] composition |
GET /v1/app/markets (raw domain model; BigNumberβ{"$bn":β¦}, bigintβ{"$bigint":β¦} β revive before use) |
morpho.ts getAllBorrowApyHistories / getBorrowApyHistory |
GET /v1/markets/borrow-apy-history, GET /v1/markets/:id/borrow-apy-history |
apy.ts resolveTokenApyHistory (DeFiLlama/Royco/StableWatch history), chart.ts getApyChart |
GET /v1/collateral/apy-history, GET /v1/collateral/:id/apy-history |
merkl.ts fetchMerklIncentiveData (borrow-incentive APR history) |
GET /v1/markets/:id/incentive-history |
token.ts getAllLoanTokenPrices / getTokenPrice |
GET /v1/prices |
chart.ts getMarketChart (CoinGecko price chart) |
GET /v1/prices/chart?coinId=&days=¤cy= (on-demand proxy) |
dashboard.ts getApySnapshot (StableWatch stable APY) |
GET /v1/stable-apy β fetched directly from StableWatch as a warmed upstream; the mcp owns this data now and no longer depends on the dashboard /apy endpoint |
| swap/meta-dex aggregators, referral, positions | out of scope (execution / backend domains) |
Cross-cutting: /v1 versioning, CORS limited to CORS_ORIGINS, a consistent error envelope
({ error: { code, message, correlationId } }), a correlation id per request (echoed as
x-correlation-id), structured JSON logs, and an OpenAPI 3.1 spec at /openapi.json (+ committed
openapi.json).
Parity gates
leverage.tsgolden-vector βtest/golden/leverage.golden.test.tsfreezes fixed inputs β exact outputs;leverage.parity.test.tsasserts the file is a byte-for-byte copy of the app'sleverage.ts. This locks every APY/LTV/ladder number to the app./strategiescomposition βtest/parity/strategies.compose.test.tsseeds the raw cache with a controlled fixture and asserts the composed contract field-by-field (sourcing, LTV math, ladder via the verbatimleverage.ts, freshness cadences,null-vs-absent,spiralHintsisolation). Runs offline in CI.- Live golden-set + app-surface parity β
scripts/capture-parity.tsprimes the warmer against real upstreams and writes the composed/strategies(+ apy/borrow histories) for a fixed market set totest/fixtures/. The parity diff vs the app is produced by feeding the same fixed inputs to the app's client-side composition and comparing (the app logs its composed markets); the PR commits the fixtures and the empty diff. This is the gate that lets us offload TVL safely.
Frozen decisions (parity-critical)
bignumber.jspinned to the app's9.3.1; no globalBigNumber.configchange βtoFixed(2)/ rounding (ROUND_HALF_UP) identical.- On-chain reads via viem replace wagmi:
getCollateralValueInLoanToken(multicall3), stUSDSstr(), spUSDGvsr()(chain 4663). The app's (intentionally lossy)BigInt(liqLtv)from the JSON number is matched exactly, not "fixed". maxLeverage = calcLeverage(maxLtv);defaultLeverage = calcLeverage(safeLtv),safeLtv = maxLtv% β 0.75β exactly as the app derives them. Ladder = integer steps1x β¦ βmaxLeverageβ(LTV=(1 β 1/lev)Β·100) then the exactmax.- Exit slippage is baked into
collateralTokens.jsonby the app's weekly refresh script; its file mtime is theexitLiquidity.asOf. The tier (the only verdict) lives inspiralHintswith its thresholds; rawslippagePctstays underexitLiquidity,null(no route) preserved.
Install
Add leverage to your client. Pick the one you use.
claude mcp add --transport http leverage https://api.spiralstake.xyz/mcpcodex mcp add leverage --url https://api.spiralstake.xyz/mcp{
"mcpServers": {
"leverage": {
"url": "https://api.spiralstake.xyz/mcp"
}
}
}Add to `~/.cursor/mcp.json`, or `.cursor/mcp.json` for a single project.
{
"servers": {
"leverage": {
"type": "http",
"url": "https://api.spiralstake.xyz/mcp"
}
}
}Add to `.vscode/mcp.json` in your workspace.
{
"mcpServers": {
"leverage": {
"url": "https://api.spiralstake.xyz/mcp"
}
}
}Add to `claude_desktop_config.json`, then restart Claude Desktop.
{
"mcpServers": {
"leverage": {
"serverUrl": "https://api.spiralstake.xyz/mcp"
}
}
}Add to `~/.codeium/windsurf/mcp_config.json`.
Score
39 / 100
Incomplete
- Documentation25/25
- Maintenance19/25
- Trust6/20
- Capability0/15
- Install experience12/15
- Documents what it does and how to connect
- Has a resolvable package or endpoint
- Exposes at least one tool, prompt or resource
- README has substantive content
- Includes a code example
- Documents its configuration
- Mentions credentials or security posture
- Last commit 1 days ago
- Has a release history
- Repository is not archived
- No licence detected
- Namespace verified in the official MCP registry
- Claimed by its owner
- Published under an organisation
- 0 tool(s) documented
- Provides prompt templates
- Provides resources
- 6 documented install method(s)
- Published to a package registry
- Offers a hosted endpoint β no local install
Version history
| Versions | Published |
|---|---|
| 0.1.1Latest | Jul 15, 2026 |
| 0.1.0 | Jul 15, 2026 |