All checks were successful
Build And Test / publish (push) Successful in 48s
88 lines
2.8 KiB
Bash
Executable File
88 lines
2.8 KiB
Bash
Executable File
#!/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/6] Testing health endpoint..."
|
|
HEALTH=$(curl -s "$BASE_URL/health")
|
|
echo "Response: $HEALTH"
|
|
|
|
# Initialize session and capture session ID
|
|
echo -e "\n[2/6] 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/6] 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/6] Getting server info..."
|
|
SERVER_INFO=$(mcp_request 3 "tools/call" '{"name":"get_server_info","arguments":{}}')
|
|
echo "$SERVER_INFO"
|
|
|
|
# List mailboxes
|
|
echo -e "\n[5/7] Listing mailboxes..."
|
|
MAILBOXES=$(mcp_request 4 "tools/call" '{"name":"list_mailboxes","arguments":{}}')
|
|
echo "$MAILBOXES"
|
|
|
|
# List contacts
|
|
echo -e "\n[6/7] Listing contacts..."
|
|
CONTACTS=$(mcp_request 5 "tools/call" '{"name":"list_contacts","arguments":{"limit":10}}')
|
|
echo "$CONTACTS"
|
|
|
|
# Draft a reply (requires REPLY_EMAIL_ID)
|
|
echo -e "\n[7/7] Drafting reply..."
|
|
if [ -n "$REPLY_EMAIL_ID" ]; then
|
|
DRAFT_REPLY=$(mcp_request 6 "tools/call" "{\"name\":\"save_draft\",\"arguments\":{\"in_reply_to_email_id\":\"$REPLY_EMAIL_ID\",\"in_reply_to_mailbox\":\"INBOX\",\"reply_all\":false,\"body\":\"Test reply draft\"}}")
|
|
echo "$DRAFT_REPLY"
|
|
else
|
|
echo "Skipping reply draft: set REPLY_EMAIL_ID to an email UID to test threading"
|
|
fi
|
|
|
|
echo -e "\n================================"
|
|
echo "All tests completed!"
|