Skip to content

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

AGE-1620: Move mcp auth out of swttings (#60)

Sujai Kumar Guptad2e91090005c
diff --git a/fern/openapi/openapi.json b/fern/openapi/openapi.json
index 3c8770537..c25ece2ce 100644
--- a/fern/openapi/openapi.json
+++ b/fern/openapi/openapi.json
@@ -3334,6 +3334,131 @@
"x-fern-ignore": true
}
},
+ "/api/v1/mcp-servers/{name}/authorize": {
+ "delete": {
+ "description": "For auth.type dcr, deletes the stored OAuth token and returns the server with auth_status auth_required, keeping the dynamically registered OAuth client so the next authorize can reuse it. No-op for header or no-auth servers (returns the server unchanged).",
+ "parameters": [
+ {
+ "description": "Configured MCP server name.",
+ "in": "path",
+ "name": "name",
+ "required": true,
+ "schema": {
+ "description": "Configured MCP server name.",
+ "minLength": 1,
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/PutMcpServerResponse"
+ }
+ }
+ },
+ "description": "The MCP server after disconnect (auth_required for dcr)."
+ },
+ "404": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/RequestErrorResponse"
+ }
+ }
+ },
+ "description": "MCP server not found."
+ }
+ },
+ "summary": "Disconnect OAuth for a configured MCP server",
+ "tags": [
+ "MCP Servers"
+ ],
+ "x-fern-sdk-group-name": [
+ "mcpServers"
+ ],
+ "x-fern-sdk-method-name": "delete_authorize"
+ },
+ "get": {
+ "description": "For servers without auth returns not_required, and for header credentials returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is where the OAuth callback then redirects the browser; without it the callback returns JSON.",
+ "parameters": [
+ {
+ "description": "Configured MCP server name.",
+ "in": "path",
+ "name": "name",
+ "required": true,
+ "schema": {
+ "description": "Configured MCP server name.",
+ "minLength": 1,
+ "type": "string"
+ }
+ },
+ {
+ "description": "Optional FE landing URL the OAuth callback redirects to, with `isSuccess`/`reason` appended.",
+ "in": "query",
+ "name": "redirect_url",
+ "required": false,
+ "schema": {
+ "description": "Optional FE landing URL the OAuth callback redirects to, with `isSuccess`/`reason` appended.",
+ "format": "uri",
+ "type": "string"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/McpAuthStatus"
+ }
+ }
+ },
+ "description": "Either already authenticated, or an authorization URL to redirect to."
+ },
+ "400": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/RequestErrorResponse"
+ }
+ }
+ },
+ "description": "DCR or authorize URL construction failed (e.g. server lacks registration_endpoint)."
+ },
+ "404": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/RequestErrorResponse"
+ }
+ }
+ },
+ "description": "MCP server not found."
+ },
+ "500": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/RequestErrorResponse"
+ }
+ }
+ },
+ "description": "Server misconfiguration (e.g. PUBLIC_BASE_URL unset)."
+ }
+ },
+ "summary": "Start (or short-circuit) the auth flow for a configured MCP server",
+ "tags": [
+ "MCP Servers"
+ ],
+ "x-fern-sdk-group-name": [
+ "mcpServers"
+ ],
+ "x-fern-sdk-method-name": "authorize"
+ }
+ },
"/api/v1/models": {
"get": {
"description": "Models across all configured model providers, addressed by fully qualified name `name/model_name`.",
@@ -4367,133 +4492,6 @@
"x-fern-sdk-method-name": "catalog"
}
},
- "/api/v1/settings/mcp-servers/{name}/authorize": {
- "delete": {
- "description": "For auth.type dcr, deletes the stored OAuth token and returns the server with auth_status auth_required, keeping the dynamically registered OAuth client so the next authorize can reuse it. No-op for header or no-auth servers (returns the server unchanged).",
- "parameters": [
- {
- "description": "Configured MCP server name.",
- "in": "path",
- "name": "name",
- "required": true,
- "schema": {
- "description": "Configured MCP server name.",
- "minLength": 1,
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/PutMcpServerResponse"
- }
- }
- },
- "description": "The MCP server after disconnect (auth_required for dcr)."
- },
- "404": {
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/RequestErrorResponse"
- }
- }
- },
- "description": "MCP server not found."
- }
- },
- "summary": "Disconnect OAuth for a configured MCP server",
- "tags": [
- "MCP Servers"
- ],
- "x-fern-sdk-group-name": [
- "settings",
- "mcpServers"
- ],
- "x-fern-sdk-method-name": "delete_authorize"
- },
- "get": {
- "description": "For servers without auth returns not_required, and for header credentials returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is where the OAuth callback then redirects the browser; without it the callback returns JSON.",
- "parameters": [
- {
- "description": "Configured MCP server name.",
- "in": "path",
- "name": "name",
- "required": true,
- "schema": {
- "description": "Configured MCP server name.",
- "minLength": 1,
- "type": "string"
- }
- },
- {
- "description": "Optional FE landing URL the OAuth callback redirects to, with `isSuccess`/`reason` appended.",
- "in": "query",
- "name": "redirect_url",
- "required": false,
- "schema": {
- "description": "Optional FE landing URL the OAuth callback redirects to, with `isSuccess`/`reason` appended.",
- "format": "uri",
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/McpAuthStatus"
- }
- }
- },
- "description": "Either already authenticated, or an authorization URL to redirect to."
- },
- "400": {
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/RequestErrorResponse"
- }
- }
- },
- "description": "DCR or authorize URL construction failed (e.g. server lacks registration_endpoint)."
- },
- "404": {
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/RequestErrorResponse"
- }
- }
- },
- "description": "MCP server not found."
- },
- "500": {
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/RequestErrorResponse"
- }
- }
- },
- "description": "Server misconfiguration (e.g. PUBLIC_BASE_URL unset)."
- }
- },
- "summary": "Start (or short-circuit) the auth flow for a configured MCP server",
- "tags": [
- "MCP Servers"
- ],
- "x-fern-sdk-group-name": [
- "settings",
- "mcpServers"
- ],
- "x-fern-sdk-method-name": "authorize"
- }
- },
"/api/v1/settings/mcp-servers/{name}/tools": {
"get": {
"description": "All tools exposed by the given configured MCP server (non-paginated), as returned by the MCP `tools/list` call.",
diff --git a/packages/frontend/src/connectorCatalog.ts b/packages/frontend/src/connectorCatalog.ts
index 4fc903fc7..181f6a845 100644
--- a/packages/frontend/src/connectorCatalog.ts
+++ b/packages/frontend/src/connectorCatalog.ts
@@ -1,6 +1,6 @@
/**
* Maps agent-ui-sdk connector-settings calls onto Harness
- * `/api/v1/settings/mcp-servers` (name-keyed upsert, authorize; no delete/disconnect).
+ * `/api/v1/settings/mcp-servers` (upsert/list/tools) and `/api/v1/mcp-servers` (authorize).
*
* UI: `oauth` / `apiKey` / `none`, connector `id`.
* Harness: `dcr` / `header` / omitted auth, resource `name`.
@@ -199,7 +199,7 @@ export function createConnectorCatalog(): ConnectorCatalogServer<
},
authenticateConnector: async req => {
const redirectUrl = `${globalThis.location.origin}${globalThis.location.pathname}`;
- const result = await client.settings.mcpServers.authorize(req.id, { redirectUrl });
+ 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}"`);
diff --git a/packages/sdk/.fern/metadata.json b/packages/sdk/.fern/metadata.json
index 744af4f79..d88b2a79e 100644
--- a/packages/sdk/.fern/metadata.json
+++ b/packages/sdk/.fern/metadata.json
@@ -27,9 +27,10 @@
"streamType": "web",
"useDefaultRequestParameterValues": true
},
- "originGitCommit": "c24ef42326caa6104fd615e295fd903d199516c1",
+ "originGitCommit": "fe9595189620be077f6a3a910beaa696525a1482",
"originGitCommitIsDirty": true,
- "invokedBy": "manual",
+ "invokedBy": "ci",
"requestedVersion": "0.0.0",
+ "ciProvider": "github",
"sdkVersion": "0.0.0"
}
diff --git a/packages/sdk/README.md b/packages/sdk/README.md
index 9bb5045e3..806f18f1a 100644
--- a/packages/sdk/README.md
+++ b/packages/sdk/README.md
@@ -62,7 +62,7 @@ following namespace:
```typescript
import { TrueHarness } from "trueharness";
-const request: TrueHarness.ListSessionsRequest = {
+const request: TrueHarness.AuthorizeMcpServersRequest = {
...
};
```
diff --git a/packages/sdk/reference.md b/packages/sdk/reference.md
index 4cdf4d58f..2cfd8c05e 100644
--- a/packages/sdk/reference.md
+++ b/packages/sdk/reference.md
@@ -107,6 +107,140 @@ await client.mcpServers.list();
</dl>
+</dd>
+</dl>
+</details>
+
+<details><summary><code>client.mcpServers.<a href="/src/api/resources/mcpServers/client/Client.ts">authorize</a>(name, { ...params }) -> TrueHarness.McpAuthStatus</code></summary>
+<dl>
+<dd>
+
+#### πŸ“ Description
+
+<dl>
+<dd>
+
+<dl>
+<dd>
+
+For servers without auth returns not_required, and for header credentials returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is where the OAuth callback then redirects the browser; without it the callback returns JSON.
+</dd>
+</dl>
+</dd>
+</dl>
+
+#### πŸ”Œ Usage
+
+<dl>
+<dd>
+
+<dl>
+<dd>
+
+```typescript
+await client.mcpServers.authorize("name");
+
+```
+</dd>
+</dl>
+</dd>
+</dl>
+
+#### βš™οΈ Parameters
+
+<dl>
+<dd>
+
+<dl>
+<dd>
+
+**name:** `string` β€” Configured MCP server name.
+
+</dd>
+</dl>
+
+<dl>
+<dd>
+
+**request:** `TrueHarness.AuthorizeMcpServersRequest`
+
+</dd>
+</dl>
+
+<dl>
+<dd>
+
+**requestOptions:** `McpServersClient.RequestOptions`
+
+</dd>
+</dl>
+</dd>
+</dl>
+
+
+</dd>
+</dl>
+</details>
+
+<details><summary><code>client.mcpServers.<a href="/src/api/resources/mcpServers/client/Client.ts">deleteAuthorize</a>(name) -> TrueHarness.PutMcpServerResponse</code></summary>
+<dl>
+<dd>
+
+#### πŸ“ Description
+
+<dl>
+<dd>
+
+<dl>
+<dd>
+
+For auth.type dcr, deletes the stored OAuth token and returns the server with auth_status auth_required, keeping the dynamically registered OAuth client so the next authorize can reuse it. No-op for header or no-auth servers (returns the server unchanged).
+</dd>
+</dl>
+</dd>
+</dl>
+
+#### πŸ”Œ Usage
+
+<dl>
+<dd>
+
+<dl>
+<dd>
+
+```typescript
+await client.mcpServers.deleteAuthorize("name");
+
+```
+</dd>
+</dl>
+</dd>
+</dl>
+
+#### βš™οΈ Parameters
+
+<dl>
+<dd>
+
+<dl>
+<dd>
+
+**name:** `string` β€” Configured MCP server name.
+
+</dd>
+</dl>
+
+<dl>
+<dd>
+
+**requestOptions:** `McpServersClient.RequestOptions`
+
+</dd>
+</dl>
+</dd>
+</dl>
+
+
</dd>
</dl>
</details>
@@ -1246,140 +1380,6 @@ await client.settings.mcpServers.catalog();
</dl>
-</dd>
-</dl>
-</details>
-
-<details><summary><code>client.settings.mcpServers.<a href="/src/api/resources/settings/resources/mcpServers/client/Client.ts">authorize</a>(name, { ...params }) -> TrueHarness.McpAuthStatus</code></summary>
-<dl>
-<dd>
-
-#### πŸ“ Description
-
-<dl>
-<dd>
-
-<dl>
-<dd>
-
-For servers without auth returns not_required, and for header credentials returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is where the OAuth callback then redirects the browser; without it the callback returns JSON.
-</dd>
-</dl>
-</dd>
-</dl>
-
-#### πŸ”Œ Usage
-
-<dl>
-<dd>
-
-<dl>
-<dd>
-
-```typescript
-await client.settings.mcpServers.authorize("name");
-
-```
-</dd>
-</dl>
-</dd>
-</dl>
-
-#### βš™οΈ Parameters
-
-<dl>
-<dd>
-
-<dl>
-<dd>
-
-**name:** `string` β€” Configured MCP server name.
-
-</dd>
-</dl>
-
-<dl>
-<dd>
-
-**request:** `TrueHarness.settings.AuthorizeMcpServersRequest`
-
-</dd>
-</dl>
-
-<dl>
-<dd>
-
-**requestOptions:** `McpServersClient.RequestOptions`
-
-</dd>
-</dl>
-</dd>
-</dl>
-
-
-</dd>
-</dl>
-</details>
-
-<details><summary><code>client.settings.mcpServers.<a href="/src/api/resources/settings/resources/mcpServers/client/Client.ts">deleteAuthorize</a>(name) -> TrueHarness.PutMcpServerResponse</code></summary>
-<dl>
-<dd>
-
-#### πŸ“ Description
-
-<dl>
-<dd>
-
-<dl>
-<dd>
-
-For auth.type dcr, deletes the stored OAuth token and returns the server with auth_status auth_required, keeping the dynamically registered OAuth client so the next authorize can reuse it. No-op for header or no-auth servers (returns the server unchanged).
-</dd>
-</dl>
-</dd>
-</dl>
-
-#### πŸ”Œ Usage
-
-<dl>
-<dd>
-
-<dl>
-<dd>
-
-```typescript
-await client.settings.mcpServers.deleteAuthorize("name");
-
-```
-</dd>
-</dl>
-</dd>
-</dl>
-
-#### βš™οΈ Parameters
-
-<dl>
-<dd>
-
-<dl>
-<dd>
-
-**name:** `string` β€” Configured MCP server name.
-
-</dd>
-</dl>
-
-<dl>
-<dd>
-
-**requestOptions:** `McpServersClient.RequestOptions`
-
-</dd>
-</dl>
-</dd>
-</dl>
-
-
</dd>
</dl>
</details>
diff --git a/packages/sdk/src/api/resources/index.ts b/packages/sdk/src/api/resources/index.ts
index 95ddeaa69..73368c63a 100644
--- a/packages/sdk/src/api/resources/index.ts
+++ b/packages/sdk/src/api/resources/index.ts
@@ -1,3 +1,4 @@
+export * from "./mcpServers/client/requests/index.js";
export * as mcpServers from "./mcpServers/index.js";
export * as models from "./models/index.js";
export * as server from "./server/index.js";
diff --git a/packages/sdk/src/api/resources/mcpServers/client/Client.ts b/packages/sdk/src/api/resources/mcpServers/client/Client.ts
index b49636a55..f085106a6 100644
--- a/packages/sdk/src/api/resources/mcpServers/client/Client.ts
+++ b/packages/sdk/src/api/resources/mcpServers/client/Client.ts
@@ -7,7 +7,7 @@ import * as core from "../../../../core/index.js";
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.js";
import * as errors from "../../../../errors/index.js";
import * as serializers from "../../../../serialization/index.js";
-import type * as TrueHarness from "../../../index.js";
+import * as TrueHarness from "../../../index.js";
export declare namespace McpServersClient {
export type Options = BaseClientOptions;
@@ -81,4 +81,205 @@ export class McpServersClient {
return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/api/v1/mcp-servers");
}
+
+ /**
+ * For servers without auth returns not_required, and for header credentials returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is where the OAuth callback then redirects the browser; without it the callback returns JSON.
+ *
+ * @param {string} name - Configured MCP server name.
+ * @param {TrueHarness.AuthorizeMcpServersRequest} request
+ * @param {McpServersClient.RequestOptions} requestOptions - Request-specific configuration.
+ *
+ * @throws {@link TrueHarness.BadRequestError}
+ * @throws {@link TrueHarness.NotFoundError}
+ * @throws {@link TrueHarness.InternalServerError}
+ * @throws {@link errors.TrueHarnessError}
+ * @throws {@link errors.TrueHarnessTimeoutError}
+ *
+ * @example
+ * await client.mcpServers.authorize("name")
+ */
+ public authorize(
+ name: string,
+ request: TrueHarness.AuthorizeMcpServersRequest = {},
+ requestOptions?: McpServersClient.RequestOptions,
+ ): core.HttpResponsePromise<TrueHarness.McpAuthStatus> {
+ return core.HttpResponsePromise.fromPromise(this.__authorize(name, request, requestOptions));
+ }
+
+ private async __authorize(
+ name: string,
+ request: TrueHarness.AuthorizeMcpServersRequest = {},
+ requestOptions?: McpServersClient.RequestOptions,
+ ): Promise<core.WithRawResponse<TrueHarness.McpAuthStatus>> {
+ const { redirectUrl } = request;
+ const _queryParams: Record<string, unknown> = {
+ redirect_url: redirectUrl,
+ };
+ const _headers: core.Fetcher.Args["headers"] = mergeHeaders(this._options?.headers, requestOptions?.headers);
+ const _response = await (this._options.fetcher ?? core.fetcher)({
+ url: core.url.join(
+ (await core.Supplier.get(this._options.baseUrl)) ??
+ (await core.Supplier.get(this._options.environment)),
+ `api/v1/mcp-servers/${core.url.encodePathParam(name)}/authorize`,
+ ),
+ method: "GET",
+ headers: _headers,
+ queryString: core.url
+ .queryBuilder()
+ .addMany(_queryParams)
+ .mergeAdditional(requestOptions?.queryParams)
+ .build(),
+ timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
+ maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
+ abortSignal: requestOptions?.abortSignal,
+ fetchFn: this._options?.fetch,
+ logging: this._options.logging,
+ });
+ if (_response.ok) {
+ return {
+ data: serializers.McpAuthStatus.parseOrThrow(_response.body, {
+ unrecognizedObjectKeys: "passthrough",
+ allowUnrecognizedUnionMembers: true,
+ allowUnrecognizedEnumValues: true,
+ skipValidation: true,
+ breadcrumbsPrefix: ["response"],
+ }),
+ rawResponse: _response.rawResponse,
+ };
+ }
+
+ if (_response.error.reason === "status-code") {
+ switch (_response.error.statusCode) {
+ case 400:
+ throw new TrueHarness.BadRequestError(
+ serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
+ unrecognizedObjectKeys: "passthrough",
+ allowUnrecognizedUnionMembers: true,
+ allowUnrecognizedEnumValues: true,
+ skipValidation: true,
+ breadcrumbsPrefix: ["response"],
+ }),
+ _response.rawResponse,
+ );
+ case 404:
+ throw new TrueHarness.NotFoundError(
+ serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
+ unrecognizedObjectKeys: "passthrough",
+ allowUnrecognizedUnionMembers: true,
+ allowUnrecognizedEnumValues: true,
+ skipValidation: true,
+ breadcrumbsPrefix: ["response"],
+ }),
+ _response.rawResponse,
+ );
+ case 500:
+ throw new TrueHarness.InternalServerError(
+ serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
+ unrecognizedObjectKeys: "passthrough",
+ allowUnrecognizedUnionMembers: true,
+ allowUnrecognizedEnumValues: true,
+ skipValidation: true,
+ breadcrumbsPrefix: ["response"],
+ }),
+ _response.rawResponse,
+ );
+ default:
+ throw new errors.TrueHarnessError({
+ statusCode: _response.error.statusCode,
+ body: _response.error.body,
+ rawResponse: _response.rawResponse,
+ });
+ }
+ }
+
+ return handleNonStatusCodeError(
+ _response.error,
+ _response.rawResponse,
+ "GET",
+ "/api/v1/mcp-servers/{name}/authorize",
+ );
+ }
+
+ /**
+ * For auth.type dcr, deletes the stored OAuth token and returns the server with auth_status auth_required, keeping the dynamically registered OAuth client so the next authorize can reuse it. No-op for header or no-auth servers (returns the server unchanged).
+ *
+ * @param {string} name - Configured MCP server name.
+ * @param {McpServersClient.RequestOptions} requestOptions - Request-specific configuration.
+ *
+ * @throws {@link TrueHarness.NotFoundError}
+ * @throws {@link errors.TrueHarnessError}
+ * @throws {@link errors.TrueHarnessTimeoutError}
+ *
+ * @example
+ * await client.mcpServers.deleteAuthorize("name")
+ */
+ public deleteAuthorize(
+ name: string,
+ requestOptions?: McpServersClient.RequestOptions,
+ ): core.HttpResponsePromise<TrueHarness.PutMcpServerResponse> {
+ return core.HttpResponsePromise.fromPromise(this.__deleteAuthorize(name, requestOptions));
+ }
+
+ private async __deleteAuthorize(
+ name: string,
+ requestOptions?: McpServersClient.RequestOptions,
+ ): Promise<core.WithRawResponse<TrueHarness.PutMcpServerResponse>> {
+ const _headers: core.Fetcher.Args["headers"] = mergeHeaders(this._options?.headers, requestOptions?.headers);
+ const _response = await (this._options.fetcher ?? core.fetcher)({
+ url: core.url.join(
+ (await core.Supplier.get(this._options.baseUrl)) ??
+ (await core.Supplier.get(this._options.environment)),
+ `api/v1/mcp-servers/${core.url.encodePathParam(name)}/authorize`,
+ ),
+ method: "DELETE",
+ headers: _headers,
+ queryString: core.url.queryBuilder().mergeAdditional(requestOptions?.queryParams).build(),
+ timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
+ maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
+ abortSignal: requestOptions?.abortSignal,
+ fetchFn: this._options?.fetch,
+ logging: this._options.logging,
+ });
+ if (_response.ok) {
+ return {
+ data: serializers.PutMcpServerResponse.parseOrThrow(_response.body, {
+ unrecognizedObjectKeys: "passthrough",
+ allowUnrecognizedUnionMembers: true,
+ allowUnrecognizedEnumValues: true,
+ skipValidation: true,
+ breadcrumbsPrefix: ["response"],
+ }),
+ rawResponse: _response.rawResponse,
+ };
+ }
+
+ if (_response.error.reason === "status-code") {
+ switch (_response.error.statusCode) {
+ case 404:
+ throw new TrueHarness.NotFoundError(
+ serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
+ unrecognizedObjectKeys: "passthrough",
+ allowUnrecognizedUnionMembers: true,
+ allowUnrecognizedEnumValues: true,
+ skipValidation: true,
+ breadcrumbsPrefix: ["response"],
+ }),
+ _response.rawResponse,
+ );
+ default:
+ throw new errors.TrueHarnessError({
+ statusCode: _response.error.statusCode,
+ body: _response.error.body,
+ rawResponse: _response.rawResponse,
+ });
+ }
+ }
+
+ return handleNonStatusCodeError(
+ _response.error,
+ _response.rawResponse,
+ "DELETE",
+ "/api/v1/mcp-servers/{name}/authorize",
+ );
+ }
}
diff --git a/packages/sdk/src/api/resources/mcpServers/client/index.ts b/packages/sdk/src/api/resources/mcpServers/client/index.ts
index cb0ff5c3b..195f9aa8a 100644
--- a/packages/sdk/src/api/resources/mcpServers/client/index.ts
+++ b/packages/sdk/src/api/resources/mcpServers/client/index.ts
@@ -1 +1 @@
-export {};
+export * from "./requests/index.js";
diff --git a/packages/sdk/src/api/resources/settings/resources/mcpServers/client/requests/AuthorizeMcpServersRequest.ts b/packages/sdk/src/api/resources/mcpServers/client/requests/AuthorizeMcpServersRequest.ts
similarity index 100%
rename from packages/sdk/src/api/resources/settings/resources/mcpServers/client/requests/AuthorizeMcpServersRequest.ts
rename to packages/sdk/src/api/resources/mcpServers/client/requests/AuthorizeMcpServersRequest.ts
diff --git a/packages/sdk/src/api/resources/mcpServers/client/requests/index.ts b/packages/sdk/src/api/resources/mcpServers/client/requests/index.ts
new file mode 100644
index 000000000..9f3c48ef4
--- /dev/null
+++ b/packages/sdk/src/api/resources/mcpServers/client/requests/index.ts
@@ -0,0 +1 @@
+export type { AuthorizeMcpServersRequest } from "./AuthorizeMcpServersRequest.js";
diff --git a/packages/sdk/src/api/resources/settings/resources/mcpServers/client/Client.ts b/packages/sdk/src/api/resources/settings/resources/mcpServers/client/Client.ts
index a8bfe7e9e..deb28c6e3 100644
--- a/packages/sdk/src/api/resources/settings/resources/mcpServers/client/Client.ts
+++ b/packages/sdk/src/api/resources/settings/resources/mcpServers/client/Client.ts
@@ -243,207 +243,6 @@ export class McpServersClient {
);
}
- /**
- * For servers without auth returns not_required, and for header credentials returns authenticated (no browser flow). For auth.type dcr, returns authenticated when a usable (or refreshable) token exists; otherwise runs DCR if needed and returns auth_required with an authorization URL. Optional redirect_url is where the OAuth callback then redirects the browser; without it the callback returns JSON.
- *
- * @param {string} name - Configured MCP server name.
- * @param {TrueHarness.settings.AuthorizeMcpServersRequest} request
- * @param {McpServersClient.RequestOptions} requestOptions - Request-specific configuration.
- *
- * @throws {@link TrueHarness.BadRequestError}
- * @throws {@link TrueHarness.NotFoundError}
- * @throws {@link TrueHarness.InternalServerError}
- * @throws {@link errors.TrueHarnessError}
- * @throws {@link errors.TrueHarnessTimeoutError}
- *
- * @example
- * await client.settings.mcpServers.authorize("name")
- */
- public authorize(
- name: string,
- request: TrueHarness.settings.AuthorizeMcpServersRequest = {},
- requestOptions?: McpServersClient.RequestOptions,
- ): core.HttpResponsePromise<TrueHarness.McpAuthStatus> {
- return core.HttpResponsePromise.fromPromise(this.__authorize(name, request, requestOptions));
- }
-
- private async __authorize(
- name: string,
- request: TrueHarness.settings.AuthorizeMcpServersRequest = {},
- requestOptions?: McpServersClient.RequestOptions,
- ): Promise<core.WithRawResponse<TrueHarness.McpAuthStatus>> {
- const { redirectUrl } = request;
- const _queryParams: Record<string, unknown> = {
- redirect_url: redirectUrl,
- };
- const _headers: core.Fetcher.Args["headers"] = mergeHeaders(this._options?.headers, requestOptions?.headers);
- const _response = await (this._options.fetcher ?? core.fetcher)({
- url: core.url.join(
- (await core.Supplier.get(this._options.baseUrl)) ??
- (await core.Supplier.get(this._options.environment)),
- `api/v1/settings/mcp-servers/${core.url.encodePathParam(name)}/authorize`,
- ),
- method: "GET",
- headers: _headers,
- queryString: core.url
- .queryBuilder()
- .addMany(_queryParams)
- .mergeAdditional(requestOptions?.queryParams)
- .build(),
- timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
- maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
- abortSignal: requestOptions?.abortSignal,
- fetchFn: this._options?.fetch,
- logging: this._options.logging,
- });
- if (_response.ok) {
- return {
- data: serializers.McpAuthStatus.parseOrThrow(_response.body, {
- unrecognizedObjectKeys: "passthrough",
- allowUnrecognizedUnionMembers: true,
- allowUnrecognizedEnumValues: true,
- skipValidation: true,
- breadcrumbsPrefix: ["response"],
- }),
- rawResponse: _response.rawResponse,
- };
- }
-
- if (_response.error.reason === "status-code") {
- switch (_response.error.statusCode) {
- case 400:
- throw new TrueHarness.BadRequestError(
- serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
- unrecognizedObjectKeys: "passthrough",
- allowUnrecognizedUnionMembers: true,
- allowUnrecognizedEnumValues: true,
- skipValidation: true,
- breadcrumbsPrefix: ["response"],
- }),
- _response.rawResponse,
- );
- case 404:
- throw new TrueHarness.NotFoundError(
- serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
- unrecognizedObjectKeys: "passthrough",
- allowUnrecognizedUnionMembers: true,
- allowUnrecognizedEnumValues: true,
- skipValidation: true,
- breadcrumbsPrefix: ["response"],
- }),
- _response.rawResponse,
- );
- case 500:
- throw new TrueHarness.InternalServerError(
- serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
- unrecognizedObjectKeys: "passthrough",
- allowUnrecognizedUnionMembers: true,
- allowUnrecognizedEnumValues: true,
- skipValidation: true,
- breadcrumbsPrefix: ["response"],
- }),
- _response.rawResponse,
- );
- default:
- throw new errors.TrueHarnessError({
- statusCode: _response.error.statusCode,
- body: _response.error.body,
- rawResponse: _response.rawResponse,
- });
- }
- }
-
- return handleNonStatusCodeError(
- _response.error,
- _response.rawResponse,
- "GET",
- "/api/v1/settings/mcp-servers/{name}/authorize",
- );
- }
-
- /**
- * For auth.type dcr, deletes the stored OAuth token and returns the server with auth_status auth_required, keeping the dynamically registered OAuth client so the next authorize can reuse it. No-op for header or no-auth servers (returns the server unchanged).
- *
- * @param {string} name - Configured MCP server name.
- * @param {McpServersClient.RequestOptions} requestOptions - Request-specific configuration.
- *
- * @throws {@link TrueHarness.NotFoundError}
- * @throws {@link errors.TrueHarnessError}
- * @throws {@link errors.TrueHarnessTimeoutError}
- *
- * @example
- * await client.settings.mcpServers.deleteAuthorize("name")
- */
- public deleteAuthorize(
- name: string,
- requestOptions?: McpServersClient.RequestOptions,
- ): core.HttpResponsePromise<TrueHarness.PutMcpServerResponse> {
- return core.HttpResponsePromise.fromPromise(this.__deleteAuthorize(name, requestOptions));
- }
-
- private async __deleteAuthorize(
- name: string,
- requestOptions?: McpServersClient.RequestOptions,
- ): Promise<core.WithRawResponse<TrueHarness.PutMcpServerResponse>> {
- const _headers: core.Fetcher.Args["headers"] = mergeHeaders(this._options?.headers, requestOptions?.headers);
- const _response = await (this._options.fetcher ?? core.fetcher)({
- url: core.url.join(
- (await core.Supplier.get(this._options.baseUrl)) ??
- (await core.Supplier.get(this._options.environment)),
- `api/v1/settings/mcp-servers/${core.url.encodePathParam(name)}/authorize`,
- ),
- method: "DELETE",
- headers: _headers,
- queryString: core.url.queryBuilder().mergeAdditional(requestOptions?.queryParams).build(),
- timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
- maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
- abortSignal: requestOptions?.abortSignal,
- fetchFn: this._options?.fetch,
- logging: this._options.logging,
- });
- if (_response.ok) {
- return {
- data: serializers.PutMcpServerResponse.parseOrThrow(_response.body, {
- unrecognizedObjectKeys: "passthrough",
- allowUnrecognizedUnionMembers: true,
- allowUnrecognizedEnumValues: true,
- skipValidation: true,
- breadcrumbsPrefix: ["response"],
- }),
- rawResponse: _response.rawResponse,
- };
- }
-
- if (_response.error.reason === "status-code") {
- switch (_response.error.statusCode) {
- case 404:
- throw new TrueHarness.NotFoundError(
- serializers.RequestErrorResponse.parseOrThrow(_response.error.body, {
- unrecognizedObjectKeys: "passthrough",
- allowUnrecognizedUnionMembers: true,
- allowUnrecognizedEnumValues: true,
- skipValidation: true,
- breadcrumbsPrefix: ["response"],
- }),
- _response.rawResponse,
- );
- default:
- throw new errors.TrueHarnessError({
- statusCode: _response.error.statusCode,
- body: _response.error.body,
- rawResponse: _response.rawResponse,
- });
- }
- }
-
- return handleNonStatusCodeError(
- _response.error,
- _response.rawResponse,
- "DELETE",
- "/api/v1/settings/mcp-servers/{name}/authorize",
- );
- }
-
/**
* All tools exposed by the given configured MCP server (non-paginated), as returned by the MCP `tools/list` call.
*
diff --git a/packages/sdk/src/api/resources/settings/resources/mcpServers/client/requests/index.ts b/packages/sdk/src/api/resources/settings/resources/mcpServers/client/requests/index.ts
index c8904f2ef..24fbbe294 100644
--- a/packages/sdk/src/api/resources/settings/resources/mcpServers/client/requests/index.ts
+++ b/packages/sdk/src/api/resources/settings/resources/mcpServers/client/requests/index.ts
@@ -1,2 +1 @@
-export type { AuthorizeMcpServersRequest } from "./AuthorizeMcpServersRequest.js";
export type { McpServerManifest } from "./McpServerManifest.js";
diff --git a/packages/sdk/tests/wire/mcpServers.test.ts b/packages/sdk/tests/wire/mcpServers.test.ts
index 79dfe0590..2d30d2d25 100644
--- a/packages/sdk/tests/wire/mcpServers.test.ts
+++ b/packages/sdk/tests/wire/mcpServers.test.ts
@@ -1,5 +1,6 @@
// This file was auto-generated by Fern from our API Definition.
+import * as TrueHarnessTypes from "../../src/api/index";
import { TrueHarness } from "../../src/Client";
import { mockServerPool } from "../mock-server/MockServerPool";
@@ -28,4 +29,140 @@ describe("McpServersClient", () => {
],
});
});
+
+ test("authorize (1)", async () => {
+ const server = mockServerPool.createServer();
+ const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
+
+ const rawResponseBody = { authorization_url: "authorization_url", status: "authenticated" };
+
+ server
+ .mockEndpoint()
+ .get("/api/v1/mcp-servers/name/authorize")
+ .respondWith()
+ .statusCode(200)
+ .jsonBody(rawResponseBody)
+ .build();
+
+ const response = await client.mcpServers.authorize("name");
+ expect(response).toEqual({
+ authorizationUrl: "authorization_url",
+ status: "authenticated",
+ });
+ });
+
+ test("authorize (2)", async () => {
+ const server = mockServerPool.createServer();
+ const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
+
+ const rawResponseBody = { error: { message: "message" } };
+
+ server
+ .mockEndpoint()
+ .get("/api/v1/mcp-servers/name/authorize")
+ .respondWith()
+ .statusCode(400)
+ .jsonBody(rawResponseBody)
+ .build();
+
+ await expect(async () => {
+ return await client.mcpServers.authorize("name");
+ }).rejects.toThrow(TrueHarnessTypes.BadRequestError);
+ });
+
+ test("authorize (3)", async () => {
+ const server = mockServerPool.createServer();
+ const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
+
+ const rawResponseBody = { error: { message: "message" } };
+
+ server
+ .mockEndpoint()
+ .get("/api/v1/mcp-servers/name/authorize")
+ .respondWith()
+ .statusCode(404)
+ .jsonBody(rawResponseBody)
+ .build();
+
+ await expect(async () => {
+ return await client.mcpServers.authorize("name");
+ }).rejects.toThrow(TrueHarnessTypes.NotFoundError);
+ });
+
+ test("authorize (4)", async () => {
+ const server = mockServerPool.createServer();
+ const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
+
+ const rawResponseBody = { error: { message: "message" } };
+
+ server
+ .mockEndpoint()
+ .get("/api/v1/mcp-servers/name/authorize")
+ .respondWith()
+ .statusCode(500)
+ .jsonBody(rawResponseBody)
+ .build();
+
+ await expect(async () => {
+ return await client.mcpServers.authorize("name");
+ }).rejects.toThrow(TrueHarnessTypes.InternalServerError);
+ });
+
+ test("delete_authorize (1)", async () => {
+ const server = mockServerPool.createServer();
+ const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
+
+ const rawResponseBody = {
+ data: {
+ auth: { type: "dcr" },
+ auth_status: { authorization_url: "authorization_url", status: "authenticated" },
+ name: "name",
+ type: "remote",
+ url: "url",
+ },
+ };
+
+ server
+ .mockEndpoint()
+ .delete("/api/v1/mcp-servers/name/authorize")
+ .respondWith()
+ .statusCode(200)
+ .jsonBody(rawResponseBody)
+ .build();
+
+ const response = await client.mcpServers.deleteAuthorize("name");
+ expect(response).toEqual({
+ data: {
+ auth: {
+ type: "dcr",
+ },
+ authStatus: {
+ authorizationUrl: "authorization_url",
+ status: "authenticated",
+ },
+ name: "name",
+ type: "remote",
+ url: "url",
+ },
+ });
+ });
+
+ test("delete_authorize (2)", async () => {
+ const server = mockServerPool.createServer();
+ const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
+
+ const rawResponseBody = { error: { message: "message" } };
+
+ server
+ .mockEndpoint()
+ .delete("/api/v1/mcp-servers/name/authorize")
+ .respondWith()
+ .statusCode(404)
+ .jsonBody(rawResponseBody)
+ .build();
+
+ await expect(async () => {
+ return await client.mcpServers.deleteAuthorize("name");
+ }).rejects.toThrow(TrueHarnessTypes.NotFoundError);
+ });
});
diff --git a/packages/sdk/tests/wire/settings/mcpServers.test.ts b/packages/sdk/tests/wire/settings/mcpServers.test.ts
index 9676d15c0..5d73e31b0 100644
--- a/packages/sdk/tests/wire/settings/mcpServers.test.ts
+++ b/packages/sdk/tests/wire/settings/mcpServers.test.ts
@@ -145,142 +145,6 @@ describe("McpServersClient", () => {
});
});
- test("authorize (1)", async () => {
- const server = mockServerPool.createServer();
- const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
-
- const rawResponseBody = { authorization_url: "authorization_url", status: "authenticated" };
-
- server
- .mockEndpoint()
- .get("/api/v1/settings/mcp-servers/name/authorize")
- .respondWith()
- .statusCode(200)
- .jsonBody(rawResponseBody)
- .build();
-
- const response = await client.settings.mcpServers.authorize("name");
- expect(response).toEqual({
- authorizationUrl: "authorization_url",
- status: "authenticated",
- });
- });
-
- test("authorize (2)", async () => {
- const server = mockServerPool.createServer();
- const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
-
- const rawResponseBody = { error: { message: "message" } };
-
- server
- .mockEndpoint()
- .get("/api/v1/settings/mcp-servers/name/authorize")
- .respondWith()
- .statusCode(400)
- .jsonBody(rawResponseBody)
- .build();
-
- await expect(async () => {
- return await client.settings.mcpServers.authorize("name");
- }).rejects.toThrow(TrueHarnessTypes.BadRequestError);
- });
-
- test("authorize (3)", async () => {
- const server = mockServerPool.createServer();
- const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
-
- const rawResponseBody = { error: { message: "message" } };
-
- server
- .mockEndpoint()
- .get("/api/v1/settings/mcp-servers/name/authorize")
- .respondWith()
- .statusCode(404)
- .jsonBody(rawResponseBody)
- .build();
-
- await expect(async () => {
- return await client.settings.mcpServers.authorize("name");
- }).rejects.toThrow(TrueHarnessTypes.NotFoundError);
- });
-
- test("authorize (4)", async () => {
- const server = mockServerPool.createServer();
- const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
-
- const rawResponseBody = { error: { message: "message" } };
-
- server
- .mockEndpoint()
- .get("/api/v1/settings/mcp-servers/name/authorize")
- .respondWith()
- .statusCode(500)
- .jsonBody(rawResponseBody)
- .build();
-
- await expect(async () => {
- return await client.settings.mcpServers.authorize("name");
- }).rejects.toThrow(TrueHarnessTypes.InternalServerError);
- });
-
- test("delete_authorize (1)", async () => {
- const server = mockServerPool.createServer();
- const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
-
- const rawResponseBody = {
- data: {
- auth: { type: "dcr" },
- auth_status: { authorization_url: "authorization_url", status: "authenticated" },
- name: "name",
- type: "remote",
- url: "url",
- },
- };
-
- server
- .mockEndpoint()
- .delete("/api/v1/settings/mcp-servers/name/authorize")
- .respondWith()
- .statusCode(200)
- .jsonBody(rawResponseBody)
- .build();
-
- const response = await client.settings.mcpServers.deleteAuthorize("name");
- expect(response).toEqual({
- data: {
- auth: {
- type: "dcr",
- },
- authStatus: {
- authorizationUrl: "authorization_url",
- status: "authenticated",
- },
- name: "name",
- type: "remote",
- url: "url",
- },
- });
- });
-
- test("delete_authorize (2)", async () => {
- const server = mockServerPool.createServer();
- const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
-
- const rawResponseBody = { error: { message: "message" } };
-
- server
- .mockEndpoint()
- .delete("/api/v1/settings/mcp-servers/name/authorize")
- .respondWith()
- .statusCode(404)
- .jsonBody(rawResponseBody)
- .build();
-
- await expect(async () => {
- return await client.settings.mcpServers.deleteAuthorize("name");
- }).rejects.toThrow(TrueHarnessTypes.NotFoundError);
- });
-
test("list_tools (1)", async () => {
const server = mockServerPool.createServer();
const client = new TrueHarness({ maxRetries: 0, baseUrl: server.baseUrl });
diff --git a/packages/server/src/apis/mcpServers.ts b/packages/server/src/apis/mcpServers.ts
index d54117db9..c66e3a272 100644
--- a/packages/server/src/apis/mcpServers.ts
+++ b/packages/server/src/apis/mcpServers.ts
@@ -31,13 +31,19 @@ import { TENANT_ID } from './sessions';
/** Registering a DCR OAuth client hits the MCP server's authorization server, so bound that call. */
export const MCP_DCR_REGISTRATION_TIMEOUT_MS = 10_000;
-export interface McpServersRouterDeps {
+export interface SettingsMcpServersRouterDeps {
mcpCatalog: McpCatalog;
mcpServerStore: IMcpServerStore;
tokenStore: IOAuthTokenStore;
logger: Logger;
}
+export interface McpServersRouterDeps {
+ mcpServerStore: IMcpServerStore;
+ tokenStore: IOAuthTokenStore;
+ logger: Logger;
+}
+
/** Omits keys whose value is `undefined` so wire objects satisfy JSONValue index signatures. */
function omitUndefinedEntries(obj: Record<string, unknown>): Record<string, unknown> {
const out: Record<string, unknown> = {};
@@ -75,7 +81,7 @@ function toConfiguredMcpServer({
/** Admin/settings MCP CRUD (mounted at /api/v1/settings/mcp-servers).
* TODO: Remove the server via txn if DCR fails to register
*/
-export function createMcpServersRouter(deps: McpServersRouterDeps) {
+export function createSettingsMcpServersRouter(deps: SettingsMcpServersRouterDeps) {
const registerDcrClient = async (params: {
serverId: string;
mcpServerUrl: string;
@@ -189,6 +195,17 @@ export function createMcpServersRouter(deps: McpServersRouterDeps) {
}
};
+ const router = new OpenAPIHono();
+ // Static `/catalog` before `/{name}/…` so "catalog" is not captured as a name.
+ router.openapi(getMcpServerCatalogRoute, catalogHandler);
+ router.openapi(listConfiguredMcpServersRoute, listConfiguredHandler);
+ router.openapi(putMcpServerRoute, putHandler);
+ router.openapi(listMcpServerToolsRoute, listToolsHandler);
+ return router;
+}
+
+/** List + authorize (mounted at /api/v1/mcp-servers). */
+export function createMcpServersRouter(deps: McpServersRouterDeps) {
const authorizeHandler: RouteHandler<typeof authorizeConfiguredMcpServerRoute> = async c => {
const { name } = c.req.valid('param');
const { redirect_url: redirectUrl } = c.req.valid('query');
@@ -246,22 +263,9 @@ export function createMcpServersRouter(deps: McpServersRouterDeps) {
return c.json({ data: toConfiguredMcpServer({ record, token: undefined }) }, 200);
};
- const router = new OpenAPIHono();
- // Static `/catalog` before `/{name}/…` so "catalog" is not captured as a name.
- router.openapi(getMcpServerCatalogRoute, catalogHandler);
- router.openapi(listConfiguredMcpServersRoute, listConfiguredHandler);
- router.openapi(putMcpServerRoute, putHandler);
- router.openapi(listMcpServerToolsRoute, listToolsHandler);
- router.openapi(authorizeConfiguredMcpServerRoute, authorizeHandler);
- router.openapi(deleteConfiguredMcpServerAuthRoute, deleteAuthHandler);
- return router;
-}
-
-/** Chat slim list (mounted at /api/v1/mcp-servers) β€” mirrors GET /api/v1/models. */
-export function createAvailableMcpServersRouter(store: IMcpServerStore) {
const router = new OpenAPIHono();
router.openapi(listAvailableMcpServersRoute, async c => {
- const records = await store.listServers({ tenant_id: TENANT_ID, names: undefined });
+ const records = await deps.mcpServerStore.listServers({ tenant_id: TENANT_ID, names: undefined });
return c.json(
{
data: records.map(record => ({ name: record.name, url: record.manifest.url })),
@@ -269,5 +273,7 @@ export function createAvailableMcpServersRouter(store: IMcpServerStore) {
200,
);
});
+ router.openapi(authorizeConfiguredMcpServerRoute, authorizeHandler);
+ router.openapi(deleteConfiguredMcpServerAuthRoute, deleteAuthHandler);
return router;
}
diff --git a/packages/server/src/apis/settings.ts b/packages/server/src/apis/settings.ts
index da6156f77..4399a16f6 100644
--- a/packages/server/src/apis/settings.ts
+++ b/packages/server/src/apis/settings.ts
@@ -14,7 +14,7 @@ import type { IModelProviderStore } from '../db/modelProviderStore';
import type { ISandboxProviderStore } from '../db/sandboxProviderStore';
import type { ISkillStore } from '../db/skillStore';
import type { IOAuthTokenStore } from '../mcp/auth/types';
-import { createMcpServersRouter } from './mcpServers';
+import { createSettingsMcpServersRouter } from './mcpServers';
import { createModelProvidersRouter } from './modelProviders';
import { createSandboxProvidersRouter } from './sandboxProviders';
import { createSkillsRouter } from './skills';
@@ -43,7 +43,7 @@ export function createSettingsRouter(deps: SettingsRouterDeps) {
);
router.route(
'/mcp-servers',
- createMcpServersRouter({
+ createSettingsMcpServersRouter({
mcpCatalog: deps.mcpCatalog,
mcpServerStore: deps.mcpServerStore,
tokenStore: deps.tokenStore,
diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts
index 9cfdf1529..3e1d83f50 100644
--- a/packages/server/src/app.ts
+++ b/packages/server/src/app.ts
@@ -9,7 +9,7 @@ import type { RedisClientType } from 'redis';
import type { Logger } from 'winston';
import { createCapabilitiesRouter } from './apis/capabilities';
import { createMcpOAuthRouter } from './apis/mcpOAuth';
-import { createAvailableMcpServersRouter } from './apis/mcpServers';
+import { createMcpServersRouter } from './apis/mcpServers';
import { createModelsRouter } from './apis/models';
import { createSessionsRouter } from './apis/sessions';
import { createSettingsRouter } from './apis/settings';
@@ -74,7 +74,14 @@ export function createServerApp(deps: ServerDeps) {
app.route('/api/v1/capabilities', createCapabilitiesRouter({ sandboxProviderStore: deps.sandboxProviderStore }));
app.route('/api/v1/models', createModelsRouter(deps.modelProviderStore));
- app.route('/api/v1/mcp-servers', createAvailableMcpServersRouter(deps.mcpServerStore));
+ app.route(
+ '/api/v1/mcp-servers',
+ createMcpServersRouter({
+ mcpServerStore: deps.mcpServerStore,
+ tokenStore: deps.tokenStore,
+ logger: deps.logger,
+ }),
+ );
// Shared OAuth callback β€” path must match the server-owned MCP_OAUTH_CALLBACK_PATH.
app.route(
'/api/v1/mcp-servers/oauth',
diff --git a/packages/server/src/routes/mcpServerRoutes.ts b/packages/server/src/routes/mcpServerRoutes.ts
index 90d20d876..681a873b3 100644
--- a/packages/server/src/routes/mcpServerRoutes.ts
+++ b/packages/server/src/routes/mcpServerRoutes.ts
@@ -1,7 +1,7 @@
/**
* DB-backed MCP server route definitions.
- * Admin routes mount at /api/v1/settings/mcp-servers; the chat list mounts at
- * /api/v1/mcp-servers.
+ * Admin routes mount at /api/v1/settings/mcp-servers; the chat list and
+ * authorize routes mount at /api/v1/mcp-servers.
*/
import { createRoute, z } from '@hono/zod-openapi';
import { RequestErrorResponseSchema } from '../schemas/errors';
@@ -151,7 +151,7 @@ export const authorizeConfiguredMcpServerRoute = createRoute({
path: '/{name}/authorize',
tags: [MCP_SERVERS_TAG],
summary: 'Start (or short-circuit) the auth flow for a configured MCP server',
- 'x-fern-sdk-group-name': ['settings', 'mcpServers'],
+ 'x-fern-sdk-group-name': ['mcpServers'],
'x-fern-sdk-method-name': 'authorize',
description:
'For servers without auth returns not_required, and for header credentials returns authenticated ' +
@@ -187,7 +187,7 @@ export const deleteConfiguredMcpServerAuthRoute = createRoute({
path: '/{name}/authorize',
tags: [MCP_SERVERS_TAG],
summary: 'Disconnect OAuth for a configured MCP server',
- 'x-fern-sdk-group-name': ['settings', 'mcpServers'],
+ 'x-fern-sdk-group-name': ['mcpServers'],
'x-fern-sdk-method-name': 'delete_authorize',
description:
'For auth.type dcr, deletes the stored OAuth token and returns the server with auth_status ' +
diff --git a/packages/server/tests/unit/apis/mcpOAuth.test.ts b/packages/server/tests/unit/apis/mcpOAuth.test.ts
index dc52f723a..821966c54 100644
--- a/packages/server/tests/unit/apis/mcpOAuth.test.ts
+++ b/packages/server/tests/unit/apis/mcpOAuth.test.ts
@@ -4,7 +4,7 @@
*/
import winston from 'winston';
import { createMcpOAuthRouter } from '../../../src/apis/mcpOAuth';
-import { createMcpServersRouter } from '../../../src/apis/mcpServers';
+import { createMcpServersRouter, createSettingsMcpServersRouter } from '../../../src/apis/mcpServers';
import { McpCatalog } from '../../../src/catalog/McpCatalog';
import { migrateSqliteToLatest } from '../../../src/db/migrateSqlite';
import { createSqliteDb } from '../../../src/db/sqlite/client';
@@ -72,7 +72,8 @@ function stubOauthFetch(): void {
describe('MCP OAuth authorize + callback', () => {
const realFetch = globalThis.fetch;
- let settingsRouter: ReturnType<typeof createMcpServersRouter>;
+ let settingsRouter: ReturnType<typeof createSettingsMcpServersRouter>;
+ let mcpServersRouter: ReturnType<typeof createMcpServersRouter>;
let oauthRouter: ReturnType<typeof createMcpOAuthRouter>;
let mcpServerStore: SqliteMcpServerStore;
let tokenStore: SqliteOAuthTokenStore;
@@ -83,12 +84,17 @@ describe('MCP OAuth authorize + callback', () => {
mcpServerStore = new SqliteMcpServerStore(db);
tokenStore = new SqliteOAuthTokenStore(db);
const logger = winston.createLogger({ silent: true });
- settingsRouter = createMcpServersRouter({
+ settingsRouter = createSettingsMcpServersRouter({
mcpCatalog: McpCatalog.load(),
mcpServerStore,
tokenStore,
logger,
});
+ mcpServersRouter = createMcpServersRouter({
+ mcpServerStore,
+ tokenStore,
+ logger,
+ });
oauthRouter = createMcpOAuthRouter({ tokenStore, mcpServerStore, logger });
});
@@ -113,7 +119,7 @@ describe('MCP OAuth authorize + callback', () => {
if (redirectUrl) {
query = `?redirect_url=${encodeURIComponent(redirectUrl)}`;
}
- const authorize = await settingsRouter.request(`/${name}/authorize${query}`);
+ const authorize = await mcpServersRouter.request(`/${name}/authorize${query}`);
expect(authorize.status).toBe(200);
const body = (await authorize.json()) as { authorization_url?: string };
return new URL(body.authorization_url ?? '').searchParams.get('state') ?? '';
@@ -132,7 +138,7 @@ describe('MCP OAuth authorize + callback', () => {
});
expect(put.status).toBe(200);
- const authorize = await settingsRouter.request(
+ const authorize = await mcpServersRouter.request(
`/oauth-mcp/authorize?redirect_url=${encodeURIComponent(FE_REDIRECT)}`,
);
expect(authorize.status).toBe(200);
@@ -156,7 +162,7 @@ describe('MCP OAuth authorize + callback', () => {
expect(token?.accessToken).toBe('access-1');
expect(token?.refreshToken).toBe('refresh-1');
- const reauthorize = await settingsRouter.request(
+ const reauthorize = await mcpServersRouter.request(
`/oauth-mcp/authorize?redirect_url=${encodeURIComponent(FE_REDIRECT)}`,
);
expect(reauthorize.status).toBe(200);
diff --git a/packages/server/tests/unit/apis/mcpServers.test.ts b/packages/server/tests/unit/apis/mcpServers.test.ts
index 1d58fdb6f..f724d6d49 100644
--- a/packages/server/tests/unit/apis/mcpServers.test.ts
+++ b/packages/server/tests/unit/apis/mcpServers.test.ts
@@ -1,5 +1,5 @@
import winston from 'winston';
-import { createAvailableMcpServersRouter, createMcpServersRouter } from '../../../src/apis/mcpServers';
+import { createMcpServersRouter, createSettingsMcpServersRouter } from '../../../src/apis/mcpServers';
import { TENANT_ID } from '../../../src/apis/sessions';
import { McpCatalog } from '../../../src/catalog/McpCatalog';
import { migrateSqliteToLatest } from '../../../src/db/migrateSqlite';
@@ -39,8 +39,8 @@ function putInit(body: unknown): RequestInit {
}
describe('mcp-servers routers', () => {
- let settingsRouter: ReturnType<typeof createMcpServersRouter>;
- let availableRouter: ReturnType<typeof createAvailableMcpServersRouter>;
+ let settingsRouter: ReturnType<typeof createSettingsMcpServersRouter>;
+ let mcpServersRouter: ReturnType<typeof createMcpServersRouter>;
let mcpServerStore: SqliteMcpServerStore;
let tokenStore: SqliteOAuthTokenStore;
const originalFetch = globalThis.fetch;
@@ -55,13 +55,18 @@ describe('mcp-servers routers', () => {
await migrateSqliteToLatest(db);
mcpServerStore = new SqliteMcpServerStore(db);
tokenStore = new SqliteOAuthTokenStore(db);
- settingsRouter = createMcpServersRouter({
+ const logger = winston.createLogger({ silent: true });
+ settingsRouter = createSettingsMcpServersRouter({
mcpCatalog: McpCatalog.load(),
mcpServerStore,
tokenStore,
- logger: winston.createLogger({ silent: true }),
+ logger,
+ });
+ mcpServersRouter = createMcpServersRouter({
+ mcpServerStore,
+ tokenStore,
+ logger,
});
- availableRouter = createAvailableMcpServersRouter(mcpServerStore);
});
afterAll(() => {
@@ -176,7 +181,7 @@ describe('mcp-servers routers', () => {
});
it('GET / on the chat router returns the slim projection without auth fields', async () => {
- const response = await availableRouter.request('/');
+ const response = await mcpServersRouter.request('/');
expect(response.status).toBe(200);
const body = (await response.json()) as { data: { name: string; url: string }[] };
expect(body.data.map(server => server.name).sort()).toEqual(['deepwiki', 'linear', 'private-mcp']);
@@ -203,15 +208,17 @@ describe('mcp-servers routers', () => {
});
it('GET /{name}/authorize short-circuits non-DCR servers and 404s unknowns', async () => {
- const noAuth = await settingsRouter.request('/deepwiki/authorize?redirect_url=https://example.com/callback');
+ const noAuth = await mcpServersRouter.request('/deepwiki/authorize?redirect_url=https://example.com/callback');
expect(noAuth.status).toBe(200);
expect(await noAuth.json()).toEqual({ status: 'not_required' });
- const headerAuth = await settingsRouter.request('/private-mcp/authorize?redirect_url=https://example.com/callback');
+ const headerAuth = await mcpServersRouter.request(
+ '/private-mcp/authorize?redirect_url=https://example.com/callback',
+ );
expect(headerAuth.status).toBe(200);
expect(await headerAuth.json()).toEqual({ status: 'authenticated' });
- const missing = await settingsRouter.request('/missing/authorize?redirect_url=https://example.com/callback');
+ const missing = await mcpServersRouter.request('/missing/authorize?redirect_url=https://example.com/callback');
expect(missing.status).toBe(404);
});
@@ -270,7 +277,7 @@ describe('mcp-servers routers', () => {
);
expect(put.status).toBe(200);
- const authorize = await settingsRouter.request(
+ const authorize = await mcpServersRouter.request(
'/oauth-mcp/authorize?redirect_url=https://example.com/after-oauth',
);
expect(authorize.status).toBe(200);
@@ -317,7 +324,7 @@ describe('mcp-servers routers', () => {
},
});
- const response = await settingsRouter.request(`/${putBodyWithDcr.name}/authorize`, { method: 'DELETE' });
+ const response = await mcpServersRouter.request(`/${putBodyWithDcr.name}/authorize`, { method: 'DELETE' });
expect(response.status).toBe(200);
expect(await response.json()).toEqual({
data: { ...putBodyWithDcr, auth_status: { status: 'auth_required' } },
@@ -337,19 +344,19 @@ describe('mcp-servers routers', () => {
});
it('DELETE /{name}/authorize is a no-op for non-DCR servers and 404s unknowns', async () => {
- const noAuth = await settingsRouter.request('/deepwiki/authorize', { method: 'DELETE' });
+ const noAuth = await mcpServersRouter.request('/deepwiki/authorize', { method: 'DELETE' });
expect(noAuth.status).toBe(200);
expect(await noAuth.json()).toEqual({
data: { ...putBody, auth_status: { status: 'not_required' } },
});
- const headerAuth = await settingsRouter.request('/private-mcp/authorize', { method: 'DELETE' });
+ const headerAuth = await mcpServersRouter.request('/private-mcp/authorize', { method: 'DELETE' });
expect(headerAuth.status).toBe(200);
expect(await headerAuth.json()).toEqual({
data: { ...putBodyWithHeaderAuth, auth_status: { status: 'authenticated' } },
});
- const missing = await settingsRouter.request('/missing/authorize', { method: 'DELETE' });
+ const missing = await mcpServersRouter.request('/missing/authorize', { method: 'DELETE' });
expect(missing.status).toBe(404);
});
});