#!/usr/bin/env python3
"""
Test client for Cost Explorer MCP Server with streamable HTTP.
"""
import asyncio
import sys
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
async def test_local_server():
"""Test the local MCP server running on port 8000."""
mcp_url = "http://localhost:8000/mcp"
headers = {}
print(f"Testing MCP server at: {mcp_url}")
try:
async with streamablehttp_client(
mcp_url,
headers,
timeout=120,
terminate_on_close=False
) as (read_stream, write_stream, _):
async with ClientSession(read_stream, write_stream) as session:
# Initialize the session
await session.initialize()
print("โ
Session initialized successfully")
# List available tools
tool_result = await session.list_tools()
print(f"โ
Available tools: {len(tool_result.tools)}")
for tool in tool_result.tools:
print(f" - {tool.name}: {tool.description}")
# Test a simple tool call
print("\n๐งช Testing get_today_date tool...")
result = await session.call_tool("get_today_date", {})
print(f"โ
get_today_date result: {result.content[0].text}")
print("\nโ
All tests passed! MCP server is working correctly.")
except Exception as e:
print(f"โ Error testing MCP server: {e}")
sys.exit(1)
if __name__ == "__main__":
asyncio.run(test_local_server())