"""Simple test script to verify MCP server tools work."""
import logging
import sys
from pathlib import Path
# Add src to path for imports when running directly
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from mcp_server.tools.corpus_answer import corpus_answer
from mcp_server.tools.text_profile import text_profile
# Configure logging
logging.basicConfig(level=logging.INFO, format="%(message)s")
logger = logging.getLogger(__name__)
def test_tools() -> None:
"""Test both MCP tools."""
separator = "=" * 60
logger.info(separator)
logger.info("Testing MCP Server Tools")
logger.info(separator)
# Test 1: corpus_answer
logger.info("\nTesting corpus_answer_tool...")
result = corpus_answer("What is climate policy?")
logger.info("Success! Tool returns correct type.")
if result.answer:
logger.info(" Answer: %s...", result.answer[:100])
logger.info(" Sources: %d documents", len(result.sources))
else:
logger.info(" (Tool not yet fully implemented - returns empty answer)")
# Basic type check - tool should return the correct schema
assert hasattr(result, "answer"), "Result should have 'answer' attribute"
assert hasattr(result, "sources"), "Result should have 'sources' attribute"
# Test 2: text_profile
logger.info("\nTesting text_profile_tool...")
result = text_profile("Machine learning is transforming technology.")
logger.info("Success! Tool returns correct type.")
logger.info(" Tokens: %d", result.token_count)
logger.info(" Sentiment: %.2f", result.sentiment)
logger.info(" Readability: %.1f", result.readability_flesch)
if result.token_count == 0:
logger.info(" (Tool not yet fully implemented - returns zero values)")
# Basic type check - tool should return the correct schema
assert hasattr(result, "token_count"), "Result should have 'token_count' attribute"
assert hasattr(result, "sentiment"), "Result should have 'sentiment' attribute"
assert hasattr(
result, "readability_flesch"
), "Result should have 'readability_flesch' attribute"
logger.info("\n%s", separator)
logger.info("All tests passed! Your MCP server tools are callable.")
logger.info("(Implement the TODOs in the tool files to get real results)")
logger.info(separator)
if __name__ == "__main__":
test_tools()