50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Test MCP client for OpenClaw server."""
|
|
|
|
import asyncio
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
try:
|
|
from mcp import ClientSession
|
|
from mcp.client.stdio import stdio_client, StdioServerParameters
|
|
except ImportError:
|
|
print("Install mcp: pip install mcp")
|
|
sys.exit(1)
|
|
|
|
|
|
async def test_mcp():
|
|
"""Test the OpenClaw MCP server."""
|
|
params = StdioServerParameters(
|
|
command="python",
|
|
args=["openclaw_mcp_server.py"]
|
|
)
|
|
|
|
print("Connecting to OpenClaw MCP server...")
|
|
|
|
async with stdio_client(params) as (read_stream, write_stream):
|
|
async with ClientSession(read_stream, write_stream) as session:
|
|
await session.initialize()
|
|
print("Connected! ✅")
|
|
|
|
# Get tools
|
|
tools_result = await session.list_tools()
|
|
print(f"\nTools available: {len(tools_result.tools)}")
|
|
for tool in tools_result.tools:
|
|
print(f" - {tool.name}: {tool.description}")
|
|
|
|
# Test list_files
|
|
print("\nTesting list_files...")
|
|
result = await session.call_tool("list_files", {"directory": "."})
|
|
print(f"Result: {result}")
|
|
|
|
# Test get_status
|
|
print("\nTesting get_status...")
|
|
result = await session.call_tool("get_status", {})
|
|
print(f"Result: {result}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_mcp())
|