-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_demo.py
More file actions
139 lines (109 loc) Β· 4.8 KB
/
test_demo.py
File metadata and controls
139 lines (109 loc) Β· 4.8 KB
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
#!/usr/bin/env python3
"""Simple test script to verify GigAPI MCP server with public demo."""
import logging
from mcp_gigapi.client import GigAPIClient
from mcp_gigapi.tools import GigAPITools
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_demo_connection():
"""Test connection to the public GigAPI demo."""
print("π Testing connection to GigAPI demo at https://gigapi.fly.dev")
# Create client
client = GigAPIClient(
host="gigapi.fly.dev",
port=443,
verify_ssl=False,
timeout=30
)
tools = GigAPITools(client)
try:
# Test 1: Health check
print("\n1οΈβ£ Testing health check...")
health = tools.health_check()
print(f"β
Health check: {health['status']}")
# Test 2: Ping
print("\n2οΈβ£ Testing ping...")
ping = tools.ping()
print(f"β
Ping: {ping['status']}")
# Test 3: List databases
print("\n3οΈβ£ Testing database listing...")
databases = tools.list_databases(database="mydb")
print(f"Raw list_databases response: {databases}")
print(f"β
Found {databases['count']} databases: {databases['databases']}")
if databases['databases']:
# Use the first database returned
database = databases['databases'][0]
print(f"π Using first database: {database}")
# Test 4: List tables
print(f"\n4οΈβ£ Testing table listing for database '{database}'...")
tables = tools.list_tables(database)
print(f"β
Found {tables['count']} tables: {tables['tables']}")
if tables['tables']:
# Use the first table found
table = tables['tables'][0]
print(f"π Using first table: {table}")
# Test 5: Get table schema
print(f"\n5οΈβ£ Testing schema retrieval for table '{table}'...")
tools.get_table_schema(database, table)
print("β
Schema retrieved successfully")
# Test 6: Count query
print(f"\n6οΈβ£ Testing count query on table '{table}'...")
count_result = tools.run_select_query(f"SELECT count(*) as total FROM {table}", database)
if count_result['success']:
print("β
Count query successful")
for result in count_result['results']:
print(f" {result}")
else:
print(f"β Count query failed: {count_result.get('error', 'Unknown error')}")
# Test 7: Simple query with LIMIT
print(f"\n7οΈβ£ Testing simple query on table '{table}'...")
query_result = tools.run_select_query(f"SELECT * FROM {table} LIMIT 3", database)
if query_result['success']:
print(f"β
Query successful, got {len(query_result['results'])} result sets")
for i, result in enumerate(query_result['results']):
print(f" Result {i+1}: {result}")
else:
print(f"β Query failed: {query_result.get('error', 'Unknown error')}")
else:
print(f"β οΈ No tables found in database '{database}', skipping table tests")
else:
print("β οΈ No databases found, skipping database-specific tests")
print("\nπ All tests completed successfully!")
except Exception as e:
print(f"\nβ Test failed with error: {e}")
logger.exception("Test failed")
raise AssertionError(f"Test failed with error: {e}") from e
def test_mcp_tools_creation():
"""Test MCP tools creation."""
print("\nπ§ Testing MCP tools creation...")
client = GigAPIClient()
from mcp_gigapi.tools import create_tools
tools = create_tools(client)
tool_names = [tool.name for tool in tools]
expected_tools = [
"run_select_query",
"list_databases",
"list_tables",
"get_table_schema",
"write_data",
"health_check",
"ping"
]
print(f"β
Created {len(tools)} tools:")
for tool_name in tool_names:
print(f" - {tool_name}")
for expected_tool in expected_tools:
if expected_tool not in tool_names:
print(f"β Missing expected tool: {expected_tool}")
raise AssertionError(f"Missing expected tool: {expected_tool}")
print("β
All expected tools created successfully!")
if __name__ == "__main__":
print("π GigAPI MCP Server Demo Test")
print("=" * 50)
# Test MCP tools creation
test_mcp_tools_creation()
# Test demo connection
test_demo_connection()
print("\n" + "=" * 50)
print("π All tests passed! GigAPI MCP server is ready to use.")