"""
Simple test script for Sealmetrics MCP Server
This script tests the basic functionality of the Sealmetrics client
without requiring the full MCP setup.
"""
import os
import asyncio
from server import SealmetricsClient, generate_conversion_pixel
async def test_client():
"""Test the Sealmetrics client"""
print("š Testing Sealmetrics MCP Server\n")
# Get credentials from environment - support both token and email/password
api_token = os.getenv("SEALMETRICS_API_TOKEN")
email = os.getenv("SEALMETRICS_EMAIL")
password = os.getenv("SEALMETRICS_PASSWORD")
if api_token:
print("š Using API Token: [REDACTED]")
print(" (Direct token authentication)\n")
client = SealmetricsClient(api_token=api_token)
elif email and password:
print(f"š§ Using email: {email}")
print("š Password: ***********\n")
client = SealmetricsClient(email=email, password=password)
else:
print("ā Error: Either SEALMETRICS_API_TOKEN or both SEALMETRICS_EMAIL and SEALMETRICS_PASSWORD must be set")
print(" Set them as environment variables or in a .env file")
return
try:
# Test 1: Authentication
print("1ļøā£ Testing Authentication...")
token = await client._get_token()
print(f" ā
Successfully authenticated! Token: [REDACTED]\n")
# Test 2: Get Accounts
print("2ļøā£ Testing Get Accounts...")
accounts = await client.get_accounts()
print(f" ā
Found {len(accounts)} account(s):")
for account_id, account_name in accounts.items():
print(f" - {account_name} (ID: {account_id})")
print()
if not accounts:
print(" ā ļø No accounts found. Cannot proceed with further tests.")
return
# Use first account for remaining tests
account_id = list(accounts.keys())[0]
print(f" Using account: {account_id}\n")
# Test 3: Get Traffic Data
print("3ļøā£ Testing Get Traffic Data (yesterday)...")
try:
traffic_data = await client.get_acquisition_data(
account_id=account_id,
date_range="yesterday",
report_type="Source",
limit=5
)
print(f" ā
Retrieved {len(traffic_data)} traffic sources:")
for item in traffic_data[:3]:
source = item.get("Source", "Unknown")
clicks = item.get("clicks", 0)
print(f" - {source}: {clicks:,} clicks")
print()
except Exception as e:
print(f" ā ļø Traffic data test failed: {str(e)}\n")
# Test 4: Get Conversions
print("4ļøā£ Testing Get Conversions (this month)...")
try:
conversions = await client.get_conversions(
account_id=account_id,
date_range="this_month",
limit=10
)
print(f" ā
Retrieved {len(conversions)} conversions")
if conversions:
total_revenue = sum(c.get("amount", 0) for c in conversions)
print(f" Total revenue: ${total_revenue:,.2f}")
print()
except Exception as e:
print(f" ā ļø Conversions test failed: {str(e)}\n")
# Test 5: Get Microconversions
print("5ļøā£ Testing Get Microconversions (this month)...")
try:
microconversions = await client.get_microconversions(
account_id=account_id,
date_range="this_month",
limit=10
)
print(f" ā
Retrieved {len(microconversions)} microconversions")
if microconversions:
labels = {}
for mc in microconversions:
label = mc.get("label", "unknown")
labels[label] = labels.get(label, 0) + 1
print(f" Event types: {', '.join(f'{k} ({v})' for k, v in labels.items())}")
print()
except Exception as e:
print(f" ā ļø Microconversions test failed: {str(e)}\n")
# Test 6: Pixel Generation
print("6ļøā£ Testing Pixel Generation...")
pixel = generate_conversion_pixel(
account_id=account_id,
event_type="conversion",
label="sales",
value=99.99,
ignore_pageview=False
)
print(f" ā
Generated pixel code ({len(pixel)} characters)")
print(f" Preview: {pixel[:100]}...")
print()
# Success!
print("ā
All tests completed successfully!")
print("\nš Next Steps:")
print(" 1. Configure Claude Desktop with your credentials")
print(" 2. Restart Claude Desktop")
print(" 3. Start asking questions about your Sealmetrics data!")
except Exception as e:
print(f"\nā Test failed with error: {str(e)}")
import traceback
traceback.print_exc()
finally:
await client.close()
def main():
"""Main entry point"""
# Load .env file if available
try:
from dotenv import load_dotenv
load_dotenv()
print("š Loaded credentials from .env file\n")
except ImportError:
print("ā¹ļø python-dotenv not installed, using environment variables\n")
asyncio.run(test_client())
if __name__ == "__main__":
main()