()
| 45 | } |
| 46 | |
| 47 | private async doInitialize(): Promise<void> { |
| 48 | const res = await fetch(`${getBaseUrl()}/mcp`, { |
| 49 | method: "POST", |
| 50 | headers: this.buildHeaders(), |
| 51 | body: JSON.stringify({ |
| 52 | jsonrpc: "2.0", |
| 53 | id: "init", |
| 54 | method: "initialize", |
| 55 | params: { |
| 56 | protocolVersion: "2024-11-05", |
| 57 | capabilities: {}, |
| 58 | clientInfo: { name: "claude-code-web", version: "1.0.0" }, |
| 59 | }, |
| 60 | } satisfies McpRequest), |
| 61 | }); |
| 62 | |
| 63 | if (!res.ok) { |
| 64 | this.initPromise = null; |
| 65 | throw new ApiError(res.status, "MCP session initialization failed"); |
| 66 | } |
| 67 | |
| 68 | this.sessionId = res.headers.get("mcp-session-id"); |
| 69 | |
| 70 | // Send "initialized" notification (fire-and-forget) |
| 71 | if (this.sessionId) { |
| 72 | fetch(`${getBaseUrl()}/mcp`, { |
| 73 | method: "POST", |
| 74 | headers: this.buildHeaders(), |
| 75 | body: JSON.stringify({ |
| 76 | jsonrpc: "2.0", |
| 77 | method: "notifications/initialized", |
| 78 | }), |
| 79 | }).catch(() => { |
| 80 | // non-critical |
| 81 | }); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | private initialize(): Promise<void> { |
| 86 | if (!this.initPromise) { |
no test coverage detected