Handle MCP sse and URL-based server mapping

This commit is contained in:
Gabrielsv01 2026-05-04 22:53:35 -03:00
parent 5de68cb803
commit 4fcb826b0b
3 changed files with 13 additions and 7 deletions

View file

@ -291,16 +291,16 @@ export function ConfigPage() {
.map((name) => [name, null] as const) .map((name) => [name, null] as const)
const upsertServerEntries = normalizedServers.map((server) => { const upsertServerEntries = normalizedServers.map((server) => {
if (server.type === "http") { if (server.type !== "stdio") {
if (server.url === "") { if (server.url === "") {
throw new Error(`MCP server ${server.name} requires an HTTP URL.`) throw new Error(`MCP server ${server.name} requires a URL.`)
} }
return [ return [
server.name, server.name,
{ {
enabled: server.enabled, enabled: server.enabled,
type: "http", type: server.type,
url: server.url, url: server.url,
headers: parseJSONObjectField( headers: parseJSONObjectField(
server.headersText, server.headersText,

View file

@ -380,6 +380,7 @@ export function MCPSection({
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="stdio">stdio</SelectItem> <SelectItem value="stdio">stdio</SelectItem>
<SelectItem value="sse">sse</SelectItem>
<SelectItem value="http">http</SelectItem> <SelectItem value="http">http</SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>

View file

@ -34,7 +34,7 @@ export interface CoreConfigForm {
mcpServers: MCPServerForm[] mcpServers: MCPServerForm[]
} }
export type MCPServerType = "http" | "stdio" export type MCPServerType = "http" | "sse" | "stdio"
export interface MCPServerForm { export interface MCPServerForm {
id: string id: string
@ -155,7 +155,10 @@ function asNumberString(value: unknown, fallback: string): string {
} }
function toMCPServerType(value: unknown): MCPServerType { function toMCPServerType(value: unknown): MCPServerType {
return value === "http" ? "http" : "stdio" if (value === "http" || value === "sse") {
return value
}
return "stdio"
} }
function makeMCPServerID(name: string): string { function makeMCPServerID(name: string): string {
@ -176,6 +179,8 @@ function mapMCPServers(value: unknown): MCPServerForm[] {
const argsList = Array.isArray(cfg.args) const argsList = Array.isArray(cfg.args)
? cfg.args.filter((item): item is string => typeof item === "string") ? cfg.args.filter((item): item is string => typeof item === "string")
: [] : []
const url = asString(cfg.url)
const type = cfg.type === undefined ? (url ? "sse" : "stdio") : toMCPServerType(cfg.type)
const env = asRecord(cfg.env) const env = asRecord(cfg.env)
const headers = asRecord(cfg.headers) const headers = asRecord(cfg.headers)
@ -183,8 +188,8 @@ function mapMCPServers(value: unknown): MCPServerForm[] {
id: makeMCPServerID(name), id: makeMCPServerID(name),
name, name,
enabled: cfg.enabled !== false, enabled: cfg.enabled !== false,
type: toMCPServerType(cfg.type), type,
url: asString(cfg.url), url,
command: asString(cfg.command), command: asString(cfg.command),
argsText: argsList.join("\n"), argsText: argsList.join("\n"),
envText: JSON.stringify(env, null, 2), envText: JSON.stringify(env, null, 2),