#!/usr/bin/env python3
"""Test MCP tools directly."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from mcp_server.tools import (
tool_get_cve_details,
tool_search_cves,
tool_get_statistics
)
def test_tools():
print("\n=== Testing MCP Tools ===\n")
# Test 1: Get statistics
print("1. Testing get_statistics...")
result = tool_get_statistics()
print(f" Result:\n{result}\n")
# Test 2: Search CVEs
print("2. Testing search_cves (keyword: 'remote')...")
result = tool_search_cves("remote", limit=3)
print(f" Result:\n{result}\n")
# Test 3: Get specific CVE (may or may not exist)
print("3. Testing get_cve_details...")
# First, search to find a real CVE ID
import json
search_result = json.loads(tool_search_cves("", limit=1))
if search_result['results']:
cve_id = search_result['results'][0]['cve_id']
print(f" Looking up: {cve_id}")
result = tool_get_cve_details(cve_id)
print(f" Result:\n{result}\n")
else:
print(" No CVEs in database to test\n")
# Test 4: Non-existent CVE
print("4. Testing get_cve_details (non-existent)...")
result = tool_get_cve_details("CVE-9999-99999")
print(f" Result:\n{result}\n")
print("✓ All tool tests complete!")
if __name__ == "__main__":
test_tools()