Skip to main content
Glama

Polymarket MCP Tool

main.py2.46 kB
from fastmcp import FastMCP import polymarket as poly import json mcp = FastMCP("Polymarket MCP") # type: ignore @mcp.tool async def prediction_markets_trending_topics() -> str: """ Use when analysing a user’s portfolio and you need external sentiment from prediction markets. Retrieves today’s trending Polymarket topics (ordered by 24-hour volume). Pass any slug from this list to `prediction_markets_markets_by_topic` to pull the individual markets for that theme. Returns ------- str A JSON array (string) of topic slugs ordered by 24-hour volume, e.g. '["Trump-Presidency", "Oil-Prices", "Iran"]'. """ return json.dumps(await poly.trending()) @mcp.tool async def prediction_markets_markets_by_topic(topic_slug: str, limit: int = 10) -> str: """ Call after you have a Polymarket topic slug (from the user or `prediction_markets_trending_topics`) and need the top markets under it. Parameters ---------- topic_slug : str Identifier such as "trump-presidency". limit : int, default 10 Number of markets to return, ranked by 24-hour volume (desc). Returns ------- str JSON array of objects with the schema: [ { "title": "Trump to win 2024?", "volume": 123456.78, "outcomes": [ {"option": "Yes", "probability": 0.42}, {"option": "No", "probability": 0.58} ] }, … ] Parse with `json.loads`. """ markets = await poly.markets_by_topic(topic_slug, limit) return json.dumps([m.model_dump() for m in markets]) @mcp.tool async def search_prediction_markets(search_term: str) -> str: """ Search prediction markets by any term. Parameters ---------- search_term : str Identifier such as "argentina". Returns ------- str JSON array of objects with the schema: [ { "title": "Trump to win 2024?", "volume": 123456.78, "outcomes": [ {"option": "Yes", "probability": 0.42}, {"option": "No", "probability": 0.58} ] }, … ] Parse with `json.loads`. """ markets = await poly.search_markets(search_term) return json.dumps([m.model_dump() for m in markets]) if __name__ == "__main__": mcp.run()

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/fernandezpablo85/polymarket-mcp'

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