Skip to main content
Glama

search_prediction_markets

Search Polymarket prediction markets by keyword to retrieve detailed market data, including titles, trading volumes, and outcome probabilities in JSON format.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
search_termYes

Implementation Reference

  • main.py:62-91 (handler)
    Handler function for the 'search_prediction_markets' tool, decorated with @mcp.tool for registration. Calls the helper in polymarket.py and returns JSON serialized 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])
  • Pydantic models defining the output schema for markets and outcomes used by the tool.
    class MarketOutcome(BaseModel): option: str probability: float class Markets(BaseModel): title: str volume: float outcomes: list[MarketOutcome]
  • Core helper function that performs the API search on Polymarket, parses events into Markets models, and returns the list of active markets.
    async def search_markets(search_term: str) -> list[Markets]: url = f"https://polymarket.com/api/events/search?_c=all&_q={search_term}&_p=1&active=true&archived=false&closed=false" events = requests.get(url, timeout=15).json()["events"] markets: list[Markets] = [] for event in events: if event.get("archived", True) or event.get("closed", True): continue if not event.get("active", False): continue if len(event["markets"]) == 1: outcomes = [ MarketOutcome( option=outcome, probability=float(price), ) for outcome, price in zip( event["markets"][0]["outcomes"], event["markets"][0]["outcomePrices"], ) ] else: outcomes: list[MarketOutcome] = [] for market in event["markets"]: outcomes.append( MarketOutcome( option=market["groupItemTitle"], probability=float(market["outcomePrices"][0]), ) ) markets.append( Markets( title=event["title"], volume=float(event["volume"]), outcomes=outcomes, ) ) return markets

Other Tools

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

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