-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.py
More file actions
132 lines (111 loc) · 4.98 KB
/
test_server.py
File metadata and controls
132 lines (111 loc) · 4.98 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
#!/usr/bin/env python3
"""
Test script for the V MCP Server
"""
import asyncio
import sys
from pathlib import Path
from fastmcp import Client
async def test_v_mcp_server():
"""Test the V MCP server functionality."""
print("Testing V MCP Server...")
print("=" * 50)
try:
# Import the MCP server directly for in-memory testing
from main import mcp, VDocumentationServer
from pathlib import Path
print("✓ Imported MCP server successfully")
# Create server instance
v_repo_path = Path(__file__).parent.parent
v_server = VDocumentationServer(v_repo_path)
# Test documentation sections
print("\n1. Testing documentation sections...")
sections = v_server.get_documentation_sections()
if "error" not in sections:
print(f"✓ Documentation sections loaded: {len(sections)} sections")
print(f" Available sections: {list(sections.keys())[:5]}...")
else:
print(f"✗ Error loading documentation: {sections['error']}")
return False
# Test examples list
print("\n2. Testing examples listing...")
examples = v_server.get_examples_list()
if examples and "error" not in examples[0]:
print(f"✓ Examples loaded: {len(examples)} examples")
print(f" Sample: {examples[0]['name'] if examples else 'None'}")
else:
print(f"✗ Error loading examples: {examples[0]['error'] if examples else 'No examples'}")
# Test stdlib modules
print("\n3. Testing standard library modules...")
modules = v_server.get_stdlib_modules()
if modules and "error" not in modules[0]:
print(f"✓ Standard library modules loaded: {len(modules)} modules")
print(f" Sample: {modules[0]['name'] if modules else 'None'}")
else:
print(f"✗ Error loading stdlib modules: {modules[0]['error'] if modules else 'No modules'}")
# Test documentation search
print("\n4. Testing documentation search...")
search_results = v_server.search_documentation("array")
if search_results:
print(f"✓ Documentation search successful: {len(search_results)} results")
print(f" Sample result: {search_results[0]['content'][:100]}...")
else:
print("✗ No search results found")
# Test specific example retrieval
print("\n5. Testing example retrieval...")
hello_world = v_server.get_example_content("hello_world")
if "error" not in hello_world:
print("✓ Hello world example retrieved successfully")
print(f" Content preview: {hello_world['content'][:100]}...")
else:
print(f"✗ Error retrieving hello world: {hello_world['error']}")
# Test MCP tools count
print("\n6. Testing MCP tools...")
# Note: We can't easily test the full MCP flow without a running server,
# but we can verify the tools are registered
print("✓ MCP server structure verified")
except Exception as e:
print(f"✗ Failed to test MCP server: {e}")
import traceback
traceback.print_exc()
return False
print("\n" + "=" * 50)
print("✓ All tests completed!")
return True
async def test_specific_example():
"""Test retrieving a specific example."""
print("\nTesting specific example retrieval...")
try:
async with Client("./main.py") as client:
# Try to get a hello world example
result = await client.call_tool("get_v_example", {"example_name": "hello_world"})
if "error" not in result.text.lower():
print("✓ Hello world example retrieved successfully")
print(f" Content preview: {result.text[:200]}...")
else:
print(f"✗ Error retrieving hello world example: {result.text}")
except Exception as e:
print(f"✗ Error testing specific example: {e}")
if __name__ == "__main__":
print("V MCP Server Test Suite")
print("Make sure you're in the v-mcp-server directory")
# Check if we're in the right directory
if not Path("main.py").exists():
print("✗ Error: main.py not found. Please run this script from the v-mcp-server directory.")
sys.exit(1)
# Check if V repository is accessible
v_repo_path = Path("../")
if not (v_repo_path / "README.md").exists():
print("⚠ Warning: V repository not found in parent directory.")
print(" Make sure you're running this from within the V repository,")
print(" or set the V_REPO_PATH environment variable.")
else:
print("✓ V repository found in parent directory")
# Run tests
success = asyncio.run(test_v_mcp_server())
asyncio.run(test_specific_example())
if success:
print("\n🎉 V MCP Server is working correctly!")
else:
print("\n❌ Some tests failed. Please check the server configuration.")
sys.exit(1)