backlog-tiny-mcp 0.35.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. backlog_mcp/__init__.py +29 -0
  2. backlog_mcp/__main__.py +10 -0
  3. backlog_mcp/auth.py +199 -0
  4. backlog_mcp/backlog.py +696 -0
  5. backlog_mcp/cli.py +2046 -0
  6. backlog_mcp/client.py +320 -0
  7. backlog_mcp/computer.py +33 -0
  8. backlog_mcp/database.py +80 -0
  9. backlog_mcp/embeddings.py +900 -0
  10. backlog_mcp/global_rules.md +126 -0
  11. backlog_mcp/guidance.py +11 -0
  12. backlog_mcp/guide/index.md +11 -0
  13. backlog_mcp/guide/memory.md +27 -0
  14. backlog_mcp/guide/projects.md +16 -0
  15. backlog_mcp/guide/search.md +72 -0
  16. backlog_mcp/guide/tasks.md +40 -0
  17. backlog_mcp/guide/workflow.md +22 -0
  18. backlog_mcp/httpd.py +270 -0
  19. backlog_mcp/migrate.py +113 -0
  20. backlog_mcp/migrations/0001-initial.sql +194 -0
  21. backlog_mcp/migrations/0002-task-assignment.sql +2 -0
  22. backlog_mcp/migrations/0003-task-edit-claims.sql +5 -0
  23. backlog_mcp/migrations/0004-memory-visibility.sql +42 -0
  24. backlog_mcp/model/CITATION.bib +9 -0
  25. backlog_mcp/model/LICENSE +202 -0
  26. backlog_mcp/model/README.md +12 -0
  27. backlog_mcp/model/UPSTREAM.md +2053 -0
  28. backlog_mcp/model/config.json +12 -0
  29. backlog_mcp/model/model.safetensors +4 -0
  30. backlog_mcp/model/modules.json +14 -0
  31. backlog_mcp/model/provenance.json +16 -0
  32. backlog_mcp/model/tokenizer.json +1 -0
  33. backlog_mcp/models.py +581 -0
  34. backlog_mcp/names.py +35 -0
  35. backlog_mcp/paths.py +53 -0
  36. backlog_mcp/protocol_storage.py +104 -0
  37. backlog_mcp/queries.py +7 -0
  38. backlog_mcp/queries.sql +531 -0
  39. backlog_mcp/records.py +215 -0
  40. backlog_mcp/render.py +479 -0
  41. backlog_mcp/server.py +2864 -0
  42. backlog_mcp/skills/autopilot/SKILL.md +96 -0
  43. backlog_mcp/skills/planning/SKILL.md +106 -0
  44. backlog_mcp/skills/planning/references/splitting.md +45 -0
  45. backlog_mcp/skills/triage/SKILL.md +104 -0
  46. backlog_mcp/skills/triage/references/conventions.md +43 -0
  47. backlog_mcp/skills.py +56 -0
  48. backlog_mcp/static/agent-config.js +20 -0
  49. backlog_mcp/static/app.css +1950 -0
  50. backlog_mcp/static/app.js +1301 -0
  51. backlog_mcp/static/assignments.js +96 -0
  52. backlog_mcp/static/breadcrumbs.js +54 -0
  53. backlog_mcp/static/comment-composer.js +95 -0
  54. backlog_mcp/static/connect.css +98 -0
  55. backlog_mcp/static/connect.html +74 -0
  56. backlog_mcp/static/connect.js +160 -0
  57. backlog_mcp/static/credentials.js +72 -0
  58. backlog_mcp/static/diagrams.js +128 -0
  59. backlog_mcp/static/dom.js +162 -0
  60. backlog_mcp/static/editor-claim.js +104 -0
  61. backlog_mcp/static/editor.js +355 -0
  62. backlog_mcp/static/index.html +137 -0
  63. backlog_mcp/static/markdown.css +33 -0
  64. backlog_mcp/static/markdown.js +72 -0
  65. backlog_mcp/static/mcp.js +177 -0
  66. backlog_mcp/static/memory-append.js +34 -0
  67. backlog_mcp/static/memory-editor.js +173 -0
  68. backlog_mcp/static/memory.js +279 -0
  69. backlog_mcp/static/package.json +1 -0
  70. backlog_mcp/static/project-form.js +71 -0
  71. backlog_mcp/static/project-settings.js +225 -0
  72. backlog_mcp/static/scope.js +90 -0
  73. backlog_mcp/static/statistics.js +87 -0
  74. backlog_mcp/static/task-browser.js +100 -0
  75. backlog_mcp/static/task-pagination.js +94 -0
  76. backlog_mcp/static/task-picker.js +164 -0
  77. backlog_mcp/static/task-table.js +74 -0
  78. backlog_mcp/static/vendor/README.md +12 -0
  79. backlog_mcp/static/vendor/dompurify-LICENSE +202 -0
  80. backlog_mcp/static/vendor/highlight-LICENSE +29 -0
  81. backlog_mcp/static/vendor/highlight-dark.css +118 -0
  82. backlog_mcp/static/vendor/highlight-light.css +118 -0
  83. backlog_mcp/static/vendor/highlight.min.js +1262 -0
  84. backlog_mcp/static/vendor/marked-LICENSE +44 -0
  85. backlog_mcp/static/vendor/marked.esm.js +80 -0
  86. backlog_mcp/static/vendor/marked.esm.js.map +7 -0
  87. backlog_mcp/static/vendor/mermaid-LICENSE +21 -0
  88. backlog_mcp/static/vendor/mermaid.min.js +4376 -0
  89. backlog_mcp/static/vendor/purify.es.mjs +2722 -0
  90. backlog_mcp/static/vendor/purify.es.mjs.map +1 -0
  91. backlog_mcp/transaction.py +47 -0
  92. backlog_mcp/version.py +79 -0
  93. backlog_mcp/webui.py +63 -0
  94. backlog_tiny_mcp-0.35.0.dist-info/METADATA +84 -0
  95. backlog_tiny_mcp-0.35.0.dist-info/RECORD +97 -0
  96. backlog_tiny_mcp-0.35.0.dist-info/WHEEL +4 -0
  97. backlog_tiny_mcp-0.35.0.dist-info/entry_points.txt +4 -0
