Skip to content

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

bugfix: use PUBLIC_BASE_URL for standalone:dev mode (#392)

Sujai Kumar Gupta5520ca8421f1
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7776ead64..5c884bc7a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -143,6 +143,7 @@ See [`packages/trueforge/.env.example`](packages/trueforge/.env.example) for eve
- `PORT` — API port (default `8790`)
- `FRONTEND_PORT` — Vite UI port in dev (default `3000`); see [`packages/frontend/README.md`](packages/frontend/README.md)
- `VITE_SERVER_URL` — point the Vite proxy at a different API
+- `PUBLIC_BASE_URL` — public origin for MCP OAuth / OIDC callbacks. Required for `pnpm standalone:dev` / `pnpm dev` and for distributed mode (e.g. `http://localhost:3000` for Vite). Non-development standalone falls back to `http://localhost:$PORT`.
- `FRONTEND_DIR` — directory of a built UI for the server to serve
- `SQLITE_PATH` — SQLite file location in standalone mode
- `REDIS_URL` / `POSTGRES_*` — used when `STANDALONE=false`
diff --git a/packages/trueforge/src/config.ts b/packages/trueforge/src/config.ts
index 7db39e5a6..5efb90e46 100644
--- a/packages/trueforge/src/config.ts
+++ b/packages/trueforge/src/config.ts
@@ -397,6 +397,12 @@ export interface SharedServerConfiguration {
* Only used when a Redis client is wired (distributed mode).
*/
REDIS_REQUEST_REPLY_POLL_INTERVAL_MS: number;
+ /**
+ * Public base URL used as the origin of MCP OAuth and OIDC callbacks.
+ * Optional at boot; MCP OAuth and OIDC callback construction fail if empty
+ * outside standalone development. Env: `PUBLIC_BASE_URL`.
+ */
+ PUBLIC_BASE_URL: string;
}
export type StandaloneServerConfiguration = SharedServerConfiguration & {
@@ -428,12 +434,6 @@ 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.
@@ -556,6 +556,7 @@ const shared: SharedServerConfiguration = {
raw: getEnv('REDIS_REQUEST_REPLY_POLL_INTERVAL_MS'),
defaultValue: 500,
}),
+ PUBLIC_BASE_URL: getEnv('PUBLIC_BASE_URL', { defaultValue: '' }) ?? '',
};
const configuration: ServerConfiguration = standalone
@@ -569,7 +570,6 @@ 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',
@@ -598,10 +598,11 @@ export function isOidcConfigured(
/**
* Public origin for OAuth callbacks.
- * Standalone → `http://localhost:$PORT`; distributed → `PUBLIC_BASE_URL` (may be `''`).
+ * Standalone (non-development) → `http://localhost:$PORT`; otherwise `PUBLIC_BASE_URL`
+ * (required in development and distributed; throws if empty).
*/
export function getPublicBaseUrl(config: ServerConfiguration = configuration): string {
- if (config.STANDALONE) {
+ if (config.STANDALONE && config.NODE_ENV !== 'development') {
return `http://localhost:${String(config.PORT)}`;
}
if (config.PUBLIC_BASE_URL === '') {
diff --git a/packages/trueforge/tests/unit/apis/auth.test.ts b/packages/trueforge/tests/unit/apis/auth.test.ts
index b2dc24bc1..1e1c75314 100644
--- a/packages/trueforge/tests/unit/apis/auth.test.ts
+++ b/packages/trueforge/tests/unit/apis/auth.test.ts
@@ -20,14 +20,22 @@ jest.mock('../../../src/config', () => {
const config = {
STANDALONE: false as const,
PUBLIC_BASE_URL: 'https://harness.example.com',
+ NODE_ENV: 'development',
OIDC,
PORT: 8790,
};
return {
__esModule: true,
default: config,
- getPublicBaseUrl: (value = config) =>
- value.STANDALONE ? `http://localhost:${String(value.PORT)}` : value.PUBLIC_BASE_URL,
+ getPublicBaseUrl: (value = config) => {
+ if (value.STANDALONE && value.NODE_ENV !== 'development') {
+ return `http://localhost:${String(value.PORT)}`;
+ }
+ if (value.PUBLIC_BASE_URL === '') {
+ throw new Error('PUBLIC_BASE_URL is required for OIDC callbacks but was empty');
+ }
+ return value.PUBLIC_BASE_URL;
+ },
};
});