#!/usr/bin/env sh
set -eu

MCP_URL="${MCP_URL:-https://api.data-apis.com/mcp}"
API_KEY="${MCP_API_KEY:-${SEC_API_KEY:-${DATA_APIS_API_KEY:-}}}"

post_json() {
  label="$1"
  payload="$2"
  mode="${3:-public}"
  printf '\n## %s\n' "$label"
  if [ "$mode" = "auth" ]; then
    curl -sS -X POST "$MCP_URL" \
      -H "Content-Type: application/json" \
      -H "x-api-key: $API_KEY" \
      -d "$payload"
  else
    curl -sS -X POST "$MCP_URL" \
      -H "Content-Type: application/json" \
      -d "$payload"
  fi
  printf '\n'
}

post_json "initialize" '{"jsonrpc":"2.0","id":"eval-initialize","method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"sec-event-intelligence-evaluator","version":"1"}}}'
post_json "tools/list" '{"jsonrpc":"2.0","id":"eval-tools-list","method":"tools/list"}'
post_json "prompts/list" '{"jsonrpc":"2.0","id":"eval-prompts-list","method":"prompts/list"}'
post_json "prompts/get sec_mcp_try_demo" '{"jsonrpc":"2.0","id":"eval-try-demo-prompt","method":"prompts/get","params":{"name":"sec_mcp_try_demo","arguments":{}}}'
post_json "tools/call sec_demo_latest_filings" '{"jsonrpc":"2.0","id":"eval-demo-latest-filings","method":"tools/call","params":{"name":"sec_demo_latest_filings","arguments":{"limit":3}}}'
post_json "tools/call sec_subscription_info" '{"jsonrpc":"2.0","id":"eval-subscription-info","method":"tools/call","params":{"name":"sec_subscription_info","arguments":{}}}'

if [ -n "$API_KEY" ]; then
  post_json "authenticated tools/call sec_latest_filings" '{"jsonrpc":"2.0","id":"eval-auth-latest-filings","method":"tools/call","params":{"name":"sec_latest_filings","arguments":{"limit":3}}}' "auth"
else
  printf '\n## authenticated production sample skipped\n'
  printf 'Set MCP_API_KEY, SEC_API_KEY, or DATA_APIS_API_KEY to run sec_latest_filings with x-api-key.\n'
fi
