"""
Basic validation script for the Codebase Insights MCP Server.
"""
import os
import json
from pathlib import Path
def test_server():
"""Test basic server setup and configuration."""
print("Testing Codebase Insights MCP Server Setup\n")
# Test 1: Check imports
print("1. Testing imports...")
try:
from mcp_server.main import mcp, GenerateCollectionInput, GenerateCollectionOutput
from mcp_server.models.api import ApiCollection, ApiEndpoint
from mcp_server.models.postman import PostmanCollection
from mcp_server.clients.bitbucket import BitbucketClient
from mcp_server.analyzers.factory import AnalyzerFactory
from mcp_server.generators.postman import PostmanCollectionGenerator
print("✅ All imports successful\n")
except ImportError as e:
print(f"❌ Import error: {e}\n")
return
# Test 2: Check environment
print("2. Checking environment variables...")
has_token = bool(os.environ.get("BITBUCKET_API_TOKEN") or os.environ.get("bitbucket_token"))
output_dir = os.environ.get("output_directory", ".")
print(f"Bitbucket token configured: {has_token}")
print(f"Output directory: {Path(output_dir).absolute()}")
if not has_token:
print("⚠️ Warning: No Bitbucket token found. Set BITBUCKET_API_TOKEN to enable repository access.")
print()
# Test 3: Validate models
print("3. Testing data models...")
try:
# Test input/output models
input_model = GenerateCollectionInput(bitbucket_repo_url="https://bitbucket.org/test/repo.git")
output_model = GenerateCollectionOutput(
success=True,
collection_path="/test/path.json",
message="Test message"
)
# Test API models
api_collection = ApiCollection(name="Test API")
# Test Postman models
postman_collection = PostmanCollection(
info={"name": "Test Collection", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"}
)
print("✅ All models validate correctly\n")
except Exception as e:
print(f"❌ Model validation error: {e}\n")
return
# Test 4: Check MCP server tools
print("4. Checking MCP server tools...")
try:
tool_count = len(mcp._tools)
print(f"✅ MCP server initialized with {tool_count} tools")
except Exception as e:
print(f"⚠️ Could not check tools: {e}")
print()
print("✅ Basic setup validation complete!")
print("\nTo test collection generation:")
print("1. Set BITBUCKET_API_TOKEN environment variable")
print("2. Run: uv run codebase-insights-mcp")
print("3. Use MCP client to call generate_collection tool")
if __name__ == "__main__":
test_server()