Fix new market listings by migrating to Gamma API#15
Conversation
- Replace CLOB client's get_markets() with direct Gamma API calls - Add proper async HTTP client for API requests - Update response formatting to match Gamma API structure - Add sorting and filtering options for market listings - Maintain backward compatibility with existing tool interface - Fix issue with fetching new market listings
- Document migration to Gamma API - Update tool schemas with new parameters - Add changelog section - Update example responses to match new format - Add note about historical data limitations
…lymarket-mcp into update-to-gamma-api
- Import main function from server module - Add __all__ export list - Update version to 0.2.0 to match server changes
- Add wrapper function to properly run async main - Import asyncio to handle async execution - Keep both sync main (for entry point) and async_main available
Additional Fix AddedI've also fixed the entry point issue that was causing the server to fail on startup. The error was: Fix AppliedUpdated
The server should now start properly without the import/async errors! |
- Add comprehensive logging throughout the request/response cycle - Log URL, parameters, headers, status codes, and response data - Handle different possible response formats (wrapped in object, etc.) - Add timeout handling and better error messages - Try multiple parameter combinations in list-markets - Add traceback logging for unexpected errors - All debug output goes to stderr for visibility in Claude logs
Enhanced Debugging AddedI've added comprehensive debugging capabilities to help diagnose why the API might not be returning data. The updated code now includes: Debug Features
How to UseAfter pulling this update:
This will help us identify:
Once we identify the issue from the logs, we can make a targeted fix! |
- Override print() to always use stderr - Redirect CLOB client stdout during initialization - Use dummy credentials if not provided to avoid errors - All debug output explicitly goes to stderr - Prevents "Error fetc..." from breaking JSON communication
Critical Fix: Stdout PollutionI found the issue! The error The ProblemMCP servers communicate with Claude via JSON-RPC over stdio. Any non-JSON output to stdout corrupts this communication channel, causing the error you saw: The FixI've updated the code to:
How to Test
The JSON-RPC communication should now work properly, and you'll see the actual debug output in the logs showing what's happening with the API requests! |
- Remove "simple request first" logic that was ignoring user parameters - Use actual user-provided parameters for API calls - Show both numeric ID and conditionId in responses - Update market ID description to clarify numeric ID format - Add fallback to minimal params only if full params fail - Fix formatting to show both IDs for easier reference
Fixed Parameter Handling IssuesBased on the debug logs, I found and fixed two major issues: 1. Parameters Were Being IgnoredThe code was always using Fixed by:
2. Wrong Market ID FormatThe API expects numeric IDs (like Fixed by:
Next TestAfter pulling this update:
Note About the Old DataThe API is returning markets from 2020-2021, which might be:
Once you test with the fixed parameter handling, we'll see if different parameters return newer markets! |
- Reduce timeout to 10 seconds (less than Claude's timeout) - Wrap tool execution in asyncio.wait_for to prevent hanging - Add graceful error messages for timeout scenarios - Better error handling for network issues - Prevent server crashes from unhandled exceptions - Remove verbose debug output that might slow responses
Server Crash Fix AddedThe server crashed due to a timeout issue where Claude's cancellation notification couldn't be handled by the MCP library. This is what happened:
Fix AppliedI've added comprehensive timeout protection:
How It Works Now
After pulling this update, the server should be much more stable and won't crash on timeouts! |
Summary
This PR updates the polymarket-mcp server to use the Gamma API directly instead of the CLOB client's
get_markets()method, which was not returning new market listings properly.Changes Made
1. Server Implementation (
server.py)get_markets()with direct HTTP calls tohttps://gamma-api.polymarket.com/marketshttpxfor better performance2. Entry Point Fix (
__init__.py)3. Documentation (
README.md)Issues Fixed
Server Stability Improvements
The server now handles timeouts gracefully:
Testing Results
The server now:
Known Issues
The Gamma API is currently returning old markets from 2020-2021. This might be:
Debug Output
All debug messages go to stderr with
[DEBUG]prefix, showing:References