Normalize an `oauth` config value: boolean, or an object with grant/scope.
(raw: unknown)
| 48 | |
| 49 | /** Normalize an `oauth` config value: boolean, or an object with grant/scope. */ |
| 50 | function normalizeOAuth(raw: unknown): McpOAuthConfig | undefined { |
| 51 | if (raw === true) return true |
| 52 | if (typeof raw === "string" && raw === "true") return true |
| 53 | if (!isPlainObject(raw)) return undefined |
| 54 | if (raw.grantType === "client_credentials") { |
| 55 | if (typeof raw.clientId !== "string" || typeof raw.clientSecret !== "string") return undefined |
| 56 | return { |
| 57 | grantType: "client_credentials", |
| 58 | clientId: String(raw.clientId), |
| 59 | clientSecret: String(raw.clientSecret), |
| 60 | scope: typeof raw.scope === "string" ? raw.scope : undefined, |
| 61 | } |
| 62 | } |
| 63 | if (raw.grantType === "private_key_jwt") { |
| 64 | if (typeof raw.clientId !== "string") return undefined |
| 65 | if (typeof raw.algorithm !== "string") return undefined |
| 66 | const privateKey = typeof raw.privateKey === "string" ? raw.privateKey : isPlainObject(raw.privateKey) ? raw.privateKey : undefined |
| 67 | if (privateKey === undefined) return undefined |
| 68 | return { |
| 69 | grantType: "private_key_jwt", |
| 70 | clientId: String(raw.clientId), |
| 71 | privateKey, |
| 72 | algorithm: String(raw.algorithm), |
| 73 | scope: typeof raw.scope === "string" ? raw.scope : undefined, |
| 74 | } |
| 75 | } |
| 76 | // Plain object (no grantType) → interactive auth-code flow with optional scope. |
| 77 | return { scope: typeof raw.scope === "string" ? raw.scope : undefined } |
| 78 | } |
| 79 | |
| 80 | /** Validate + normalize a single server config object from disk. */ |
| 81 | function normalizeServerConfig(raw: unknown): McpServerConfig | undefined { |
no test coverage detected