Initial commit: MCP Summary Server
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify MCP summary server connectivity and functionality.
|
||||
"""
|
||||
|
||||
import json
|
||||
import requests
|
||||
import sys
|
||||
|
||||
def test_health_check(url):
|
||||
"""Test basic health check."""
|
||||
try:
|
||||
response = requests.get(url, timeout=5)
|
||||
print(f"✓ Health check: {response.status_code}")
|
||||
print(f" Response: {response.json()}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"✗ Health check failed: {e}")
|
||||
return False
|
||||
|
||||
def test_mcp_initialize(url, api_key=None):
|
||||
"""Test MCP initialization."""
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
if api_key:
|
||||
headers["Authorization"] = f"Bearer {api_key}"
|
||||
|
||||
payload = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "initialize",
|
||||
"params": {
|
||||
"protocolVersion": "2025-11-25",
|
||||
"capabilities": {},
|
||||
"clientInfo": {
|
||||
"name": "test-client",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=10)
|
||||
print(f"✓ MCP Initialize: {response.status_code}")
|
||||
print(f" Response: {response.json()}")
|
||||
return response.status_code == 200
|
||||
except Exception as e:
|
||||
print(f"✗ MCP Initialize failed: {e}")
|
||||
return False
|
||||
|
||||
def test_tools_list(url, api_key=None):
|
||||
"""Test tools/list endpoint."""
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
if api_key:
|
||||
headers["Authorization"] = f"Bearer {api_key}"
|
||||
|
||||
payload = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": 2,
|
||||
"method": "tools/list",
|
||||
"params": {}
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=10)
|
||||
print(f"✓ Tools List: {response.status_code}")
|
||||
print(f" Response: {response.json()}")
|
||||
return response.status_code == 200
|
||||
except Exception as e:
|
||||
print(f"✗ Tools List failed: {e}")
|
||||
return False
|
||||
|
||||
def test_summarize(url, api_key=None):
|
||||
"""Test summarize_document tool."""
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
if api_key:
|
||||
headers["Authorization"] = f"Bearer {api_key}"
|
||||
|
||||
# Simple test text
|
||||
test_text = """
|
||||
The Supreme Court of Canada decided in R v. Smith, 2020 SCC 15, that the
|
||||
police had violated the accused's section 8 Charter rights by conducting a
|
||||
warrantless search of his vehicle. The Court found that the officers did not
|
||||
have reasonable grounds to believe that evidence would be destroyed if they
|
||||
waited to obtain a warrant. The evidence was excluded under section 24(2) of
|
||||
the Charter, and the conviction was overturned.
|
||||
"""
|
||||
|
||||
payload = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": 3,
|
||||
"method": "tools/call",
|
||||
"params": {
|
||||
"name": "summarize_document",
|
||||
"arguments": {
|
||||
"text": test_text,
|
||||
"max_length": 50
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, headers=headers, json=payload, timeout=120)
|
||||
print(f"✓ Summarize Test: {response.status_code}")
|
||||
print(f" Response: {response.json()}")
|
||||
return response.status_code == 200
|
||||
except Exception as e:
|
||||
print(f"✗ Summarize Test failed: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
url = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:8080"
|
||||
api_key = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
|
||||
print("=" * 60)
|
||||
print("MCP Summary Server Test")
|
||||
print("=" * 60)
|
||||
print(f"URL: {url}")
|
||||
print(f"API Key: {'[SET]' if api_key else '[NOT SET]'}")
|
||||
print("=" * 60)
|
||||
|
||||
print("\n1. Testing health check...")
|
||||
health_ok = test_health_check(url)
|
||||
|
||||
print("\n2. Testing MCP initialization...")
|
||||
init_ok = test_mcp_initialize(url, api_key)
|
||||
|
||||
print("\n3. Testing tools list...")
|
||||
tools_ok = test_tools_list(url, api_key)
|
||||
|
||||
print("\n4. Testing summarize tool...")
|
||||
summarize_ok = test_summarize(url, api_key)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("Summary:")
|
||||
print(f" Health Check: {'✓' if health_ok else '✗'}")
|
||||
print(f" MCP Initialize: {'✓' if init_ok else '✗'}")
|
||||
print(f" Tools List: {'✓' if tools_ok else '✗'}")
|
||||
print(f" Summarize: {'✓' if summarize_ok else '✗'}")
|
||||
print("=" * 60)
|
||||
|
||||
if all([health_ok, init_ok, tools_ok, summarize_ok]):
|
||||
print("\n✓ All tests passed!")
|
||||
return 0
|
||||
else:
|
||||
print("\n✗ Some tests failed. Check the errors above.")
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user