Spaces:
Runtime error
Runtime error
File size: 4,773 Bytes
48a7f49 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
#!/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")
|