(forceRefresh: boolean, externalSignal: AbortSignal)
| 120 | } |
| 121 | |
| 122 | async connectClient(forceRefresh: boolean, externalSignal: AbortSignal) { |
| 123 | if (this.status === "disabled") { |
| 124 | return; |
| 125 | } |
| 126 | if (!forceRefresh) { |
| 127 | // Already connected |
| 128 | if (this.status === "connected") { |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | // Connection is already in progress; wait for it to complete |
| 133 | if (this.connectionPromise) { |
| 134 | await this.connectionPromise; |
| 135 | return; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | this.status = "connecting"; |
| 140 | this.tools = []; |
| 141 | this.prompts = []; |
| 142 | this.resources = []; |
| 143 | this.resourceTemplates = []; |
| 144 | this.errors = []; |
| 145 | this.infos = []; |
| 146 | this.stdioOutput = { stdout: "", stderr: "" }; |
| 147 | |
| 148 | this.abortController.abort(); |
| 149 | this.abortController = new AbortController(); |
| 150 | |
| 151 | // currently support oauth for sse transports only |
| 152 | if (this.options.type === "sse") { |
| 153 | if (!this.options.requestOptions) { |
| 154 | this.options.requestOptions = { |
| 155 | headers: {}, |
| 156 | }; |
| 157 | } |
| 158 | const accessToken = await getOauthToken( |
| 159 | this.options.url, |
| 160 | this.extras?.ide!, |
| 161 | ); |
| 162 | if (accessToken) { |
| 163 | this.isProtectedResource = true; |
| 164 | this.options.requestOptions.headers = { |
| 165 | ...this.options.requestOptions.headers, |
| 166 | Authorization: `Bearer ${accessToken}`, |
| 167 | }; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | const vars = getTemplateVariables(JSON.stringify(this.options)); |
| 172 | const unrendered = vars.map((v) => { |
| 173 | const stripped = v.replace("secrets.", ""); |
| 174 | try { |
| 175 | return decodeSecretLocation(stripped).secretName; |
| 176 | } catch { |
| 177 | return stripped; |
| 178 | } |
| 179 | }); |
no test coverage detected