#!/bin/bash
# AWS Athena MCP Server - cURL 示例
# 替换 YOUR_API_ENDPOINT 为你的实际 API Gateway 端点
API_ENDPOINT="https://your-api-id.execute-api.us-east-1.amazonaws.com/prod/mcp"
echo "=== 1. 列出所有可用工具 ==="
curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}' | jq '.'
echo -e "\n=== 2. 显示所有数据库 ==="
curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "run_query",
"arguments": {
"database": "default",
"query": "SHOW DATABASES"
}
}
}' | jq '.'
echo -e "\n=== 3. 显示表 ==="
curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "run_query",
"arguments": {
"database": "default",
"query": "SHOW TABLES"
}
}
}' | jq '.'
echo -e "\n=== 4. 查询表结构 ==="
curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "run_query",
"arguments": {
"database": "default",
"query": "DESCRIBE your_table_name"
}
}
}' | jq '.'
echo -e "\n=== 5. 执行 SELECT 查询 ==="
curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 5,
"method": "tools/call",
"params": {
"name": "run_query",
"arguments": {
"database": "default",
"query": "SELECT * FROM your_table_name LIMIT 10",
"maxRows": 10
}
}
}' | jq '.'
echo -e "\n=== 6. 带超时的查询 ==="
QUERY_RESPONSE=$(curl -s -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 6,
"method": "tools/call",
"params": {
"name": "run_query",
"arguments": {
"database": "default",
"query": "SELECT COUNT(*) as total FROM large_table",
"timeoutMs": 5000
}
}
}')
echo "$QUERY_RESPONSE" | jq '.'
# 提取 queryExecutionId(如果查询超时)
QUERY_ID=$(echo "$QUERY_RESPONSE" | jq -r '.result.content[0].text' | jq -r '.queryExecutionId // empty')
if [ ! -z "$QUERY_ID" ]; then
echo -e "\n=== 7. 检查查询状态 ==="
curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d "{
\"jsonrpc\": \"2.0\",
\"id\": 7,
\"method\": \"tools/call\",
\"params\": {
\"name\": \"get_status\",
\"arguments\": {
\"queryExecutionId\": \"$QUERY_ID\"
}
}
}" | jq '.'
echo -e "\n=== 8. 获取查询结果 ==="
curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d "{
\"jsonrpc\": \"2.0\",
\"id\": 8,
\"method\": \"tools/call\",
\"params\": {
\"name\": \"get_result\",
\"arguments\": {
\"queryExecutionId\": \"$QUERY_ID\",
\"maxRows\": 100
}
}
}" | jq '.'
fi
echo -e "\n=== 9. 列出保存的查询 ==="
curl -X POST "$API_ENDPOINT" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 9,
"method": "tools/call",
"params": {
"name": "list_saved_queries",
"arguments": {}
}
}' | jq '.'
echo -e "\n完成!"