Spaces:
Sleeping
Sleeping
File size: 2,237 Bytes
250bf8c |
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 |
"""
Test MCP connection and tool availability.
"""
import asyncio
import json
from mcp import ClientSession
from mcp.client.sse import sse_client
SERVER_URL = "http://localhost:8000/sse"
async def test_mcp_connection():
"""Test MCP connection and list available tools."""
print("π Testing MCP Connection")
print("=" * 40)
try:
async with sse_client(SERVER_URL) as (sse, write):
async with ClientSession(sse, write) as session:
await session.initialize()
# List available tools
print("π Available Tools:")
tools = session.list_tools()
if hasattr(tools, 'tools'):
for tool in tools.tools:
print(f" β
{tool.name}")
else:
print(f" Tools response: {tools}")
# Test calling start_adaptive_session
print("\nπ§ͺ Testing start_adaptive_session tool...")
try:
response = await session.call_tool("start_adaptive_session", {
"student_id": "test_student",
"concept_id": "test_concept",
"initial_difficulty": 0.5
})
print(f" β
Tool call successful: {response}")
except Exception as e:
print(f" β Tool call failed: {e}")
# Test calling get_learning_path (existing tool)
print("\nπ§ͺ Testing get_learning_path tool...")
try:
response = await session.call_tool("get_learning_path", {
"student_id": "test_student",
"concept_ids": ["test_concept"],
"student_level": "beginner"
})
print(f" β
Tool call successful: {type(response)}")
except Exception as e:
print(f" β Tool call failed: {e}")
except Exception as e:
print(f"β Connection failed: {e}")
if __name__ == "__main__":
asyncio.run(test_mcp_connection())
|