Skip to main content
Glama
test_server.py5.1 kB
#!/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)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Nexlab-One/python-vlang-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server