This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is an MCP (Model Context Protocol) server that provides access to the Prediction Market Metadata API. The server wraps the REST API defined in llms_dflow.json and exposes it as MCP tools for use with Claude Desktop, Cursor, and other MCP clients.
Base API URL: https://prediction-markets-api.dflow.net
# Start server in development mode with hot reload
bun run dev
# Start server in production mode
bun start
# Build the project
bun run build
# Run tests
bun run testbun run src/index.tsThe entire server implementation is contained in src/index.ts. This is intentional for simplicity - the server is a thin wrapper around the external API.
Key components:
-
DFlowAPIClient (lines 23-85): HTTP client that handles all API communication
- Implements request timeout handling (30s default)
- Constructs URLs with query parameters
- Handles GET and POST requests
- Returns parsed JSON responses
-
TOOLS array (lines 103-696): Complete tool definitions
- Each tool maps to one API endpoint
- Tool definitions include JSON schemas for parameter validation
- Organized by endpoint category (events, markets, trades, forecasts, candlesticks, live data, series, utilities)
-
Request handlers (lines 698-849):
ListToolsRequestSchema: Returns all available toolsCallToolRequestSchema: Routes tool calls to appropriate API endpoints using a large switch statement- Error handling returns descriptive messages
The server exposes 25 tools across 8 categories:
- Events: Get individual events, paginated event lists, search events
- Markets: Get markets by ticker or mint address, batch queries
- Trades: Query trade history with filtering and pagination
- Forecasts: Historical forecast percentile data
- Candlesticks: OHLC data for events and markets
- Live Data: Real-time milestone information
- Series: Series templates and metadata
- Utilities: Outcome mints, filtering, tags, and search
The server uses stdio transport (line 853), which is the standard for MCP servers. This means:
- Communication happens over stdin/stdout
- The server must be launched as a subprocess by the MCP client
- No HTTP server or network configuration needed
- package.json: Dependencies include
@modelcontextprotocol/sdkfor MCP protocol implementation - tsconfig.json: Standard TypeScript config targeting ES2022 with ESNext modules and bundler resolution
- llms_dflow.json: OpenAPI specification for the underlying REST API (not used at runtime, serves as documentation)
- bun.lock: Bun's lockfile (not bun.lockb, this is a text-based lock format)
- .gitignore: Standard Node.js gitignore that excludes node_modules, dist, logs, and environment files
When adding or modifying tools, follow this pattern:
- Add tool definition to
TOOLSarray with name, description, andinputSchema - Add corresponding case to the switch statement in the
CallToolRequestSchemahandler - Use
apiClient.get()orapiClient.post()to make the API request - Extract path parameters from args and pass remaining args as query params or request body
Example:
// Tool definition
{
name: 'get_event',
description: 'Get a single event by ticker',
inputSchema: {
type: 'object',
properties: {
event_id: { type: 'string', description: 'Event ticker' },
withNestedMarkets: { type: 'boolean', description: 'Include nested markets' }
},
required: ['event_id']
}
}
// Handler implementation
case 'get_event':
result = await apiClient.get(`/api/v1/event/${args.event_id}`, {
withNestedMarkets: args.withNestedMarkets,
});
break;To test the server manually with MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"dflow-mcp": {
"command": "bun",
"args": ["run", "/absolute/path/to/dflow-mcp/src/index.ts"]
}
}
}- Runtime: Designed for Bun but compatible with Node.js 18+
- MCP SDK Version:
@modelcontextprotocol/sdk^0.5.0 - Request Timeout: 30 seconds (configurable via
DEFAULT_TIMEOUT) - Error Handling: HTTP errors and timeouts are caught and returned as MCP error responses
- JSON Serialization: Handles BigInt values by converting to strings