test_client.py•2.58 kB
#!/usr/bin/env python3
"""
Simple test client for the CSV MCP server.
"""
import asyncio
import json
from fastmcp import Client
async def test_csv_server():
"""Test the CSV MCP server functionality."""
try:
# Connect to the server
client = Client("csv_mcp_server/server.py")
async with client:
print("Connected to CSV MCP server!")
# Test basic server info
print("\n--- Server Info ---")
tools = await client.list_tools()
print(f"Available tools: {len(tools)}")
for tool in tools:
print(f" - {tool.name}: {tool.description}")
resources = await client.list_resources()
print(f"Available resources: {len(resources)}")
for resource in resources:
print(f" - {resource.uri}: {resource.name}")
prompts = await client.list_prompts()
print(f"Available prompts: {len(prompts)}")
for prompt in prompts:
print(f" - {prompt.name}: {prompt.description}")
# Test creating a CSV file
print("\n--- Testing CSV Creation ---")
result = await client.call_tool("create_csv", {
"filename": "test_data",
"headers": ["name", "age", "city"],
"data": [
["Alice", 25, "New York"],
["Bob", 30, "Los Angeles"],
["Charlie", 35, "Chicago"]
]
})
print(f"Create CSV result: {result.data}")
# Test reading the CSV file
print("\n--- Testing CSV Reading ---")
result = await client.call_tool("read_csv", {
"filename": "test_data"
})
print(f"Read CSV result: {result.data}")
# Test getting file info
print("\n--- Testing File Info ---")
result = await client.call_tool("get_info", {
"filename": "test_data"
})
print(f"File info: {result.data}")
# Test listing CSV files
print("\n--- Testing File Listing ---")
result = await client.call_tool("list_csv_files", {})
print(f"File listing: {result.data}")
except Exception as e:
print(f"Error testing server: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
asyncio.run(test_csv_server())