@@ -0,0 +1,96 @@
1
+ import { el, button, field, link, taskRoute, projectRoute } from "./dom.js";
2
+
3
+ let marker;
4
+ function browserMarker() {
5
+ if (marker) return marker;
6
+ const key = "backlog:assignment-marker";
7
+ try {
8
+ marker = sessionStorage.getItem(key);
9
+ } catch {}
10
+ if (!marker) {
11
+ marker = `browser-${crypto.randomUUID()}`;
12
+ try {
13
+ sessionStorage.setItem(key, marker);
14
+ } catch {}
15
+ }
16
+ return marker;
17
+ }
18
+ export async function assignmentControl(task, { call, principal, notify, refresh }) {
19
+ const { project } = await call("project_board", { project: task.project });
20
+ if (project.role === "reader") return null;
21
+ if (task.assigned && !task.assigned.startsWith(principal + ":")) return null;
22
+ const control = button(task.assigned ? "Release task" : "Claim task", async () => {
23
+ control.disabled = true;
24
+ try {
25
+ await call("task_claim", {
26
+ task: task.id,
27
+ expected: task.assigned || null,
28
+ assigned: task.assigned ? null : `${principal}:${browserMarker()}`,
29
+ ...(task.assigned?.startsWith(`${principal}:ui-edit-`) ? { restore: true } : {}),
30
+ });
31
+ await refresh();
32
+ } catch (error) {
33
+ notify(error);
34
+ } finally {
35
+ control.disabled = false;
36
+ }
37
+ });
38
+ return control;
39
+ }
40
+
41
+ export async function assignmentsPage(target, { call, navigate, principal }) {
42
+ const prefixValue = target.params.get("prefix") || "";
43
+ const offset = Math.max(0, Number(target.params.get("offset")) || 0);
44
+ const limit = 50;
45
+ const data = await call("task_assigned", { prefix: prefixValue || null, offset, limit });
46
+ const prefix = el("input", { value: prefixValue, placeholder: `${principal}:` });
47
+ const href = (nextOffset = 0) => {
48
+ const params = new URLSearchParams({ view: "assigned" });
49
+ if (prefix.value.trim()) params.set("prefix", prefix.value.trim());
50
+ if (nextOffset) params.set("offset", nextOffset);
51
+ return `/ui/?${params}`;
52
+ };
53
+ return el(
54
+ "section",
55
+ { class: "assignments-page" },
56
+ el("h1", {}, "Assigned tasks"),
57
+ el(
58
+ "p",
59
+ { class: "muted" },
60
+ `Across accessible projects and statuses. Default: ${principal}. Closing a task does not release its assignment.`,
61
+ ),
62
+ el(
63
+ "form",
64
+ {
65
+ class: "row",
66
+ onsubmit: (event) => {
67
+ event.preventDefault();
68
+ navigate(href());
69
+ },
70
+ },
71
+ field("Assignment prefix", prefix),
72
+ el("button", { type: "submit" }, "Filter"),
73
+ ),
74
+ el(
75
+ "p",
76
+ { class: "muted" },
77
+ `${data.count} assignments · ${data.items.length ? offset + 1 : 0}–${offset + data.items.length} shown`,
78
+ ),
79
+ ...data.items.map((task) =>
80
+ el(
81
+ "article",
82
+ { class: "panel" },
83
+ link(`#${task.id} ${task.title}`, taskRoute(task.id)),
84
+ el("p", {}, link(task.project, projectRoute(task.project)), ` · ${task.status}`),
85
+ el("p", { class: "assignment-label" }, task.assigned),
86
+ ),
87
+ ),
88
+ data.items.length ? null : el("p", {}, "No matching assignments."),
89
+ el(
90
+ "div",
91
+ { class: "row" },
92
+ offset ? link("Previous", href(Math.max(0, offset - limit)), "button") : null,
93
+ offset + data.items.length < data.count ? link("Next", href(offset + limit), "button") : null,
94
+ ),
95
+ );
96
+ }
@@ -0,0 +1,54 @@
1
+ import { el, link, projectRoute, memoryRoute, taskRoute } from "./dom.js";
2
+
3
+ export function breadcrumbs(target, project) {
4
+ const items = [{ label: "Projects", href: "/ui/" }];
5
+ if (project) items.push({ label: project, href: projectRoute(project) });
6
+ switch (target.kind) {
7
+ case "tasks":
8
+ items.push({ label: "All tasks" });
9
+ break;
10
+ case "stats":
11
+ items.push({ label: "Statistics" });
12
+ break;
13
+ case "assigned":
14
+ items.push({ label: "Assigned tasks" });
15
+ break;
16
+ case "settings":
17
+ items.push({ label: "Settings" });
18
+ break;
19
+ case "board":
20
+ if (target.params.get("status") === "deleted") items.push({ label: "Deleted tasks" });
21
+ break;
22
+ case "task":
23
+ case "edit":
24
+ items.push({ label: `Task #${target.id}`, href: taskRoute(target.id) });
25
+ if (target.kind === "edit") items.push({ label: "Edit" });
26
+ break;
27
+ case "new":
28
+ items.push({ label: "New task" });
29
+ break;
30
+ case "memory":
31
+ items.push({ label: "Memory", href: memoryRoute(project) });
32
+ if (target.id)
33
+ items.push({
34
+ label: `Note #${target.id}`,
35
+ href: memoryRoute(project, new URLSearchParams({ note: target.id })),
36
+ });
37
+ if (target.params.get("create") === "true") items.push({ label: "New note" });
38
+ else if (target.params.get("edit") === "true") items.push({ label: "Edit" });
39
+ break;
40
+ }
41
+ return el(
42
+ "ol",
43
+ {},
44
+ ...items.map((item, index) =>
45
+ el(
46
+ "li",
47
+ {},
48
+ index === items.length - 1
49
+ ? el("span", { "aria-current": "page" }, item.label)
50
+ : link(item.label, item.href),
51
+ ),
52
+ ),
53
+ );
54
+ }
@@ -0,0 +1,95 @@
1
+ import { el, button } from "./dom.js";
2
+
3
+ export function commentComposer({ taskId, draftKey, call, markdown, onAdded }) {
4
+ const body = el("textarea", {
5
+ placeholder: "Write a comment in Markdown…",
6
+ "aria-label": "Comment",
7
+ });
8
+ const draftStatus = el("small", { class: "muted", role: "status" });
9
+ const summary = el("summary", {}, "Add a comment");
10
+ function showDraft() {
11
+ summary.textContent = body.value ? "Continue comment draft" : "Add a comment";
12
+ }
13
+ try {
14
+ body.value = localStorage.getItem(draftKey) || "";
15
+ if (body.value) draftStatus.textContent = "Draft saved on this device";
16
+ } catch {
17
+ draftStatus.textContent = "Draft storage is unavailable in this browser.";
18
+ }
19
+ showDraft();
20
+ body.oninput = () => {
21
+ showDraft();
22
+ try {
23
+ if (body.value) localStorage.setItem(draftKey, body.value);
24
+ else localStorage.removeItem(draftKey);
25
+ draftStatus.textContent = body.value ? "Draft saved on this device" : "";
26
+ } catch {
27
+ draftStatus.textContent = "Could not save this draft. Keep this page open.";
28
+ }
29
+ };
30
+ const preview = el("div", { class: "comment-preview markdown", hidden: true });
31
+ const error = el("p", { class: "error", role: "alert", hidden: true });
32
+ const write = button("Write", () => changeView(false));
33
+ const previewButton = button("Preview", () => changeView(true));
34
+ function changeView(showPreview) {
35
+ if (showPreview) preview.replaceChildren(markdown(body.value));
36
+ body.hidden = showPreview;
37
+ preview.hidden = !showPreview;
38
+ write.setAttribute("aria-pressed", String(!showPreview));
39
+ previewButton.setAttribute("aria-pressed", String(showPreview));
40
+ }
41
+ const submit = el("button", { type: "submit", class: "primary" }, "Add comment");
42
+ const form = el(
43
+ "form",
44
+ { class: "comment-form" },
45
+ el("div", { class: "editor-tabs" }, write, previewButton),
46
+ body,
47
+ preview,
48
+ error,
49
+ el(
50
+ "div",
51
+ { class: "form-actions" },
52
+ el("div", {}, el("small", { class: "muted" }, "Markdown supported"), draftStatus),
53
+ submit,
54
+ ),
55
+ );
56
+ const composer = el("details", { class: "comment-composer" }, summary, form);
57
+ changeView(false);
58
+ form.onsubmit = async (event) => {
59
+ event.preventDefault();
60
+ if (submit.disabled) return;
61
+ if (!body.value.trim()) {
62
+ changeView(false);
63
+ error.textContent = "Write a comment before sending.";
64
+ error.hidden = false;
65
+ body.focus();
66
+ return;
67
+ }
68
+ submit.disabled = true;
69
+ body.disabled = true;
70
+ error.hidden = true;
71
+ let added;
72
+ try {
73
+ added = await call("task_comment_add", { task_id: taskId, body: body.value });
74
+ } catch (failure) {
75
+ error.textContent = failure.message;
76
+ error.hidden = false;
77
+ return;
78
+ } finally {
79
+ submit.disabled = false;
80
+ body.disabled = false;
81
+ }
82
+ body.value = "";
83
+ preview.replaceChildren();
84
+ showDraft();
85
+ try {
86
+ localStorage.removeItem(draftKey);
87
+ draftStatus.textContent = "";
88
+ } catch {
89
+ draftStatus.textContent = "Comment sent, but the saved draft could not be cleared.";
90
+ }
91
+ composer.open = false;
92
+ await onAdded(added);
93
+ };
94
+ return composer;
95
+ }
@@ -0,0 +1,98 @@
1
+ .connect-header {
2
+ justify-content: space-between;
3
+ }
4
+ .connect-page {
5
+ max-width: 1180px;
6
+ padding-top: 48px;
7
+ }
8
+ .connect-page h1 {
9
+ font-size: clamp(28px, 4vw, 40px);
10
+ max-width: 750px;
11
+ }
12
+ .connect-layout {
13
+ display: grid;
14
+ grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
15
+ gap: 24px;
16
+ align-items: start;
17
+ margin-top: 32px;
18
+ }
19
+ .connect-layout > .panel {
20
+ margin: 0;
21
+ min-width: 0;
22
+ }
23
+ .connection-form {
24
+ display: grid;
25
+ gap: 18px;
26
+ }
27
+ .connection-form h2,
28
+ .connection-form label,
29
+ .connection-form p {
30
+ margin: 0;
31
+ }
32
+ .connection-note {
33
+ font-size: 12px;
34
+ line-height: 1.6;
35
+ }
36
+ .agent-options {
37
+ display: grid;
38
+ grid-template-columns: repeat(2, minmax(0, 1fr));
39
+ gap: 16px;
40
+ padding-bottom: 20px;
41
+ }
42
+ .agent-options label {
43
+ margin: 0;
44
+ }
45
+ .setup-empty {
46
+ padding: 50px 12px;
47
+ color: var(--muted);
48
+ text-align: center;
49
+ }
50
+ .setup-block {
51
+ margin: 24px 0;
52
+ min-width: 0;
53
+ }
54
+ .setup-block .section-heading {
55
+ flex-wrap: wrap;
56
+ margin-bottom: 8px;
57
+ }
58
+ .setup-block h3 {
59
+ margin: 0;
60
+ }
61
+ .setup-block p {
62
+ font-size: 13px;
63
+ margin: 0 0 12px;
64
+ }
65
+ .setup-code {
66
+ width: 100%;
67
+ font:
68
+ 12px/1.7 ui-monospace,
69
+ monospace;
70
+ padding: 14px;
71
+ background: var(--code-bg);
72
+ overflow-wrap: anywhere;
73
+ resize: vertical;
74
+ min-height: 100px;
75
+ }
76
+ .setup-next {
77
+ padding-top: 16px;
78
+ border-top: 1px solid var(--line);
79
+ }
80
+ #copy-status:empty {
81
+ display: none;
82
+ }
83
+ @media (max-width: 760px) {
84
+ .connect-page {
85
+ padding-top: 28px;
86
+ }
87
+ .connect-layout {
88
+ grid-template-columns: minmax(0, 1fr);
89
+ gap: 18px;
90
+ margin-top: 24px;
91
+ }
92
+ .setup-empty {
93
+ padding: 24px 0;
94
+ }
95
+ .agent-options {
96
+ grid-template-columns: minmax(0, 1fr);
97
+ }
98
+ }
@@ -0,0 +1,74 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ <meta name="referrer" content="no-referrer" />
7
+ <title>Connect your agent · Backlog</title>
8
+ <link rel="icon" href="data:," />
9
+ <link rel="stylesheet" href="./app.css" />
10
+ <link rel="stylesheet" href="./connect.css" />
11
+ <script src="./console-agent-config.js"></script>
12
+ <script type="module" src="./connect.js"></script>
13
+ </head>
14
+ <body>
15
+ <header class="connect-header">
16
+ <a class="brand" href="/ui/">Backlog<span class="brand-dot">.</span></a>
17
+ <a class="button quiet" href="/ui/">Back to workspace</a>
18
+ </header>
19
+ <main class="connect-page">
20
+ <div class="eyebrow">Bring your agent</div>
21
+ <h1>Your backlog, inside your agent.</h1>
22
+ <p class="subtitle">Connect through MCP to work with projects, tasks, and shared context.</p>
23
+ <div class="connect-layout">
24
+ <form id="connection-form" class="panel connection-form">
25
+ <h2>1. Connection details</h2>
26
+ <label>MCP endpoint<input id="endpoint" type="url" required readonly /></label>
27
+ <label>Computer Name<input id="computer" required /></label>
28
+ <label
29
+ >Authentication<select id="method">
30
+ <option value="basic">Username &amp; password</option>
31
+ <option value="bearer">Bearer token</option>
32
+ <option value="none">No authentication</option>
33
+ </select></label
34
+ >
35
+ <label id="username-field"
36
+ >Username<input id="username" autocomplete="username" required
37
+ /></label>
38
+ <label id="secret-field"
39
+ ><span id="secret-label">Password</span
40
+ ><input id="secret" type="password" autocomplete="current-password" required
41
+ /></label>
42
+ <p class="muted connection-note">
43
+ Generation runs in your browser. This page does not send or save your credentials.
44
+ </p>
45
+ <p id="connection-error" class="error" role="alert" hidden></p>
46
+ <button type="submit" class="primary">Generate setup</button>
47
+ </form>
48
+ <section class="panel setup-panel" aria-labelledby="setup-title">
49
+ <h2 id="setup-title">2. Configure your agent</h2>
50
+ <div class="agent-options">
51
+ <label>Agent<select id="agent"></select></label>
52
+ <label>Configuration level<select id="level">
53
+ <option value="user">User · all projects</option>
54
+ <option value="project">Project · this project only</option>
55
+ </select></label>
56
+ <label>Server name<input id="server-name" form="connection-form" value="backlog"
57
+ pattern="[A-Za-z0-9_-]{1,64}" maxlength="64" spellcheck="false" required /></label>
58
+ </div>
59
+ <label id="include-credentials-field" class="inline">
60
+ <input id="include-credentials" type="checkbox" checked />Include authentication headers
61
+ </label>
62
+ <p id="setup-empty" class="setup-empty">
63
+ Enter your connection details to generate a ready-to-copy setup.
64
+ </p>
65
+ <div id="setup-output" hidden></div>
66
+ <p id="copy-status" class="muted" role="status"></p>
67
+ </section>
68
+ </div>
69
+ <noscript
70
+ ><p class="panel">Enable JavaScript to generate your agent configuration.</p></noscript
71
+ >
72
+ </main>
73
+ </body>
74
+ </html>
@@ -0,0 +1,160 @@
1
+ import { agentConfig } from "./agent-config.js";
2
+ import { loadCredentials } from "./credentials.js";
3
+ import { el, button, link } from "./dom.js";
4
+
5
+ const form = document.querySelector("#connection-form");
6
+ const endpoint = document.querySelector("#endpoint");
7
+ const computer = document.querySelector("#computer");
8
+ const method = document.querySelector("#method");
9
+ const username = document.querySelector("#username");
10
+ const secret = document.querySelector("#secret");
11
+ const agent = document.querySelector("#agent");
12
+ const level = document.querySelector("#level");
13
+ const serverName = document.querySelector("#server-name");
14
+ const includeCredentials = document.querySelector("#include-credentials");
15
+ const output = document.querySelector("#setup-output");
16
+ const empty = document.querySelector("#setup-empty");
17
+ const error = document.querySelector("#connection-error");
18
+ const status = document.querySelector("#copy-status");
19
+ const levelKey = "mcp-console-agent-level:/console";
20
+ endpoint.value = new URL("/mcp", location.origin).href;
21
+ const computerWords = ["cedar", "maple", "birch", "pine", "oak", "elm", "willow", "aspen"];
22
+ computer.value =
23
+ computerWords[Math.floor(Math.random() * computerWords.length)] +
24
+ "-" +
25
+ (Math.floor(Math.random() * 9999) + 1);
26
+ try {
27
+ if (localStorage.getItem(levelKey) === "project") level.value = "project";
28
+ } catch {}
29
+ let generated;
30
+
31
+ function populateAgents() {
32
+ const selected = agent.value;
33
+ const variants = agentConfig({
34
+ endpoint: endpoint.value, computer: "computer", method: "none", level: level.value,
35
+ });
36
+ agent.replaceChildren(...variants.map((variant) => el("option", { value: variant.id }, variant.label)));
37
+ if (variants.some((variant) => variant.id === selected)) agent.value = selected;
38
+ }
39
+
40
+ function codeBlock(variant) {
41
+ const code = el("textarea", {
42
+ class: "setup-code", readOnly: true, spellcheck: false,
43
+ "aria-label": `${variant.language.toUpperCase()} configuration`,
44
+ rows: Math.min(12, variant.code.split("\n").length + 1),
45
+ });
46
+ code.value = variant.code;
47
+ const copy = button("Copy configuration", async () => {
48
+ try {
49
+ await navigator.clipboard.writeText(variant.code);
50
+ status.textContent = "Configuration copied.";
51
+ } catch {
52
+ code.focus();
53
+ code.select();
54
+ status.textContent = "Copy is unavailable. The text is selected; press Ctrl+C or ⌘C.";
55
+ }
56
+ });
57
+ return el(
58
+ "section", { class: "setup-block" },
59
+ el("div", { class: "section-heading" }, el("h3", {}, variant.target), copy),
60
+ el("p", { class: "muted" }, variant.instructions),
61
+ code,
62
+ );
63
+ }
64
+
65
+ function render() {
66
+ status.textContent = "";
67
+ if (!generated) return;
68
+ const variant = generated.find((item) => item.id === agent.value);
69
+ output.replaceChildren(
70
+ ...[
71
+ includeCredentials.checked && method.value !== "none"
72
+ ? el("p", { class: "connection-note muted" }, "Generated text contains your credentials. Keep it private.")
73
+ : null,
74
+ codeBlock(variant),
75
+ el("p", { class: "setup-next" }, variant.verify),
76
+ link("Official setup documentation ↗", variant.link),
77
+ ].filter(Boolean),
78
+ );
79
+ empty.hidden = true;
80
+ output.hidden = false;
81
+ requestAnimationFrame(fitCode);
82
+ }
83
+
84
+ function clearOutput() {
85
+ generated = undefined;
86
+ output.replaceChildren();
87
+ output.hidden = true;
88
+ empty.hidden = false;
89
+ status.textContent = "";
90
+ error.hidden = true;
91
+ }
92
+
93
+ function generate() {
94
+ clearOutput();
95
+ if (!form.checkValidity()) return;
96
+ try {
97
+ generated = agentConfig({
98
+ endpoint: endpoint.value,
99
+ computer: computer.value,
100
+ method: method.value,
101
+ username: username.value,
102
+ secret: secret.value,
103
+ name: serverName.value,
104
+ level: level.value,
105
+ includeCredentials: includeCredentials.checked,
106
+ });
107
+ render();
108
+ } catch (failure) {
109
+ error.textContent = failure.message;
110
+ error.hidden = false;
111
+ }
112
+ }
113
+
114
+ function authenticationFields() {
115
+ const basic = method.value === "basic", authenticated = method.value !== "none";
116
+ document.querySelector("#username-field").hidden = !basic;
117
+ document.querySelector("#secret-field").hidden = !authenticated;
118
+ document.querySelector("#include-credentials-field").hidden = !authenticated;
119
+ username.required = basic && includeCredentials.checked;
120
+ secret.required = authenticated && includeCredentials.checked;
121
+ document.querySelector("#secret-label").textContent = basic ? "Password" : "Bearer token";
122
+ }
123
+ method.onchange = () => {
124
+ secret.value = "";
125
+ authenticationFields();
126
+ generate();
127
+ };
128
+ const credentials = loadCredentials(endpoint.value);
129
+ if (credentials) {
130
+ method.value = credentials.method;
131
+ username.value = credentials.username;
132
+ secret.value = credentials.secret;
133
+ }
134
+ authenticationFields();
135
+ populateAgents();
136
+ generate();
137
+ form.addEventListener("input", generate);
138
+ form.onsubmit = (event) => {
139
+ event.preventDefault();
140
+ generate();
141
+ };
142
+ agent.onchange = render;
143
+ level.onchange = () => {
144
+ try { localStorage.setItem(levelKey, level.value); } catch {}
145
+ populateAgents();
146
+ generate();
147
+ };
148
+ serverName.oninput = generate;
149
+ includeCredentials.onchange = () => {
150
+ authenticationFields();
151
+ generate();
152
+ };
153
+
154
+ function fitCode() {
155
+ for (const code of output.querySelectorAll("textarea")) {
156
+ code.style.height = "auto";
157
+ code.style.height = Math.min(420, code.scrollHeight + 2) + "px";
158
+ }
159
+ }
160
+ window.addEventListener("resize", fitCode);
@@ -0,0 +1,72 @@
1
+ function credentialKeys(endpoint) {
2
+ const address = new URL(endpoint, location.origin).href;
3
+ return ["/console", "/console/"].map(
4
+ (path) => `mcp-console-credentials:${JSON.stringify([path, address])}`,
5
+ );
6
+ }
7
+
8
+ export function authorization(record) {
9
+ if (!record) return "";
10
+ const { method, username, secret } = record;
11
+ if (typeof username !== "string" || typeof secret !== "string")
12
+ throw new Error("Enter valid authentication fields.");
13
+ if (method === "basic") {
14
+ if (username.includes(":") || /[\x00-\x1f\x7f]/.test(username + secret))
15
+ throw new Error("Basic credentials cannot contain control characters or a colon in the username.");
16
+ const bytes = new TextEncoder().encode(`${username}:${secret}`);
17
+ return "Basic " + btoa(Array.from(bytes, (byte) => String.fromCharCode(byte)).join(""));
18
+ }
19
+ if (method === "bearer") {
20
+ if (!/^[A-Za-z0-9._~+/-]+=*$/.test(secret))
21
+ throw new Error("Enter a valid Bearer token.");
22
+ return "Bearer " + secret;
23
+ }
24
+ throw new Error("Choose Basic or Bearer authentication.");
25
+ }
26
+
27
+ export function loadCredentials(endpoint) {
28
+ const address = new URL(endpoint, location.origin).href;
29
+ for (const key of credentialKeys(endpoint)) {
30
+ try {
31
+ const record = JSON.parse(localStorage.getItem(key));
32
+ if (record?.version !== 1 || record.endpoint !== address || typeof record.header !== "string")
33
+ continue;
34
+ authorization(record);
35
+ return record;
36
+ } catch {
37
+ // Keep manual login available when storage is unavailable or invalid.
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+
43
+ export function clearCredentials(endpoint) {
44
+ for (const key of credentialKeys(endpoint)) {
45
+ try {
46
+ localStorage.removeItem(key);
47
+ } catch {}
48
+ }
49
+ const legacyKey = `backlog:auth:${new URL(endpoint, location.origin).pathname}`;
50
+ try {
51
+ localStorage.removeItem(legacyKey);
52
+ } catch {}
53
+ try {
54
+ sessionStorage.removeItem(legacyKey);
55
+ } catch {}
56
+ }
57
+
58
+ export function saveCredentials(endpoint, fields) {
59
+ const record = {
60
+ version: 1,
61
+ endpoint: new URL(endpoint, location.origin).href,
62
+ method: fields.method,
63
+ username: fields.username,
64
+ secret: fields.secret,
65
+ header: "",
66
+ };
67
+ authorization(record);
68
+ clearCredentials(endpoint);
69
+ try {
70
+ localStorage.setItem(credentialKeys(endpoint)[0], JSON.stringify(record));
71
+ } catch {}
72
+ }