Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,12 @@ When multiple venues quote the same pair, their prices naturally diverge due to
| `paid_call` | Fetches an x402-gated URL and handles the `402 → sign → retry` loop. | **Yes — it signs with a real Stellar key** |
| `payment_budget` | Reports the configured limits and what is left of today's budget. | No |
| `lens_get_price` | Reads Lens's own aggregated price for a watched pair. | No |
| `lens_quote` | What one order of a size the caller names would cost: the best route, the order-book depth and the price-impact ladder, in one answer. | No |
| `lens_list_pairs` | Lists the pairs watched on one network, one bounded page at a time, each with its latest price and the issuer of both assets in full. | No |
| `lens_get_pools` | Lists AMM pools with their newest reserves, spot price and fee — how much liquidity stands behind a pair. | No |
| `lens_screen_pairs` | Ranks watched pairs by volume, 24h change, price or liquidity, with the same filters as `GET /screener`. | No |

`payment_budget` appears whenever a spend budget is configured, which the example always sets, and `lens_get_price` only where the server can reach Lens's own price data. The three data tools follow the same rule: they are advertised only where the host supplies Lens's data, and each one runs the very function its REST route runs, so a page over MCP is the same rows and cursor as a page over HTTP. Every one of them is served over **either** transport, and the tool list, schemas and error codes are identical whichever you pick. Which transport runs is selected by configuration; **stdio is the default**, so an existing setup needs no changes.
`payment_budget` appears whenever a spend budget is configured, which the example always sets, and `lens_get_price` only where the server can reach Lens's own price data. The three data tools follow the same rule: they are advertised only where the host supplies Lens's data, and each one runs the very function its REST route runs, so a page over MCP is the same rows and cursor as a page over HTTP. `lens_quote` follows it on the pricing side: it is advertised only where the host can read Lens's markets, and its three legs are the very calls `GET /price/:assetA/:assetB/route`, `GET /price/:assetA/:assetB/depth` and `GET /impact/:assetA/:assetB` make, so one quote over MCP is the same route, depth and impact the three HTTP requests return — at the order size the caller names instead of a fixed 1000. A leg that cannot price the order arrives as a qualified part of the answer (`depth.status: "unavailable"` with its reason, or `impact: null`), never as a zero and never as a failed call; only a read that outright fails answers `ERR_SERVICE_UNREACHABLE`, which means retry. Every one of them is served over **either** transport, and the tool list, schemas and error codes are identical whichever you pick. Which transport runs is selected by configuration; **stdio is the default**, so an existing setup needs no changes.

**⚠️ Warning:** the mainnet key signs with real XLM. Read the configuration,
spending warning, and worked example before running.
Expand Down
5 changes: 4 additions & 1 deletion docs/mcp-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ The Lens MCP server (`src/mcp/server.ts`) offers an agent two kinds of thing:

- **Tools** — functions it calls to *do* something: `bazaar_search`,
`paid_call`, `lens_get_price`, and where Lens's own data is reachable the
three data tools `lens_list_pairs`, `lens_get_pools` and `lens_screen_pairs`.
data tools `lens_list_pairs`, `lens_get_pools`, `lens_screen_pairs` and
`lens_quote` — one order size in, and the route, the depth ladder and the
price-impact ladder out, which is what an agent needs to ask "what would
*my* trade cost" in a single call.
- **Resources** — read-only content it attaches to its context once, instead of
re-fetching by calling a tool every turn.

Expand Down
5 changes: 4 additions & 1 deletion src/mcp/priceTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ const VALID_NETWORKS: readonly NetworkName[] = ['testnet', 'mainnet']
* issuer. Codes are matched case-sensitively because that is how Stellar stores
* them — "usdc" and "USDC" are different strings on the ledger — so a lowercase
* code is refused rather than quietly folded.
*
* Exported because every Lens market tool declares the same asset grammar in its
* input schema; a second copy of the pattern is a second thing to keep in sync.
*/
const ASSET_PATTERN = '^(?:native|[A-Z][A-Z0-9]{0,11}(?::G[A-Z2-7]{55})?)$'
export const ASSET_PATTERN = '^(?:native|[A-Z][A-Z0-9]{0,11}(?::G[A-Z2-7]{55})?)$'
const ASSET_RE = new RegExp(ASSET_PATTERN)
const ISSUER_RE = /^G[A-Z2-7]{55}$/

Expand Down
48 changes: 48 additions & 0 deletions src/mcp/quoteQueries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { getBestRoute } from '../aggregator/bestRoute'
import { getDepth, getImpact } from '../pricing/depth'
import { activeNetwork, getNetworkConfig } from '../config'
import type { NetworkName } from '../config'
import type { LensQuoteQueries } from './quoteTool.js'

/**
* The data layer behind `lens_quote` (#685), built from the three functions the
* REST routes call: `getBestRoute` serves `GET /price/:a/:b/route`, `getDepth`
* serves `GET /price/:a/:b/depth` and `getImpact` serves `GET /impact/:a/:b`.
* Asking through MCP is therefore a different transport, not a different answer.
*
* It lives here rather than in `quoteTool.ts` so the tool logic stays testable
* with a stub and a stdio server that does not serve Lens's own markets never
* imports `pg` — the same split {@link createLensPriceQueries} makes.
*/
export function createLensQuoteQueries(): LensQuoteQueries {
return {
activeNetwork,

// The declared pair list for that network — the exact list REST's `findPair`
// searches — with issuers intact. Not the process-wide live registry: a pair
// REST cannot resolve, this tool must not quietly price.
watchedPairs(network: NetworkName) {
return getNetworkConfig(network).pairs
},

// Argument order matches the route: the pair's own asset objects, its pair
// key, the caller's order size, then the network.
route(assetA, assetB, pairKey, amount, network) {
return getBestRoute(assetA, assetB, pairKey, amount, network)
},

// `getDepth` takes the network first and needs the fee reader's Horizon URL,
// read from the same network's config the route reads it from.
depth(network: NetworkName, pairKey: string, amount: number) {
return getDepth(network, pairKey, amount, {
horizonUrl: getNetworkConfig(network).horizon.url,
})
},

// The thresholds and liquidity fraction come from the tool, which is where
// they are documented — this layer only passes them down.
impact(pairKey, network, thresholds, liquidityFraction) {
return getImpact(pairKey, { thresholds: [...thresholds], liquidityFraction }, network)
},
}
}
Loading
Loading