fix: Resolve MCP package shadowing issue and add package structure tests

🐛 Fixes:
- Fix mcp package shadowing by importing external MCP before sys.path modification
- Update mcp/server.py to avoid shadowing installed mcp package
- Update tests/test_mcp_server.py import order

 Tests Added:
- Add tests/test_package_structure.py with 23 comprehensive tests
- Test cli package structure and imports
- Test mcp package structure and imports
- Test backwards compatibility
- All package structure tests passing 

📊 Test Results:
- 205 tests passed 
- 67 tests skipped (PDF features, PyMuPDF not installed)
- 23 new package structure tests added
- Total: 272 tests (excluding test_mcp_server.py which needs more work)

⚠️ Known Issue:
- test_mcp_server.py still has import issues (67 tests)
- Will be fixed in next commit
- Main functionality tests all passing

Impact: Package structure working, 75% of tests passing
This commit is contained in:
yusyus
2025-10-26 00:26:57 +03:00
parent fb0cb99e6b
commit cb0d3e885e
6 changed files with 485 additions and 6 deletions

View File

@@ -13,9 +13,17 @@ import time
from pathlib import Path
from typing import Any
# Add parent directory to path for imports
sys.path.insert(0, str(Path(__file__).parent.parent))
# CRITICAL: Remove current directory from sys.path to avoid shadowing the mcp package
# Our local 'mcp/' directory would otherwise shadow the installed 'mcp' package
current_dir = str(Path(__file__).parent.parent)
if current_dir in sys.path:
sys.path.remove(current_dir)
if '' in sys.path:
sys.path.remove('')
if '.' in sys.path:
sys.path.remove('.')
# Now import the external MCP package (from site-packages)
try:
from mcp.server import Server
from mcp.types import Tool, TextContent
@@ -24,6 +32,10 @@ except ImportError:
print("Install with: pip install mcp")
sys.exit(1)
# NOW add parent directory back for importing local cli modules
# The MCP package is already imported, so no more shadowing
sys.path.insert(0, current_dir)
# Initialize MCP server
app = Server("skill-seeker")