diff --git a/demo/connectors/connectors.js b/demo/connectors/connectors.js new file mode 100644 index 0000000..b58fbc3 --- /dev/null +++ b/demo/connectors/connectors.js @@ -0,0 +1,560 @@ +// Draws each `.panel` from its data-start state and wires the clicks, so every +// frame can be walked through. data-always says whether the host's policy lets +// a user always allow a tool; data-inline draws the element standing on a page +// of its own, whose first screen has no back arrow. Nothing here is fetched. + +const ICONS = { + back: '', + close: '', + plus: '', + menu: '', + plug: '', + warn: '', + info: '', + lock: '', + shield: '', + refresh: '', + window: '', +}; +const icon = (name, style = "") => + ``; + +const esc = (text) => + String(text).replace( + /[&<>"]/g, + (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c], + ); + +// The host's optional presets: a name and a URL, and whether the server takes a +// token in the form rather than signing in through its own page. +const PRESETS = [ + { name: "Linear", url: "https://mcp.linear.app/mcp", token: false }, + { name: "GitHub", url: "https://api.githubcopilot.com/mcp/", token: false }, + { name: "Notion", url: "https://mcp.notion.com/mcp", token: false }, + { name: "Sentry", url: "https://mcp.sentry.dev/mcp", token: true }, +]; + +const LINEAR_TOOLS = [ + { name: "list_issues", desc: "List issues by team, state or assignee.", hint: "read-only", on: true, always: true }, + { name: "get_issue", desc: "Read one issue with its comments.", hint: "read-only", on: true, always: false }, + { name: "create_issue", desc: "Open an issue in a team.", hint: "", on: true, always: false }, + { name: "update_issue", desc: "Change an issue's state, assignee or title.", hint: "", on: true, always: false }, + { name: "create_comment", desc: "Comment on an issue.", hint: "", on: true, always: false }, + { name: "list_projects", desc: "List projects and their leads.", hint: "read-only", on: true, always: false }, + { name: "delete_issue", desc: "Delete an issue for good.", hint: "destructive", on: false, always: false }, + { name: "list_users", desc: "List members of the workspace.", hint: "read-only", on: false, always: false }, +]; + +const CONNECTORS = [ + { + id: "linear", + name: "Linear", + url: "https://mcp.linear.app/mcp", + scope: "personal", + status: "connected", + tools: LINEAR_TOOLS, + }, + { + id: "github", + name: "GitHub", + url: "https://api.githubcopilot.com/mcp/", + scope: "personal", + status: "auth", + tools: [], + }, + { + id: "wiki", + name: "Team wiki", + url: "http://10.0.4.12:8080/mcp", + scope: "personal", + status: "refused", + why: "A private address: only https to a public host is allowed.", + tools: [], + }, + { + id: "sentry", + name: "Sentry", + url: "https://mcp.sentry.dev/mcp", + scope: "personal", + status: "off", + tools: [], + }, + { + id: "notion", + name: "Notion", + url: "https://mcp.notion.com/mcp", + scope: "team", + status: "changed", + tools: [], + }, + { + id: "docs", + name: "Northwind docs", + url: "https://docs.northwind.example/mcp", + scope: "team", + status: "connected", + readOnly: true, + tools: [{ on: true }, { on: true }, { on: true }], + }, +]; + +const CHANGES = [ + { name: "search", kind: "same", desc: "Search pages and databases." }, + { name: "fetch_page", kind: "same", desc: "Read one page." }, + { name: "update_page", kind: "changed", desc: "Its inputs changed: it now takes a parent_id." }, + { name: "create_page", kind: "new", desc: "Create a page under a parent." }, + { name: "archive_page", kind: "removed", desc: "No longer offered by the server." }, +]; + +const STATUS = { + connected: (c) => { + const on = c.tools.filter((t) => t.on).length; + return `Connected · ${on} of ${c.tools.length} tools on`; + }, + auth: () => 'Needs authorization', + changed: () => 'Tools changed', + refused: () => 'Refused by URL policy', + off: () => 'Off', +}; + +const ACTION = { + connected: () => "", + auth: (i) => `Connect`, + changed: (i) => `Review`, + refused: () => "", + off: (i) => `Turn on`, +}; + +function mount(panel) { + const always = panel.dataset.always ?? "permit"; + const inline = panel.hasAttribute("data-inline"); + const connectors = CONNECTORS.map((c) => ({ ...c, tools: c.tools.map((t) => ({ ...t })) })); + let state = { view: panel.dataset.start }; + if (state.view === "tools") state = { view: "tools", index: 0 }; + if (state.view === "waiting") state = { view: "waiting", index: 1 }; + if (state.view === "changed") state = { view: "changed", index: 4 }; + if (state.view === "add") state = { view: "add", preset: "", name: "", url: "", error: null }; + let toast = ""; + + const header = (title, { back = true, sub = "", extra = "" } = {}) => ` +
+ ${ + back + ? `` + : inline + ? "" + : `` + } +
${title}${sub ? `${sub}` : ""}
+ ${extra} + ${inline ? "" : ``} +
`; + + const row = (c, i) => ` + `; + + const listView = () => { + const groups = [ + ["personal", "Personal", "Only you"], + ["team", "Team", "Everyone in Northwind"], + ]; + const sections = groups + .map(([scope, label, who]) => { + const rows = connectors + .map((c, i) => [c, i]) + .filter(([c]) => c.scope === scope) + .map(([c, i]) => row(c, i)) + .join(""); + return rows + ? `
${label}${who}
${rows}
` + : ""; + }) + .join(""); + return ` + ${header("Connectors", { + back: !inline, + sub: `${connectors.length}`, + extra: ``, + })} +
${sections}
+
`; + }; + + const addView = () => { + const preset = PRESETS.find((p) => p.name === state.preset); + const options = [ + ``, + ...PRESETS.map( + (p) => ``, + ), + ].join(""); + return ` + ${header("Add a connector")} +
+
+
+ + +
Presets are the servers this app suggests.
+
+
+ + +
What the agent and the approval cards call it.
+
+
+ + + ${state.error ? `` : ""} +
${preset ? "Set by the preset." : "A remote MCP server, over https."}
+
+ ${ + preset?.token + ? `
+
Kept by the app's server, never shown again.
` + : "" + } +
Save to
+ + +
Only the places you may write to are offered.
+
${icon("shield")}Its tools are off until you choose them, and each call asks you first.
+
+
+
+ + + +
`; + }; + + const waitingView = () => { + const c = connectors[state.index]; + const host = new URL(c.url).host; + return ` + ${header(`Connect ${esc(c.name)}`)} +
+
+
+

