mcp-sentiment / usage /debug_imports.py
phil71x
feat: Update dependencies and add new packages for sentiment analysis
48a7f49
#!/usr/bin/env python3
"""
MCP Import Debugging Utility.
This script checks and debugs MCP package imports to help troubleshoot
import-related issues with the MCP client libraries.
Purpose: Troubleshooting import issues
Usage: Diagnostic utility
To run this script:
pdm run python usage/debug_imports.py
Dependencies:
- mcp (install with: pdm add mcp)
This utility helps identify which MCP components are available and
which import paths work correctly.
"""
def check_mcp_imports():
"""Check various import paths for MCP components."""
print("πŸ” MCP Package Import Debugging")
print("=" * 40)
# Try different import paths
import_attempts = [
# Basic imports
("mcp", "import mcp"),
("mcp.ClientSession", "from mcp import ClientSession"),
("mcp.StdioServerParameters", "from mcp import StdioServerParameters"),
# Try mcp.types
("mcp.types", "import mcp.types"),
(
"mcp.types.StdioServerParameters",
"from mcp.types import StdioServerParameters",
),
# Try mcp.client
("mcp.client.stdio", "from mcp.client.stdio import stdio_client"),
# Try other possible locations
("mcp.server", "from mcp.server import Server"),
("mcp.client", "from mcp.client import ClientSession"),
# Try smolagents
("smolagents", "import smolagents"),
("smolagents.mcp_client", "from smolagents.mcp_client import MCPClient"),
]
successful_imports = []
failed_imports = []
for module_name, import_statement in import_attempts:
try:
exec(import_statement)
successful_imports.append((module_name, import_statement))
print(f"βœ… {import_statement}")
except ImportError as e:
failed_imports.append((module_name, import_statement, str(e)))
print(f"❌ {import_statement}")
print(f" Error: {e}")
print("\nπŸ“Š Results:")
print(f" βœ… Successful: {len(successful_imports)}")
print(f" ❌ Failed: {len(failed_imports)}")
# Try to inspect what's actually in the mcp module
print("\nπŸ” Exploring mcp module contents:")
try:
import mcp
print(f" mcp module location: {mcp.__file__}")
print(f" mcp module attributes: {dir(mcp)}")
# Check for StdioServerParameters in different locations
if hasattr(mcp, "StdioServerParameters"):
print(" βœ… Found StdioServerParameters in mcp")
else:
print(" ❌ StdioServerParameters not found in mcp")
# Check mcp.types if it exists
try:
import mcp.types
print(f" mcp.types attributes: {dir(mcp.types)}")
except ImportError:
print(" ❌ mcp.types not available")
# Check mcp.client if it exists
try:
import mcp.client
print(f" mcp.client attributes: {dir(mcp.client)}")
except ImportError:
print(" ❌ mcp.client not available")
except ImportError as e:
print(f" ❌ Can't import mcp at all: {e}")
# Check smolagents if available
print("\nπŸ” Exploring smolagents module:")
try:
import smolagents
print(f" smolagents module location: {smolagents.__file__}")
print(f" smolagents version: {getattr(smolagents, '__version__', 'unknown')}")
try:
import smolagents.mcp_client
print(" βœ… smolagents.mcp_client is available")
except ImportError:
print(" ❌ smolagents.mcp_client not available")
except ImportError as e:
print(f" ❌ Can't import smolagents: {e}")
print("\nπŸ’‘ Recommendations:")
if len(successful_imports) > 0:
print(" Some MCP imports work - check successful ones above")
else:
print(" No MCP imports working - install with: pdm add mcp")
# Check for smolagents specifically
smolagents_works = any("smolagents" in imp[0] for imp in successful_imports)
if smolagents_works:
print(" βœ… smolagents is working - use sentiment_mcp.py")
else:
print(" Install smolagents with: pdm add 'smolagents[mcp]'")
return successful_imports, failed_imports
if __name__ == "__main__":
print("πŸš€ MCP Import Debugging Utility")
print("This tool helps diagnose MCP package import issues.")
print("=" * 50)
check_mcp_imports()
print("\nπŸ“‹ Next Steps:")
print("1. If MCP imports fail: pdm add mcp")
print("2. If smolagents imports fail: pdm add 'smolagents[mcp]'")
print("3. Try running: pdm run python usage/sentiment_mcp.py")
print("4. Backup option: pdm run python usage/sentiment_gradio.py")