-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_oauth_mcp.py
More file actions
114 lines (91 loc) · 3.93 KB
/
test_oauth_mcp.py
File metadata and controls
114 lines (91 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
"""
Test script for Multi-Cloud OAuth MCP functionality.
This demonstrates how to use the updated MCP client with authentication headers.
"""
import asyncio
from mcp.client.streamable_http import streamablehttp_client
from mcp import ClientSession
# Test configuration - replace with your actual credentials
user_token = "..." # Replace with valid user token
user_cloud_id = "..." # Replace with valid cloud ID
async def test_http_mcp_with_auth():
"""Test HTTP MCP connection with authentication headers."""
print("🔧 Testing HTTP MCP with Multi-Cloud OAuth")
print("=" * 60)
# Example based on your provided sample
async with streamablehttp_client(
"http://localhost:9000/mcp",
headers={
"Authorization": f"Bearer {user_token}",
"X-Atlassian-Cloud-Id": user_cloud_id,
},
) as (read_stream, write_stream, _):
async with ClientSession(read_stream, write_stream) as session:
await session.initialize()
print("✓ Successfully connected to HTTP MCP server")
try:
# List available tools
print("\n📋 Available tools:")
tools_response = await session.list_tools()
for item in tools_response:
if isinstance(item, tuple) and item[0] == "tools":
for tool in item[1]:
print(f" - {tool.name}: {tool.description}")
# Test calling a tool
print("\n🛠️ Testing tool execution:")
response = await session.call_tool(
"jira_get_all_projects",
{},
)
print(f"Tool response: {response}")
except Exception as e:
print(f"Error during tool execution: {e}")
async def test_api_with_auth():
"""Test the FastAPI endpoint with authentication."""
import httpx
print("\n🌐 Testing FastAPI endpoint with authentication")
print("=" * 60)
async with httpx.AsyncClient() as client:
try:
# Test with authentication headers in the request body
response = await client.post(
"http://localhost:8000/chat",
json={
"message": "List all available JIRA projects",
"session_id": "test-oauth-session",
"auth_token": user_token,
"cloud_id": user_cloud_id,
"response_format": "natural"
}
)
if response.status_code == 200:
result = response.json()
print("✓ API call successful")
print(f"Response: {result['response']}")
print(f"Tool executed: {result['tool_executed']}")
else:
print(f"❌ API call failed: {response.status_code} - {response.text}")
except Exception as e:
print(f"Error calling API: {e}")
async def main():
"""Run all tests."""
print("🔐 Multi-Cloud OAuth MCP Testing Suite")
print("=" * 60)
# Check if credentials are provided
if user_token == "..." or user_cloud_id == "...":
print("⚠️ Please update user_token and user_cloud_id with your actual credentials")
print(" user_token should be your Bearer token")
print(" user_cloud_id should be your Atlassian Cloud ID")
return
try:
# Test 1: Direct HTTP MCP connection
await test_http_mcp_with_auth()
# Test 2: FastAPI endpoint with authentication
await test_api_with_auth()
print("\n✅ All tests completed!")
except Exception as e:
print(f"❌ Test failed: {e}")
if __name__ == "__main__":
print("Starting OAuth MCP tests...")
asyncio.run(main())