This document helps agents work effectively with the DFlow MCP Server repository.
This is a Model Context Protocol (MCP) server that provides access to the Prediction Market Metadata API defined in llms_dflow.json. The server implements a complete JSON-RPC interface with 23 tools covering events, markets, trades, forecasts, live data, and analytics.
# Install dependencies
bun install
# Development mode with hot reload
bun run dev
# Start production server
bun start
# TypeScript compilation check
bun run tsc --noEmit
# Build for distribution
bun run build# Run comprehensive server test
./test-server.sh
# Run TypeScript tests
bun run testdflow-mcp/
├── src/
│ └── index.ts # Main MCP server implementation
├── tests/
│ └── server.test.ts # TypeScript test suite
├── .github/workflows/
│ └── test.yml # CI/CD pipeline
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── README.md # User documentation
├── llms_dflow.json # API specification (source of truth)
├── AGENTS.md # This file (agent documentation)
└── test-server.sh # Quick server validation script
- DFlowAPIClient: HTTP client for API communication with timeout handling
- Server Setup: MCP server configuration and initialization
- Tool Definitions: 23 MCP tools mapped from OpenAPI specification
- Request Handling: JSON-RPC request routing and response formatting
- API Client: Handles HTTP requests to
https://api.llm.dflow.org - Tool Registry: Maps OpenAPI endpoints to MCP tools
- Type Safety: TypeScript interfaces for all request/response types
- Error Handling: Comprehensive error catching and MCP-formatted responses
get_event- Single event by tickerget_events- Paginated event list with filteringsearch_events- Search by title/tickerget_live_data_by_event- Live data for event
get_market- Market by tickerget_market_by_mint- Market by mint addressget_markets- Paginated markets with filtersget_markets_batch- Batch market lookup (up to 100)get_market_candlesticks- OHLC data for marketget_market_candlesticks_by_mint- Candlesticks by mint
get_trades- Trades across marketsget_trades_by_mint- Trades for specific marketget_forecast_percentile_history- Forecast analyticsget_forecast_percentile_history_by_mint- Forecast by mint
get_live_data- Live data for milestonesget_live_data_by_mint- Live data by mintget_series- All series templatesget_series_by_ticker- Series by tickerget_event_candlesticks- Event candlesticks
get_outcome_mints- Outcome mint addressesfilter_outcome_mints- Filter addresses to outcome mintsget_tags_by_categories- Category-tag mappingget_filters_by_sports- Sports filtering options
- API URL:
https://api.llm.dflow.org - Timeout: 30 seconds (configurable)
- Transport: MCP stdio (JSON-RPC 2.0)
- All tools accept JSON-RPC requests with validated input schemas
- Responses are formatted as MCP text content with JSON strings
- Errors return formatted error messages with context
- Current API implementation does not require authentication
- If auth is added later, configure in DFlowAPIClient headers
- Define Tool Schema: Add to TOOLS array in server setup
- Implement Handler: Add case in main switch statement
- Map API Endpoint: Use DFlowAPIClient methods
- Validate Parameters: MCP handles schema validation
Example pattern:
{
name: 'new_endpoint',
description: 'Description of the tool',
inputSchema: {
type: 'object',
properties: {
param1: { type: 'string', description: 'Param description' }
},
required: ['param1']
}
}- Use try-catch blocks for API calls
- Format errors as MCP text content with
isError: true - Include context about which tool failed
- Preserve original error messages for debugging
- All tool parameters should be typed in inputSchema
- Use type guards for complex parameter validation
- Maintain consistent naming between API and tools
- Use strict TypeScript settings (configured in tsconfig.json)
- Import statements at top, grouped by type
- Explicit return types for public functions
- Use
constby default,letonly when necessary
- Tool names: snake_case with descriptive names
- Parameters: snake_case matching API specification
- Variables: camelCase for local variables
- Functions: camelCase with descriptive verbs
- Tool descriptions should explain purpose and expected response
- Parameter descriptions should include units and constraints
- Include examples for complex tools in README
# Quick validation
./test-server.sh
# Direct tool testing
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_events","arguments":{}}}' | bun run src/index.ts- Test MCP protocol compliance
- Validate JSON schemas
- Test error handling scenarios
- Verify API endpoint mapping
- Check TypeScript compilation with
bun run tsc --noEmit - Ensure all dependencies installed with
bun install - Verify stdio transport is working (common in CI environments)
- MCP handles schema validation automatically
- Missing required parameters return validation errors
- Invalid types are caught before API calls
- Current API doesn't have documented rate limits
- Monitor response headers for rate limit information
- Implement exponential backoff if needed
- Use
bun run devfor hot reloading during development - Server communicates via stdio, not HTTP server
- Test with actual MCP client (Claude Desktop, Cursor)
- Build with
bun run buildfor optimized bundle - Use
bun startfor production execution - Monitor server startup and connection handling
- GitHub Actions workflow in
.github/workflows/test.yml - Tests compilation and basic server functionality
- Can add integration tests with mock API responses
The API specification in llms_dflow.json is the single source of truth:
- OpenAPI 3.0 format
- Complete with schemas, parameters, and responses
- All tools derived from this specification
- Update tools when API specification changes
- WebSocket support for real-time data
- Caching layer for frequently accessed data
- Pagination helpers for large datasets
- Rate limiting and retry logic
- Authentication token management
- Connection pooling for high-volume usage
- Response compression for large payloads
- Request deduplication for concurrent calls
- Health check endpoints for monitoring
When working with this repository:
- Always test after changes: Run
./test-server.shto validate - Check API specification: Reference
llms_dflow.jsonfor endpoint details - Maintain type safety: Use TypeScript strict mode
- Follow MCP patterns: Standard JSON-RPC 2.0 with stdio transport
- Document new tools: Update README.md and AGENTS.md when adding tools
The server is designed to be a direct, type-safe wrapper around the Prediction Market API with comprehensive MCP protocol support.