()
| 31 | let serverInstance: http.Server | null = null; |
| 32 | |
| 33 | const createServerForOAuth = () => |
| 34 | http.createServer((req, res) => { |
| 35 | try { |
| 36 | if (!req.url) { |
| 37 | throw new Error("no url found"); |
| 38 | } |
| 39 | |
| 40 | const parsedUrl = url.parse(req.url, true); |
| 41 | if (!parsedUrl.query["code"]) { |
| 42 | throw new Error("no query params found"); |
| 43 | } |
| 44 | |
| 45 | const code = parsedUrl.query["code"] as string; |
| 46 | const state = parsedUrl.query["state"] as string | undefined; |
| 47 | |
| 48 | void handleMCPOauthCode(code, state); |
| 49 | |
| 50 | const html = ` |
| 51 | <!DOCTYPE html> |
| 52 | <html> |
| 53 | <head><title>Authentication Complete</title></head> |
| 54 | <body>Authentication Complete. You can close this page now.</body> |
| 55 | </html>`; |
| 56 | |
| 57 | res.writeHead(200, { |
| 58 | "Content-Type": "text/html", |
| 59 | }); |
| 60 | res.end(html); |
| 61 | } catch (error) { |
| 62 | res.writeHead(400, { "Content-Type": "text/plain" }); |
| 63 | res.end(`Unexpected redirect error: ${(error as Error).message}`); |
| 64 | } |
| 65 | }); |
| 66 | |
| 67 | type MCPOauthStorage = GlobalContextType["mcpOauthStorage"][string]; |
| 68 | type MCPOauthStorageKey = keyof MCPOauthStorage; |
no test coverage detected