async function main() {
  // 1. Initialize MCP session
  const initRes = await fetch('http://localhost:3456/mcp', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json, text/event-stream',
      'x-api-key': '114521f3f9e6858480d6269446a446ef'
    },
    body: JSON.stringify({
      jsonrpc: '2.0',
      id: 1,
      method: 'initialize',
      params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'test', version: '1.0' } }
    })
  });
  const initData = await initRes.json();
  console.log('Init:', JSON.stringify(initData, null, 2));
  const sessionId = initRes.headers.get('mcp-session-id');
  console.log('Session ID:', sessionId);

  if (!sessionId) {
    console.error('No session ID returned');
    return;
  }

  // 2. Call search_messages for gmail
  const searchRes = await fetch('http://localhost:3456/mcp', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json, text/event-stream',
      'x-api-key': '114521f3f9e6858480d6269446a446ef',
      'mcp-session-id': sessionId
    },
    body: JSON.stringify({
      jsonrpc: '2.0',
      id: 2,
      method: 'tools/call',
      params: {
        name: 'search_messages',
        arguments: { q: 'test', account: 'gmail', maxResults: 3 }
      }
    })
  });
  const searchData = await searchRes.json();
  console.log('Search result:', JSON.stringify(searchData, null, 2));
}
main().catch(console.error);