Waiting for ${esc(c.name)}

+

Sign in and allow access in the window that opened. This panel carries on by itself when you are done.

+

${esc(host)}

+
+ + +
+
+
+ `; + }; + + const askControl = (tool, ti) => { + if (!tool.on) return ""; + if (always === "forbid") { + return `
${icon("lock")}Asks every time
`; + } + return `
On each call + + +
`; + }; + + const toolsView = () => { + const c = connectors[state.index]; + const on = c.tools.filter((t) => t.on).length; + const tools = c.tools + .map( + (t, ti) => ` + `, + ) + .join(""); + const policyNote = + always === "forbid" + ? `
${icon("lock")}Northwind asks you on every call to a connector tool. Always allow is turned off by your organisation.
` + : `
${icon("shield")}Each call asks you first. Always allow skips the question for that tool only.
`; + return ` + ${header(esc(c.name), { sub: `${on} of ${c.tools.length} on` })} +
+
+
+ ${esc(c.url)}Connected +
+ ${policyNote} + ${tools} +
+
+
+ + + + + +
`; + }; + + const changedView = () => { + const c = connectors[state.index]; + const tag = { + same: "", + changed: 'Changed', + new: 'New', + removed: 'Removed', + }; + const rows = CHANGES.map( + (t) => ` +
+ ${esc(t.name)} + ${t.kind === "same" || t.kind === "removed" ? "" : ``} + ${esc(t.desc)} + ${tag[t.kind] ? `${tag[t.kind]}` : ""} +
`, + ).join(""); + return ` + ${header(esc(c.name), { sub: "tools changed" })} +
+
+
${icon("warn")}The server's tools are not the ones approved on Nov 28. The unchanged tools keep working; the rest stay out of the run until you approve them.
+ ${rows} +
+
+
+ + + +
`; + }; + + const readOnlyView = () => { + const c = connectors[state.index]; + return ` + ${header(esc(c.name), { sub: "team" })} +
+
${icon("lock")}A team connector, set up by an admin. You can use its tools; only an admin can change it.
+
${esc(c.url)}
+
`; + }; + + const via = (name) => + `${icon("plug")}${esc(name)} · your connector`; + + const approvalCard = () => ` +
+
${icon("shield", "width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.75")}Call a tool on Linear?
+
+
+
Tool
list_issues
+
From
${via("Linear")}
+
Server
mcp.linear.app
+
Server says
read-only. Connector tools ask whatever the server says.
+
+
{ "team": "Platform", "state": "In Progress", "assignee": "me" }
+
+
+ ${ + always === "permit" + ? '' + : 'Northwind asks on every connector call.' + } + +
+
`; + + const chatView = () => { + const first = + always === "permit" + ? ` +
What did I close on Linear this week?
+
+
+
get_issue${via("Linear")}✓ done
+
PLAT-412 Retry flaky upload test: Done, Nov 27
+
+

