Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

DCR auth - fix DB names, fix response schema (#46)

Heer Ambavid11499fda37a
diff --git a/fern/openapi/openapi.json b/fern/openapi/openapi.json
index 923f80f20..1a708e097 100644
--- a/fern/openapi/openapi.json
+++ b/fern/openapi/openapi.json
@@ -527,26 +527,6 @@
],
"type": "object"
},
- "ConfiguredMcpAuthorizeResponse": {
- "properties": {
- "authorization_url": {
- "description": "Present only when status is auth_required.",
- "format": "uri",
- "type": "string"
- },
- "status": {
- "enum": [
- "authenticated",
- "auth_required"
- ],
- "type": "string"
- }
- },
- "required": [
- "status"
- ],
- "type": "object"
- },
"ConfiguredMcpServer": {
"additionalProperties": false,
"properties": {
@@ -1386,14 +1366,15 @@
"additionalProperties": false,
"properties": {
"authorization_url": {
- "description": "Present only when status is auth_required and a live authorize flow produced a URL.",
+ "description": "When auth is required, this contains the URL to redirect the user to for authorization.",
"format": "uri",
"type": "string"
},
"status": {
"enum": [
"authenticated",
- "auth_required"
+ "auth_required",
+ "not_required"
],
"type": "string"
}
@@ -4394,7 +4375,7 @@
},
"/api/v1/settings/mcp-servers/{name}/authorize": {
"get": {
- "description": "For servers without auth or with header credentials, returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is stored for a future FE landing redirect (callback currently returns JSON only).",
+ "description": "For servers without auth returns not_required, and for header credentials returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is stored for a future FE landing redirect (callback currently returns JSON only).",
"parameters": [
{
"description": "Configured MCP server name.",
@@ -4424,7 +4405,7 @@
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/ConfiguredMcpAuthorizeResponse"
+ "$ref": "#/components/schemas/McpAuthStatus"
}
}
},
diff --git a/packages/sdk/.fern/metadata.json b/packages/sdk/.fern/metadata.json
index cdbdd2d0c..e1732ead8 100644
--- a/packages/sdk/.fern/metadata.json
+++ b/packages/sdk/.fern/metadata.json
@@ -26,9 +26,10 @@
"streamType": "web",
"useDefaultRequestParameterValues": true
},
- "originGitCommit": "2b3669cdde6474fd8a7defbb670126df4d0be147",
+ "originGitCommit": "37a4fd4ccf9bbfdd6079a2be14b950617bd0577e",
"originGitCommitIsDirty": true,
- "invokedBy": "manual",
+ "invokedBy": "ci",
"requestedVersion": "0.0.0",
+ "ciProvider": "github",
"sdkVersion": "0.0.0"
}
diff --git a/packages/sdk/reference.md b/packages/sdk/reference.md
index a36c89853..354cab8b8 100644
--- a/packages/sdk/reference.md
+++ b/packages/sdk/reference.md
@@ -1255,7 +1255,7 @@ await client.settings.mcpServers.catalog();
</dl>
</details>
-<details><summary><code>client.settings.mcpServers.<a href="/src/api/resources/settings/resources/mcpServers/client/Client.ts">authorize</a>(name, { ...params }) -> TrueHarness.ConfiguredMcpAuthorizeResponse</code></summary>
+<details><summary><code>client.settings.mcpServers.<a href="/src/api/resources/settings/resources/mcpServers/client/Client.ts">authorize</a>(name, { ...params }) -> TrueHarness.McpAuthStatus</code></summary>
<dl>
<dd>
@@ -1267,7 +1267,7 @@ await client.settings.mcpServers.catalog();
<dl>
<dd>
-For servers without auth or with header credentials, returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is stored for a future FE landing redirect (callback currently returns JSON only).
+For servers without auth returns not_required, and for header credentials returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is stored for a future FE landing redirect (callback currently returns JSON only).
</dd>
</dl>
</dd>
diff --git a/packages/sdk/src/api/resources/settings/resources/mcpServers/client/Client.ts b/packages/sdk/src/api/resources/settings/resources/mcpServers/client/Client.ts
index 302f3125f..4b52208c6 100644
--- a/packages/sdk/src/api/resources/settings/resources/mcpServers/client/Client.ts
+++ b/packages/sdk/src/api/resources/settings/resources/mcpServers/client/Client.ts
@@ -244,7 +244,7 @@ export class McpServersClient {
}
/**
- * For servers without auth or with header credentials, returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is stored for a future FE landing redirect (callback currently returns JSON only).
+ * For servers without auth returns not_required, and for header credentials returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is stored for a future FE landing redirect (callback currently returns JSON only).
*
* @param {string} name - Configured MCP server name.
* @param {TrueHarness.settings.AuthorizeMcpServersRequest} request
@@ -263,7 +263,7 @@ export class McpServersClient {
name: string,
request: TrueHarness.settings.AuthorizeMcpServersRequest = {},
requestOptions?: McpServersClient.RequestOptions,
- ): core.HttpResponsePromise<TrueHarness.ConfiguredMcpAuthorizeResponse> {
+ ): core.HttpResponsePromise<TrueHarness.McpAuthStatus> {
return core.HttpResponsePromise.fromPromise(this.__authorize(name, request, requestOptions));
}
@@ -271,7 +271,7 @@ export class McpServersClient {
name: string,
request: TrueHarness.settings.AuthorizeMcpServersRequest = {},
requestOptions?: McpServersClient.RequestOptions,
- ): Promise<core.WithRawResponse<TrueHarness.ConfiguredMcpAuthorizeResponse>> {
+ ): Promise<core.WithRawResponse<TrueHarness.McpAuthStatus>> {
const { redirectUrl } = request;
const _queryParams: Record<string, unknown> = {
redirect_url: redirectUrl,
@@ -298,7 +298,7 @@ export class McpServersClient {
});
if (_response.ok) {
return {
- data: serializers.ConfiguredMcpAuthorizeResponse.parseOrThrow(_response.body, {
+ data: serializers.McpAuthStatus.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
diff --git a/packages/sdk/src/api/types/ConfiguredMcpAuthorizeResponse.ts b/packages/sdk/src/api/types/ConfiguredMcpAuthorizeResponse.ts
deleted file mode 100644
index 7608b9537..000000000
--- a/packages/sdk/src/api/types/ConfiguredMcpAuthorizeResponse.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-// This file was auto-generated by Fern from our API Definition.
-
-import type * as TrueHarness from "../index.js";
-
-export interface ConfiguredMcpAuthorizeResponse {
- /** Present only when status is auth_required. */
- authorizationUrl?: string;
- status: TrueHarness.ConfiguredMcpAuthorizeResponseStatus;
-}
diff --git a/packages/sdk/src/api/types/ConfiguredMcpAuthorizeResponseStatus.ts b/packages/sdk/src/api/types/ConfiguredMcpAuthorizeResponseStatus.ts
deleted file mode 100644
index 955ad1ac2..000000000
--- a/packages/sdk/src/api/types/ConfiguredMcpAuthorizeResponseStatus.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-// This file was auto-generated by Fern from our API Definition.
-
-export const ConfiguredMcpAuthorizeResponseStatus = {
- Authenticated: "authenticated",
- AuthRequired: "auth_required",
-} as const;
-export type ConfiguredMcpAuthorizeResponseStatus =
- (typeof ConfiguredMcpAuthorizeResponseStatus)[keyof typeof ConfiguredMcpAuthorizeResponseStatus];
diff --git a/packages/sdk/src/api/types/McpAuthStatus.ts b/packages/sdk/src/api/types/McpAuthStatus.ts
index 423b7b050..2c8c0ede9 100644
--- a/packages/sdk/src/api/types/McpAuthStatus.ts
+++ b/packages/sdk/src/api/types/McpAuthStatus.ts
@@ -3,7 +3,7 @@
import type * as TrueHarness from "../index.js";
export interface McpAuthStatus {
- /** Present only when status is auth_required and a live authorize flow produced a URL. */
+ /** When auth is required, this contains the URL to redirect the user to for authorization. */
authorizationUrl?: string;
status: TrueHarness.McpAuthStatusStatus;
}
diff --git a/packages/sdk/src/api/types/McpAuthStatusStatus.ts b/packages/sdk/src/api/types/McpAuthStatusStatus.ts
index b8bd39b92..8383fdc35 100644
--- a/packages/sdk/src/api/types/McpAuthStatusStatus.ts
+++ b/packages/sdk/src/api/types/McpAuthStatusStatus.ts
@@ -3,5 +3,6 @@
export const McpAuthStatusStatus = {
Authenticated: "authenticated",
AuthRequired: "auth_required",
+ NotRequired: "not_required",
} as const;
export type McpAuthStatusStatus = (typeof McpAuthStatusStatus)[keyof typeof McpAuthStatusStatus];
diff --git a/packages/sdk/src/api/types/index.ts b/packages/sdk/src/api/types/index.ts
index 23a90e6c6..5667ea909 100644
--- a/packages/sdk/src/api/types/index.ts
+++ b/packages/sdk/src/api/types/index.ts
@@ -23,8 +23,6 @@ export * from "./ChatCompletionContentPartRefusal.js";
export * from "./ChatCompletionContentPartText.js";
export * from "./ChatCompletionMessageToolCall.js";
export * from "./ChatCompletionMessageToolCallFunction.js";
-export * from "./ConfiguredMcpAuthorizeResponse.js";
-export * from "./ConfiguredMcpAuthorizeResponseStatus.js";
export * from "./ConfiguredMcpServer.js";
export * from "./ConfiguredMcpServerAuth.js";
export * from "./ContextManagementConfig.js";
diff --git a/packages/sdk/src/serialization/types/ConfiguredMcpAuthorizeResponse.ts b/packages/sdk/src/serialization/types/ConfiguredMcpAuthorizeResponse.ts
deleted file mode 100644
index f01233579..000000000
--- a/packages/sdk/src/serialization/types/ConfiguredMcpAuthorizeResponse.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-// This file was auto-generated by Fern from our API Definition.
-
-import type * as TrueHarness from "../../api/index.js";
-import * as core from "../../core/index.js";
-import type * as serializers from "../index.js";
-import { ConfiguredMcpAuthorizeResponseStatus } from "./ConfiguredMcpAuthorizeResponseStatus.js";
-
-export const ConfiguredMcpAuthorizeResponse: core.serialization.ObjectSchema<
- serializers.ConfiguredMcpAuthorizeResponse.Raw,
- TrueHarness.ConfiguredMcpAuthorizeResponse
-> = core.serialization.object({
- authorizationUrl: core.serialization.property("authorization_url", core.serialization.string().optional()),
- status: ConfiguredMcpAuthorizeResponseStatus,
-});
-
-export declare namespace ConfiguredMcpAuthorizeResponse {
- export interface Raw {
- authorization_url?: string | null;
- status: ConfiguredMcpAuthorizeResponseStatus.Raw;
- }
-}
diff --git a/packages/sdk/src/serialization/types/ConfiguredMcpAuthorizeResponseStatus.ts b/packages/sdk/src/serialization/types/ConfiguredMcpAuthorizeResponseStatus.ts
deleted file mode 100644
index dda954c10..000000000
--- a/packages/sdk/src/serialization/types/ConfiguredMcpAuthorizeResponseStatus.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-// This file was auto-generated by Fern from our API Definition.
-
-import type * as TrueHarness from "../../api/index.js";
-import * as core from "../../core/index.js";
-import type * as serializers from "../index.js";
-
-export const ConfiguredMcpAuthorizeResponseStatus: core.serialization.Schema<
- serializers.ConfiguredMcpAuthorizeResponseStatus.Raw,
- TrueHarness.ConfiguredMcpAuthorizeResponseStatus
-> = core.serialization.enum_(["authenticated", "auth_required"]);
-
-export declare namespace ConfiguredMcpAuthorizeResponseStatus {
- export type Raw = "authenticated" | "auth_required";
-}
diff --git a/packages/sdk/src/serialization/types/McpAuthStatusStatus.ts b/packages/sdk/src/serialization/types/McpAuthStatusStatus.ts
index fdd3f680c..b6c1b78e1 100644
--- a/packages/sdk/src/serialization/types/McpAuthStatusStatus.ts
+++ b/packages/sdk/src/serialization/types/McpAuthStatusStatus.ts
@@ -7,8 +7,8 @@ import type * as serializers from "../index.js";
export const McpAuthStatusStatus: core.serialization.Schema<
serializers.McpAuthStatusStatus.Raw,
TrueHarness.McpAuthStatusStatus
-> = core.serialization.enum_(["authenticated", "auth_required"]);
+> = core.serialization.enum_(["authenticated", "auth_required", "not_required"]);
export declare namespace McpAuthStatusStatus {
- export type Raw = "authenticated" | "auth_required";
+ export type Raw = "authenticated" | "auth_required" | "not_required";
}
diff --git a/packages/sdk/src/serialization/types/index.ts b/packages/sdk/src/serialization/types/index.ts
index 23a90e6c6..5667ea909 100644
--- a/packages/sdk/src/serialization/types/index.ts
+++ b/packages/sdk/src/serialization/types/index.ts
@@ -23,8 +23,6 @@ export * from "./ChatCompletionContentPartRefusal.js";
export * from "./ChatCompletionContentPartText.js";
export * from "./ChatCompletionMessageToolCall.js";
export * from "./ChatCompletionMessageToolCallFunction.js";
-export * from "./ConfiguredMcpAuthorizeResponse.js";
-export * from "./ConfiguredMcpAuthorizeResponseStatus.js";
export * from "./ConfiguredMcpServer.js";
export * from "./ConfiguredMcpServerAuth.js";
export * from "./ContextManagementConfig.js";
diff --git a/packages/server/src/apis/mcpServers.ts b/packages/server/src/apis/mcpServers.ts
index 45ecc8bdc..043cd1289 100644
--- a/packages/server/src/apis/mcpServers.ts
+++ b/packages/server/src/apis/mcpServers.ts
@@ -25,7 +25,7 @@ import {
listMcpServerToolsRoute,
putMcpServerRoute,
} from '../routes/mcpServerRoutes';
-import type { ConfiguredMcpServer, McpServerManifest } from '../schemas/mcpServer';
+import type { ConfiguredMcpServer, McpAuthStatus, McpServerManifest } from '../schemas/mcpServer';
import { resolveConfiguredMcpRequestHeaders, resolveMcpAuthStatus } from '../schemas/mcpServer';
import { TENANT_ID } from './sessions';
@@ -54,14 +54,22 @@ function omitUndefinedEntries(obj: Record<string, unknown>): Record<string, unkn
* `token` is the DCR access token stored for this server (keyed by `record.id`), or undefined for
* header/no-auth servers and DCR servers that have never authorized. Only DCR reads it.
*/
-function toConfiguredMcpServer(
- record: McpServerRecord,
- token: OAuthToken | undefined,
- nowMs: number,
-): ConfiguredMcpServer {
+function toConfiguredMcpServer({
+ record,
+ token,
+ nowMs = Date.now(),
+}: {
+ record: McpServerRecord;
+ token: OAuthToken | undefined;
+ nowMs?: number;
+}): ConfiguredMcpServer {
return {
...record.manifest,
- auth_status: resolveMcpAuthStatus(record.manifest, token, nowMs),
+ auth_status: resolveMcpAuthStatus({
+ manifest: record.manifest,
+ ...(token !== undefined ? { token } : {}),
+ nowMs,
+ }),
};
}
@@ -97,7 +105,10 @@ export function createMcpServersRouter(deps: McpServersRouterDeps) {
// Only DCR servers have tokens; batch the lookup.
const dcrIds = records.filter(record => record.manifest.auth?.type === 'dcr').map(record => record.id);
const tokens = await deps.tokenStore.getTokens({ ids: dcrIds });
- return c.json({ data: records.map(record => toConfiguredMcpServer(record, tokens.get(record.id), nowMs)) }, 200);
+ return c.json(
+ { data: records.map(record => toConfiguredMcpServer({ record, token: tokens.get(record.id), nowMs })) },
+ 200,
+ );
};
const putHandler: RouteHandler<typeof putMcpServerRoute> = async c => {
@@ -134,7 +145,7 @@ export function createMcpServersRouter(deps: McpServersRouterDeps) {
}
// A re-upsert preserves `id`, so a DCR server may already carry a token from a prior authorize.
const token = record.manifest.auth?.type === 'dcr' ? await deps.tokenStore.getToken({ id: record.id }) : undefined;
- return c.json({ data: toConfiguredMcpServer(record, token, Date.now()) }, 200);
+ return c.json({ data: toConfiguredMcpServer({ record, token }) }, 200);
};
const listToolsHandler: RouteHandler<typeof listMcpServerToolsRoute> = async c => {
@@ -177,10 +188,11 @@ export function createMcpServersRouter(deps: McpServersRouterDeps) {
if (!record) {
return c.json({ error: { message: `MCP server not found: ${name}` } }, 404);
}
- // Header auth (and no auth): credentials already on the row — no browser flow.
+
if (record.manifest.auth?.type !== 'dcr') {
- return c.json({ status: 'authenticated' as const }, 200);
+ return c.json(resolveMcpAuthStatus({ manifest: record.manifest }), 200);
}
+
try {
if (redirectUrl) {
validateRedirectUris({ redirectUris: [redirectUrl] });
@@ -195,10 +207,10 @@ export function createMcpServersRouter(deps: McpServersRouterDeps) {
clientName: configuration.OAUTH_CLIENT_NAME,
...(redirectUrl !== undefined ? { redirectUrl } : {}),
});
- if (isMcpAuthRequired(result)) {
- return c.json({ status: 'auth_required' as const, authorization_url: result.authUrl.href }, 200);
- }
- return c.json({ status: 'authenticated' as const }, 200);
+ const authStatus: McpAuthStatus = isMcpAuthRequired(result)
+ ? { status: 'auth_required', authorization_url: result.authUrl.href }
+ : { status: 'authenticated' };
+ return c.json(authStatus, 200);
} catch (error) {
if (error instanceof McpConnectionError) {
deps.logger.warn(`MCP authorize failed for "${name}"`, extractErrorLogFields(error));
diff --git a/packages/server/src/db/mcpOAuthTypes.ts b/packages/server/src/db/mcpOAuthTypes.ts
index 4b5b6bb46..a19aaa04a 100644
--- a/packages/server/src/db/mcpOAuthTypes.ts
+++ b/packages/server/src/db/mcpOAuthTypes.ts
@@ -1,12 +1,6 @@
-/**
- * Canonical JSON shapes for MCP OAuth columns (`mcp_server`, `oauth_token`,
- * `oauth_pending_authorization`). Owned by the server DB layer — not the harness.
- *
- * Contract types from `@truefoundry/utils-core/core` happen to match field for field today, so the
- * converters at the bottom are the seam that lets either side change without the other noticing.
- */
import type {
OAuthClientRecord as ContractOAuthClientRecord,
+ OAuthPendingAuthorization as ContractOAuthPendingAuthorization,
OAuthToken as ContractOAuthToken,
} from '@truefoundry/utils-core/core';
@@ -21,48 +15,48 @@ export const PENDING_AUTHORIZATION_TTL_MS = 10 * 60 * 1000;
/** RFC 8414 AS metadata cached at DCR time (`mcp_server.oauth_server`). */
export interface OAuthServer {
- authorizationEndpoint: string;
- tokenEndpoint: string;
- codeChallengeMethodsSupported: string[] | null;
+ authorization_endpoint: string;
+ token_endpoint: string;
+ code_challenge_methods_supported: string[] | null;
}
/** RFC 7591 DCR response (`mcp_server.oauth_client`). */
export interface OAuthClient {
- clientId: string;
- clientSecret: string | null;
+ client_id: string;
+ client_secret: string | null;
}
/** `oauth_pending_authorization.auth_data` JSONB. */
export interface OAuthPendingAuthorizationData {
/** MCP server URL from authorize time — needed by the shared callback for RFC 8707 `resource`. */
- mcpServerUrl: string;
- codeVerifier: string | null;
- redirectUrl: string | null;
+ mcp_server_url: string;
+ code_verifier: string | null;
+ redirect_url: string | null;
}
/** `oauth_token.token` JSONB. */
export interface OAuthToken {
- accessToken: string;
- refreshToken: string | null;
+ access_token: string;
+ refresh_token: string | null;
/** ISO 8601 */
- expiresAt: string;
+ expires_at: string;
scope: string | null;
}
export function toStoredOAuthToken(token: ContractOAuthToken): OAuthToken {
return {
- accessToken: token.accessToken,
- refreshToken: token.refreshToken,
- expiresAt: token.expiresAt,
+ access_token: token.accessToken,
+ refresh_token: token.refreshToken,
+ expires_at: token.expiresAt,
scope: token.scope,
};
}
export function fromStoredOAuthToken(stored: OAuthToken): ContractOAuthToken {
return {
- accessToken: stored.accessToken,
- refreshToken: stored.refreshToken,
- expiresAt: stored.expiresAt,
+ accessToken: stored.access_token,
+ refreshToken: stored.refresh_token,
+ expiresAt: stored.expires_at,
scope: stored.scope,
};
}
@@ -73,13 +67,13 @@ export function toStoredOAuthClientRecord(record: ContractOAuthClientRecord): {
} {
return {
server: {
- authorizationEndpoint: record.server.authorizationEndpoint,
- tokenEndpoint: record.server.tokenEndpoint,
- codeChallengeMethodsSupported: record.server.codeChallengeMethodsSupported,
+ authorization_endpoint: record.server.authorizationEndpoint,
+ token_endpoint: record.server.tokenEndpoint,
+ code_challenge_methods_supported: record.server.codeChallengeMethodsSupported,
},
client: {
- clientId: record.client.clientId,
- clientSecret: record.client.clientSecret,
+ client_id: record.client.clientId,
+ client_secret: record.client.clientSecret,
},
};
}
@@ -90,13 +84,34 @@ export function fromStoredOAuthClientRecord(params: {
}): ContractOAuthClientRecord {
return {
server: {
- authorizationEndpoint: params.server.authorizationEndpoint,
- tokenEndpoint: params.server.tokenEndpoint,
- codeChallengeMethodsSupported: params.server.codeChallengeMethodsSupported,
+ authorizationEndpoint: params.server.authorization_endpoint,
+ tokenEndpoint: params.server.token_endpoint,
+ codeChallengeMethodsSupported: params.server.code_challenge_methods_supported,
},
client: {
- clientId: params.client.clientId,
- clientSecret: params.client.clientSecret,
+ clientId: params.client.client_id,
+ clientSecret: params.client.client_secret,
},
};
}
+
+/** The blob half of a pending authorization; `state`/`id` live in their own columns. */
+export function toStoredOAuthPendingAuthorizationData(
+ pending: ContractOAuthPendingAuthorization,
+): OAuthPendingAuthorizationData {
+ return {
+ mcp_server_url: pending.mcpServerUrl,
+ code_verifier: pending.codeVerifier,
+ redirect_url: pending.redirectUrl,
+ };
+}
+
+export function fromStoredOAuthPendingAuthorizationData(
+ stored: OAuthPendingAuthorizationData,
+): Pick<ContractOAuthPendingAuthorization, 'mcpServerUrl' | 'codeVerifier' | 'redirectUrl'> {
+ return {
+ mcpServerUrl: stored.mcp_server_url,
+ codeVerifier: stored.code_verifier,
+ redirectUrl: stored.redirect_url,
+ };
+}
diff --git a/packages/server/src/db/postgres/token-store/queries/pendingAuthorization.ts b/packages/server/src/db/postgres/token-store/queries/pendingAuthorization.ts
index 2dafbb935..36884ef49 100644
--- a/packages/server/src/db/postgres/token-store/queries/pendingAuthorization.ts
+++ b/packages/server/src/db/postgres/token-store/queries/pendingAuthorization.ts
@@ -1,6 +1,10 @@
import type { OAuthPendingAuthorization } from '@truefoundry/utils-core/core';
import type { Kysely } from 'kysely';
-import { PENDING_AUTHORIZATION_TTL_MS, type OAuthPendingAuthorizationData } from '../../../mcpOAuthTypes';
+import {
+ fromStoredOAuthPendingAuthorizationData,
+ PENDING_AUTHORIZATION_TTL_MS,
+ toStoredOAuthPendingAuthorizationData,
+} from '../../../mcpOAuthTypes';
import { json, now, nowMinusMs } from '../../sqlExpressions';
import type { Database } from '../../types';
@@ -9,11 +13,7 @@ export async function savePendingAuthorization(
pending: OAuthPendingAuthorization,
): Promise<void> {
// `state` and `id` are their own columns; only the remainder goes in the blob.
- const authData: OAuthPendingAuthorizationData = {
- mcpServerUrl: pending.mcpServerUrl,
- codeVerifier: pending.codeVerifier,
- redirectUrl: pending.redirectUrl,
- };
+ const authData = toStoredOAuthPendingAuthorizationData(pending);
await db
.insertInto('oauth_pending_authorization')
@@ -48,8 +48,6 @@ export async function consumePendingAuthorization(
return {
state: row.id,
id: row.oauth_server_id,
- mcpServerUrl: row.auth_data.mcpServerUrl,
- codeVerifier: row.auth_data.codeVerifier,
- redirectUrl: row.auth_data.redirectUrl,
+ ...fromStoredOAuthPendingAuthorizationData(row.auth_data),
};
}
diff --git a/packages/server/src/db/postgres/types.ts b/packages/server/src/db/postgres/types.ts
index 9f70ffda1..e8eef19cb 100644
--- a/packages/server/src/db/postgres/types.ts
+++ b/packages/server/src/db/postgres/types.ts
@@ -339,12 +339,12 @@ export interface McpServerTable {
/** the uniqueness target; also duplicated inside `manifest` */
name: string;
manifest: JSONColumnType<McpServerManifest, McpServerManifest, McpServerManifest>;
- /** OAuthServer — { authorizationEndpoint, tokenEndpoint, codeChallengeMethodsSupported? }.
+ /** OAuthServer — { authorization_endpoint, token_endpoint, code_challenge_methods_supported }.
* RFC 8414 authorization-server metadata, discovered once at registration time.
*/
oauth_server: JSONColumnType<OAuthServer, OAuthServer, OAuthServer> | null;
- /** OAuthClient — { clientId, clientSecret? }. RFC 7591 DCR response.
- * Token auth is form-body (client_secret_post) when clientSecret is set; presence of secret
+ /** OAuthClient — { client_id, client_secret }. RFC 7591 DCR response.
+ * Token auth is form-body (client_secret_post) when client_secret is set; presence of secret
* alone decides the method (same as servicefoundry outbound DCR). Both oauth_server and
* oauth_client are null until first successful DCR.
*/
diff --git a/packages/server/src/db/sqlite/token-store/queries/pendingAuthorization.ts b/packages/server/src/db/sqlite/token-store/queries/pendingAuthorization.ts
index 8df808e8f..7a7ddc060 100644
--- a/packages/server/src/db/sqlite/token-store/queries/pendingAuthorization.ts
+++ b/packages/server/src/db/sqlite/token-store/queries/pendingAuthorization.ts
@@ -1,6 +1,11 @@
import type { OAuthPendingAuthorization } from '@truefoundry/utils-core/core';
import { sql, type Kysely } from 'kysely';
-import { PENDING_AUTHORIZATION_TTL_MS, type OAuthPendingAuthorizationData } from '../../../mcpOAuthTypes';
+import {
+ fromStoredOAuthPendingAuthorizationData,
+ PENDING_AUTHORIZATION_TTL_MS,
+ toStoredOAuthPendingAuthorizationData,
+ type OAuthPendingAuthorizationData,
+} from '../../../mcpOAuthTypes';
import { isoMsAgo, jsonbBind, jsonText, nowIso } from '../../sqlExpressions';
import type { Database } from '../../types';
@@ -9,11 +14,7 @@ export async function savePendingAuthorization(
pending: OAuthPendingAuthorization,
): Promise<void> {
// `state` and `id` are their own columns; only the remainder goes in the blob.
- const authData: OAuthPendingAuthorizationData = {
- mcpServerUrl: pending.mcpServerUrl,
- codeVerifier: pending.codeVerifier,
- redirectUrl: pending.redirectUrl,
- };
+ const authData = toStoredOAuthPendingAuthorizationData(pending);
await db
.insertInto('oauth_pending_authorization')
@@ -48,8 +49,6 @@ export async function consumePendingAuthorization(
return {
state: row.id,
id: row.oauth_server_id,
- mcpServerUrl: row.auth_data.mcpServerUrl,
- codeVerifier: row.auth_data.codeVerifier,
- redirectUrl: row.auth_data.redirectUrl,
+ ...fromStoredOAuthPendingAuthorizationData(row.auth_data),
};
}
diff --git a/packages/server/src/db/sqlite/types.ts b/packages/server/src/db/sqlite/types.ts
index 1ed970a80..d555cca8c 100644
--- a/packages/server/src/db/sqlite/types.ts
+++ b/packages/server/src/db/sqlite/types.ts
@@ -224,7 +224,7 @@ export interface OAuthPendingAuthorizationTable {
id: string;
/** FK -> mcp_server.id, ON DELETE CASCADE */
oauth_server_id: string;
- /** { mcpServerUrl, codeVerifier, redirectUrl } — same writer/lifecycle, so merged into one column */
+ /** { mcp_server_url, code_verifier, redirect_url } — same writer/lifecycle, so merged into one column */
auth_data: JsonbColumn<OAuthPendingAuthorizationData>;
created_at: string;
}
diff --git a/packages/server/src/routes/mcpServerRoutes.ts b/packages/server/src/routes/mcpServerRoutes.ts
index 833291b26..caee59dfc 100644
--- a/packages/server/src/routes/mcpServerRoutes.ts
+++ b/packages/server/src/routes/mcpServerRoutes.ts
@@ -9,6 +9,7 @@ import { GetMcpServerCatalogResponseSchema } from '../schemas/mcpCatalog';
import {
ListAvailableMcpServersResponseSchema,
ListConfiguredMcpServersResponseSchema,
+ McpAuthStatusSchema,
PutMcpServerRequestSchema,
PutMcpServerResponseSchema,
} from '../schemas/mcpServer';
@@ -146,13 +147,6 @@ const McpAuthorizeQuerySchema = z.object({
.describe('Optional FE landing URL after OAuth (stored on pending auth; callback does not redirect yet).'),
});
-const ConfiguredMcpAuthorizeResponseSchema = z
- .object({
- status: z.enum(['authenticated', 'auth_required']),
- authorization_url: z.string().url().optional().describe('Present only when status is auth_required.'),
- })
- .openapi('ConfiguredMcpAuthorizeResponse');
-
export const authorizeConfiguredMcpServerRoute = createRoute({
method: 'get',
path: '/{name}/authorize',
@@ -161,9 +155,9 @@ export const authorizeConfiguredMcpServerRoute = createRoute({
'x-fern-sdk-group-name': ['settings', 'mcpServers'],
'x-fern-sdk-method-name': 'authorize',
description:
- 'For servers without auth or with header credentials, returns authenticated (no browser flow). ' +
- 'For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise ' +
- 'runs DCR if needed and returns auth_required with an authorization URL. ' +
+ 'For servers without auth returns not_required, and for header credentials returns authenticated ' +
+ '(no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token ' +
+ 'exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. ' +
'Optional redirect_url is stored for a future FE landing redirect (callback currently returns JSON only).',
request: {
params: McpServerNameParamsSchema,
@@ -171,7 +165,7 @@ export const authorizeConfiguredMcpServerRoute = createRoute({
},
responses: {
200: {
- content: { 'application/json': { schema: ConfiguredMcpAuthorizeResponseSchema } },
+ content: { 'application/json': { schema: McpAuthStatusSchema } },
description: 'Either already authenticated, or an authorization URL to redirect to.',
},
400: {
diff --git a/packages/server/src/schemas/mcpServer.ts b/packages/server/src/schemas/mcpServer.ts
index f451dc8b6..d366913e7 100644
--- a/packages/server/src/schemas/mcpServer.ts
+++ b/packages/server/src/schemas/mcpServer.ts
@@ -52,12 +52,12 @@ export const McpServerManifestSchema = McpServerManifestObjectSchema.openapi('Mc
export const McpAuthStatusSchema = z
.object({
- status: z.enum(['authenticated', 'auth_required']),
+ status: z.enum(['authenticated', 'auth_required', 'not_required']),
authorization_url: z
.string()
.url()
.optional()
- .describe('Present only when status is auth_required and a live authorize flow produced a URL.'),
+ .describe('When auth is required, this contains the URL to redirect the user to for authorization.'),
})
.strict()
.openapi('McpAuthStatus');
@@ -105,14 +105,21 @@ export function resolveConfiguredMcpRequestHeaders(manifest: McpServerManifest):
return {};
}
-export function resolveMcpAuthStatus(
- manifest: McpServerManifest,
- token: OAuthToken | undefined,
- nowMs: number,
-): McpAuthStatus {
+export function resolveMcpAuthStatus({
+ manifest,
+ token,
+ nowMs = Date.now(),
+}: {
+ manifest: McpServerManifest;
+ token?: OAuthToken;
+ nowMs?: number;
+}): McpAuthStatus {
if (manifest.auth?.type === 'dcr') {
const authenticated = token && isOAuthAccessTokenUsable(token.expiresAt, nowMs);
return authenticated ? { status: 'authenticated' } : { status: 'auth_required' };
}
- return { status: 'authenticated' };
+ if (manifest.auth?.type === 'header') {
+ return { status: 'authenticated' };
+ }
+ return { status: 'not_required' };
}
diff --git a/packages/server/tests/unit/apis/mcpServers.test.ts b/packages/server/tests/unit/apis/mcpServers.test.ts
index 9e947095e..5efdee288 100644
--- a/packages/server/tests/unit/apis/mcpServers.test.ts
+++ b/packages/server/tests/unit/apis/mcpServers.test.ts
@@ -79,17 +79,17 @@ describe('mcp-servers routers', () => {
);
});
- it('PUT upserts a server and returns authenticated auth_status for no-auth servers', async () => {
+ it('PUT upserts a server and returns not_required auth_status for no-auth servers', async () => {
const response = await settingsRouter.request('/', putInit(putBody));
expect(response.status).toBe(200);
expect(await response.json()).toEqual({
- data: { ...putBody, auth_status: { status: 'authenticated' } },
+ data: { ...putBody, auth_status: { status: 'not_required' } },
});
const list = await settingsRouter.request('/');
expect(list.status).toBe(200);
expect(await list.json()).toEqual({
- data: [{ ...putBody, auth_status: { status: 'authenticated' } }],
+ data: [{ ...putBody, auth_status: { status: 'not_required' } }],
});
});
@@ -141,6 +141,32 @@ describe('mcp-servers routers', () => {
await tokenStore.deleteToken({ id: record.id });
});
+ it('PUT re-upsert of a DCR server reports authenticated when a usable token already exists', async () => {
+ // First upsert creates the row (no token yet) so we can key a token off its id.
+ await settingsRouter.request('/', putInit(putBodyWithDcr));
+ const record = await mcpServerStore.getServer({ tenant_id: TENANT_ID, name: putBodyWithDcr.name });
+ if (record === undefined) throw new Error('expected DCR server to exist');
+
+ await tokenStore.saveToken({
+ id: record.id,
+ token: {
+ accessToken: 'access-1',
+ refreshToken: 'refresh-1',
+ expiresAt: '2099-01-01T00:00:00.000Z',
+ scope: null,
+ },
+ });
+
+ // A re-upsert preserves the id, so the PUT response must reflect the carried-over token.
+ const response = await settingsRouter.request('/', putInit(putBodyWithDcr));
+ expect(response.status).toBe(200);
+ expect(await response.json()).toEqual({
+ data: { ...putBodyWithDcr, auth_status: { status: 'authenticated' } },
+ });
+
+ await tokenStore.deleteToken({ id: record.id });
+ });
+
it('PUT with header auth stores headers and reports authenticated', async () => {
const response = await settingsRouter.request('/', putInit(putBodyWithHeaderAuth));
expect(response.status).toBe(200);
@@ -177,9 +203,9 @@ describe('mcp-servers routers', () => {
});
it('GET /{name}/authorize short-circuits non-DCR servers and 404s unknowns', async () => {
- const authenticated = await settingsRouter.request('/deepwiki/authorize?redirect_url=https://example.com/callback');
- expect(authenticated.status).toBe(200);
- expect(await authenticated.json()).toEqual({ status: 'authenticated' });
+ const noAuth = await settingsRouter.request('/deepwiki/authorize?redirect_url=https://example.com/callback');
+ expect(noAuth.status).toBe(200);
+ expect(await noAuth.json()).toEqual({ status: 'not_required' });
const headerAuth = await settingsRouter.request('/private-mcp/authorize?redirect_url=https://example.com/callback');
expect(headerAuth.status).toBe(200);