#!/usr/bin/env python3
"""
Simple test script to verify Jira API connection
Run this before setting up the MCP server to ensure your credentials work.
"""
import os
import asyncio
import httpx
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
JIRA_BASE_URL = os.getenv("JIRA_BASE_URL")
JIRA_EMAIL = os.getenv("JIRA_EMAIL")
JIRA_API_TOKEN = os.getenv("JIRA_API_TOKEN")
async def test_jira_connection():
"""Test basic Jira API connection."""
print("๐ง Testing Jira API Connection...")
print(f"๐ URL: {JIRA_BASE_URL}")
print(f"๐ง Email: {JIRA_EMAIL}")
print(f"๐ Token: {'*' * len(JIRA_API_TOKEN) if JIRA_API_TOKEN else 'NOT SET'}")
print("-" * 50)
if not all([JIRA_BASE_URL, JIRA_EMAIL, JIRA_API_TOKEN]):
print("โ Missing environment variables!")
print("Please ensure .env file contains:")
print("- JIRA_BASE_URL")
print("- JIRA_EMAIL")
print("- JIRA_API_TOKEN")
return False
try:
async with httpx.AsyncClient() as client:
# Test 1: Get current user info
print("๐งช Test 1: Getting current user info...")
response = await client.get(
f"{JIRA_BASE_URL}/rest/api/3/myself",
auth=(JIRA_EMAIL, JIRA_API_TOKEN),
headers={"Accept": "application/json"},
timeout=10.0
)
if response.status_code == 200:
user_data = response.json()
print(f"โ
Success! Logged in as: {user_data.get('displayName')} ({user_data.get('emailAddress')})")
else:
print(f"โ Failed: HTTP {response.status_code}")
print(f"Response: {response.text}")
return False
# Test 2: List projects
print("\n๐งช Test 2: Listing accessible projects...")
response = await client.get(
f"{JIRA_BASE_URL}/rest/api/3/project",
auth=(JIRA_EMAIL, JIRA_API_TOKEN),
headers={"Accept": "application/json"},
timeout=10.0
)
if response.status_code == 200:
projects = response.json()
print(f"โ
Success! Found {len(projects)} accessible projects:")
for project in projects[:5]: # Show first 5
print(f" ๐ {project.get('key')}: {project.get('name')}")
if len(projects) > 5:
print(f" ... and {len(projects) - 5} more")
else:
print(f"โ Failed: HTTP {response.status_code}")
print(f"Response: {response.text}")
return False
# Test 3: Search for recent issues
print("\n๐งช Test 3: Searching for recent issues...")
response = await client.get(
f"{JIRA_BASE_URL}/rest/api/3/search/jql",
params={
"jql": "project = SCRUM order by updated DESC",
"maxResults": 3,
"fields": "summary,status,assignee,issuetype"
},
auth=(JIRA_EMAIL, JIRA_API_TOKEN),
headers={"Accept": "application/json"},
timeout=10.0
)
if response.status_code == 200:
search_results = response.json()
issues = search_results.get("issues", [])
print(f"โ
Success! Found {search_results.get('total', 0)} total issues (showing {len(issues)}):")
for issue in issues:
fields = issue.get("fields", {})
print(f" ๐ซ {issue.get('key')}: {fields.get('summary', 'No summary')}")
else:
print(f"โ Failed: HTTP {response.status_code}")
print(f"Response: {response.text}")
return False
print("\n๐ All tests passed! Your Jira connection is working correctly.")
print("\n๐ Next steps:")
print("1. Configure Claude Desktop with the MCP server")
print("2. Restart Claude Desktop")
print("3. Try asking Claude: 'List my Jira projects'")
return True
except httpx.TimeoutException:
print("โ Connection timeout - check your JIRA_BASE_URL")
return False
except httpx.ConnectError:
print("โ Connection error - check your internet connection and JIRA_BASE_URL")
return False
except Exception as e:
print(f"โ Unexpected error: {str(e)}")
return False
if __name__ == "__main__":
asyncio.run(test_jira_connection())