"""
Get current token prices across supported blockchain networks.
"""
import json
from typing import List, Optional, Union
from mcp import types
from pydantic import BaseModel
from ...helpers import make_odos_request, resolve_chain_id
from ...mcp import mcp
class GetChainTokenPricesArgs(BaseModel):
"""Arguments for getting chain token prices"""
chain_id: Union[str, int]
token_addresses: Optional[List[str]] = []
currencyId: Optional[str] = None
@mcp.tool(
name="get_chain_token_prices",
description=(
"Get all of the whitelisted token prices on an Odos supported chain, "
"or specific tokens if list is provided"
),
)
async def get_chain_token_prices(
args: GetChainTokenPricesArgs,
) -> list[types.TextContent]:
"""
Gets token prices for all whitelisted tokens on a chain,
or specific tokens if addresses provided.
"""
try:
chain_id = resolve_chain_id(args.chain_id)
# Build URL with path parameters
url = f"/pricing/token/{chain_id}"
# Add query parameters
params = {}
if args.token_addresses:
params["token_addresses"] = args.token_addresses
if args.currencyId:
params["currencyId"] = [args.currencyId]
response_data = await make_odos_request(url, method="GET", params=params)
output = {
"message": "Successfully fetched chain token prices.",
"chainId": chain_id,
"currencyId": response_data.get("currencyId"),
"tokenPrices": response_data.get("tokenPrices", {}),
"tokenCount": len(response_data.get("tokenPrices", {})),
}
return [types.TextContent(type="text", text=json.dumps(output, indent=2))]
except ConnectionError as e:
return [
types.TextContent(
type="text", text=f"❌ API Error in get_chain_token_prices: {str(e)}"
)
]
except (ValueError, KeyError, TypeError) as e:
return [
types.TextContent(
type="text",
text=f"❌ Unexpected Error in get_chain_token_prices: {str(e)}",
)
]