Skip to main content
Glama
pyth_mcp_client.pyβ€’2.28 kB
import asyncio import time from fastmcp import Client client = Client("http://localhost:8000/mcp") async def demo_pyth_tools(): async with client: btc_usd_id = "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43" # Example 1: Search for Bitcoin price feeds print("=== Example 1: Search for Bitcoin price feeds ===") result = await client.call_tool("get_price_feeds", { "query": "bitcoin", "asset_type": "crypto" }) # Access the structured_content dictionary from CallToolResult data = result.structured_content price_feeds = data.get("price_feeds", []) print(f"Found {len(price_feeds)} Bitcoin price feeds") print(data) print() # Example 2: Get latest price for BTC/USD print("=== Example 2: Get latest BTC/USD price ===") result = await client.call_tool("get_latest_price_updates", { "ids": [btc_usd_id], "parsed": True }) print(result.structured_content) print() # Example 3: Get historical price at specific timestamp print("=== Example 3: Get historical price at timestamp ===") # Get price from 5 minutes ago five_minutes_ago = int(time.time()) - 300 result = await client.call_tool("get_price_updates_at_time", { "publish_time": five_minutes_ago, "ids": [btc_usd_id], "parsed": True }) print(f"Price at timestamp {five_minutes_ago}:") print(result.structured_content) print() # Example 4: Get publisher stake caps print("=== Example 4: Get publisher stake caps ===") result = await client.call_tool("get_publisher_stake_caps", { "parsed": True }) print(result.structured_content) print() # Example 5: Get TWAP (5-minute time window) print("=== Example 5: Get 5-minute TWAP for BTC/USD ===") result = await client.call_tool("get_twap_latest", { "window_seconds": 300, # 5 minutes "ids": [btc_usd_id], "parsed": True }) print(result.structured_content) asyncio.run(demo_pyth_tools())

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/itsOmSarraf/pyth-network-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server