Skip to content

fix: resolve FastAPI/MCP dependency conflict (anyio version incompatibility)#5

Open
vicmuchina wants to merge 8 commits intocaiovicentino:mainfrom
vicmuchina:fix/dependency-conflict-fastapi-anyio
Open

fix: resolve FastAPI/MCP dependency conflict (anyio version incompatibility)#5
vicmuchina wants to merge 8 commits intocaiovicentino:mainfrom
vicmuchina:fix/dependency-conflict-fastapi-anyio

Conversation

@vicmuchina
Copy link

@vicmuchina vicmuchina commented Jan 1, 2026

This PR has been updated with comprehensive installation and OpenCode integration fixes.

New Additions

Files Added

  • run_with_env.sh - Helper script for proper environment setup
  • run_opencode_mcp.py - Isolated MCP server runner for OpenCode
  • test_server_init.py - Server initialization test script
  • COMPLETE_INSTALLATION_GUIDE.md - Comprehensive installation guide with all issues and solutions
  • INSTALLATION_COMPLETE.md - Quick reference guide

Issues Resolved

  1. ✅ FastAPI/MCP dependency conflict (anyio version incompatibility)
  2. ✅ typing_extensions system package conflict
  3. ✅ Python path priority issues
  4. ✅ OpenCode integration issues
  5. ✅ Installation timeout issues

Key Points

  • Always use Python 3.12.3 (not 3.13.5 or system Python)
  • Always use the helper script run_with_env.sh
  • typing_extensions must be 4.12.2+
  • PYTHONPATH must prioritize virtualenv
  • OpenCode config must use helper script

See COMPLETE_INSTALLATION_GUIDE.md for detailed installation instructions and troubleshooting.

CRITICAL FIX: Market discovery tools were returning historical data (2020-2021)
instead of current data (2024-2027).

Problem:
- Gamma API was missing the closed=false parameter
- Without it, API returns ALL markets including closed/historical ones

Solution:
Add closed=false parameter to all market discovery Gamma API calls:
- search_markets()
- get_trending_markets()
- filter_markets_by_category()
- get_closing_soon_markets()
- get_sports_markets()
- get_crypto_markets()

Additional fixes:
- Fixed timezone comparison in get_closing_soon_markets()
- Fixed event_markets to handle different response formats

Test Results:
Without closed=false: Returns markets from 2020-2021 (historical)
With closed=false: Returns markets from 2024-2027 (current)

Verification:
python3 test_gamma_closed_parameter.py

Impact:
- Minimal change: Only adds closed=false to API parameters
- Maintains original architecture
- Gamma API is NOT deprecated
- No breaking changes
- All 8 market discovery tools now return current data
This test confirms the fix is working:
- Without closed=false: Returns historical data (2020-2021)
- With closed=false: Returns current data (2024-2027)

All 8 market discovery tools now return current market data.
Fixes:
1. Pin pydantic to 2.9.2 (compatible with mcp 1.20+)
2. Update mcp to >=1.20.0
3. Add typing-extensions dependency
4. Update pydantic-settings to >=2.3.0
5. Create run-polymarket-mcp.sh startup script

Root cause:
- pydantic 2.11.7 changed internal structure, AnyUrl not in main namespace
- mcp 1.11.0 requires specific pydantic version
- typing-extensions system version conflicts with pydantic 2.11+

This fixes the ImportError and provides proper startup script.
This document provides:
- Summary of the fix
- Code changes made
- Test results
- Dependencies information
- How to run the server
- Architecture overview
…bility)

Fixes critical installation failure caused by incompatible anyio version
requirements between fastapi and MCP packages.

## Problem
Package installation failed with:
```
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
- fastapi 0.104.0 depends on anyio<4.0.0 and >=3.7.1
- mcp 1.25.0 depends on anyio>=4.5
```

These two dependencies have incompatible anyio version requirements, making
the package impossible to install.

## Solution
Updated pyproject.toml dependencies to resolve the conflict:
- fastapi: >=0.104.0 → >=0.109.0 (compatible with anyio>=4.5)
- pydantic: >=2.9.0,<2.10.0 → >=2.9.0 (removed upper bound)

FastAPI 0.109+ dropped the anyio<4.0.0 constraint and is compatible with
anyio>=4.5, satisfying MCP's requirements.

## Tested
✓ Clean virtual environment installation successful
✓ Package imports correctly: `import polymarket_mcp`
✓ All dependencies resolve without conflicts

Breaking change: None - only updated minimum version requirements
- Add COMPLETE_INSTALLATION_GUIDE.md with all issues and solutions
- Add run_with_env.sh helper script for proper PYTHONPATH management
- Add run_opencode_mcp.py for OpenCode integration
- Add test_server_init.py for server initialization testing
- Add INSTALLATION_COMPLETE.md for quick reference
- Document typing_extensions compatibility issues and solutions
- Document Python version requirements (3.12.3)
- Document OpenCode integration steps
- Provide troubleshooting guide
…shooting

- Add critical installation issues and solutions section
- Document typing_extensions system package conflict
- Document Python path priority issues
- Document OpenCode integration steps
- Add complete 7-step installation procedure
- Add quick start commands
- Add critical points to avoid common issues
- Add troubleshooting section
- Add best practices
- Link to comprehensive installation guide
- Add install-fixed-version.sh for pinned dependency installation
- Add install-with-conda.sh for Conda environment setup
- Add install-with-micromamba.sh for Micromamba environment setup
- Add run-mcp-isolated.sh for isolated MCP server execution
- Add run-polymarket-mcp-isolated.sh for isolated Polymarket MCP execution
- Add run_isolated_mcp.py for Python-based isolated MCP runner
- Simplify run-polymarket-mcp.sh to use exec for proper signal handling
- Add comprehensive solution documentation (FINAL_SOLUTION.md, etc.)
- Add ISSUES_FIXED.md documenting resolved installation issues
- Update .gitignore to exclude environment directories (.micromamba-env/, .final-env/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant