test_stateless_simple.pyā¢3.62 kB
#!/usr/bin/env python3
"""Simple test for the stateless MCP server."""
import tempfile
import sys
from pathlib import Path
print("š§ Starting test script...")
# Add the src directory to the path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from quantalogic_markdown_mcp.mcp_server import MarkdownMCPServer
def test_stateless_server():
"""Test basic functionality of the stateless server."""
print("š§ Starting stateless server test...")
# Create a temporary markdown file
with tempfile.NamedTemporaryFile(mode='w', suffix='.md', delete=False) as f:
f.write("""# Test Document
## Introduction
This is a test document for the stateless server.
## Features
- Feature 1
- Feature 2
## Conclusion
End of document.
""")
temp_path = f.name
print(f"š Created test document: {temp_path}")
try:
# Initialize the server
print("š Initializing MCP server...")
server = MarkdownMCPServer()
print("ā
Server initialized successfully!")
# Test list_sections
print("\nš Testing list_sections...")
result = server.call_tool_sync("list_sections", {"document_path": temp_path})
print(f" Result: {result.get('success', False)}")
if result.get('success'):
sections = result.get('sections', [])
print(f" Found {len(sections)} sections")
for section in sections:
print(f" - {section.get('title', 'Unknown')} (ID: {section.get('id', 'Unknown')})")
# Test get_section
if result.get('success') and result.get('sections'):
first_section_id = result['sections'][0]['id']
print(f"\nš Testing get_section with ID: {first_section_id}...")
result = server.call_tool_sync("get_section", {"document_path": temp_path, "section_id": first_section_id})
print(f" Result: {result.get('success', False)}")
if result.get('success'):
section = result.get('section', {})
print(f" Retrieved: {section.get('title', 'Unknown')}")
# Test insert_section
print("\nā Testing insert_section...")
result = server.call_tool_sync("insert_section", {
"document_path": temp_path,
"heading": "New Section",
"content": "This is a new section added by the stateless server.",
"position": 2
})
print(f" Result: {result.get('success', False)}")
# Verify the section was added
print("\nš Verifying section was added...")
result = server.call_tool_sync("list_sections", {"document_path": temp_path})
print(f" Result: {result.get('success', False)}")
if result.get('success'):
sections = result.get('sections', [])
print(f" Now have {len(sections)} sections")
for section in sections:
print(f" - {section.get('title', 'Unknown')} (ID: {section.get('id', 'Unknown')})")
print("\nā
All tests completed successfully!")
return True
except Exception as e:
print(f"\nā Error during testing: {e}")
import traceback
traceback.print_exc()
return False
finally:
# Clean up
Path(temp_path).unlink(missing_ok=True)
if __name__ == "__main__":
success = test_stateless_server()
if success:
print("\nš Test suite completed successfully!")
else:
print("\nš„ Test suite failed!")
sys.exit(1)