(mcpUrl: string, bearer: string)
| 91 | |
| 92 | /** initialize → session id → notifications/initialized, all on the API key. */ |
| 93 | const openSession = async (mcpUrl: string, bearer: string): Promise<string> => { |
| 94 | const initialize = await mcpPost(mcpUrl, { bearer, body: INITIALIZE_REQUEST }); |
| 95 | const sessionId = initialize.headers.get("mcp-session-id"); |
| 96 | await initialize.text(); |
| 97 | if (initialize.status !== 200 || !sessionId) { |
| 98 | throw new Error(`openSession: initialize failed (${initialize.status})`); |
| 99 | } |
| 100 | const initialized = await mcpPost(mcpUrl, { |
| 101 | bearer, |
| 102 | sessionId, |
| 103 | body: INITIALIZED_NOTIFICATION, |
| 104 | }); |
| 105 | await initialized.text(); |
| 106 | if (initialized.status !== 202) { |
| 107 | throw new Error(`openSession: notifications/initialized failed (${initialized.status})`); |
| 108 | } |
| 109 | return sessionId; |
| 110 | }; |
| 111 | |
| 112 | /** One tools/list on an open session; the response must be a real tool list, |
| 113 | * so a validation count of one can never come from requests that bounced at |
no test coverage detected