Skip to content

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

chore: live SFY auth status on single-server GET and mid-turn authorize (#668)

Srajan Asthana1c167805a721
diff --git a/.changeset/tf-mcp-auth-all-modes.md b/.changeset/tf-mcp-auth-all-modes.md
new file mode 100644
index 000000000..9a7aad6c1
--- /dev/null
+++ b/.changeset/tf-mcp-auth-all-modes.md
@@ -0,0 +1,5 @@
+---
+"@truefoundry/trueforge": patch
+---
+
+TrueFoundry MCP: live SFY auth status on single-server GET and mid-turn authorize gating for every auth mode.
diff --git a/packages/trueforge/src/truefoundry/TrueFoundryMcpServerStore.ts b/packages/trueforge/src/truefoundry/TrueFoundryMcpServerStore.ts
index b6badcd1b..0adaed9e8 100644
--- a/packages/trueforge/src/truefoundry/TrueFoundryMcpServerStore.ts
+++ b/packages/trueforge/src/truefoundry/TrueFoundryMcpServerStore.ts
@@ -86,37 +86,34 @@ export class TrueFoundryMcpServerStore<TTransaction = never> implements IMcpServ
this.#perServerHeaders = input.perServerHeaders ?? {};
}
- /** Bearer resolved at connect time plus optional per-server overrides; oauth servers re-check auth first. */
+ /** Gateway Bearer (+ optional per-server overrides); SFY authorize first, else authRequired. */
resolveInvokeHeaders(input: { record: McpServerRecord; userRef: string }): RemoteMcpHeaders {
const { record, userRef } = input;
const headers = async (): Promise<Record<string, string>> => ({
...withoutAuthorization(this.#perServerHeaders[record.name]),
Authorization: `Bearer ${await this.#resolveAccessToken()}`,
});
- if (record.manifest.auth?.type === 'dcr') {
- return async () => {
- const status = await this.authorize({
- tenant_id: record.tenant_id,
- name: record.name,
- userRef,
- });
- if (status.status === 'auth_required') {
- const authUrl = status.authorization_url;
- if (authUrl === undefined || authUrl.length === 0) {
- throw new HTTPException(422, {
- message: `MCP server "${record.name}" requires authentication but returned no authorization URL`,
- });
- }
- return {
- authRequired: {
- servers: [{ id: record.name, name: record.name, auth_url: authUrl }],
- },
- };
+ return async () => {
+ const status = await this.authorize({
+ tenant_id: record.tenant_id,
+ name: record.name,
+ userRef,
+ });
+ if (status.status === 'auth_required') {
+ const authUrl = status.authorization_url;
+ if (authUrl === undefined || authUrl.length === 0) {
+ throw new HTTPException(422, {
+ message: `MCP server "${record.name}" requires authentication but returned no authorization URL`,
+ });
}
- return { headers: await headers() };
- };
- }
- return async () => ({ headers: await headers() });
+ return {
+ authRequired: {
+ servers: [{ id: record.name, name: record.name, auth_url: authUrl }],
+ },
+ };
+ }
+ return { headers: await headers() };
+ };
}
async listServers(input: ListMcpServersInput, transaction?: TTransaction): Promise<McpServerRecord[]> {
@@ -190,28 +187,25 @@ export class TrueFoundryMcpServerStore<TTransaction = never> implements IMcpServ
void input.userRef;
const out = new Map<string, McpAuthStatus>();
- if (input.records.length > 1) {
- for (const record of input.records) {
- out.set(record.name, resolveMcpAuthStatus({ manifest: record.manifest }));
+ // List responses stay stubbed; single-server GET (e.g. GET /mcp-servers/{name}) hits SFY live status
+ // for every auth mode (oauth2, header/env per-user, …).
+ const [record] = input.records;
+ if (record === undefined || input.records.length !== 1) {
+ for (const item of input.records) {
+ out.set(item.name, resolveMcpAuthStatus({ manifest: item.manifest }));
}
return out;
}
- for (const record of input.records) {
- if (record.manifest.auth?.type === 'dcr') {
- out.set(
- record.name,
- await this.#client.getMcpAuthStatus({
- accessToken: await this.#resolveAccessToken(),
- mcpServerId: record.id,
- subjectId: this.#subject.id,
- subjectType: this.#subject.type,
- }),
- );
- continue;
- }
- out.set(record.name, resolveMcpAuthStatus({ manifest: record.manifest }));
- }
+ out.set(
+ record.name,
+ await this.#client.getMcpAuthStatus({
+ accessToken: await this.#resolveAccessToken(),
+ mcpServerId: record.id,
+ subjectId: this.#subject.id,
+ subjectType: this.#subject.type,
+ }),
+ );
return out;
}
diff --git a/packages/trueforge/tests/unit/truefoundry/TrueFoundryMcpServerStore.test.ts b/packages/trueforge/tests/unit/truefoundry/TrueFoundryMcpServerStore.test.ts
index 6f985371c..5b2229562 100644
--- a/packages/trueforge/tests/unit/truefoundry/TrueFoundryMcpServerStore.test.ts
+++ b/packages/trueforge/tests/unit/truefoundry/TrueFoundryMcpServerStore.test.ts
@@ -1,5 +1,5 @@
import { getPublicBaseUrl } from '../../../src/config';
-import { McpServerNotFoundError } from '../../../src/db/mcpServerStore';
+import { McpServerNotFoundError, type McpServerRecord } from '../../../src/db/mcpServerStore';
import { createTrueFoundryRequestContext } from '../../../src/truefoundry/accessToken';
import { MCP_PROXY_BASE_URL_TEMPLATE } from '../../../src/truefoundry/mapSfyMcpServers';
import type { TrueFoundryMcpApiClient } from '../../../src/truefoundry/TrueFoundryMcpServerStore';
@@ -82,6 +82,23 @@ function dcrRecord(overrides: { name?: string } = {}) {
};
}
+function truefoundryRecordWithoutAuth(overrides: { name?: string; id?: string } = {}) {
+ const name = overrides.name ?? 'private-api';
+ return {
+ id: overrides.id ?? 'mcp-id-header',
+ tenant_id: TENANT,
+ name,
+ manifest: {
+ type: 'truefoundry' as const,
+ name,
+ url: `https://gateway.example/mcp-server/${name}`,
+ description: 'Per-user token MCP',
+ },
+ created_at: '2026-01-15T12:00:00.000Z',
+ updated_at: '2026-01-16T12:00:00.000Z',
+ };
+}
+
describe('resolveAuthorizeRedirectURL', () => {
it('builds an absolute FE landing from return_to', () => {
const returnTo = '/?screenType=mcp-auth&pUid=popup-1';
@@ -162,7 +179,7 @@ describe('TrueFoundryMcpServerStore', () => {
expect(statuses.get('slack')).toEqual({ status: 'authenticated' });
});
- it('calls live status for a single record', async () => {
+ it('calls live status for a single dcr record', async () => {
const { store, client } = createStore();
client.getMcpAuthStatus.mockResolvedValue({
status: 'auth_required',
@@ -183,13 +200,30 @@ describe('TrueFoundryMcpServerStore', () => {
authorization_url: 'https://consent.example/authorize',
});
});
+
+ it('calls live status for a single truefoundry record without wire auth', async () => {
+ const { store, client } = createStore();
+ client.getMcpAuthStatus.mockResolvedValue({ status: 'auth_required' });
+ const record = truefoundryRecordWithoutAuth();
+ const statuses = await store.resolveAuthStatuses({
+ records: [record],
+ userRef: 'user-1',
+ });
+ expect(client.getMcpAuthStatus).toHaveBeenCalledWith({
+ accessToken: ACCESS_TOKEN,
+ mcpServerId: record.id,
+ subjectId: 'user-1',
+ subjectType: 'user',
+ });
+ expect(statuses.get(record.name)).toEqual({ status: 'auth_required' });
+ });
});
describe('resolveInvokeHeaders mid-turn', () => {
- async function invoke(store: TrueFoundryMcpServerStore) {
- const headers = store.resolveInvokeHeaders({ record: dcrRecord(), userRef: 'user-1' });
+ async function invoke(store: TrueFoundryMcpServerStore, record: McpServerRecord = dcrRecord()) {
+ const headers = store.resolveInvokeHeaders({ record, userRef: 'user-1' });
if (typeof headers !== 'function') {
- throw new Error('expected async headers resolver for truefoundry+dcr');
+ throw new Error('expected async headers resolver for truefoundry MCP');
}
return headers();
}
@@ -207,6 +241,29 @@ describe('TrueFoundryMcpServerStore', () => {
});
});
+ it('gates non-dcr truefoundry servers through authorize as well', async () => {
+ const { store, client } = createStore();
+ const record = truefoundryRecordWithoutAuth();
+ client.getMcpServerByName.mockResolvedValue({
+ id: record.id,
+ name: record.name,
+ proxyUrl: `${MCP_PROXY_BASE_URL_TEMPLATE}/mcp-server/${record.name}`,
+ createdAt: record.created_at,
+ updatedAt: record.updated_at,
+ manifest: { description: record.manifest.description, auth_data: { type: 'header' } },
+ });
+ client.getMcpAuthorize.mockResolvedValue({
+ status: 'auth_required',
+ authorization_url: 'https://consent.example/auth-override',
+ });
+ await expect(invoke(store, record)).resolves.toEqual({
+ authRequired: {
+ servers: [{ id: record.name, name: record.name, auth_url: 'https://consent.example/auth-override' }],
+ },
+ });
+ expect(client.getMcpAuthorize).toHaveBeenCalled();
+ });
+
it('returns gateway Bearer when authorize reports authenticated', async () => {
const { store } = createStore();
await expect(invoke(store)).resolves.toEqual({
diff --git a/packages/trueforge/tests/unit/truefoundry/perServerMcpHeaders.test.ts b/packages/trueforge/tests/unit/truefoundry/perServerMcpHeaders.test.ts
index 0ed40a21a..f6927ede5 100644
--- a/packages/trueforge/tests/unit/truefoundry/perServerMcpHeaders.test.ts
+++ b/packages/trueforge/tests/unit/truefoundry/perServerMcpHeaders.test.ts
@@ -10,10 +10,17 @@ import {
function unusedClient(): TrueFoundryMcpApiClient {
const unused = (): Promise<never> => Promise.reject(new Error('unused'));
return {
- getMcpServerByName: unused,
+ getMcpServerByName: async ({ name }) => ({
+ id: name,
+ name,
+ proxyUrl: `https://gateway.example/mcp-server/${name}`,
+ createdAt: '2026-01-15T12:00:00.000Z',
+ updatedAt: '2026-01-16T12:00:00.000Z',
+ manifest: { description: name },
+ }),
listMcpServers: unused,
- listGatewayInstallations: unused,
- getMcpAuthorize: unused,
+ listGatewayInstallations: async () => [{ isDefault: true, manifest: { url: 'https://gateway.example' } }],
+ getMcpAuthorize: async () => ({ status: 'authenticated' }),
getMcpAuthStatus: unused,
deleteMcpAuth: unused,
vendToken: () => Promise.resolve('caller-token'),