diff --git a/apps/web/app/(app)/actions.ts b/apps/web/app/(app)/actions.ts index 6724226b..cf57fe9e 100644 --- a/apps/web/app/(app)/actions.ts +++ b/apps/web/app/(app)/actions.ts @@ -1040,6 +1040,12 @@ export async function createConnectionAction(f: FormData) { const user = asWebActor(await requireUser()); await attempt(f, async () => { const protocol = str(f, "protocol"); + // PEP-236: a remote MCP server — the test (initialize + tools/list) runs on saving. + if (protocol === "mcp") { + const kind = str(f, "authKind"); + const c = await createConnection(db, user.id, { protocol: "mcp", name: str(f, "name"), baseUrl: str(f, "baseUrl"), secret: String(f.get("secret") ?? "").trim(), authKind: kind === "header" || kind === "none" ? kind : "bearer", authHeader: str(f, "authHeader") || null }); + return `/connections?created=${c.id}&check=${c.checkStatus ?? "down"}#c${c.id}`; + } if (isGatewayProtocol(protocol)) { const config = Object.fromEntries(PROTOCOL_FIELDS.filter((k) => f.has(k)).map((k) => [k, str(f, k)])); // An SSH key keeps its line breaks; a password is one line. @@ -1116,7 +1122,10 @@ export async function grantConnectionAction(f: FormData) { await attempt(f, async () => { const agent = str(f, "agentId"); const mode = (k: string): GrantMode => (["auto", "ask"].includes(str(f, k)) ? (str(f, k) as GrantMode) : "off"); - await grantConnection(db, user.id, Number(str(f, "connectionId")), { projectId: Number(str(f, "projectId")), agentId: agent ? Number(agent) : null, readMode: mode("readMode"), writeMode: mode("writeMode"), operations: String(f.get("operations") ?? ""), term: isGrantTerm(str(f, "term")) ? (str(f, "term") as GrantTerm) : DEFAULT_GRANT_TERM }); + // PEP-236: an MCP server's own mode per tool — fields «tool:»; empty = as reading / writing. + const tools: Record = {}; + for (const [k, v] of f.entries()) if (k.startsWith("tool:") && ["auto", "ask", "off"].includes(String(v))) tools[k.slice(5)] = String(v) as GrantMode; + await grantConnection(db, user.id, Number(str(f, "connectionId")), { projectId: Number(str(f, "projectId")), agentId: agent ? Number(agent) : null, readMode: mode("readMode"), writeMode: mode("writeMode"), operations: String(f.get("operations") ?? ""), tools, term: isGrantTerm(str(f, "term")) ? (str(f, "term") as GrantTerm) : DEFAULT_GRANT_TERM }); }); } diff --git a/apps/web/app/(app)/connections/page.tsx b/apps/web/app/(app)/connections/page.tsx index cdbccc3c..a05e71c6 100644 --- a/apps/web/app/(app)/connections/page.tsx +++ b/apps/web/app/(app)/connections/page.tsx @@ -32,6 +32,8 @@ import { type GrantMode, type GatewayProtocol, GATEWAY_PROTOCOLS, + mcpTools, + type McpTool, } from "@peppa/core"; import { AccessRequestList } from "@/components/AccessRequests"; import { ApprovalList } from "@/components/ConnectionApprovals"; @@ -116,6 +118,11 @@ function GrantLine({ g, engineer, t }: { g: ConnectionGrantView; engineer: boole {g.state === "idle" && {t("снято: {n} ч без дела", { n: g.idleHours })}} {g.idleAskedAt && {t("не используется {n} ч — снять?", { n: g.idleHours })}} {engineer && g.operations.length > 0 && {g.operations.join(", ")}} + {g.tools && Object.keys(g.tools).length > 0 && ( + + · {t("инструменты: {list}", { list: Object.entries(g.tools).map(([name, mode]) => `${name} — ${modeText(mode, t)}`).join(", ") })} + + )}
{g.idleAskedAt && ( <> @@ -233,13 +240,14 @@ function GrantForm({ c, projects, agents, engineer, t }: { c: ConnectionView; pr - {/* PEP-251: changing a database and sending letters ask the owner by default. */} - + {/* PEP-251: changing a database and sending letters ask the owner by default. PEP-236: an MCP server's writing tools too. */} +
+ {c.protocol === "mcp" && }

- {c.protocol === "http" ? t("Чтение — смотреть данные, ничего не меняя. Запись — создавать, менять, удалять и отправлять. «Спрашивать меня» пока означает отказ: подтверждение запросов появится позже.") : t.text(PROTOCOL_TEXT[c.protocol as GatewayProtocol].modes)} - {c.protocol !== "http" && <> {t("«Спрашивать меня» пока означает отказ: подтверждение запросов появится позже.")}} + {c.protocol === "mcp" ? t("Чтение — инструменты, которые сервер отметил как только читающие. Запись — все остальные. Свой режим инструмента важнее.") : c.protocol === "http" ? t("Чтение — смотреть данные, ничего не меняя. Запись — создавать, менять, удалять и отправлять. «Спрашивать меня» пока означает отказ: подтверждение запросов появится позже.") : t.text(PROTOCOL_TEXT[c.protocol as GatewayProtocol].modes)} + {c.protocol !== "http" && c.protocol !== "mcp" && <> {t("«Спрашивать меня» пока означает отказ: подтверждение запросов появится позже.")}}

{/* PEP-260: an «echo» operation can hand the key back in a form masking doesn't know. */} {c.protocol === "http" &&

{t("Не разрешайте агенту действия, которые возвращают присланное обратно: проверку, отладку, «кто я» с ключом. Через них сервис может показать агенту ключ.")}

} @@ -291,10 +299,11 @@ function ConnectionCard({ c, projects, agents, engineer, t }: { c: ConnectionVie {active && c.hasKey && (
- + )} + {c.protocol === "mcp" && }
{t("Кому разрешено")} @@ -324,12 +333,12 @@ function ConnectionCard({ c, projects, agents, engineer, t }: { c: ConnectionVie ) : (
- {c.protocol === "ssh" ? ( + {c.protocol === "mcp" && c.authKind === "none" ? null : c.protocol === "ssh" ? (