The open-source agent harness - the runtime layer that turns an LLM into a working agent.
Make the public base uri only required in distributed mode and add scopes in .env.example (#155)
Sujai Kumar Guptae25c0bfe4569
diff --git a/README.md b/README.mdindex 79f31a107..cbddde116 100644--- a/README.md+++ b/README.md@@ -64,11 +64,10 @@ docker compose up --buildThen open [http://localhost:8791](http://localhost:8791).-| Configuration | Default | Description |-| ----------------------------------------------------- | ----------------------- | ---------------------------------------------- |-| `POSTGRES_USER` / `POSTGRES_PASSWORD` / `POSTGRES_DB` | from `.env` | Postgres credentials (`packages/server/.env`). |-| `PUBLIC_BASE_URL` | `http://localhost:8791` | Public origin for MCP OAuth / OIDC callbacks. |-| Host ports | `8791`, `5433`, `6380` | App, Postgres, and Redis. |+| Configuration | Default | Description |+| ----------------------------------------------------- | ---------------------- | ---------------------------------------------- |+| `POSTGRES_USER` / `POSTGRES_PASSWORD` / `POSTGRES_DB` | from `.env` | Postgres credentials (`packages/server/.env`). |+| Host ports | `8791`, `5433`, `6380` | App, Postgres, and Redis. |Every environment variable is documented in [`packages/server/.env.example`](packages/server/.env.example).diff --git a/SECURITY.md b/SECURITY.mdindex 98601dbf0..fac20fda3 100644--- a/SECURITY.md+++ b/SECURITY.md@@ -6,9 +6,7 @@ Please do **not** report security vulnerabilities through public GitHub issues,Instead, report them privately through one of these channels:-<!-- TODO: confirm the security contact email and enable GitHub private vulnerability reporting -->--- Email: **[email protected]**+- Email: **[[email protected]](mailto:[email protected])**- GitHub: use [private vulnerability reporting](#) on this repositoryPlease include as much of the following as you can:diff --git a/charts/truefoundry-utils/README.md b/charts/truefoundry-utils/README.mdindex 204221a5f..532e330d9 100644--- a/charts/truefoundry-utils/README.md+++ b/charts/truefoundry-utils/README.md@@ -166,7 +166,7 @@ extraObjects:| `replicaCount` | `1` | Number of server replicas. || `image.repository` | `tfy.jfrog.io/tfy-images/truefoundry-utils` | Image repository. || `image.tag` | chart `appVersion` | Image tag; stamped on release. |-| `server.publicBaseUrl`| `""` | Public origin for OAuth/OIDC callbacks. |+| `server.publicBaseUrl`| `""` | Public origin for OAuth/OIDC callbacks (optional; required for MCP OAuth / OIDC). || `postgresql.enabled` | `true` | Bundle the Bitnami Postgres subchart. || `redis.enabled` | `true` | Bundle the Bitnami Redis subchart. || `service.type` | `ClusterIP` | Service type. |diff --git a/charts/truefoundry-utils/templates/NOTES.txt b/charts/truefoundry-utils/templates/NOTES.txtindex d297bee19..bcbfabd51 100644--- a/charts/truefoundry-utils/templates/NOTES.txt+++ b/charts/truefoundry-utils/templates/NOTES.txt@@ -15,7 +15,7 @@ Redis: {{ if .Values.redis.enabled }}bundled{{- else }}external (Secret or ur{{- if not .Values.server.publicBaseUrl }}-NOTE: server.publicBaseUrl is empty. MCP OAuth and OIDC callbacks will fail until you set it to the public origin (e.g. https://truefoundry-utils.example.com).+WARNING: server.publicBaseUrl is empty. MCP OAuth and OIDC callbacks will fail until you set it to the public origin (e.g. https://truefoundry-utils.example.com).{{- end }}{{- if and (not .Values.postgresql.enabled) (not .Values.externalPostgres.host) }}diff --git a/charts/truefoundry-utils/values.yaml b/charts/truefoundry-utils/values.yamlindex 329e8191a..28e95a9b0 100644--- a/charts/truefoundry-utils/values.yaml+++ b/charts/truefoundry-utils/values.yaml@@ -46,8 +46,7 @@ service:server:# Container port the server listens on (PORT).port: 8790- # Public origin for MCP OAuth / OIDC callbacks (PUBLIC_BASE_URL). Optional;- # empty string is injected as-is (distributed mode keeps it empty until set).+ # Public origin for MCP OAuth / OIDC callbacks (PUBLIC_BASE_URL).publicBaseUrl: ""# Seconds the server is given to drain turns on SIGTERM (GRACEFUL_TIMEOUT_SECONDS).gracefulTimeoutSeconds: 30diff --git a/docs/quickstart.mdx b/docs/quickstart.mdxindex 7b54a81e1..f37d2f558 100644--- a/docs/quickstart.mdx+++ b/docs/quickstart.mdx@@ -30,15 +30,14 @@ TrueForge runs in [two modes](/introduction#two-ways-to-run-it): **local mode**Then open [http://localhost:8791](http://localhost:8791).- | Configuration | Default | Description |- | ----------------------------------------------------- | ----------------------- | -------------------------------------------------------- |- | `POSTGRES_USER` / `POSTGRES_PASSWORD` / `POSTGRES_DB` | from `.env` | Postgres credentials, read from `packages/server/.env`. |- | `PUBLIC_BASE_URL` | `http://localhost:8791` | Public origin, used for MCP OAuth callbacks. |+ | Configuration | Default | Description |+ | ----------------------------------------------------- | ----------- | -------------------------------------------------------- |+ | `POSTGRES_USER` / `POSTGRES_PASSWORD` / `POSTGRES_DB` | from `.env` | Postgres credentials, read from `packages/server/.env`. || Host ports | `8791`, `5433`, `6380` | App, Postgres, and Redis. |</Tab><Tab title="Hosted mode (Kubernetes)">- The Helm chart deploys the server in hosted mode with bundled Postgres and Redis (or point it at your own). No values are required for a basic install:+ The Helm chart deploys the server in hosted mode with bundled Postgres and Redis (or point it at your own):```bash# TODO: replace <HELM_REPO> with the published Helm repo URL@@ -48,7 +47,6 @@ TrueForge runs in [two modes](/introduction#two-ways-to-run-it): **local mode**| Value | Default | Description || ---------------------- | ------- | ------------------------------------------------------------------------ |- | `server.publicBaseUrl` | `""` | Public origin for MCP OAuth / OIDC callbacks; set once you expose the service. || `replicaCount` | `1` | Number of server replicas (peered over Redis). || `postgresql.enabled` | `true` | Bundle Postgres; set `false` + `externalPostgres.*` to bring your own. || `redis.enabled` | `true` | Bundle Redis; set `false` + `externalRedis.url` or `existingSecret`. |@@ -182,18 +180,6 @@ With TrueForge open in your browser, this walkthrough takes you from an empty wo```</Accordion>- <Accordion title="What is PUBLIC_BASE_URL and when do I need to set it?">- The public origin the server hands to MCP servers for OAuth callbacks. It defaults to `http://localhost:<port>`, which is correct as long as you access TrueForge from the same machine.-- Set it when the server is reachable at a different address — behind a domain, reverse proxy, or on another host:-- ```bash- PUBLIC_BASE_URL=https://agents.example.com npx @truefoundry/trueforge- ```-- In hosted mode, set it in `packages/server/.env` (Docker Compose) or via `server.publicBaseUrl` (Helm).-- </Accordion></AccordionGroup>## Next stepsdiff --git a/packages/server/.env.example b/packages/server/.env.exampleindex 597d1b5af..ac4d7110c 100644--- a/packages/server/.env.example+++ b/packages/server/.env.example@@ -74,11 +74,9 @@ REDIS_URL=redis://localhost:6379## A subscribe request stays open for 10 minutes by default.# TURN_SUBSCRIBE_TIMEOUT_MS=600000-## PUBLIC_BASE_URL — origin of the fixed callback routes for server OIDC and-## MCP OAuth/DCR.-## Standalone (STANDALONE=true): unset/blank → http://localhost:${PORT}.-## Distributed (STANDALONE=false): unset/blank → empty; callbacks fail until set.-# PUBLIC_BASE_URL=http://localhost:8790+## Used when STANDALONE=false (ignored in standalone). Public origin of the+## fixed callback routes for server OIDC and MCP OAuth/DCR.+# PUBLIC_BASE_URL=http://localhost:3000## ---------------------------------------------------------------------------## MCP knobs.@@ -135,5 +133,5 @@ POSTGRES_PORT=5432# OIDC_USER_ROLE_CLAIM=groups## Case-sensitive role value granting admin access. Optional; defaults to "admin".# OIDC_ADMIN_ROLE_VALUE=admin-## Comma-separated OAuth scopes for login. Optional; defaults to "openid,profile,email,groups".+## Comma-separated OAuth scopes for login. Optional; defaults to "openid,profile,email".# OIDC_SCOPES=openid,profile,emaildiff --git a/packages/server/.env.test b/packages/server/.env.testindex 531d915db..210582e41 100644--- a/packages/server/.env.test+++ b/packages/server/.env.test@@ -1,9 +1,8 @@# Dummy values so config.ts loads in unit tests; no service is contacted.-# STANDALONE defaults to true → SQLite (Postgres env below is unused).+# STANDALONE defaults to true → SQLite (Postgres / PUBLIC_BASE_URL unused).POSTGRES_USER=testPOSTGRES_PASSWORD=testPOSTGRES_DB=testPOSTGRES_HOST=localhostPOSTGRES_PORT=5432-PUBLIC_BASE_URL=https://harness.example.comMCP_DCR_OAUTH_CLIENT_NAME=truefoundry-harnessdiff --git a/packages/server/src/auth/cookies.ts b/packages/server/src/auth/cookies.tsindex ad06c016f..16af6e3e5 100644--- a/packages/server/src/auth/cookies.ts+++ b/packages/server/src/auth/cookies.ts@@ -2,7 +2,7 @@ import type { Context } from 'hono';import { deleteCookie, getCookie, setCookie } from 'hono/cookie';import type { Logger } from 'winston';import { z } from 'zod';-import configuration from '../config';+import { getPublicBaseUrl } from '../config';export const OAUTH_STATE_COOKIE = 'oauth_state';export const ID_TOKEN_COOKIE = 'id_token';@@ -15,16 +15,23 @@ const OAuthStateSchema = z.object({export type OAuthState = z.infer<typeof OAuthStateSchema>;-const AUTH_COOKIE_ATTRIBUTES = {- httpOnly: true,- sameSite: 'Lax' as const,- secure: configuration.PUBLIC_BASE_URL.startsWith('https://'),- path: '/',-};+function getAuthCookieAttributes(): {+ httpOnly: boolean;+ sameSite: 'Lax' | 'Strict' | 'None';+ secure: boolean;+ path: string;+} {+ return {+ httpOnly: true,+ sameSite: 'Lax' as const,+ secure: getPublicBaseUrl().startsWith('https://'),+ path: '/',+ };+}export function setAuthCookie(params: { context: Context; name: string; value: string; maxAgeSeconds: number }): void {setCookie(params.context, params.name, params.value, {- ...AUTH_COOKIE_ATTRIBUTES,+ ...getAuthCookieAttributes(),maxAge: params.maxAgeSeconds,});}@@ -51,7 +58,7 @@ export function readOAuthStateCookie(params: { context: Context; logger: Logger}export function clearAuthCookie(params: { context: Context; name: string }): void {- deleteCookie(params.context, params.name, AUTH_COOKIE_ATTRIBUTES);+ deleteCookie(params.context, params.name, getAuthCookieAttributes());}export function readIdTokenCookie(params: { context: Context }): string | undefined {diff --git a/packages/server/src/auth/oidc.ts b/packages/server/src/auth/oidc.tsindex 7504904b6..362bfaad6 100644--- a/packages/server/src/auth/oidc.ts+++ b/packages/server/src/auth/oidc.ts@@ -9,7 +9,7 @@ import {randomPKCECodeVerifier,randomState,} from 'openid-client';-import configuration, { type OIDCConfig } from '../config';+import { getPublicBaseUrl, type OIDCConfig } from '../config';import { buildAuthorizationRequestParams } from './claims';import { ID_TOKEN_COOKIE, OAUTH_STATE_COOKIE, setAuthCookie } from './cookies';@@ -66,10 +66,7 @@ export async function initOidc(oidc: OIDCConfig | undefined): Promise<Configurat}function authCallbackUrl(): string {- const publicBaseUrl = configuration.PUBLIC_BASE_URL;- if (publicBaseUrl === '') {- throw new Error('PUBLIC_BASE_URL is required for OIDC callbacks but was empty');- }+ const publicBaseUrl = getPublicBaseUrl();return `${publicBaseUrl}${CALLBACK_PATH}`;}diff --git a/packages/server/src/config.ts b/packages/server/src/config.tsindex 4002f9914..82c1d7615 100644--- a/packages/server/src/config.ts+++ b/packages/server/src/config.ts@@ -212,27 +212,6 @@ function buildPostgresConnectionString(parts: {return `postgres://${encodeURIComponent(parts.user)}:${encodeURIComponent(parts.password)}@${parts.host}:${String(parts.port)}/${encodeURIComponent(parts.database)}`;}-/**- * Resolves `PUBLIC_BASE_URL` for callback origins (MCP OAuth / OIDC).- * - Non-empty env → that value (not trimmed).- * - Standalone + unset/blank → `http://localhost:${port}` so local boots without an env file.- * - Distributed + unset/blank → `""` (callbacks fail lazily until configured).- */-export function resolvePublicBaseUrl(options: {- port: number;- standalone: boolean;- override: string | undefined;-}): string {- const { port, standalone, override } = options;- if (override !== undefined && override.trim() !== '') {- return override;- }- if (standalone) {- return `http://localhost:${String(port)}`;- }- return '';-}-function resolveOIDCConfig(): OIDCConfig | undefined {const issuerUrl = getEnv('OIDC_ISSUER_URL');const clientId = getEnv('OIDC_CLIENT_ID');@@ -286,7 +265,7 @@ export interface OIDCConfig {*/OIDC_ADMIN_ROLE_VALUE: string;/** Comma-separated OAuth scopes for the authorization request. Env: `OIDC_SCOPES`.- * Optional; defaults to "openid,profile,email,groups". Whitespace around entries is stripped.+ * Optional; defaults to "openid,profile,email". Whitespace around entries is stripped.* Okta `groups` claims require the `groups` scope; Azure AD app roles typically omit it.*/OIDC_SCOPES: string[];@@ -335,14 +314,6 @@ export interface SharedServerConfiguration {MCP_REQUEST_TIMEOUT_MS: number;/** Max milliseconds for an MCP transport connection. Env: `MCP_CONNECT_TIMEOUT_MS`. Default 30 seconds. */MCP_CONNECT_TIMEOUT_MS: number;- /**- * Public base URL of this server used as the origin of MCP OAuth and OIDC- * callbacks. Not trimmed when non-empty.- * Env: `PUBLIC_BASE_URL`.- * Standalone default (unset/blank): `http://localhost:${PORT}`.- * Distributed (unset/blank): `""` — callbacks fail until set.- */- PUBLIC_BASE_URL: string;/*** Client name used for Dynamic Client Registration (DCR) of MCP servers.* This is the client name shown on authorization-server consent screens.@@ -424,6 +395,12 @@ export type DistributedServerConfiguration = SharedServerConfiguration & {* Env: `STANDALONE`. Default: true (so this branch requires an explicit `false`).*/STANDALONE: false;+ /**+ * Public base URL of this server used as the origin of MCP OAuth and OIDC+ * callbacks. Optional at boot; MCP OAuth and OIDC callback construction fail+ * if empty.+ */+ PUBLIC_BASE_URL: string;/*** Postgres connection string derived from `POSTGRES_*` (not read from env directly).* Form: `postgres://USER:PASSWORD@HOST:PORT/DB` with user/password URL-encoded.@@ -480,11 +457,6 @@ const shared: SharedServerConfiguration = {SKILL_CATALOG_PATH: resolveOptionalPathEnv('SKILL_CATALOG_PATH'),SANDBOX_CATALOG_PATH: resolveOptionalPathEnv('SANDBOX_CATALOG_PATH'),FRONTEND_DIR: resolveFrontendDir(),- PUBLIC_BASE_URL: resolvePublicBaseUrl({- port,- standalone,- override: getEnv('PUBLIC_BASE_URL'),- }),MCP_REQUEST_TIMEOUT_MS: parsePositiveInt({envKey: 'MCP_REQUEST_TIMEOUT_MS',@@ -555,6 +527,7 @@ const configuration: ServerConfiguration = standalone: {...shared,STANDALONE: false,+ PUBLIC_BASE_URL: getEnv('PUBLIC_BASE_URL', { defaultValue: '' }) ?? '',DATABASE_URL: resolvePostgresDatabaseUrl(),DATABASE_POOL_MAX: parsePositiveInt({envKey: 'DATABASE_POOL_MAX',@@ -581,4 +554,18 @@ export function isOidcConfigured(return !value.STANDALONE && value.OIDC !== undefined;}+/**+ * Public origin for OAuth callbacks.+ * Standalone → `http://localhost:$PORT`; distributed → `PUBLIC_BASE_URL` (may be `''`).+ */+export function getPublicBaseUrl(config: ServerConfiguration = configuration): string {+ if (config.STANDALONE) {+ return `http://localhost:${String(config.PORT)}`;+ }+ if (config.PUBLIC_BASE_URL === '') {+ throw new Error('PUBLIC_BASE_URL is required for OIDC callbacks but was empty');+ }+ return config.PUBLIC_BASE_URL;+}+export default configuration;diff --git a/packages/server/src/mcp/auth/mcpOAuthHelpers.ts b/packages/server/src/mcp/auth/mcpOAuthHelpers.tsindex b33c953d5..3b28cf627 100644--- a/packages/server/src/mcp/auth/mcpOAuthHelpers.ts+++ b/packages/server/src/mcp/auth/mcpOAuthHelpers.ts@@ -4,7 +4,7 @@ import type {OAuthTokens,} from '@modelcontextprotocol/sdk/shared/auth.js';import { McpConnectionError } from '@truefoundry/utils-core/core';-import configuration from '../../config';+import { getPublicBaseUrl } from '../../config';import type { OAuthClientCredentials, OAuthServerMetadata, OAuthToken } from './types';/** Fixed OAuth callback path for every MCP server. */@@ -15,11 +15,12 @@ export const DEFAULT_MCP_ACCESS_TOKEN_TTL_SECONDS = 3600;/** Builds the server-owned MCP OAuth callback URL. */export function mcpOAuthCallbackUrl(): string {- const publicBaseUrl = configuration.PUBLIC_BASE_URL;- if (publicBaseUrl === '') {+ try {+ const publicBaseUrl = getPublicBaseUrl();+ return `${publicBaseUrl}${MCP_OAUTH_CALLBACK_PATH}`;+ } catch {throw new McpConnectionError('PUBLIC_BASE_URL is required for MCP OAuth registration but was empty', 500);}- return `${publicBaseUrl}${MCP_OAUTH_CALLBACK_PATH}`;}/** Uses form-body client authentication when a secret is present. */diff --git a/packages/server/tests/unit/apis/auth.test.ts b/packages/server/tests/unit/apis/auth.test.tsindex 999f807a6..fee01ddcd 100644--- a/packages/server/tests/unit/apis/auth.test.ts+++ b/packages/server/tests/unit/apis/auth.test.ts@@ -17,14 +17,17 @@ jest.mock('../../../src/config', () => {OIDC_ADMIN_ROLE_VALUE: 'admin',OIDC_SCOPES: ['openid', 'profile', 'email', 'groups'],};+ const config = {+ STANDALONE: false as const,+ PUBLIC_BASE_URL: 'https://harness.example.com',+ OIDC,+ PORT: 8790,+ };return {__esModule: true,- default: {- STANDALONE: false,- PUBLIC_BASE_URL: 'https://harness.example.com',- OIDC,- PORT: 8790,- },+ default: config,+ getPublicBaseUrl: (value = config) =>+ value.STANDALONE ? `http://localhost:${String(value.PORT)}` : value.PUBLIC_BASE_URL,};});diff --git a/packages/server/tests/unit/apis/mcpServers.test.ts b/packages/server/tests/unit/apis/mcpServers.test.tsindex c02e96ca9..446004795 100644--- a/packages/server/tests/unit/apis/mcpServers.test.ts+++ b/packages/server/tests/unit/apis/mcpServers.test.ts@@ -7,6 +7,7 @@ import { migrateSqliteToLatest } from '../../../src/db/migrateSqlite';import { createSqliteDb } from '../../../src/db/sqlite/client';import { SqliteMcpServerStore } from '../../../src/db/sqlite/mcp-server-store/SqliteMcpServerStore';import { SqliteOAuthTokenStore } from '../../../src/db/sqlite/token-store/SqliteOAuthTokenStore';+import { mcpOAuthCallbackUrl } from '../../../src/mcp/auth/mcpOAuthHelpers';const putBody = {type: 'remote' as const,@@ -406,7 +407,7 @@ describe('mcp-servers routers', () => {client_id: 'dyn-client-1',client_secret: 'dyn-secret-1',token_endpoint_auth_method: 'client_secret_post',- redirect_uris: [`${process.env['PUBLIC_BASE_URL'] ?? ''}/api/v1/mcp-servers/oauth/callback`],+ redirect_uris: [mcpOAuthCallbackUrl()],grant_types: ['authorization_code', 'refresh_token'],response_types: ['code'],}),diff --git a/packages/server/tests/unit/config/resolvePublicBaseUrl.test.ts b/packages/server/tests/unit/config/resolvePublicBaseUrl.test.tsdeleted file mode 100644index 3ba0b7703..000000000--- a/packages/server/tests/unit/config/resolvePublicBaseUrl.test.ts+++ /dev/null@@ -1,42 +0,0 @@-import { resolvePublicBaseUrl } from '../../../src/config';--describe('resolvePublicBaseUrl', () => {- it('returns a non-empty override in either mode', () => {- expect(- resolvePublicBaseUrl({- port: 8790,- standalone: true,- override: 'https://example.com',- }),- ).toBe('https://example.com');- expect(- resolvePublicBaseUrl({- port: 8790,- standalone: false,- override: 'https://example.com',- }),- ).toBe('https://example.com');- });-- it('does not trim a non-empty override', () => {- expect(- resolvePublicBaseUrl({- port: 8790,- standalone: false,- override: 'https://example.com/',- }),- ).toBe('https://example.com/');- });-- it('falls back to localhost in standalone when unset or blank', () => {- expect(resolvePublicBaseUrl({ port: 8790, standalone: true, override: undefined })).toBe('http://localhost:8790');- expect(resolvePublicBaseUrl({ port: 8790, standalone: true, override: '' })).toBe('http://localhost:8790');- expect(resolvePublicBaseUrl({ port: 3000, standalone: true, override: ' ' })).toBe('http://localhost:3000');- });-- it('keeps empty string in distributed when unset or blank', () => {- expect(resolvePublicBaseUrl({ port: 8790, standalone: false, override: undefined })).toBe('');- expect(resolvePublicBaseUrl({ port: 8790, standalone: false, override: '' })).toBe('');- expect(resolvePublicBaseUrl({ port: 8790, standalone: false, override: ' ' })).toBe('');- });-});diff --git a/packages/server/tests/unit/mcp/auth/mcpOAuth.test.ts b/packages/server/tests/unit/mcp/auth/mcpOAuth.test.tsindex 35d201f1a..7c0be740d 100644--- a/packages/server/tests/unit/mcp/auth/mcpOAuth.test.ts+++ b/packages/server/tests/unit/mcp/auth/mcpOAuth.test.ts@@ -4,7 +4,6 @@*/import { resourceUrlFromServerUrl } from '@modelcontextprotocol/sdk/shared/auth-utils.js';import { McpConnectionError } from '@truefoundry/utils-core/core';-import configuration from '../../../../src/config';import { InMemoryOAuthClientStore, InMemoryOAuthTokenStore } from '../../../../src/mcp/auth/inMemoryStores';import {buildMcpAuthorizationUrl,@@ -33,7 +32,6 @@ function newStores(): Stores {const withNoTransaction = <T>(callback: (transaction: undefined) => Promise<T>) => callback(undefined);-const PUBLIC_BASE_URL = 'https://harness.example.com';const CLIENT_NAME = 'harness';const SERVER_URL = 'https://mcp.example.com/sse';const AS_ORIGIN = 'https://auth.example.com';@@ -42,19 +40,9 @@ const SERVER_NAME = 'svc';const USER_REF = 'user-a';const realFetch = globalThis.fetch;-const previousPublicBaseUrl = configuration.PUBLIC_BASE_URL;--beforeAll(() => {- configuration.PUBLIC_BASE_URL = PUBLIC_BASE_URL;-});--afterAll(() => {- configuration.PUBLIC_BASE_URL = previousPublicBaseUrl;-});afterEach(() => {globalThis.fetch = realFetch;- configuration.PUBLIC_BASE_URL = PUBLIC_BASE_URL;});function json(body: unknown, status = 200): Response {@@ -311,19 +299,6 @@ describe('createMcpOAuthClient / ensureMcpClientRegistered', () => {expect(registerCallCount()).toBe(2);expect(await mcpServerStore.getClient({ id: SERVER_ID })).toBeUndefined();});-- it('throws when PUBLIC_BASE_URL is empty (no trimming)', async () => {- configuration.PUBLIC_BASE_URL = '';- await expect(- ensureMcpClientRegistered({- mcpServerStore: new InMemoryOAuthClientStore(),- serverId: SERVER_ID,- mcpServerUrl: SERVER_URL,- mcpServerName: SERVER_NAME,- clientName: CLIENT_NAME,- }),- ).rejects.toMatchObject({ message: expect.stringContaining('PUBLIC_BASE_URL') });- });});describe('buildMcpAuthorizationUrl', () => {diff --git a/packages/server/tests/unit/runtime/getMcpConnection.test.ts b/packages/server/tests/unit/runtime/getMcpConnection.test.tsindex ee6831606..a90b28717 100644--- a/packages/server/tests/unit/runtime/getMcpConnection.test.ts+++ b/packages/server/tests/unit/runtime/getMcpConnection.test.ts@@ -4,6 +4,7 @@ import { migrateSqliteToLatest } from '../../../src/db/migrateSqlite';import { createSqliteDb } from '../../../src/db/sqlite/client';import { SqliteMcpServerStore } from '../../../src/db/sqlite/mcp-server-store/SqliteMcpServerStore';import { SqliteOAuthTokenStore } from '../../../src/db/sqlite/token-store/SqliteOAuthTokenStore';+import { mcpOAuthCallbackUrl } from '../../../src/mcp/auth/mcpOAuthHelpers';import { getMcpConnection } from '../../../src/runtime/sessionResources';describe('getMcpConnection', () => {@@ -50,7 +51,7 @@ describe('getMcpConnection', () => {client_id: 'dyn-client-1',client_secret: 'dyn-secret-1',token_endpoint_auth_method: 'client_secret_post',- redirect_uris: [`${process.env['PUBLIC_BASE_URL'] ?? ''}/api/v1/mcp-servers/oauth/callback`],+ redirect_uris: [mcpOAuthCallbackUrl()],grant_types: ['authorization_code', 'refresh_token'],response_types: ['code'],}),