@useclickly/mcp-server 1.0.0 → 1.0.1
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.
- package/dist/cli.cjs +621 -6
- package/dist/cli.cjs.map +7 -1
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +598 -8
- package/dist/cli.js.map +7 -1
- package/dist/http-bridge.d.ts +33 -0
- package/dist/http-bridge.d.ts.map +1 -0
- package/dist/index.cjs +472 -7
- package/dist/index.cjs.map +7 -1
- package/dist/index.d.ts +16 -19
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +435 -7
- package/dist/index.js.map +7 -1
- package/dist/server.d.ts +33 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/store.d.ts +46 -0
- package/dist/store.d.ts.map +1 -0
- package/package.json +12 -11
- package/LICENSE +0 -21
package/dist/cli.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/cli.ts", "../src/server.ts", "../src/store.ts", "../src/http-bridge.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * `clickly-mcp` CLI\n *\n * Subcommands:\n * server Start the MCP stdio server + HTTP bridge on :4747\n * doctor Check environment: Node version, port availability, store writability\n * init Print (or write) the claude_desktop_config.json / .cursor/mcp.json snippet\n */\n\nimport fs from \"node:fs\";\nimport net from \"node:net\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { createServer } from \"./server.js\";\n\nconst [, , cmd, ...args] = process.argv;\n\n/* \u2500\u2500\u2500 Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nfunction log(msg: string): void {\n process.stderr.write(msg + \"\\n\");\n}\n\nfunction out(msg: string): void {\n process.stdout.write(msg + \"\\n\");\n}\n\nfunction parseFlag(flag: string, fallback: string): string {\n const idx = args.indexOf(flag);\n return idx !== -1 && args[idx + 1] != null ? (args[idx + 1] as string) : fallback;\n}\n\nfunction isPortFree(port: number): Promise<boolean> {\n return new Promise((resolve) => {\n const srv = net.createServer();\n srv.once(\"error\", () => resolve(false));\n srv.once(\"listening\", () => srv.close(() => resolve(true)));\n srv.listen(port, \"127.0.0.1\");\n });\n}\n\n/* \u2500\u2500\u2500 server \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nasync function cmdServer(): Promise<void> {\n const port = parseInt(parseFlag(\"--port\", \"4747\"), 10);\n const storePath = parseFlag(\"--store\", path.join(os.homedir(), \".clickly\", \"sessions.json\"));\n\n log(`[clickly-mcp] Starting MCP server (stdio) + HTTP bridge on :${port}`);\n log(`[clickly-mcp] Persistence: ${storePath}`);\n log(`[clickly-mcp] Ready. Connect your AI agent via stdio.`);\n\n const handle = await createServer({ port, storePath });\n\n process.on(\"SIGINT\", async () => {\n log(\"\\n[clickly-mcp] Shutting down\u2026\");\n await handle.close();\n process.exit(0);\n });\n\n process.on(\"SIGTERM\", async () => {\n await handle.close();\n process.exit(0);\n });\n}\n\n/* \u2500\u2500\u2500 doctor \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nasync function cmdDoctor(): Promise<void> {\n let allOk = true;\n const port = parseInt(parseFlag(\"--port\", \"4747\"), 10);\n const storePath = path.join(os.homedir(), \".clickly\", \"sessions.json\");\n\n out(\"clickly-mcp doctor\\n\");\n\n // Node version\n const nodeVersion = process.versions.node;\n const major = parseInt(nodeVersion.split(\".\")[0] ?? \"0\", 10);\n const nodeOk = major >= 18;\n out(` Node.js: ${nodeVersion} ${nodeOk ? \"\u2713\" : \"\u2717 (need \u2265 18)\"}`);\n if (!nodeOk) allOk = false;\n\n // Port availability\n const portFree = await isPortFree(port);\n out(` Port ${port}: ${portFree ? \"available \u2713\" : \"IN USE \u2717 (another process is running on this port)\"}`);\n if (!portFree) allOk = false;\n\n // Store directory writability\n const storeDir = path.dirname(storePath);\n let storeOk = false;\n try {\n fs.mkdirSync(storeDir, { recursive: true });\n const testFile = path.join(storeDir, \".write-test\");\n fs.writeFileSync(testFile, \"ok\");\n fs.unlinkSync(testFile);\n storeOk = true;\n } catch {\n storeOk = false;\n }\n out(` Store dir (${storeDir}): ${storeOk ? \"writable \u2713\" : \"NOT writable \u2717\"}`);\n if (!storeOk) allOk = false;\n\n // Existing sessions\n if (fs.existsSync(storePath)) {\n try {\n const data = JSON.parse(fs.readFileSync(storePath, \"utf-8\"));\n const count = (data.sessions ?? []).length;\n out(` Persisted sessions: ${count}`);\n } catch {\n out(` Persisted sessions: (could not parse ${storePath})`);\n }\n } else {\n out(` Persisted sessions: none yet (store will be created on first use)`);\n }\n\n out(`\\n ${allOk ? \"All checks passed \u2713\" : \"Some checks failed \u2717 \u2014 fix the issues above before starting\"}`);\n process.exit(allOk ? 0 : 1);\n}\n\n/* \u2500\u2500\u2500 init \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nfunction cmdInit(): void {\n const write = args.includes(\"--write\");\n const binPath = process.execPath; // node\n const mcpBin = new URL(\"../dist/cli.js\", import.meta.url).pathname;\n\n // Claude Code / claude_desktop_config.json snippet\n const claudeSnippet = JSON.stringify(\n {\n mcpServers: {\n clickly: {\n command: \"node\",\n args: [mcpBin, \"server\"],\n env: {},\n },\n },\n },\n null,\n 2,\n );\n\n // Cursor .cursor/mcp.json snippet\n const cursorSnippet = JSON.stringify(\n {\n mcpServers: {\n clickly: {\n command: \"node\",\n args: [mcpBin, \"server\"],\n },\n },\n },\n null,\n 2,\n );\n\n if (!write) {\n out(\"# Clickly MCP \u2014 setup snippets\\n\");\n out(\"## Claude Code (~/.claude.json or claude_desktop_config.json)\\n\");\n out(claudeSnippet);\n out(\"\\n## Cursor (.cursor/mcp.json)\\n\");\n out(cursorSnippet);\n out(\n \"\\nRun `clickly-mcp init --write` to automatically write the Claude Code config.\\n\",\n );\n out(`(node binary: ${binPath})`);\n return;\n }\n\n // --write: merge into Claude Code config\n const claudeConfigDir = path.join(os.homedir(), \".claude\");\n const claudeConfigPath = path.join(claudeConfigDir, \"claude_desktop_config.json\");\n\n try {\n fs.mkdirSync(claudeConfigDir, { recursive: true });\n\n let existing: Record<string, unknown> = {};\n if (fs.existsSync(claudeConfigPath)) {\n existing = JSON.parse(fs.readFileSync(claudeConfigPath, \"utf-8\"));\n }\n\n const mcpServers = (existing.mcpServers as Record<string, unknown>) ?? {};\n mcpServers.clickly = { command: \"node\", args: [mcpBin, \"server\"], env: {} };\n existing.mcpServers = mcpServers;\n\n fs.writeFileSync(claudeConfigPath, JSON.stringify(existing, null, 2), \"utf-8\");\n out(`\u2713 Written to ${claudeConfigPath}`);\n out(\" Restart Claude Code (or your agent) to pick up the new MCP server.\");\n } catch (err) {\n out(`\u2717 Could not write config: ${err instanceof Error ? err.message : err}`);\n process.exit(1);\n }\n}\n\n/* \u2500\u2500\u2500 Dispatch \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nswitch (cmd) {\n case \"server\":\n cmdServer().catch((err) => {\n log(`[clickly-mcp] Fatal: ${err instanceof Error ? err.message : err}`);\n process.exit(1);\n });\n break;\n\n case \"doctor\":\n cmdDoctor().catch((err) => {\n log(`doctor error: ${err instanceof Error ? err.message : err}`);\n process.exit(1);\n });\n break;\n\n case \"init\":\n cmdInit();\n break;\n\n default:\n out(\"clickly-mcp \u2014 MCP server for the Clickly annotation toolbar\\n\");\n out(\"Usage: clickly-mcp <command> [options]\\n\");\n out(\"Commands:\");\n out(\" server Start the MCP stdio server (+ HTTP bridge on :4747)\");\n out(\" Options: --port <n> HTTP bridge port (default: 4747)\");\n out(\" --store <path> Persistence file (default: ~/.clickly/sessions.json)\");\n out(\" doctor Check environment (Node version, port, store writability)\");\n out(\" init Print config snippets for Claude Code / Cursor\");\n out(\" Options: --write Write directly to ~/.claude/claude_desktop_config.json\");\n process.exit(cmd ? 1 : 0);\n}\n", "/**\n * @useclickly/mcp-server \u2014 real implementation.\n *\n * Exposes a Model Context Protocol stdio server backed by an in-process\n * HTTP bridge. AI coding agents connect via stdio; the browser component\n * connects via HTTP on localhost:4747.\n *\n * MCP tools\n * \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n * clickly_list_sessions List all annotation sessions\n * clickly_list_annotations List annotations for a session\n * clickly_get_annotation Fetch a single annotation by ID\n * clickly_acknowledge Mark annotation as acknowledged\n * clickly_resolve Mark annotation as resolved\n * clickly_dismiss Mark annotation as dismissed\n * clickly_reply Append a thread message to an annotation\n */\n\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { z } from \"zod\";\nimport { AnnotationStore } from \"./store.js\";\nimport { createHttpBridge } from \"./http-bridge.js\";\n\nexport { AnnotationStore } from \"./store.js\";\n\n/* \u2500\u2500\u2500 Public types \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nexport interface ServerOptions {\n /** HTTP port for the browser bridge. Default: 4747. */\n port?: number;\n /** On-disk path for session persistence. Default: ~/.clickly/sessions.json. */\n storePath?: string;\n /** Custom store instance (useful for testing). */\n store?: AnnotationStore;\n}\n\nexport interface ServerHandle {\n port: number;\n close(): Promise<void>;\n}\n\n/* \u2500\u2500\u2500 Shared input schemas \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nconst SessionIdSchema = {\n sessionId: z.string().describe(\"Session ID returned by the browser bridge\"),\n};\n\nconst AnnotationIdSchema = {\n ...SessionIdSchema,\n annotationId: z.string().describe(\"Annotation ID\"),\n};\n\n/* \u2500\u2500\u2500 Helper \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nfunction errResult(message: string) {\n return {\n isError: true as const,\n content: [{ type: \"text\" as const, text: message }],\n };\n}\n\nfunction okResult(data: unknown) {\n return {\n content: [\n {\n type: \"text\" as const,\n text: typeof data === \"string\" ? data : JSON.stringify(data, null, 2),\n },\n ],\n };\n}\n\n/* \u2500\u2500\u2500 createServer \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nexport async function createServer(options: ServerOptions = {}): Promise<ServerHandle> {\n const port = options.port ?? 4747;\n const store =\n options.store ?? new AnnotationStore({ storePath: options.storePath });\n\n /* \u2500\u2500 HTTP bridge (browser \u2192 server) \u2500\u2500\u2500 */\n const bridge = createHttpBridge(store, port);\n\n /* \u2500\u2500 MCP server (stdio, agent \u2192 server) \u2500\u2500\u2500 */\n const mcp = new McpServer(\n { name: \"clickly\", version: \"1.0.0\" },\n {\n capabilities: { tools: {} },\n instructions:\n \"Clickly exposes UI annotations captured in a running React development app. \" +\n \"Use these tools to read feedback, acknowledge issues, resolve them, or reply \" +\n \"to start a conversation thread with the developer.\",\n },\n );\n\n /* \u2500\u2500 clickly_list_sessions \u2500\u2500\u2500 */\n mcp.registerTool(\n \"clickly_list_sessions\",\n {\n description:\n \"List all Clickly annotation sessions. Each session corresponds to a page/URL \" +\n \"where the developer opened the Clickly toolbar. Returns session IDs, URLs, \" +\n \"creation timestamps, and annotation counts.\",\n inputSchema: {},\n },\n async () => {\n const sessions = store.listSessions();\n const rows = sessions.map((s) => ({\n sessionId: s.id,\n url: s.url,\n createdAt: new Date(s.createdAt).toISOString(),\n annotationCount: store.listAnnotations(s.id).length,\n }));\n return okResult(rows);\n },\n );\n\n /* \u2500\u2500 clickly_list_annotations \u2500\u2500\u2500 */\n mcp.registerTool(\n \"clickly_list_annotations\",\n {\n description:\n \"List all annotations in a session. Includes element path, position, React \" +\n \"component tree, source file/line, feedback comment, and lifecycle status.\",\n inputSchema: SessionIdSchema,\n },\n async ({ sessionId }) => {\n const session = store.getSession(sessionId);\n if (!session) return errResult(`Session not found: ${sessionId}`);\n return okResult(store.listAnnotations(sessionId));\n },\n );\n\n /* \u2500\u2500 clickly_get_annotation \u2500\u2500\u2500 */\n mcp.registerTool(\n \"clickly_get_annotation\",\n {\n description:\n \"Fetch a single annotation by ID. Returns the full AFS 1.1 record including \" +\n \"element metadata, bounding box, React component chain, source location, \" +\n \"and any thread messages.\",\n inputSchema: AnnotationIdSchema,\n },\n async ({ sessionId, annotationId }) => {\n const annotation = store.getAnnotation(sessionId, annotationId);\n if (!annotation) {\n return errResult(\n `Annotation not found: ${annotationId} in session ${sessionId}`,\n );\n }\n return okResult(annotation);\n },\n );\n\n /* \u2500\u2500 clickly_acknowledge \u2500\u2500\u2500 */\n mcp.registerTool(\n \"clickly_acknowledge\",\n {\n description:\n \"Mark an annotation as 'acknowledged' \u2014 you have seen it and are working on it. \" +\n \"The developer's UI will show an acknowledged badge on the annotation pin.\",\n inputSchema: AnnotationIdSchema,\n },\n async ({ sessionId, annotationId }) => {\n try {\n const updated = store.updateAnnotation(sessionId, annotationId, {\n status: \"acknowledged\",\n });\n return okResult(\n `Acknowledged annotation ${updated.id} in session ${sessionId}.`,\n );\n } catch (err) {\n return errResult(err instanceof Error ? err.message : String(err));\n }\n },\n );\n\n /* \u2500\u2500 clickly_resolve \u2500\u2500\u2500 */\n mcp.registerTool(\n \"clickly_resolve\",\n {\n description:\n \"Mark an annotation as 'resolved' \u2014 the issue has been fixed. Optionally include \" +\n \"a resolution note. The pin will show as resolved in the developer's browser.\",\n inputSchema: {\n ...AnnotationIdSchema,\n note: z\n .string()\n .optional()\n .describe(\"Optional resolution note to append to the thread\"),\n },\n },\n async ({ sessionId, annotationId, note }) => {\n try {\n const existing = store.getAnnotation(sessionId, annotationId);\n if (!existing) return errResult(`Annotation not found: ${annotationId}`);\n\n const thread = existing.thread ? [...existing.thread] : [];\n if (note) {\n thread.push({\n id: crypto.randomUUID(),\n role: \"agent\",\n content: note,\n timestamp: Date.now(),\n });\n }\n\n const updated = store.updateAnnotation(sessionId, annotationId, {\n status: \"resolved\",\n resolvedAt: new Date().toISOString(),\n resolvedBy: \"agent\",\n ...(note ? { thread } : {}),\n });\n return okResult(\n `Resolved annotation ${updated.id}.${note ? ` Note: \"${note}\"` : \"\"}`,\n );\n } catch (err) {\n return errResult(err instanceof Error ? err.message : String(err));\n }\n },\n );\n\n /* \u2500\u2500 clickly_dismiss \u2500\u2500\u2500 */\n mcp.registerTool(\n \"clickly_dismiss\",\n {\n description:\n \"Mark an annotation as 'dismissed' \u2014 it is not actionable or is a duplicate. \" +\n \"Dismissed annotations are hidden from the default list view.\",\n inputSchema: AnnotationIdSchema,\n },\n async ({ sessionId, annotationId }) => {\n try {\n const updated = store.updateAnnotation(sessionId, annotationId, {\n status: \"dismissed\",\n });\n return okResult(`Dismissed annotation ${updated.id}.`);\n } catch (err) {\n return errResult(err instanceof Error ? err.message : String(err));\n }\n },\n );\n\n /* \u2500\u2500 clickly_reply \u2500\u2500\u2500 */\n mcp.registerTool(\n \"clickly_reply\",\n {\n description:\n \"Append a thread message to an annotation. Use this to ask a clarifying question, \" +\n \"describe what you changed, or communicate back to the developer who left feedback.\",\n inputSchema: {\n ...AnnotationIdSchema,\n message: z.string().describe(\"Your reply message\"),\n },\n },\n async ({ sessionId, annotationId, message }) => {\n try {\n const existing = store.getAnnotation(sessionId, annotationId);\n if (!existing) return errResult(`Annotation not found: ${annotationId}`);\n\n const thread = [\n ...(existing.thread ?? []),\n {\n id: crypto.randomUUID(),\n role: \"agent\" as const,\n content: message,\n timestamp: Date.now(),\n },\n ];\n\n store.updateAnnotation(sessionId, annotationId, { thread });\n return okResult(`Reply added to annotation ${annotationId}.`);\n } catch (err) {\n return errResult(err instanceof Error ? err.message : String(err));\n }\n },\n );\n\n /* \u2500\u2500 Connect stdio transport \u2500\u2500\u2500 */\n const transport = new StdioServerTransport();\n await mcp.connect(transport);\n\n return {\n port,\n close: async () => {\n await mcp.close();\n await bridge.close();\n },\n };\n}\n", "/**\n * Annotation + Session store.\n *\n * Holds everything in-memory for fast reads.\n * Persists to a JSON file on every mutating operation so the MCP client\n * can survive a server restart without losing annotations.\n */\n\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport type { Annotation } from \"@useclickly/core\";\n\n/* \u2500\u2500\u2500 Types \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nexport interface Session {\n id: string;\n url: string;\n createdAt: number;\n /** Monotonically increasing counter \u2014 incremented on every annotation mutation. */\n seq: number;\n}\n\nexport interface AnnotationRecord extends Annotation {\n sessionId: string;\n}\n\nexport interface StoreOptions {\n /**\n * Where to persist sessions + annotations.\n * Defaults to `~/.clickly/sessions.json`.\n */\n storePath?: string;\n}\n\n/* \u2500\u2500\u2500 Persisted shape \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\ninterface PersistedData {\n sessions: Session[];\n annotations: AnnotationRecord[];\n}\n\n/* \u2500\u2500\u2500 Store \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nexport class AnnotationStore {\n private sessions = new Map<string, Session>();\n /** sessionId \u2192 (annotationId \u2192 AnnotationRecord) */\n private annotations = new Map<string, Map<string, AnnotationRecord>>();\n /** Listeners waiting for new annotations in a session (SSE bridge) */\n private listeners = new Map<string, Set<(a: AnnotationRecord, seq: number) => void>>();\n\n readonly storePath: string;\n\n constructor(options: StoreOptions = {}) {\n this.storePath =\n options.storePath ?? path.join(os.homedir(), \".clickly\", \"sessions.json\");\n this._load();\n }\n\n /* \u2500\u2500 Sessions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n createSession(url: string): Session {\n const id = crypto.randomUUID();\n const session: Session = { id, url, createdAt: Date.now(), seq: 0 };\n this.sessions.set(id, session);\n this.annotations.set(id, new Map());\n this._persist();\n return session;\n }\n\n getSession(sessionId: string): Session | undefined {\n return this.sessions.get(sessionId);\n }\n\n listSessions(): Session[] {\n return [...this.sessions.values()].sort((a, b) => b.createdAt - a.createdAt);\n }\n\n /* \u2500\u2500 Annotations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n addAnnotation(sessionId: string, annotation: Annotation): AnnotationRecord {\n const session = this.sessions.get(sessionId);\n if (!session) throw new Error(`Session not found: ${sessionId}`);\n\n const bucket = this.annotations.get(sessionId)!;\n const record: AnnotationRecord = { ...annotation, sessionId };\n bucket.set(annotation.id, record);\n\n session.seq += 1;\n const seq = session.seq;\n\n this._persist();\n this._emit(sessionId, record, seq);\n return record;\n }\n\n getAnnotation(sessionId: string, annotationId: string): AnnotationRecord | undefined {\n return this.annotations.get(sessionId)?.get(annotationId);\n }\n\n listAnnotations(sessionId: string): AnnotationRecord[] {\n const bucket = this.annotations.get(sessionId);\n if (!bucket) return [];\n return [...bucket.values()].sort((a, b) => a.timestamp - b.timestamp);\n }\n\n updateAnnotation(\n sessionId: string,\n annotationId: string,\n patch: Partial<Annotation>,\n ): AnnotationRecord {\n const session = this.sessions.get(sessionId);\n if (!session) throw new Error(`Session not found: ${sessionId}`);\n\n const bucket = this.annotations.get(sessionId);\n const existing = bucket?.get(annotationId);\n if (!existing) throw new Error(`Annotation not found: ${annotationId}`);\n\n const updated: AnnotationRecord = { ...existing, ...patch, sessionId };\n bucket!.set(annotationId, updated);\n\n session.seq += 1;\n const seq = session.seq;\n\n this._persist();\n this._emit(sessionId, updated, seq);\n return updated;\n }\n\n /* \u2500\u2500 SSE subscriptions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n subscribe(\n sessionId: string,\n cb: (annotation: AnnotationRecord, seq: number) => void,\n ): () => void {\n if (!this.listeners.has(sessionId)) {\n this.listeners.set(sessionId, new Set());\n }\n this.listeners.get(sessionId)!.add(cb);\n return () => this.listeners.get(sessionId)?.delete(cb);\n }\n\n private _emit(sessionId: string, annotation: AnnotationRecord, seq: number): void {\n this.listeners.get(sessionId)?.forEach((cb) => cb(annotation, seq));\n }\n\n /* \u2500\u2500 Persistence \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\n private _persist(): void {\n try {\n const dir = path.dirname(this.storePath);\n if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });\n\n const data: PersistedData = {\n sessions: [...this.sessions.values()],\n annotations: [...this.annotations.values()].flatMap((m) => [...m.values()]),\n };\n fs.writeFileSync(this.storePath, JSON.stringify(data, null, 2), \"utf-8\");\n } catch {\n // Persistence failures are non-fatal \u2014 data is still in-memory.\n }\n }\n\n private _load(): void {\n try {\n if (!fs.existsSync(this.storePath)) return;\n const raw = fs.readFileSync(this.storePath, \"utf-8\");\n const data: PersistedData = JSON.parse(raw);\n\n for (const session of data.sessions ?? []) {\n this.sessions.set(session.id, session);\n this.annotations.set(session.id, new Map());\n }\n for (const annotation of data.annotations ?? []) {\n this.annotations.get(annotation.sessionId)?.set(annotation.id, annotation);\n }\n } catch {\n // Corrupted or missing file \u2014 start fresh.\n }\n }\n}\n", "/**\n * HTTP bridge \u2014 lets the in-browser <Clickly /> component talk to this server.\n *\n * Endpoints\n * \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n * POST /sessions\n * Body: { url: string }\n * Returns: { sessionId: string }\n *\n * POST /sessions/:sessionId/annotations\n * Body: Annotation (AFS 1.1)\n * Returns: { ok: true, id: string }\n *\n * GET /sessions/:sessionId/annotations\n * Returns: Annotation[]\n *\n * GET /sessions/:sessionId/events\n * Server-Sent Events stream \u2014 emits `annotation` events on every add/update.\n * Each event: `data: { annotation, seq }\\n\\n`\n *\n * GET /sessions\n * Returns: Session[]\n *\n * GET /health\n * Returns: { ok: true, version: string }\n */\n\nimport http from \"node:http\";\nimport type { AnnotationStore } from \"./store.js\";\n\nconst VERSION = \"1.0.0\";\n\n/* \u2500\u2500\u2500 CORS helper \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nfunction cors(res: http.ServerResponse): void {\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.setHeader(\"Access-Control-Allow-Methods\", \"GET, POST, OPTIONS\");\n res.setHeader(\"Access-Control-Allow-Headers\", \"Content-Type\");\n}\n\n/* \u2500\u2500\u2500 Response helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nfunction json(res: http.ServerResponse, status: number, body: unknown): void {\n cors(res);\n const payload = JSON.stringify(body);\n res.writeHead(status, {\n \"Content-Type\": \"application/json\",\n \"Content-Length\": Buffer.byteLength(payload),\n });\n res.end(payload);\n}\n\nfunction notFound(res: http.ServerResponse): void {\n json(res, 404, { error: \"not_found\" });\n}\n\nfunction badRequest(res: http.ServerResponse, message: string): void {\n json(res, 400, { error: \"bad_request\", message });\n}\n\n/* \u2500\u2500\u2500 Body reader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nfunction readBody(req: http.IncomingMessage): Promise<unknown> {\n return new Promise((resolve, reject) => {\n let raw = \"\";\n req.on(\"data\", (chunk) => (raw += chunk));\n req.on(\"end\", () => {\n try {\n resolve(raw ? JSON.parse(raw) : {});\n } catch {\n reject(new Error(\"Invalid JSON body\"));\n }\n });\n req.on(\"error\", reject);\n });\n}\n\n/* \u2500\u2500\u2500 Router \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nfunction route(\n req: http.IncomingMessage,\n): { method: string; segments: string[] } | null {\n const url = new URL(req.url ?? \"/\", \"http://localhost\");\n const segments = url.pathname.replace(/^\\//, \"\").split(\"/\").filter(Boolean);\n return { method: req.method?.toUpperCase() ?? \"GET\", segments };\n}\n\n/* \u2500\u2500\u2500 Bridge factory \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */\n\nexport interface BridgeHandle {\n port: number;\n close(): Promise<void>;\n}\n\nexport function createHttpBridge(store: AnnotationStore, port: number): BridgeHandle {\n const server = http.createServer(async (req, res) => {\n // Preflight\n if (req.method === \"OPTIONS\") {\n cors(res);\n res.writeHead(204);\n res.end();\n return;\n }\n\n const r = route(req);\n if (!r) return notFound(res);\n const { method, segments } = r;\n\n try {\n // GET /health\n if (method === \"GET\" && segments[0] === \"health\") {\n return json(res, 200, { ok: true, version: VERSION });\n }\n\n // GET /sessions\n if (method === \"GET\" && segments.length === 1 && segments[0] === \"sessions\") {\n return json(res, 200, store.listSessions());\n }\n\n // POST /sessions\n if (method === \"POST\" && segments.length === 1 && segments[0] === \"sessions\") {\n const body = (await readBody(req)) as { url?: string };\n if (!body.url) return badRequest(res, \"url is required\");\n const session = store.createSession(body.url);\n return json(res, 201, { sessionId: session.id });\n }\n\n // Routes under /sessions/:sessionId/...\n if (segments[0] === \"sessions\" && segments[1]) {\n const sessionId = segments[1];\n const session = store.getSession(sessionId);\n if (!session) return json(res, 404, { error: \"session_not_found\" });\n\n const sub = segments[2];\n\n // GET /sessions/:id/annotations\n if (method === \"GET\" && sub === \"annotations\" && segments.length === 3) {\n return json(res, 200, store.listAnnotations(sessionId));\n }\n\n // POST /sessions/:id/annotations\n if (method === \"POST\" && sub === \"annotations\" && segments.length === 3) {\n const body = await readBody(req);\n if (!body || typeof body !== \"object\") return badRequest(res, \"body required\");\n const annotation = body as Record<string, unknown>;\n if (!annotation.id || !annotation.comment || !annotation.elementPath) {\n return badRequest(res, \"id, comment, elementPath are required\");\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const record = store.addAnnotation(sessionId, annotation as any);\n return json(res, 201, { ok: true, id: record.id });\n }\n\n // GET /sessions/:id/events \u2014 SSE\n if (method === \"GET\" && sub === \"events\" && segments.length === 3) {\n cors(res);\n res.writeHead(200, {\n \"Content-Type\": \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n \"X-Accel-Buffering\": \"no\", // disable nginx buffering\n });\n\n // Send current sequence as a \"connected\" event\n res.write(`event: connected\\ndata: ${JSON.stringify({ seq: session.seq })}\\n\\n`);\n\n // Subscribe to future annotations\n const unsubscribe = store.subscribe(sessionId, (annotation, seq) => {\n const payload = JSON.stringify({ annotation, seq });\n res.write(`event: annotation\\ndata: ${payload}\\n\\n`);\n });\n\n // Heartbeat every 15s to keep connection alive through proxies\n const heartbeat = setInterval(() => {\n res.write(`: heartbeat\\n\\n`);\n }, 15_000);\n\n req.on(\"close\", () => {\n clearInterval(heartbeat);\n unsubscribe();\n });\n return; // SSE \u2014 don't close\n }\n }\n\n notFound(res);\n } catch (err) {\n const message = err instanceof Error ? err.message : \"internal_error\";\n json(res, 500, { error: \"internal_error\", message });\n }\n });\n\n server.listen(port);\n\n return {\n port,\n close: () =>\n new Promise((resolve, reject) =>\n server.close((err) => (err ? reject(err) : resolve())),\n ),\n };\n}\n"],
|
|
5
|
+
"mappings": ";AASA,OAAOA,SAAQ;AACf,OAAO,SAAS;AAChB,OAAOC,SAA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,KAAK,CAAC;AAAA,IAChB,CAAC;AACD;AAAA,EAEF,KAAK;AACH,YAAQ;AACR;AAAA,EAEF;AACE,QAAI,oEAA+D;AACnE,QAAI,0CAA0C;AAC9C,QAAI,WAAW;AACf,QAAI,gEAAgE;AACpE,QAAI,mEAAmE;AACvE,QAAI,0FAA0F;AAC9F,QAAI,sEAAsE;AAC1E,QAAI,2DAA2D;AAC/D,QAAI,sFAAsF;AAC1F,YAAQ,KAAK,MAAM,IAAI,CAAC;AAC5B;",
|
|
6
|
+
"names": ["fs", "os", "path", "path", "os", "fs"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP bridge — lets the in-browser <Clickly /> component talk to this server.
|
|
3
|
+
*
|
|
4
|
+
* Endpoints
|
|
5
|
+
* ─────────
|
|
6
|
+
* POST /sessions
|
|
7
|
+
* Body: { url: string }
|
|
8
|
+
* Returns: { sessionId: string }
|
|
9
|
+
*
|
|
10
|
+
* POST /sessions/:sessionId/annotations
|
|
11
|
+
* Body: Annotation (AFS 1.1)
|
|
12
|
+
* Returns: { ok: true, id: string }
|
|
13
|
+
*
|
|
14
|
+
* GET /sessions/:sessionId/annotations
|
|
15
|
+
* Returns: Annotation[]
|
|
16
|
+
*
|
|
17
|
+
* GET /sessions/:sessionId/events
|
|
18
|
+
* Server-Sent Events stream — emits `annotation` events on every add/update.
|
|
19
|
+
* Each event: `data: { annotation, seq }\n\n`
|
|
20
|
+
*
|
|
21
|
+
* GET /sessions
|
|
22
|
+
* Returns: Session[]
|
|
23
|
+
*
|
|
24
|
+
* GET /health
|
|
25
|
+
* Returns: { ok: true, version: string }
|
|
26
|
+
*/
|
|
27
|
+
import type { AnnotationStore } from "./store.js";
|
|
28
|
+
export interface BridgeHandle {
|
|
29
|
+
port: number;
|
|
30
|
+
close(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export declare function createHttpBridge(store: AnnotationStore, port: number): BridgeHandle;
|
|
33
|
+
//# sourceMappingURL=http-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-bridge.d.ts","sourceRoot":"","sources":["../src/http-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA6DlD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CA2GnF"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,475 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
29
|
|
|
3
|
-
// src/
|
|
4
|
-
|
|
5
|
-
|
|
30
|
+
// packages/mcp-server/src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AnnotationStore: () => AnnotationStore,
|
|
34
|
+
createServer: () => createServer
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// packages/mcp-server/src/server.ts
|
|
39
|
+
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
40
|
+
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
41
|
+
var import_zod = require("zod");
|
|
42
|
+
|
|
43
|
+
// packages/mcp-server/src/store.ts
|
|
44
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
45
|
+
var import_node_os = __toESM(require("node:os"), 1);
|
|
46
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
47
|
+
var AnnotationStore = class {
|
|
48
|
+
sessions = /* @__PURE__ */ new Map();
|
|
49
|
+
/** sessionId → (annotationId → AnnotationRecord) */
|
|
50
|
+
annotations = /* @__PURE__ */ new Map();
|
|
51
|
+
/** Listeners waiting for new annotations in a session (SSE bridge) */
|
|
52
|
+
listeners = /* @__PURE__ */ new Map();
|
|
53
|
+
storePath;
|
|
54
|
+
constructor(options = {}) {
|
|
55
|
+
this.storePath = options.storePath ?? import_node_path.default.join(import_node_os.default.homedir(), ".clickly", "sessions.json");
|
|
56
|
+
this._load();
|
|
57
|
+
}
|
|
58
|
+
/* ── Sessions ─────────────────────────────────────────────────────── */
|
|
59
|
+
createSession(url) {
|
|
60
|
+
const id = crypto.randomUUID();
|
|
61
|
+
const session = { id, url, createdAt: Date.now(), seq: 0 };
|
|
62
|
+
this.sessions.set(id, session);
|
|
63
|
+
this.annotations.set(id, /* @__PURE__ */ new Map());
|
|
64
|
+
this._persist();
|
|
65
|
+
return session;
|
|
66
|
+
}
|
|
67
|
+
getSession(sessionId) {
|
|
68
|
+
return this.sessions.get(sessionId);
|
|
69
|
+
}
|
|
70
|
+
listSessions() {
|
|
71
|
+
return [...this.sessions.values()].sort((a, b) => b.createdAt - a.createdAt);
|
|
72
|
+
}
|
|
73
|
+
/* ── Annotations ──────────────────────────────────────────────────── */
|
|
74
|
+
addAnnotation(sessionId, annotation) {
|
|
75
|
+
const session = this.sessions.get(sessionId);
|
|
76
|
+
if (!session) throw new Error(`Session not found: ${sessionId}`);
|
|
77
|
+
const bucket = this.annotations.get(sessionId);
|
|
78
|
+
const record = { ...annotation, sessionId };
|
|
79
|
+
bucket.set(annotation.id, record);
|
|
80
|
+
session.seq += 1;
|
|
81
|
+
const seq = session.seq;
|
|
82
|
+
this._persist();
|
|
83
|
+
this._emit(sessionId, record, seq);
|
|
84
|
+
return record;
|
|
85
|
+
}
|
|
86
|
+
getAnnotation(sessionId, annotationId) {
|
|
87
|
+
return this.annotations.get(sessionId)?.get(annotationId);
|
|
88
|
+
}
|
|
89
|
+
listAnnotations(sessionId) {
|
|
90
|
+
const bucket = this.annotations.get(sessionId);
|
|
91
|
+
if (!bucket) return [];
|
|
92
|
+
return [...bucket.values()].sort((a, b) => a.timestamp - b.timestamp);
|
|
93
|
+
}
|
|
94
|
+
updateAnnotation(sessionId, annotationId, patch) {
|
|
95
|
+
const session = this.sessions.get(sessionId);
|
|
96
|
+
if (!session) throw new Error(`Session not found: ${sessionId}`);
|
|
97
|
+
const bucket = this.annotations.get(sessionId);
|
|
98
|
+
const existing = bucket?.get(annotationId);
|
|
99
|
+
if (!existing) throw new Error(`Annotation not found: ${annotationId}`);
|
|
100
|
+
const updated = { ...existing, ...patch, sessionId };
|
|
101
|
+
bucket.set(annotationId, updated);
|
|
102
|
+
session.seq += 1;
|
|
103
|
+
const seq = session.seq;
|
|
104
|
+
this._persist();
|
|
105
|
+
this._emit(sessionId, updated, seq);
|
|
106
|
+
return updated;
|
|
107
|
+
}
|
|
108
|
+
/* ── SSE subscriptions ────────────────────────────────────────────── */
|
|
109
|
+
subscribe(sessionId, cb) {
|
|
110
|
+
if (!this.listeners.has(sessionId)) {
|
|
111
|
+
this.listeners.set(sessionId, /* @__PURE__ */ new Set());
|
|
112
|
+
}
|
|
113
|
+
this.listeners.get(sessionId).add(cb);
|
|
114
|
+
return () => this.listeners.get(sessionId)?.delete(cb);
|
|
115
|
+
}
|
|
116
|
+
_emit(sessionId, annotation, seq) {
|
|
117
|
+
this.listeners.get(sessionId)?.forEach((cb) => cb(annotation, seq));
|
|
118
|
+
}
|
|
119
|
+
/* ── Persistence ──────────────────────────────────────────────────── */
|
|
120
|
+
_persist() {
|
|
121
|
+
try {
|
|
122
|
+
const dir = import_node_path.default.dirname(this.storePath);
|
|
123
|
+
if (!import_node_fs.default.existsSync(dir)) import_node_fs.default.mkdirSync(dir, { recursive: true });
|
|
124
|
+
const data = {
|
|
125
|
+
sessions: [...this.sessions.values()],
|
|
126
|
+
annotations: [...this.annotations.values()].flatMap((m) => [...m.values()])
|
|
127
|
+
};
|
|
128
|
+
import_node_fs.default.writeFileSync(this.storePath, JSON.stringify(data, null, 2), "utf-8");
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
_load() {
|
|
133
|
+
try {
|
|
134
|
+
if (!import_node_fs.default.existsSync(this.storePath)) return;
|
|
135
|
+
const raw = import_node_fs.default.readFileSync(this.storePath, "utf-8");
|
|
136
|
+
const data = JSON.parse(raw);
|
|
137
|
+
for (const session of data.sessions ?? []) {
|
|
138
|
+
this.sessions.set(session.id, session);
|
|
139
|
+
this.annotations.set(session.id, /* @__PURE__ */ new Map());
|
|
140
|
+
}
|
|
141
|
+
for (const annotation of data.annotations ?? []) {
|
|
142
|
+
this.annotations.get(annotation.sessionId)?.set(annotation.id, annotation);
|
|
143
|
+
}
|
|
144
|
+
} catch {
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// packages/mcp-server/src/http-bridge.ts
|
|
150
|
+
var import_node_http = __toESM(require("node:http"), 1);
|
|
151
|
+
var VERSION = "1.0.0";
|
|
152
|
+
function cors(res) {
|
|
153
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
154
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
155
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
156
|
+
}
|
|
157
|
+
function json(res, status, body) {
|
|
158
|
+
cors(res);
|
|
159
|
+
const payload = JSON.stringify(body);
|
|
160
|
+
res.writeHead(status, {
|
|
161
|
+
"Content-Type": "application/json",
|
|
162
|
+
"Content-Length": Buffer.byteLength(payload)
|
|
163
|
+
});
|
|
164
|
+
res.end(payload);
|
|
165
|
+
}
|
|
166
|
+
function notFound(res) {
|
|
167
|
+
json(res, 404, { error: "not_found" });
|
|
168
|
+
}
|
|
169
|
+
function badRequest(res, message) {
|
|
170
|
+
json(res, 400, { error: "bad_request", message });
|
|
171
|
+
}
|
|
172
|
+
function readBody(req) {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
let raw = "";
|
|
175
|
+
req.on("data", (chunk) => raw += chunk);
|
|
176
|
+
req.on("end", () => {
|
|
177
|
+
try {
|
|
178
|
+
resolve(raw ? JSON.parse(raw) : {});
|
|
179
|
+
} catch {
|
|
180
|
+
reject(new Error("Invalid JSON body"));
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
req.on("error", reject);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function route(req) {
|
|
187
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
188
|
+
const segments = url.pathname.replace(/^\//, "").split("/").filter(Boolean);
|
|
189
|
+
return { method: req.method?.toUpperCase() ?? "GET", segments };
|
|
6
190
|
}
|
|
191
|
+
function createHttpBridge(store, port) {
|
|
192
|
+
const server = import_node_http.default.createServer(async (req, res) => {
|
|
193
|
+
if (req.method === "OPTIONS") {
|
|
194
|
+
cors(res);
|
|
195
|
+
res.writeHead(204);
|
|
196
|
+
res.end();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const r = route(req);
|
|
200
|
+
if (!r) return notFound(res);
|
|
201
|
+
const { method, segments } = r;
|
|
202
|
+
try {
|
|
203
|
+
if (method === "GET" && segments[0] === "health") {
|
|
204
|
+
return json(res, 200, { ok: true, version: VERSION });
|
|
205
|
+
}
|
|
206
|
+
if (method === "GET" && segments.length === 1 && segments[0] === "sessions") {
|
|
207
|
+
return json(res, 200, store.listSessions());
|
|
208
|
+
}
|
|
209
|
+
if (method === "POST" && segments.length === 1 && segments[0] === "sessions") {
|
|
210
|
+
const body = await readBody(req);
|
|
211
|
+
if (!body.url) return badRequest(res, "url is required");
|
|
212
|
+
const session = store.createSession(body.url);
|
|
213
|
+
return json(res, 201, { sessionId: session.id });
|
|
214
|
+
}
|
|
215
|
+
if (segments[0] === "sessions" && segments[1]) {
|
|
216
|
+
const sessionId = segments[1];
|
|
217
|
+
const session = store.getSession(sessionId);
|
|
218
|
+
if (!session) return json(res, 404, { error: "session_not_found" });
|
|
219
|
+
const sub = segments[2];
|
|
220
|
+
if (method === "GET" && sub === "annotations" && segments.length === 3) {
|
|
221
|
+
return json(res, 200, store.listAnnotations(sessionId));
|
|
222
|
+
}
|
|
223
|
+
if (method === "POST" && sub === "annotations" && segments.length === 3) {
|
|
224
|
+
const body = await readBody(req);
|
|
225
|
+
if (!body || typeof body !== "object") return badRequest(res, "body required");
|
|
226
|
+
const annotation = body;
|
|
227
|
+
if (!annotation.id || !annotation.comment || !annotation.elementPath) {
|
|
228
|
+
return badRequest(res, "id, comment, elementPath are required");
|
|
229
|
+
}
|
|
230
|
+
const record = store.addAnnotation(sessionId, annotation);
|
|
231
|
+
return json(res, 201, { ok: true, id: record.id });
|
|
232
|
+
}
|
|
233
|
+
if (method === "GET" && sub === "events" && segments.length === 3) {
|
|
234
|
+
cors(res);
|
|
235
|
+
res.writeHead(200, {
|
|
236
|
+
"Content-Type": "text/event-stream",
|
|
237
|
+
"Cache-Control": "no-cache",
|
|
238
|
+
Connection: "keep-alive",
|
|
239
|
+
"X-Accel-Buffering": "no"
|
|
240
|
+
// disable nginx buffering
|
|
241
|
+
});
|
|
242
|
+
res.write(`event: connected
|
|
243
|
+
data: ${JSON.stringify({ seq: session.seq })}
|
|
7
244
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
245
|
+
`);
|
|
246
|
+
const unsubscribe = store.subscribe(sessionId, (annotation, seq) => {
|
|
247
|
+
const payload = JSON.stringify({ annotation, seq });
|
|
248
|
+
res.write(`event: annotation
|
|
249
|
+
data: ${payload}
|
|
250
|
+
|
|
251
|
+
`);
|
|
252
|
+
});
|
|
253
|
+
const heartbeat = setInterval(() => {
|
|
254
|
+
res.write(`: heartbeat
|
|
255
|
+
|
|
256
|
+
`);
|
|
257
|
+
}, 15e3);
|
|
258
|
+
req.on("close", () => {
|
|
259
|
+
clearInterval(heartbeat);
|
|
260
|
+
unsubscribe();
|
|
261
|
+
});
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
notFound(res);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
const message = err instanceof Error ? err.message : "internal_error";
|
|
268
|
+
json(res, 500, { error: "internal_error", message });
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
server.listen(port);
|
|
272
|
+
return {
|
|
273
|
+
port,
|
|
274
|
+
close: () => new Promise(
|
|
275
|
+
(resolve, reject) => server.close((err) => err ? reject(err) : resolve())
|
|
276
|
+
)
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// packages/mcp-server/src/server.ts
|
|
281
|
+
var SessionIdSchema = {
|
|
282
|
+
sessionId: import_zod.z.string().describe("Session ID returned by the browser bridge")
|
|
283
|
+
};
|
|
284
|
+
var AnnotationIdSchema = {
|
|
285
|
+
...SessionIdSchema,
|
|
286
|
+
annotationId: import_zod.z.string().describe("Annotation ID")
|
|
287
|
+
};
|
|
288
|
+
function errResult(message) {
|
|
289
|
+
return {
|
|
290
|
+
isError: true,
|
|
291
|
+
content: [{ type: "text", text: message }]
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function okResult(data) {
|
|
295
|
+
return {
|
|
296
|
+
content: [
|
|
297
|
+
{
|
|
298
|
+
type: "text",
|
|
299
|
+
text: typeof data === "string" ? data : JSON.stringify(data, null, 2)
|
|
300
|
+
}
|
|
301
|
+
]
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
async function createServer(options = {}) {
|
|
305
|
+
const port = options.port ?? 4747;
|
|
306
|
+
const store = options.store ?? new AnnotationStore({ storePath: options.storePath });
|
|
307
|
+
const bridge = createHttpBridge(store, port);
|
|
308
|
+
const mcp = new import_mcp.McpServer(
|
|
309
|
+
{ name: "clickly", version: "1.0.0" },
|
|
310
|
+
{
|
|
311
|
+
capabilities: { tools: {} },
|
|
312
|
+
instructions: "Clickly exposes UI annotations captured in a running React development app. Use these tools to read feedback, acknowledge issues, resolve them, or reply to start a conversation thread with the developer."
|
|
313
|
+
}
|
|
314
|
+
);
|
|
315
|
+
mcp.registerTool(
|
|
316
|
+
"clickly_list_sessions",
|
|
317
|
+
{
|
|
318
|
+
description: "List all Clickly annotation sessions. Each session corresponds to a page/URL where the developer opened the Clickly toolbar. Returns session IDs, URLs, creation timestamps, and annotation counts.",
|
|
319
|
+
inputSchema: {}
|
|
320
|
+
},
|
|
321
|
+
async () => {
|
|
322
|
+
const sessions = store.listSessions();
|
|
323
|
+
const rows = sessions.map((s) => ({
|
|
324
|
+
sessionId: s.id,
|
|
325
|
+
url: s.url,
|
|
326
|
+
createdAt: new Date(s.createdAt).toISOString(),
|
|
327
|
+
annotationCount: store.listAnnotations(s.id).length
|
|
328
|
+
}));
|
|
329
|
+
return okResult(rows);
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
mcp.registerTool(
|
|
333
|
+
"clickly_list_annotations",
|
|
334
|
+
{
|
|
335
|
+
description: "List all annotations in a session. Includes element path, position, React component tree, source file/line, feedback comment, and lifecycle status.",
|
|
336
|
+
inputSchema: SessionIdSchema
|
|
337
|
+
},
|
|
338
|
+
async ({ sessionId }) => {
|
|
339
|
+
const session = store.getSession(sessionId);
|
|
340
|
+
if (!session) return errResult(`Session not found: ${sessionId}`);
|
|
341
|
+
return okResult(store.listAnnotations(sessionId));
|
|
342
|
+
}
|
|
343
|
+
);
|
|
344
|
+
mcp.registerTool(
|
|
345
|
+
"clickly_get_annotation",
|
|
346
|
+
{
|
|
347
|
+
description: "Fetch a single annotation by ID. Returns the full AFS 1.1 record including element metadata, bounding box, React component chain, source location, and any thread messages.",
|
|
348
|
+
inputSchema: AnnotationIdSchema
|
|
349
|
+
},
|
|
350
|
+
async ({ sessionId, annotationId }) => {
|
|
351
|
+
const annotation = store.getAnnotation(sessionId, annotationId);
|
|
352
|
+
if (!annotation) {
|
|
353
|
+
return errResult(
|
|
354
|
+
`Annotation not found: ${annotationId} in session ${sessionId}`
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
return okResult(annotation);
|
|
358
|
+
}
|
|
359
|
+
);
|
|
360
|
+
mcp.registerTool(
|
|
361
|
+
"clickly_acknowledge",
|
|
362
|
+
{
|
|
363
|
+
description: "Mark an annotation as 'acknowledged' \u2014 you have seen it and are working on it. The developer's UI will show an acknowledged badge on the annotation pin.",
|
|
364
|
+
inputSchema: AnnotationIdSchema
|
|
365
|
+
},
|
|
366
|
+
async ({ sessionId, annotationId }) => {
|
|
367
|
+
try {
|
|
368
|
+
const updated = store.updateAnnotation(sessionId, annotationId, {
|
|
369
|
+
status: "acknowledged"
|
|
370
|
+
});
|
|
371
|
+
return okResult(
|
|
372
|
+
`Acknowledged annotation ${updated.id} in session ${sessionId}.`
|
|
373
|
+
);
|
|
374
|
+
} catch (err) {
|
|
375
|
+
return errResult(err instanceof Error ? err.message : String(err));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
);
|
|
379
|
+
mcp.registerTool(
|
|
380
|
+
"clickly_resolve",
|
|
381
|
+
{
|
|
382
|
+
description: "Mark an annotation as 'resolved' \u2014 the issue has been fixed. Optionally include a resolution note. The pin will show as resolved in the developer's browser.",
|
|
383
|
+
inputSchema: {
|
|
384
|
+
...AnnotationIdSchema,
|
|
385
|
+
note: import_zod.z.string().optional().describe("Optional resolution note to append to the thread")
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
async ({ sessionId, annotationId, note }) => {
|
|
389
|
+
try {
|
|
390
|
+
const existing = store.getAnnotation(sessionId, annotationId);
|
|
391
|
+
if (!existing) return errResult(`Annotation not found: ${annotationId}`);
|
|
392
|
+
const thread = existing.thread ? [...existing.thread] : [];
|
|
393
|
+
if (note) {
|
|
394
|
+
thread.push({
|
|
395
|
+
id: crypto.randomUUID(),
|
|
396
|
+
role: "agent",
|
|
397
|
+
content: note,
|
|
398
|
+
timestamp: Date.now()
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
const updated = store.updateAnnotation(sessionId, annotationId, {
|
|
402
|
+
status: "resolved",
|
|
403
|
+
resolvedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
404
|
+
resolvedBy: "agent",
|
|
405
|
+
...note ? { thread } : {}
|
|
406
|
+
});
|
|
407
|
+
return okResult(
|
|
408
|
+
`Resolved annotation ${updated.id}.${note ? ` Note: "${note}"` : ""}`
|
|
409
|
+
);
|
|
410
|
+
} catch (err) {
|
|
411
|
+
return errResult(err instanceof Error ? err.message : String(err));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
);
|
|
415
|
+
mcp.registerTool(
|
|
416
|
+
"clickly_dismiss",
|
|
417
|
+
{
|
|
418
|
+
description: "Mark an annotation as 'dismissed' \u2014 it is not actionable or is a duplicate. Dismissed annotations are hidden from the default list view.",
|
|
419
|
+
inputSchema: AnnotationIdSchema
|
|
420
|
+
},
|
|
421
|
+
async ({ sessionId, annotationId }) => {
|
|
422
|
+
try {
|
|
423
|
+
const updated = store.updateAnnotation(sessionId, annotationId, {
|
|
424
|
+
status: "dismissed"
|
|
425
|
+
});
|
|
426
|
+
return okResult(`Dismissed annotation ${updated.id}.`);
|
|
427
|
+
} catch (err) {
|
|
428
|
+
return errResult(err instanceof Error ? err.message : String(err));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
);
|
|
432
|
+
mcp.registerTool(
|
|
433
|
+
"clickly_reply",
|
|
434
|
+
{
|
|
435
|
+
description: "Append a thread message to an annotation. Use this to ask a clarifying question, describe what you changed, or communicate back to the developer who left feedback.",
|
|
436
|
+
inputSchema: {
|
|
437
|
+
...AnnotationIdSchema,
|
|
438
|
+
message: import_zod.z.string().describe("Your reply message")
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
async ({ sessionId, annotationId, message }) => {
|
|
442
|
+
try {
|
|
443
|
+
const existing = store.getAnnotation(sessionId, annotationId);
|
|
444
|
+
if (!existing) return errResult(`Annotation not found: ${annotationId}`);
|
|
445
|
+
const thread = [
|
|
446
|
+
...existing.thread ?? [],
|
|
447
|
+
{
|
|
448
|
+
id: crypto.randomUUID(),
|
|
449
|
+
role: "agent",
|
|
450
|
+
content: message,
|
|
451
|
+
timestamp: Date.now()
|
|
452
|
+
}
|
|
453
|
+
];
|
|
454
|
+
store.updateAnnotation(sessionId, annotationId, { thread });
|
|
455
|
+
return okResult(`Reply added to annotation ${annotationId}.`);
|
|
456
|
+
} catch (err) {
|
|
457
|
+
return errResult(err instanceof Error ? err.message : String(err));
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
const transport = new import_stdio.StdioServerTransport();
|
|
462
|
+
await mcp.connect(transport);
|
|
463
|
+
return {
|
|
464
|
+
port,
|
|
465
|
+
close: async () => {
|
|
466
|
+
await mcp.close();
|
|
467
|
+
await bridge.close();
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
472
|
+
0 && (module.exports = {
|
|
473
|
+
AnnotationStore,
|
|
474
|
+
createServer
|
|
475
|
+
});
|