add_forecast
Submit a numerical forecast to a specific question on Fatebook to track predictions. Enables AI assistants and users to input and manage probability estimates for better decision-making.
Instructions
Add a forecast to a Fatebook question
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | No | ||
| forecast | Yes | ||
| optionId | No | ||
| questionId | Yes |
Implementation Reference
- main.py:269-304 (handler)Primary handler implementation for the 'add_forecast' MCP tool. Decorated with @mcp.tool() for automatic registration. Handles input validation, API key management, calls Fatebook's addForecast endpoint, and provides detailed error logging via ctx.error.@mcp.tool() async def add_forecast( ctx: Context, questionId: str, forecast: float, apiKey: str = "", optionId: str = "" ) -> bool: """Add a forecast to a Fatebook question""" api_key = apiKey or os.getenv("FATEBOOK_API_KEY") if not api_key: await ctx.error("API key is required but not provided") raise ValueError( "API key is required (provide as parameter or set FATEBOOK_API_KEY environment variable)" ) # Validate forecast parameter if not 0 <= forecast <= 1: await ctx.error(f"Invalid forecast parameter: {forecast}") raise ValueError("forecast must be between 0 and 1") data = {"questionId": questionId, "forecast": forecast, "apiKey": api_key} # Add optional parameter for multi-choice questions if optionId: data["optionId"] = optionId try: async with httpx.AsyncClient() as client: response = await client.post("https://fatebook.io/api/v0/addForecast", json=data) response.raise_for_status() return True except httpx.HTTPError as e: await ctx.error(f"HTTP error occurred: {e}") raise except Exception as e: await ctx.error(f"Unexpected error occurred: {e}") raise
- src/fatebook_mcp/__main__.py:253-284 (handler)Alternative or package handler implementation for 'add_forecast' tool using standard mcp.tool() decorator. Similar logic to main.py version but without Context parameter and ctx.error logging.@mcp.tool() async def add_forecast( questionId: str, forecast: float, apiKey: str = "", optionId: str = "" ) -> bool: """Add a forecast to a Fatebook question""" api_key = apiKey or os.getenv("FATEBOOK_API_KEY") if not api_key: raise ValueError( "API key is required (provide as parameter or set FATEBOOK_API_KEY environment variable)" ) # Validate forecast parameter if not 0 <= forecast <= 1: raise ValueError("forecast must be between 0 and 1") data = {"questionId": questionId, "forecast": forecast, "apiKey": api_key} # Add optional parameter for multi-choice questions if optionId: data["optionId"] = optionId try: async with httpx.AsyncClient() as client: response = await client.post("https://fatebook.io/api/v0/addForecast", json=data) response.raise_for_status() return True except httpx.HTTPError: raise except Exception: raise
- src/fatebook_mcp/models.py:32-52 (schema)Pydantic model for Forecast objects, defining structure relevant to forecasts including validation for forecast value (0-1) matching add_forecast input validation.class Forecast(BaseModel): """Forecast made on a question""" id: Optional[Union[str, int]] = None forecast: float = Field(ge=0, le=1, description="Forecast value between 0 and 1") user: User created_at: Optional[datetime] = Field(None, alias="createdAt") option_id: Optional[Union[str, int]] = Field( None, alias="optionId", description="For multi-choice questions" ) @field_validator("id", "option_id") @classmethod def convert_id_to_string(cls, v): """Convert integer IDs to strings""" return str(v) if v is not None else v class Config: populate_by_name = True by_alias = True # Use aliases when serializing