#!/usr/bin/env python3
"""
Test HTTP response from AgentCore Runtime MCP endpoint.
"""
import asyncio
import httpx
import os
async def test_http_response():
"""Test the HTTP response from AgentCore Runtime."""
# Get the agent ARN
agent_arn = None
if os.path.exists('agent_arn.txt'):
with open('agent_arn.txt', 'r') as f:
agent_arn = f.read().strip()
if not agent_arn:
print("ā Error: agent_arn.txt not found")
return
# Encode ARN for URL
encoded_arn = agent_arn.replace(':', '%3A').replace('/', '%2F')
# Construct the MCP endpoint URL
region = "us-west-2"
mcp_url = f"https://bedrock-agentcore.{region}.amazonaws.com/runtimes/{encoded_arn}/invocations?qualifier=DEFAULT"
print(f"š Testing HTTP response from: {mcp_url}")
# Test with different headers
headers = {
"Content-Type": "application/json",
"Accept": "application/json"
}
try:
async with httpx.AsyncClient() as client:
# Try a simple GET request first
print("š Trying GET request...")
response = await client.get(mcp_url, headers=headers)
print(f"GET Response: {response.status_code}")
print(f"Headers: {dict(response.headers)}")
if response.text:
print(f"Body: {response.text[:500]}...")
# Try a POST request (MCP initialization)
print("\nš Trying POST request...")
mcp_init_payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}
response = await client.post(mcp_url, headers=headers, json=mcp_init_payload)
print(f"POST Response: {response.status_code}")
print(f"Headers: {dict(response.headers)}")
if response.text:
print(f"Body: {response.text[:500]}...")
except Exception as e:
print(f"ā HTTP Error: {e}")
if __name__ == "__main__":
asyncio.run(test_http_response())