Skip to content

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

Read public base url from config (#73)

Chirag Jainb316895584ec
diff --git a/AGENTS.md b/AGENTS.md
index 6aae2bf1c..19410bb66 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,5 +1,5 @@
- Workspace tasks MUST use `package.json` scripts; add a script when a missing workflow is repeatable like the existing commands, not ad hoc commands.
-- Release wiring MUST keep dist-free host development, `pnpm smoke`, and packed CJS/ESM consumers of `@truefoundry/utils-core` working without changes in `tfy-llm-gateway` (beyond the package rename from `@truefoundry/utils`).
+- Release wiring MUST keep dist-free host development, `pnpm smoke`, and packed CJS/ESM consumers of `@truefoundry/utils-core` working without changes.
- Shared Postgres/Redis settings in `docker-compose.yml` and `docker-compose.dev.yml` (image versions, health checks, `env_file`) MUST stay synchronized; intentional differences (app services, data paths, project `name`, host ports, in-network `POSTGRES_HOST` / `REDIS_URL`) MUST stay explicit. `packages/server/.env` is the host-dev + secrets source; `docker-compose.yml` may read it but MUST override container connectivity so host-dev localhost values are not used inside the smoke-test stack.
- Changes to types or schemas MUST keep `packages/harness`, `packages/frontend`, `packages/server`, and `patches` synchronized; they MUST NOT update only one affected layer.
- TypeScript code MUST NOT use assertion escapes such as `as T`, `as unknown as T`, non-null `!`, or `as never` to silence type errors; implementations MUST use sound contracts, guards, or corrected types.
@@ -16,3 +16,4 @@
- Functions with more than one parameter of the same type MUST take a single options object (e.g. `f({ a, b }: { a: string; b: string })`); they MUST NOT use multiple positional parameters of that repeated type (e.g. `f(a: string, b: string)`).
- Zod unions MUST use `z.discriminatedUnion` whenever every member carries a shared literal discriminator field; `z.union` is only permitted when no such common discriminator exists.
- HTTP/OpenAPI wire shapes (path params, query params, request/response JSON fields) and database identifiers (table/column names, persisted jsonb document keys) MUST use `snake_case`.
+- Server code MUST NOT read environment variables via `process.env` directly; all env reads MUST go through `packages/server/src/config.ts`, unless there is a documented special requirement (for example bootstrap before config is loaded).
diff --git a/packages/server/src/mcp/auth/mcpOAuthHelpers.ts b/packages/server/src/mcp/auth/mcpOAuthHelpers.ts
index 98644f43b..b33c953d5 100644
--- a/packages/server/src/mcp/auth/mcpOAuthHelpers.ts
+++ b/packages/server/src/mcp/auth/mcpOAuthHelpers.ts
@@ -4,6 +4,7 @@ import type {
OAuthTokens,
} from '@modelcontextprotocol/sdk/shared/auth.js';
import { McpConnectionError } from '@truefoundry/utils-core/core';
+import configuration from '../../config';
import type { OAuthClientCredentials, OAuthServerMetadata, OAuthToken } from './types';
/** Fixed OAuth callback path for every MCP server. */
@@ -14,7 +15,7 @@ export const DEFAULT_MCP_ACCESS_TOKEN_TTL_SECONDS = 3600;
/** Builds the server-owned MCP OAuth callback URL. */
export function mcpOAuthCallbackUrl(): string {
- const publicBaseUrl = process.env['PUBLIC_BASE_URL'] ?? '';
+ const publicBaseUrl = configuration.PUBLIC_BASE_URL;
if (publicBaseUrl === '') {
throw new McpConnectionError('PUBLIC_BASE_URL is required for MCP OAuth registration but was empty', 500);
}
diff --git a/packages/server/tests/unit/mcp/auth/mcpOAuth.test.ts b/packages/server/tests/unit/mcp/auth/mcpOAuth.test.ts
index 34cdbb363..8a775eef8 100644
--- a/packages/server/tests/unit/mcp/auth/mcpOAuth.test.ts
+++ b/packages/server/tests/unit/mcp/auth/mcpOAuth.test.ts
@@ -4,6 +4,7 @@
*/
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,
@@ -38,23 +39,19 @@ const SERVER_ID = 'mcp-server-id-1';
const SERVER_NAME = 'svc';
const realFetch = globalThis.fetch;
-const previousPublicBaseUrl = process.env['PUBLIC_BASE_URL'];
+const previousPublicBaseUrl = configuration.PUBLIC_BASE_URL;
beforeAll(() => {
- process.env['PUBLIC_BASE_URL'] = PUBLIC_BASE_URL;
+ configuration.PUBLIC_BASE_URL = PUBLIC_BASE_URL;
});
afterAll(() => {
- if (previousPublicBaseUrl === undefined) {
- delete process.env['PUBLIC_BASE_URL'];
- } else {
- process.env['PUBLIC_BASE_URL'] = previousPublicBaseUrl;
- }
+ configuration.PUBLIC_BASE_URL = previousPublicBaseUrl;
});
afterEach(() => {
globalThis.fetch = realFetch;
- process.env['PUBLIC_BASE_URL'] = PUBLIC_BASE_URL;
+ configuration.PUBLIC_BASE_URL = PUBLIC_BASE_URL;
});
function json(body: unknown, status = 200): Response {
@@ -300,7 +297,7 @@ describe('createMcpOAuthClient / ensureMcpClientRegistered', () => {
});
it('throws when PUBLIC_BASE_URL is empty (no trimming)', async () => {
- process.env['PUBLIC_BASE_URL'] = '';
+ configuration.PUBLIC_BASE_URL = '';
await expect(
ensureMcpClientRegistered({
mcpServerStore: new InMemoryOAuthClientStore(),