One so far, PLAT-412. Let me list the rest of the team's issues.

+
` + : ` +
Show this week's error rate from Grafana.
+
+
+
show_dashboard${via("Grafana")}✓ done
+
{ "panel": "api / 5xx rate", "from": "now-7d",
+  "points": [0.4, 0.3, 0.9, 0.5, 0.4, 0.3, 0.2], "unit": "%" }
+
${icon("info")}This tool has an interactive view. Views from connectors are not shown; this is its result.
+
+

5xx peaked at 0.9% on Wednesday. Now the open incidents on Linear.

+
`; + return ` + ${header("Support assistant", { back: false, extra: `` })} +
+
+ ${first} +
${approvalCard()}
+
+
+
Reply…
`; + }; + + const render = () => { + const views = { + list: listView, + add: addView, + waiting: waitingView, + tools: toolsView, + changed: changedView, + readonly: readOnlyView, + chat: chatView, + }; + panel.innerHTML = + views[state.view]() + (toast ? `
${esc(toast)}
` : ""); + toast = ""; + }; + + const toList = (message = "") => { + toast = message; + state = { view: "list" }; + }; + + panel.addEventListener("change", (event) => { + const target = event.target; + if (state.view === "add" && target.dataset.f === "preset") { + const preset = PRESETS.find((p) => p.name === target.value); + state = { + ...state, + preset: target.value, + name: preset?.name ?? "", + url: preset?.url ?? "", + error: null, + }; + render(); + } + }); + + panel.addEventListener("input", (event) => { + const field = event.target.dataset?.f; + if (state.view === "add" && (field === "name" || field === "url")) { + state[field] = event.target.value; + } + }); + + panel.addEventListener("click", (event) => { + const el = event.target.closest("[data-act]"); + if (!el) return; + const act = el.dataset.act; + const index = el.dataset.index === undefined ? null : Number(el.dataset.index); + if (index !== null && act !== "open") event.stopPropagation(); + if (act === "open") { + const c = connectors[index]; + if (c.readOnly) state = { view: "readonly", index }; + else if (c.status === "auth") state = { view: "waiting", index }; + else if (c.status === "changed") state = { view: "changed", index }; + else if (c.status === "refused") state = { view: "add", preset: "", name: c.name, url: c.url, error: c.why, editing: index }; + else if (c.tools.length) state = { view: "tools", index }; + else return; + } else if (act === "connect") state = { view: "waiting", index }; + else if (act === "review") state = { view: "changed", index }; + else if (act === "turn-on") { + connectors[index].status = "auth"; + toast = `${connectors[index].name} is on; connect it to use its tools`; + } else if (act === "add") state = { view: "add", preset: "", name: "", url: "", error: null }; + else if (act === "back" || act === "to-list") { + if (panel.dataset.start === "chat" && act === "back") state = { view: "chat" }; + else toList(); + } else if (act === "save-add") { + let host = ""; + try { + const url = new URL(state.url); + host = url.protocol === "https:" ? url.hostname : ""; + } catch { + host = ""; + } + const isPrivate = /^(localhost|127\.|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|169\.254\.|\[?::1\]?$)/.test(host); + if (state.name.trim() === "") { + state = { ...state, error: null }; + toast = "Give it a name"; + } else if (host === "" || isPrivate) { + state = { + ...state, + error: "Refused by the URL policy: only https, and no private, loopback or link-local address.", + }; + } else { + const fresh = { + id: `new-${Date.now()}`, + name: state.name.trim(), + url: state.url, + scope: "personal", + status: "auth", + tools: [], + }; + if (state.editing !== undefined) connectors.splice(state.editing, 1, fresh); + else connectors.unshift(fresh); + const index = connectors.indexOf(fresh); + if (PRESETS.find((p) => p.name === state.preset)?.token) { + fresh.status = "connected"; + fresh.tools = LINEAR_TOOLS.map((t) => ({ ...t, on: false, always: false })); + toast = `Tested ${fresh.name}; choose its tools`; + state = { view: "tools", index }; + } else state = { view: "waiting", index }; + } + } else if (act === "authorized") { + const c = connectors[state.index]; + c.status = "connected"; + c.tools = LINEAR_TOOLS.map((t) => ({ ...t, on: false, always: false })); + toast = `Signed in to ${c.name}; choose its tools`; + state = { view: "tools", index: state.index }; + } else if (act === "toggle") { + const tool = connectors[state.index].tools[Number(el.dataset.tool)]; + tool.on = el.checked; + if (!tool.on) tool.always = false; + } else if (act === "ask" || act === "always") { + event.preventDefault(); + connectors[state.index].tools[Number(el.dataset.tool)].always = act === "always"; + } else if (act === "save-tools") toList(`Saved ${connectors[state.index].name}`); + else if (act === "disable") { + connectors[state.index].status = "off"; + toList(`${connectors[state.index].name} is off; its sign-in and tools are kept`); + } else if (act === "remove") { + const [gone] = connectors.splice(state.index, 1); + toList(`Removed ${gone.name} and signed out of it`); + } else if (act === "approve-changes") { + const c = connectors[state.index]; + c.status = "connected"; + c.tools = [{ on: true }, { on: true }, { on: true }, { on: true }, { on: false }]; + toList(`Approved the new tools of ${c.name}`); + } else return; + render(); + }); + render(); +} + +for (const panel of document.querySelectorAll(".panel")) mount(panel); + +for (const button of document.querySelectorAll("[data-theme-pick]")) { + button.addEventListener("click", () => { + const pick = button.dataset.themePick; + if (pick === "system") delete document.documentElement.dataset.theme; + else document.documentElement.dataset.theme = pick; + for (const other of document.querySelectorAll("[data-theme-pick]")) { + other.setAttribute("aria-pressed", String(other === button)); + } + }); +} diff --git a/demo/connectors/index.html b/demo/connectors/index.html new file mode 100644 index 0000000..a989002 --- /dev/null +++ b/demo/connectors/index.html @@ -0,0 +1,1325 @@ + + + + + + Connectors design + + + +
+ Connectors + design study for the connectors panel; every frame is clickable +
+ + + +
+
+
+
+

Remote MCP servers a user connects

+

+ A connector is a remote MCP server the user adds by URL or from a preset the host + offers. Its tools join the agent's run once the user has signed in to it and chosen which + tools to turn on. Every call to a connector tool asks for approval, whatever the server + says about the tool, unless the host's policy lets the user always allow that tool. +

+

+ The same panel is drawn twice: inside the chat, as the routines and skills views are, + and as <ag-ui-connectors> on a settings page of the host's own, with + no chat beside it. +

+
+ +

Inside the chat

+

A full-panel view in place of the conversation, with a back arrow to it.

+
+
+
+
+ 1. The list. One row per connector, grouped as the policy answers (personal or + team), each with its status: connected (and how many tools are on), + needs authorization (Connect), tools changed (Review), refused by the + URL policy (the reason, no way to connect), and off. A team connector the caller + may not write opens read-only. +
+
+
+
+
+ 2. Adding one. A preset fills the name and the URL and locks the URL; Custom + leaves both free. A preset whose server takes a token asks for it here (pick Sentry); + it is tested straight away. The others sign in through the server's own page after saving. Try an + http:// or private address: the URL policy refuses it under the field. +
+
+
+
+
+ 3. Connect. The server's authorization page opens in a popup and the panel waits + for the callback's message. Click Allow in the drawn popup: the panel then tests the + server and lists its tools (frame 4). If the popup is blocked or closed, Open again. +
+
+
+
+
+ 4. Tools from the test, when the policy permits always allow. One switch per tool + puts it in the run. Each tool that is on asks every time by default; the user may set + it to Always allow. What the server says about a tool (read-only, destructive) is shown + as its claim, not acted on. +
+
+
+
+
+ 5. The same, when the policy does not permit it. The choice is shown locked at + Ask every time, with one line saying why, rather than hidden, so a user who heard of it + learns it is the host's rule. +
+
+
+
+
+ 6. Tools changed. The server's tools differ from what the user approved. The + unchanged tools keep working; a new tool comes in off, a changed one is out of the run + until approved again, and a removed one is listed so the user sees it went. +
+
+
+
+
+ 7. Provenance, policy permits always allow. A connector tool's card and its + approval card name the connector, its host, and that it is the user's own, not the + app's. The server marks list_issues read-only and it still asks. Always + allow sits on the card, beside Approve. +
+
+
+
+
+ 8. Provenance, policy forbids it, and an MCP App. No Always allow on the card, + only a line saying every call asks. Above it, a connector tool that carries an MCP Apps + view renders as a plain result, with one line saying the view is not shown. +
+
+
+ +

On a page of its own: <ag-ui-connectors>

+

+ The same screens, on the host's settings page with no chat. Its first screen has no back + arrow (there is nothing to go back to); the screens behind a row do. +

+
+ +
+

Connectors

+

Servers your assistant may call for you. Each call asks first.

+
<ag-ui-connectors data-connectors-url="/agent/connectors/">
+
+
+
+ +
+

Questions for the owner

+
    +
  1. + Where Always allow is set: on the tools screen (frame 4), on the approval card + (frame 7), or both. Recommended: both, the card's box sets the same stored answer. +
  2. +
  3. + Always allow when the policy forbids it: locked with its reason on the tools + screen and absent from the approval card with one line (frames 5 and 8), or hidden + everywhere. Recommended: as drawn. +
  4. +
  5. + How the chat opens the panel: the header holds six buttons at 240px, so a + Connectors button comes behind its own opt-in attribute, as the skill editor's does; + or only a row in the header's More menu. Recommended: the More menu row by default, + the header button behind an opt-in. +
  6. +
  7. + Which tools are on after the first test: none (the user turns each on, with Turn + all on), or all. Recommended: none, as drawn; the stored allow-list's empty value + already means none. +
  8. +
  9. + Tools changed: only the changed tools leave the run until reviewed (drawn), or + the whole connector stops. Recommended: only the changed tools. +
  10. +
  11. + Off and Remove: both (off keeps the sign-in and the tool choices, Remove deletes + the connector and revokes its credential), or Remove only. Recommended: both, as drawn. +
  12. +
  13. + MCP Apps from a connector: out of the first cut? A connector tool with a view + renders as a plain result (frame 8). Recommended: yes, out of the first cut. +
  14. +
+
+
+ + + diff --git a/demo/mock-server.mjs b/demo/mock-server.mjs index d7d5102..7906f4a 100644 --- a/demo/mock-server.mjs +++ b/demo/mock-server.mjs @@ -41,7 +41,7 @@ const HTML = "text/html; charset=utf-8"; const APP_PAGE = { path: "app/index.html", contentType: HTML }; const SCENARIO_PATH = /^\/scenarios\/[a-z0-9-]+\/$/; // Static files are served from these directories only, by extension. -const STATIC_DIRS = ["app", "page", "threads", "agents", "editors"]; +const STATIC_DIRS = ["app", "page", "threads", "agents", "editors", "connectors"]; const TYPES = new Map([ [".html", HTML], [".js", "text/javascript"], @@ -55,6 +55,8 @@ const PAGE_ASSETS = new Map([ ["/agents/", { path: "agents/index.html", contentType: HTML }], // The routines and skill editors as elements of their own, beside a chat or alone. ["/editors/", { path: "editors/index.html", contentType: HTML }], + // A static design study of the connectors panel; it loads no bundle. + ["/connectors/", { path: "connectors/index.html", contentType: HTML }], // Every page loads it; it does nothing unless the URL carries `?readout`. ["/viewport-readout.js", { path: "viewport-readout.js", contentType: "text/javascript" }], ]); @@ -1717,6 +1719,7 @@ server.listen(PORT, HOST, () => { process.stdout.write(` thread list: http://localhost:${PORT}/threads/\n`); process.stdout.write(` agents home: http://localhost:${PORT}/agents/\n`); process.stdout.write(` editor elements: http://localhost:${PORT}/editors/\n`); + process.stdout.write(` connectors design: http://localhost:${PORT}/connectors/\n`); // Any wildcard bind reaches the LAN, so the addresses are worth printing for // both spellings rather than only the one this file happens to default to. if (HOST === "::" || HOST === "0.0.0.0") {