The open-source agent harness - the runtime layer that turns an LLM into a working agent.
chore [mcp oauth]: support mcp oauth flow for FE (#56)
sayan-truefoundrya483a93e9460
diff --git a/packages/frontend/src/connectorCatalog.ts b/packages/frontend/src/connectorCatalog.tsindex cc73c8bb0..34f700f81 100644--- a/packages/frontend/src/connectorCatalog.ts+++ b/packages/frontend/src/connectorCatalog.ts@@ -2,7 +2,7 @@* Maps trueforge-ui connector-settings calls onto Harness* `/api/v1/settings/mcp-servers` (upsert/list/tools) and `/api/v1/mcp-servers` (authorize).*- * UI: `oauth` / `apiKey` / `none`, connector `id`.+ * UI: `dcr` / `header` / `none`, connector `id`.* Harness: `dcr` / `header` / omitted auth, resource `name`.*/import type {@@ -30,12 +30,11 @@ export function toUiAuthPublic(auth: Harness.ConfiguredMcpServerAuth | undefinedreturn { type: 'none' };}if (auth.type === 'dcr') {- // Public oauth rows require authUrl; Harness only has a URL after authorize.- return { type: 'oauth', authUrl: '' };+ return { type: 'dcr' };}const headerName = Object.keys(auth.headers)[0];return {- type: 'apiKey',+ type: 'header',...(headerName === undefined ? {} : { headerName }),};}@@ -44,7 +43,7 @@ export function toHarnessAuth(auth: ConnectorAuth): Harness.ConfiguredMcpServerAif (auth.type === 'none') {return undefined;}- if (auth.type === 'oauth') {+ if (auth.type === 'dcr') {return { type: 'dcr' };}const apiKey = auth.apiKey?.trim();@@ -110,7 +109,7 @@ async function getConfigured(name: string): Promise<Harness.ConfiguredMcpServer>}async function resolveWriteAuth(req: { id?: string; auth: ConnectorAuth }): Promise<ConnectorAuth> {- if (req.auth.type !== 'apiKey') {+ if (req.auth.type !== 'header') {return req.auth;}const apiKey = req.auth.apiKey?.trim();@@ -134,9 +133,10 @@ async function resolveWriteAuth(req: { id?: string; auth: ConnectorAuth }): Promif (stored === undefined) {throw new Error(`MCP server "${req.id}" has no stored header credentials to reuse`);}- return { type: 'apiKey', apiKey: stored, headerName };+ return { type: 'header', apiKey: stored, headerName };}+/** Settings connector port for `createTrueFoundryServer`. Delete omitted; disconnect unsupported. */export function createConnectorCatalog(): ConnectorCatalogServer<ToolBase,UiConnectorAuth,@@ -184,16 +184,11 @@ export function createConnectorCatalog(): ConnectorCatalogServer<return toUiConnector(body.data);},authenticateConnector: async req => {- const redirectUrl = req.redirectURL ?? `${globalThis.location.origin}${globalThis.location.pathname}`;- const result = await client.mcpServers.authorize(req.id, { redirectUrl });- if (result.status === 'auth_required') {- if (result.authorizationUrl === undefined) {- throw new Error(`Authorization URL missing for MCP server "${req.id}"`);- }- return { authorization_endpoint: result.authorizationUrl };- }- const server = await getConfigured(req.id);- return toUiConnector(server);+ const result = await client.mcpServers.authorize(+ req.id,+ req.redirectURL === undefined ? {} : { redirectUrl: req.redirectURL },+ );+ return { status: result.status, authorization_endpoint: result.authorizationUrl };},disconnectConnector: async req => {const existing = await getConfigured(req.id);diff --git a/packages/frontend/tests/connectorCatalog.test.ts b/packages/frontend/tests/connectorCatalog.test.tsindex 1752e8d13..9fb83d75c 100644--- a/packages/frontend/tests/connectorCatalog.test.ts+++ b/packages/frontend/tests/connectorCatalog.test.ts@@ -12,28 +12,28 @@ import {describe('connectorCatalog mappers', () => {it('maps harness auth to UI public auth without secrets', () => {assert.deepEqual(toUiAuthPublic(undefined), { type: 'none' });- assert.deepEqual(toUiAuthPublic({ type: 'dcr' }), { type: 'oauth', authUrl: '' });+ assert.deepEqual(toUiAuthPublic({ type: 'dcr' }), { type: 'dcr' });assert.deepEqual(toUiAuthPublic({ type: 'header', headers: { Authorization: 'Bearer secret' } }), {- type: 'apiKey',+ type: 'header',headerName: 'Authorization',});});it('maps UI write auth onto harness dcr/header/omit', () => {assert.equal(toHarnessAuth({ type: 'none' }), undefined);- assert.deepEqual(toHarnessAuth({ type: 'oauth' }), { type: 'dcr' });- assert.deepEqual(toHarnessAuth({ type: 'apiKey', apiKey: 'sk-test' }), {+ assert.deepEqual(toHarnessAuth({ type: 'dcr' }), { type: 'dcr' });+ assert.deepEqual(toHarnessAuth({ type: 'header', apiKey: 'sk-test' }), {type: 'header',headers: { Authorization: 'sk-test' },});- assert.deepEqual(toHarnessAuth({ type: 'apiKey', apiKey: 'tok', headerName: 'X-Api-Key' }), {+ assert.deepEqual(toHarnessAuth({ type: 'header', apiKey: 'tok', headerName: 'X-Api-Key' }), {type: 'header',headers: { 'X-Api-Key': 'tok' },});});- it('rejects apiKey auth without a key', () => {- assert.throws(() => toHarnessAuth({ type: 'apiKey' }), /API key is required/i);+ it('rejects header auth without a key', () => {+ assert.throws(() => toHarnessAuth({ type: 'header' }), /API key is required/i);});it('maps catalog presets using name as id', () => {@@ -48,7 +48,7 @@ describe('connectorCatalog mappers', () => {id: 'linear',name: 'linear',url: 'https://mcp.linear.app/mcp',- auth: { type: 'oauth', authUrl: '' },+ auth: { type: 'dcr' },},);});@@ -114,7 +114,7 @@ describe('connectorCatalog mappers', () => {toHarnessManifest({name: 'linear',url: 'https://mcp.linear.app/mcp',- auth: { type: 'oauth' },+ auth: { type: 'dcr' },}),{name: 'linear',diff --git a/packages/trueforge-ui-sdk/example/src/App.tsx b/packages/trueforge-ui-sdk/example/src/App.tsxindex a1dc9b6c2..2aa87584f 100644--- a/packages/trueforge-ui-sdk/example/src/App.tsx+++ b/packages/trueforge-ui-sdk/example/src/App.tsx@@ -29,11 +29,11 @@ function MissingEnv({ missing }: { missing: string[] }) {}function toPublicAuth(auth: ConnectorAuth): ConnectorAuthPublic {- if (auth.type === 'oauth') {- return { type: 'oauth', authUrl: auth.authUrl ?? 'https://example.com/oauth' };+ if (auth.type === 'dcr') {+ return { type: 'dcr', authUrl: auth.authUrl ?? 'https://example.com/oauth' };}- if (auth.type === 'apiKey') {- return { type: 'apiKey', ...(auth.headerName != null ? { headerName: auth.headerName } : {}) };+ if (auth.type === 'header') {+ return { type: 'header', ...(auth.headerName != null ? { headerName: auth.headerName } : {}) };}return { type: 'none' };}@@ -44,14 +44,14 @@ const exampleConnectorCatalog: ConnectorCatalogEntry[] = [name: 'GitHub',description: 'Access repositories, pull requests, and issues.',url: 'https://mcp.example.com/github',- auth: { type: 'oauth', authUrl: 'https://example.com/oauth/github' },+ auth: { type: 'dcr', authUrl: 'https://example.com/oauth/github' },},{id: 'connector-linear',name: 'Linear',description: 'Manage issues and projects.',url: 'https://mcp.example.com/linear',- auth: { type: 'apiKey', headerName: 'Authorization' },+ auth: { type: 'header', headerName: 'Authorization' },},{id: 'connector-filesystem',@@ -153,8 +153,8 @@ const emptyCatalog: CatalogServer = {description: catalogEntry?.description ?? 'Custom MCP server.',url: req.url,auth: toPublicAuth(req.auth),- requiresAuth: req.auth.type === 'oauth',- authenticated: req.auth.type === 'apiKey',+ requiresAuth: req.auth.type === 'dcr',+ authenticated: req.auth.type === 'header',};definedConnectors = [...definedConnectors, connector];return connector;@@ -167,8 +167,8 @@ const emptyCatalog: CatalogServer = {description: current?.description ?? 'Custom MCP server.',url: req.url,auth: toPublicAuth(req.auth),- requiresAuth: req.auth.type === 'oauth',- authenticated: req.auth.type === 'apiKey',+ requiresAuth: req.auth.type === 'dcr',+ authenticated: req.auth.type === 'header',};definedConnectors = definedConnectors.map(item => (item.id === req.id ? connector : item));return connector;diff --git a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/AddMcpServerForm.tsx b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/AddMcpServerForm.tsxindex 95f9b4250..265db8f85 100644--- a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/AddMcpServerForm.tsx+++ b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/AddMcpServerForm.tsx@@ -23,9 +23,9 @@ type AddMcpServerFormProps = {};const AUTH_OPTIONS: Array<{ value: McpAuthType; label: string }> = [- { value: 'oauth', label: 'OAuth' },+ { value: 'dcr', label: 'OAuth' },{ value: 'none', label: 'None' },- { value: 'apiKey', label: 'API Key' },+ { value: 'header', label: 'API Key' },];const inputClassName =@@ -40,14 +40,14 @@ const RequiredMark = () => (const AddMcpServerForm = ({ open, onOpenChange, onAdd, busy = false }: AddMcpServerFormProps) => {const [name, setName] = useState('');const [url, setUrl] = useState('');- const [authType, setAuthType] = useState<McpAuthType>('oauth');+ const [authType, setAuthType] = useState<McpAuthType>('dcr');const [apiKey, setApiKey] = useState('');const [headerName, setHeaderName] = useState('');const resetForm = () => {setName('');setUrl('');- setAuthType('oauth');+ setAuthType('dcr');setApiKey('');setHeaderName('');};@@ -57,16 +57,16 @@ const AddMcpServerForm = ({ open, onOpenChange, onAdd, busy = false }: AddMcpSeronOpenChange(nextOpen);};- const isValid = !!name.trim() && !!url.trim() && (authType !== 'apiKey' || !!apiKey.trim());+ const isValid = !!name.trim() && !!url.trim() && (authType !== 'header' || !!apiKey.trim());const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {event.preventDefault();if (!isValid || busy) return;const auth: ConnectorAuth =- authType === 'apiKey'+ authType === 'header'? {- type: 'apiKey',+ type: 'header',apiKey: apiKey.trim(),...(headerName.trim() ? { headerName: headerName.trim() } : {}),}@@ -171,13 +171,13 @@ const AddMcpServerForm = ({ open, onOpenChange, onAdd, busy = false }: AddMcpSer</div></fieldset>- {authType === 'oauth' ? (+ {authType === 'dcr' ? (<p className="text-sm leading-6 text-muted-foreground">You'll be sent to the provider to authorise this server after adding it.</p>) : null}- {authType === 'apiKey' ? (+ {authType === 'header' ? (<><div><label htmlFor="mcp-server-api-key" className="mb-1.5 block text-sm font-medium text-foreground">diff --git a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/ConnectorDetails.tsx b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/ConnectorDetails.tsxindex d2e3906ab..8e29f605f 100644--- a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/ConnectorDetails.tsx+++ b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/ConnectorDetails.tsx@@ -81,7 +81,7 @@ const ConnectorDetails = ({ connector, onBack, onDisconnect, busy = false }: Con</span></div>- {connector.auth.type === 'oauth' && !connector.requiresAuth ? (+ {connector.auth.type === 'dcr' && !connector.requiresAuth ? (<Button variant="outline" size="sm" type="button" disabled={busy} onClick={onDisconnect}>Disconnect</Button>diff --git a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/ConnectorSettings.tsx b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/ConnectorSettings.tsxindex 1a72e621c..329a76090 100644--- a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/ConnectorSettings.tsx+++ b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/ConnectorSettings.tsx@@ -161,26 +161,26 @@ const ConnectorSettings = () => {const createFromCatalog = async (entry: ConnectorCatalogEntry, authOverride?: ConnectorAuth) => {const auth: ConnectorAuth =authOverride ??- (entry.auth.type === 'apiKey'+ (entry.auth.type === 'header'? {- type: 'apiKey',+ type: 'header',...(entry.auth.headerName ? { headerName: entry.auth.headerName } : {}),}- : entry.auth.type === 'oauth'- ? { type: 'oauth' }+ : entry.auth.type === 'dcr'+ ? { type: 'dcr' }: { type: 'none' });const created = await connectorCatalog.createConnector({name: entry.name,url: entry.url,auth,});- if (auth.type === 'oauth') {+ if (auth.type === 'dcr') {await authorizeOAuthConnector(created.id);}};const handleConnect = (entry: ConnectorCatalogEntry) => {- if (entry.auth.type === 'apiKey') {+ if (entry.auth.type === 'header') {setApiKey('');setConnectorAwaitingKey(entry);return;@@ -204,9 +204,9 @@ const ConnectorSettings = () => {const entry = connectorAwaitingKey;void runMutation(async () => {const auth: ConnectorAuth = {- type: 'apiKey',+ type: 'header',apiKey: apiKey.trim(),- ...(entry.auth.type === 'apiKey' && entry.auth.headerName ? { headerName: entry.auth.headerName } : {}),+ ...(entry.auth.type === 'header' && entry.auth.headerName ? { headerName: entry.auth.headerName } : {}),};const existing = connectors.ordered.find(({ connector }) => connector.id === entry.id);const existingConnector = existing?.isConfigured ? existing.connector : undefined;@@ -231,7 +231,7 @@ const ConnectorSettings = () => {url: draft.url,auth: draft.auth,});- if (draft.auth.type === 'oauth') {+ if (draft.auth.type === 'dcr') {await authorizeOAuthConnector(created.id);}});diff --git a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/authTypeLabels.ts b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/authTypeLabels.tsindex ed98a090d..40efc2c92 100644--- a/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/authTypeLabels.ts+++ b/packages/trueforge-ui-sdk/src/containers/SettingsBuilder/authTypeLabels.ts@@ -1,6 +1,6 @@/** Display labels for connector auth types (catalog + details). */export const AUTH_TYPE_LABELS: Record<string, string> = {- oauth: 'OAuth2',- apiKey: 'API Key',+ dcr: 'OAuth2',+ header: 'API Key',none: 'No Auth',};diff --git a/packages/trueforge-ui-sdk/src/server/ServerContext.test.tsx b/packages/trueforge-ui-sdk/src/server/ServerContext.test.tsxindex 99cb4268b..f04293f33 100644--- a/packages/trueforge-ui-sdk/src/server/ServerContext.test.tsx+++ b/packages/trueforge-ui-sdk/src/server/ServerContext.test.tsx@@ -42,12 +42,12 @@ const catalog: CatalogServer = {description: '',url: req.url,auth:- req.auth.type === 'oauth'- ? { type: 'oauth' as const, authUrl: 'https://example.com/oauth' }- : req.auth.type === 'apiKey'- ? { type: 'apiKey' as const }+ req.auth.type === 'dcr'+ ? { type: 'dcr' as const, authUrl: 'https://example.com/oauth' }+ : req.auth.type === 'header'+ ? { type: 'header' as const }: { type: 'none' as const },- requiresAuth: req.auth.type === 'oauth',+ requiresAuth: req.auth.type === 'dcr',authenticated: false,})),updateConnector: vi.fn(async req => ({@@ -56,12 +56,12 @@ const catalog: CatalogServer = {description: '',url: req.url,auth:- req.auth.type === 'oauth'- ? { type: 'oauth' as const, authUrl: 'https://example.com/oauth' }- : req.auth.type === 'apiKey'- ? { type: 'apiKey' as const }+ req.auth.type === 'dcr'+ ? { type: 'dcr' as const, authUrl: 'https://example.com/oauth' }+ : req.auth.type === 'header'+ ? { type: 'header' as const }: { type: 'none' as const },- requiresAuth: req.auth.type === 'oauth',+ requiresAuth: req.auth.type === 'dcr',authenticated: false,})),authenticateConnector: vi.fn(async ({ id }) => ({@@ -69,7 +69,7 @@ const catalog: CatalogServer = {name: '',description: '',url: '',- auth: { type: 'oauth' as const, authUrl: 'https://example.com/oauth' },+ auth: { type: 'dcr' as const, authUrl: 'https://example.com/oauth' },requiresAuth: false,authenticated: true,})),diff --git a/packages/trueforge-ui-sdk/src/server/createTrueFoundryServer.test.ts b/packages/trueforge-ui-sdk/src/server/createTrueFoundryServer.test.tsindex 2c4d86316..ea54acf45 100644--- a/packages/trueforge-ui-sdk/src/server/createTrueFoundryServer.test.ts+++ b/packages/trueforge-ui-sdk/src/server/createTrueFoundryServer.test.ts@@ -96,12 +96,12 @@ describe('createTrueFoundryServer', () => {description: '',url: req.url,auth:- req.auth.type === 'oauth'- ? { type: 'oauth' as const, authUrl: 'https://example.com/oauth' }- : req.auth.type === 'apiKey'- ? { type: 'apiKey' as const }+ req.auth.type === 'dcr'+ ? { type: 'dcr' as const, authUrl: 'https://example.com/oauth' }+ : req.auth.type === 'header'+ ? { type: 'header' as const }: { type: 'none' as const },- requiresAuth: req.auth.type === 'oauth',+ requiresAuth: req.auth.type === 'dcr',authenticated: false,})),updateConnector: vi.fn(async req => ({@@ -110,12 +110,12 @@ describe('createTrueFoundryServer', () => {description: '',url: req.url,auth:- req.auth.type === 'oauth'- ? { type: 'oauth' as const, authUrl: 'https://example.com/oauth' }- : req.auth.type === 'apiKey'- ? { type: 'apiKey' as const }+ req.auth.type === 'dcr'+ ? { type: 'dcr' as const, authUrl: 'https://example.com/oauth' }+ : req.auth.type === 'header'+ ? { type: 'header' as const }: { type: 'none' as const },- requiresAuth: req.auth.type === 'oauth',+ requiresAuth: req.auth.type === 'dcr',authenticated: false,})),authenticateConnector: vi.fn(async ({ id }) => ({@@ -123,7 +123,7 @@ describe('createTrueFoundryServer', () => {name: '',description: '',url: '',- auth: { type: 'oauth' as const, authUrl: 'https://example.com/oauth' },+ auth: { type: 'dcr' as const, authUrl: 'https://example.com/oauth' },requiresAuth: false,authenticated: true,})),diff --git a/packages/trueforge-ui-sdk/src/server/types.ts b/packages/trueforge-ui-sdk/src/server/types.tsindex 73f9137e4..8f2efa8f2 100644--- a/packages/trueforge-ui-sdk/src/server/types.ts+++ b/packages/trueforge-ui-sdk/src/server/types.ts@@ -431,22 +431,21 @@ export interface ToolBase {}/** Strict auth type id. Hosts widen branches via intersection + re-union. */-export type ConnectorAuthType = 'oauth' | 'apiKey' | 'none';+export type ConnectorAuthType = 'dcr' | 'header' | 'none';// Write (create/update) — export branches so hosts can intersect extras-export type ConnectorAuthOAuth = { type: 'oauth'; authUrl?: string };+export type ConnectorAuthOAuth = { type: 'dcr'; authUrl?: string };export type ConnectorAuthApiKey = {- type: 'apiKey';+ type: 'header';apiKey?: string;headerName?: string;};export type ConnectorAuthNone = { type: 'none' };export type ConnectorAuth = ConnectorAuthOAuth | ConnectorAuthApiKey | ConnectorAuthNone;-// Public (list/detail) — no secrets; oauth requires authUrl-export type ConnectorAuthPublicOAuth = { type: 'oauth'; authUrl: string };+export type ConnectorAuthPublicOAuth = { type: 'dcr'; authUrl?: string };export type ConnectorAuthPublicApiKey = {- type: 'apiKey';+ type: 'header';headerName?: string;};export type ConnectorAuthPublicNone = { type: 'none' };@@ -504,7 +503,7 @@ export interface AuthenticateConnectorRequest {export interface ConnectorAuthenticationResult<TConnector extends ConnectorBase = ConnectorBase> {connector?: TConnector;status?: string;- authorization_endpoint?: string;+ authorization_endpoint?: string | undefined;}export interface ConnectorCatalogServer<