mcp-pdf-tools/test_pages_parameter.py
Ryan Malloy 58d43851b9 Add HTTPS URL support and fix MCP parameter validation
Features:
- HTTPS URL support: Process PDFs directly from URLs with intelligent caching
- Smart caching: 1-hour cache to avoid repeated downloads
- Content validation: Verify downloads are actually PDF files
- Security: Proper User-Agent headers, HTTPS preferred over HTTP
- MCP parameter fixes: Handle pages parameter as string "[2,3]" format
- Backward compatibility: Still supports local file paths and list parameters

Technical changes:
- Added download_pdf_from_url() with caching and validation
- Updated validate_pdf_path() to handle URLs and local paths
- Added parse_pages_parameter() for flexible parameter parsing
- Updated all 8 tools to accept string pages parameters
- Enhanced error handling for network and validation issues

All tools now support:
- Local paths: "/path/to/file.pdf"
- HTTPS URLs: "https://example.com/document.pdf"
- Flexible pages: "[2,3]", "1,2,3", or [1,2,3]

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 02:25:53 -06:00

52 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""
Test the updated pages parameter parsing
"""
import asyncio
import sys
import os
# Add src to path
sys.path.insert(0, 'src')
from mcp_pdf_tools.server import parse_pages_parameter
def test_page_parsing():
"""Test page parameter parsing"""
print("Testing page parameter parsing...")
# Test different input formats
test_cases = [
(None, None),
("1,2,3", [1, 2, 3]),
("[2, 3]", [2, 3]), # This is the problematic case from the user
("5", [5]),
([0, 1, 2], [0, 1, 2]),
("0,1,2", [0, 1, 2]),
("[0,1,2]", [0, 1, 2])
]
all_passed = True
for input_val, expected in test_cases:
try:
result = parse_pages_parameter(input_val)
if result == expected:
print(f"'{input_val}' -> {result}")
else:
print(f"'{input_val}' -> {result}, expected {expected}")
all_passed = False
except Exception as e:
print(f"'{input_val}' -> Error: {e}")
all_passed = False
return all_passed
if __name__ == "__main__":
success = test_page_parsing()
if success:
print("\n🎉 All page parameter parsing tests passed!")
else:
print("\n🚨 Some tests failed!")
sys.exit(0 if success else 1)