diff --git a/dashboard/src/api.ts b/dashboard/src/api.ts index 48259c2..624b1d7 100644 --- a/dashboard/src/api.ts +++ b/dashboard/src/api.ts @@ -1,7 +1,7 @@ import type { AgentBundlePreview, AgentItemBody, - AgentMcpServer, + AgentMcpServerBody, AgentRepoBody, AgentSetDetail, AgentSetSummary, @@ -465,13 +465,13 @@ export const api = { method: 'DELETE', }), /** - * Adds one MCP server to a set, or changes the headers of a server. + * Adds one MCP server to a set, or changes the headers or the upstream CA of a server. * * @param setId The id of the agent set. - * @param body The name, the URL, the auth mode and the headers of the server. + * @param body The name, the URL, the auth mode, the headers and the upstream CA of the server. * @returns The whole set after the change. */ - putAgentMcpServer: (setId: string, body: AgentMcpServer) => + putAgentMcpServer: (setId: string, body: AgentMcpServerBody) => request(`/api/agent-sets/${setId}/mcp-servers`, { method: 'PUT', body: JSON.stringify(body), @@ -600,12 +600,19 @@ export const api = { * @param name The environment variable name of the key. * @param hosts The hosts for which the egress proxy swaps in the key. * @param secret The key. Without it, the orchestrator keeps the stored key. - * @returns The name, the hosts and the last four characters of the key. + * @param upstreamCa The upstream CA for all hosts as PEM, an empty string to remove the upstream CA of the hosts, + * or undefined to keep the upstream CAs of the hosts. + * @returns The name, the hosts, the last four characters and the upstream CA of the key, and the flag for hosts + * with different upstream CAs. */ - putApiKey: (name: string, hosts: string[], secret?: string) => + putApiKey: (name: string, hosts: string[], secret?: string, upstreamCa?: string) => request(`/api/api-keys/${encodeURIComponent(name)}`, { method: 'PUT', - body: JSON.stringify({ hosts, ...(secret ? { secret } : {}) }), + body: JSON.stringify({ + hosts, + ...(secret ? { secret } : {}), + ...(upstreamCa !== undefined ? { upstreamCa } : {}), + }), }), /** * Removes an API key. diff --git a/dashboard/src/components/McpServers.tsx b/dashboard/src/components/McpServers.tsx index 86a4c5d..fd6e26c 100644 --- a/dashboard/src/components/McpServers.tsx +++ b/dashboard/src/components/McpServers.tsx @@ -22,10 +22,11 @@ import { SelectTrigger, SelectValue, } from '@/components/ui/select'; +import { Textarea } from '@/components/ui/textarea'; import type { AgentMcpAuth, AgentMcpHeader, - AgentMcpServer, + AgentMcpServerBody, AgentMcpServerState, McpConnectBody, } from '../../../shared/types.ts'; @@ -38,20 +39,30 @@ const TOKEN_STATUS = { } as const; /** - * Checks if a text is an http or https URL. + * Gives the scheme of a URL. * * @param raw The URL as typed. - * @returns True for an http or https URL. + * @returns The scheme with its colon, or null when the text is not a URL. */ -function validUrl(raw: string): boolean { +function schemeOf(raw: string): string | null { try { - const url = new URL(raw.trim()); - return url.protocol === 'https:' || url.protocol === 'http:'; + return new URL(raw.trim()).protocol; } catch { - return false; + return null; } } +/** + * Checks if a text is an http or https URL. + * + * @param raw The URL as typed. + * @returns True for an http or https URL. + */ +function validUrl(raw: string): boolean { + const scheme = schemeOf(raw); + return scheme === 'https:' || scheme === 'http:'; +} + /** * The list of MCP servers, with its own add button. * @@ -148,7 +159,8 @@ export function McpSection({ * * The name, the URL and the auth mode are fixed once the server exists. A * secret field of a stored server starts empty, and an empty field keeps the - * stored secret. + * stored secret. The upstream CA field starts with the upstream CA of the host, + * and a save sets the upstream CA of the host to the content of the field. * * @param server The server to edit, or null for a new server. * @param busy True while a save runs, which disables the buttons. @@ -170,9 +182,9 @@ export function McpDialog({ busy: boolean; error: string | null; onCancel: () => void; - onSave: (body: AgentMcpServer) => void; + onSave: (body: AgentMcpServerBody) => void; onConnect: ( - body: AgentMcpServer, + body: AgentMcpServerBody, client: Omit, ) => Promise; }) { @@ -189,6 +201,8 @@ export function McpDialog({ const [redirectUri, setRedirectUri] = useState(null); const [clientId, setClientId] = useState(''); const [clientSecret, setClientSecret] = useState(''); + const [upstreamCa, setUpstreamCa] = useState(server?.upstreamCa ?? ''); + const https = schemeOf(url) === 'https:'; /** * Checks if the header of a row has a stored secret, so an empty value keeps the secret. @@ -206,7 +220,7 @@ export function McpDialog({ }; /** The server that a save sends. */ - const body: AgentMcpServer = { + const body: AgentMcpServerBody = { name: name.trim(), url: url.trim(), auth, @@ -222,6 +236,7 @@ export function McpDialog({ : auth === 'headers' ? headers.filter((h) => h.name.trim() !== '' || h.value !== '') : [], + ...(https ? { upstreamCa } : {}), }; /** @@ -392,6 +407,25 @@ export function McpDialog({ ) : null} + {https ? ( +
+ +