This commit is contained in:
73
test.sh
Executable file
73
test.sh
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# MCP Server Test Script
|
||||||
|
# Usage: API_KEY=your-key ./test.sh [base_url]
|
||||||
|
|
||||||
|
BASE_URL="${1:-https://agentmcp.yigit.run}"
|
||||||
|
MCP_ENDPOINT="$BASE_URL/mcp"
|
||||||
|
|
||||||
|
if [ -z "$API_KEY" ]; then
|
||||||
|
echo "Error: API_KEY environment variable is required"
|
||||||
|
echo "Usage: API_KEY=your-key ./test.sh [base_url]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Testing MCP server at $BASE_URL"
|
||||||
|
echo "================================"
|
||||||
|
|
||||||
|
# Test health endpoint
|
||||||
|
echo -e "\n[1/5] Testing health endpoint..."
|
||||||
|
HEALTH=$(curl -s "$BASE_URL/health")
|
||||||
|
echo "Response: $HEALTH"
|
||||||
|
|
||||||
|
# Initialize session and capture session ID
|
||||||
|
echo -e "\n[2/5] Initializing MCP session..."
|
||||||
|
INIT_RESPONSE=$(curl -s -D - -X POST "$MCP_ENDPOINT" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Accept: application/json, text/event-stream" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test-script","version":"1.0"}}}')
|
||||||
|
|
||||||
|
SESSION_ID=$(echo "$INIT_RESPONSE" | grep -i "mcp-session-id" | cut -d' ' -f2 | tr -d '\r\n')
|
||||||
|
|
||||||
|
if [ -z "$SESSION_ID" ]; then
|
||||||
|
echo "Error: Failed to get session ID"
|
||||||
|
echo "$INIT_RESPONSE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Session ID: $SESSION_ID"
|
||||||
|
echo "$INIT_RESPONSE" | tail -n1
|
||||||
|
|
||||||
|
# Helper function for MCP requests
|
||||||
|
mcp_request() {
|
||||||
|
local id=$1
|
||||||
|
local method=$2
|
||||||
|
local params=$3
|
||||||
|
|
||||||
|
curl -s -X POST "$MCP_ENDPOINT" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Accept: application/json, text/event-stream" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-H "Mcp-Session-Id: $SESSION_ID" \
|
||||||
|
-d "{\"jsonrpc\":\"2.0\",\"id\":$id,\"method\":\"$method\",\"params\":$params}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# List available tools
|
||||||
|
echo -e "\n[3/5] Listing available tools..."
|
||||||
|
TOOLS=$(mcp_request 2 "tools/list" "{}")
|
||||||
|
echo "$TOOLS" | grep -o '"name":"[^"]*"' | head -20 || echo "$TOOLS"
|
||||||
|
|
||||||
|
# Get server info
|
||||||
|
echo -e "\n[4/5] Getting server info..."
|
||||||
|
SERVER_INFO=$(mcp_request 3 "tools/call" '{"name":"get_server_info","arguments":{}}')
|
||||||
|
echo "$SERVER_INFO"
|
||||||
|
|
||||||
|
# List mailboxes
|
||||||
|
echo -e "\n[5/5] Listing mailboxes..."
|
||||||
|
MAILBOXES=$(mcp_request 4 "tools/call" '{"name":"list_mailboxes","arguments":{}}')
|
||||||
|
echo "$MAILBOXES"
|
||||||
|
|
||||||
|
echo -e "\n================================"
|
||||||
|
echo "All tests completed!"
|
||||||
Reference in New Issue
Block a user