@surfaces-ui/mcp 0.4.0 → 0.6.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,6EAA6E;AAC7E,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AA6B7E,wEAAwE;AACxE,MAAM,UAAU,iBAAiB,CAAC,QAAQ,GAAoB,OAAO,CAAC,QAAQ,EAAE,GAAG,GAAuC,OAAO,CAAC,GAAG,EAAE,IAAI,GAAW,EAAE,CAAC,OAAO,EAAE;IAChK,IAAI,QAAQ,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,qBAAqB,EAAE,QAAQ,EAAE,4BAA4B,CAAC,CAAC;IAC5H,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,QAAQ,EAAE,4BAA4B,CAAC,CAAC;IACzI,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,QAAQ,EAAE,4BAA4B,CAAC,CAAC;AAC9G,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACpC,IAAI,MAAe,CAAC;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CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,KAA8B,CAAC;QACpD,UAAU,GAAG,CAAC,MAAM,GAAG,CAAC,wEAAwE,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,cAAc,CAAC;QAC5H,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,sDAAsD,CAAC,CAAC;IAC5F,CAAC;;QAAM,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAEnC,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK;QAAE,GAAG,CAAC,eAAe,OAAO,+EAA+E,OAAO,gDAAgD,CAAC,CAAC;IAC9K,MAAM,KAAK,GAAG,aAAa,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IACvG,IAAI,CAAC,kBAAkB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC/C,GAAG,CAAC,uFAAuF,CAAC,CAAC;IAC7F,GAAG,CAAC,8GAA8G,CAAC,CAAC;IACpH,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC5D,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\n/** The database types a source reached through its own MCP server can be. */\nexport const DIALECTS = [\"teradata\", \"postgres\", \"mysql\", \"duckdb\"] as const;\nexport type SetupDialect = (typeof DIALECTS)[number];\n\n/** One entry of a desktop app's list of local MCP servers. */\nexport interface DesktopServer {\n command?: string;\n args?: string[];\n env?: Record<string, string>;\n}\n\ninterface DesktopConfig {\n mcpServers?: Record<string, DesktopServer>;\n [key: string]: unknown;\n}\n\n/** A local MCP server found in the desktop config that looks like a database's. */\nexport interface DatabaseServer {\n /** Its name in the config (`teradata-community`). */\n name: string;\n /** The database type its name and command point to, when they point to one. */\n dialect?: SetupDialect;\n command: string;\n args: string[];\n /** The environment variable that holds its connection string, when one can be told. Never the value. */\n secretName?: string;\n /** Its other environment variables, by name. Surfaces hands a database's server one value, so these are not carried over. */\n otherNames: string[];\n}\n\n/** Where the Claude desktop app keeps its list of local MCP servers. */\nexport function desktopConfigFile(platform: NodeJS.Platform = process.platform, env: Record<string, string | undefined> = process.env, home: string = os.homedir()): string {\n if (platform === \"darwin\") return path.join(home, \"Library\", \"Application Support\", \"Claude\", \"claude_desktop_config.json\");\n if (platform === \"win32\") return path.join(env.APPDATA ?? path.join(home, \"AppData\", \"Roaming\"), \"Claude\", \"claude_desktop_config.json\");\n return path.join(env.XDG_CONFIG_HOME ?? path.join(home, \".config\"), \"Claude\", \"claude_desktop_config.json\");\n}\n\n/** Reads the desktop config, or an empty one when the file is not there yet. */\nexport function readDesktopConfig(file: string): DesktopConfig {\n if (!fs.existsSync(file)) return {};\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(file, \"utf8\"));\n } catch {\n throw new Error(`${file} is not valid JSON, so it was left as it is. Fix it (a missing comma or bracket is the usual cause), then run setup again.`);\n }\n if (parsed === null || typeof parsed !== \"object\" || Array.isArray(parsed)) throw new Error(`${file} must hold a JSON object. It was left as it is.`);\n return parsed as DesktopConfig;\n}\n\nconst HINTS: [SetupDialect, RegExp][] = [\n [\"teradata\", /teradata|vantage/i],\n [\"postgres\", /postgres|\\bpg\\b|supabase|neon/i],\n [\"mysql\", /mysql|mariadb/i],\n [\"duckdb\", /duckdb|motherduck/i],\n];\n\n/** The variable a server reads its connection string from: `DATABASE_URI`, else the only one that is named like one, else the only one there is. */\nfunction secretNameOf(env: Record<string, string>): string | undefined {\n const names = Object.keys(env);\n if (names.includes(\"DATABASE_URI\")) return \"DATABASE_URI\";\n const likely = names.filter((name) => /URI|URL|DSN|CONNECTION/i.test(name));\n if (likely.length === 1) return likely[0];\n return names.length === 1 ? names[0] : undefined;\n}\n\n/**\n * The local servers in a desktop config that a Surfaces source could be made\n * from: every one started by a command, except the Surfaces server itself.\n * Those that look like a database's (by name, command or arguments) come\n * first and carry the type they look like.\n */\nexport function databaseServers(config: DesktopConfig, own = \"surfaces\"): DatabaseServer[] {\n const found: DatabaseServer[] = [];\n for (const [name, server] of Object.entries(config.mcpServers ?? {})) {\n if (name === own || !server || typeof server.command !== \"string\" || server.command === \"\") continue;\n const args = Array.isArray(server.args) ? server.args.map(String) : [];\n if (args.some((arg) => arg.startsWith(\"@surfaces-ui/mcp\"))) continue;\n const text = [name, server.command, ...args].join(\" \");\n const dialect = HINTS.find(([, pattern]) => pattern.test(text))?.[0];\n const env = server.env && typeof server.env === \"object\" ? server.env : {};\n const secretName = secretNameOf(env);\n found.push({ name, dialect, command: server.command, args, secretName, otherNames: Object.keys(env).filter((key) => key !== secretName) });\n }\n return found.sort((a, b) => Number(b.dialect !== undefined) - Number(a.dialect !== undefined));\n}\n\n/** A command and its arguments as the one line `SURFACES_SOURCE_SERVER` takes, quoting what holds a space. */\nexport function commandLine(command: string, args: string[]): string {\n return [command, ...args].map((word) => (/\\s/.test(word) ? `\"${word}\"` : word)).join(\" \");\n}\n\nexport interface SurfacesEntryOptions {\n /** The exact version of `@surfaces-ui/mcp` to start. */\n version: string;\n dialect: SetupDialect;\n /** The command that starts the database's MCP server, its program by full path where that is known. */\n command: string;\n args: string[];\n /** The connection string. Left out, the database's server is started without one. */\n secret?: string;\n /** The variable the database's server reads it from. */\n secretName?: string;\n /** How to start `npx`; its full path where a desktop app would not find it. */\n npx?: string;\n}\n\n/** The entry that starts the Surfaces server over one database. */\nexport function surfacesEntry(options: SurfacesEntryOptions): DesktopServer {\n const env: Record<string, string> = { SURFACES_SOURCE_DIALECT: options.dialect, SURFACES_SOURCE_SERVER: commandLine(options.command, options.args) };\n if (options.secret !== undefined && options.secret !== \"\") env.SURFACES_SOURCE_SECRET = options.secret;\n if (options.secretName && options.secretName !== \"DATABASE_URI\") env.SURFACES_SOURCE_SECRET_NAME = options.secretName;\n return { command: options.npx ?? \"npx\", args: [\"-y\", `@surfaces-ui/mcp@${options.version}`], env };\n}\n\n/** The entry that starts the Surfaces server on its sample data. */\nexport function sampleEntry(version: string, npx = \"npx\"): DesktopServer {\n return { command: npx, args: [\"-y\", `@surfaces-ui/mcp@${version}`] };\n}\n\n/**\n * Writes the Surfaces entry into the desktop config, keeping every other\n * server and setting as it was. The file is written beside itself and moved\n * into place, so a crash cannot leave half a file, and it is kept readable\n * by its owner only, since it can hold a connection string.\n */\nexport function writeSurfacesEntry(file: string, entry: DesktopServer, name = \"surfaces\"): { replaced: boolean } {\n const config = readDesktopConfig(file);\n const servers = config.mcpServers ?? {};\n const replaced = Object.hasOwn(servers, name);\n const next = { ...config, mcpServers: { ...servers, [name]: entry } };\n fs.mkdirSync(path.dirname(file), { recursive: true });\n const draft = `${file}.surfaces-setup`;\n fs.writeFileSync(draft, `${JSON.stringify(next, null, 2)}\\n`, { mode: 0o600 });\n fs.renameSync(draft, file);\n return { replaced };\n}\n\n/** What `runSetup` needs from the terminal, so it can be run in a test. */\nexport interface SetupTerminal {\n say(text: string): void;\n ask(question: string): Promise<string>;\n /** Asks without showing what is typed. */\n askHidden(question: string): Promise<string>;\n}\n\nexport interface SetupOptions {\n /** The desktop config file. */\n file: string;\n /** The version of `@surfaces-ui/mcp` the entry starts. */\n version: string;\n terminal: SetupTerminal;\n /** Finds a program's full path, for a desktop app that starts servers without a shell's PATH. */\n findProgram(command: string): string | undefined;\n /** Use this server from the config, without asking. */\n use?: string;\n /** The database type, where it cannot be told or is to be overridden. */\n dialect?: string;\n /** Set up the sample data only. */\n sample?: boolean;\n}\n\nconst asDialect = (text: string | undefined): SetupDialect | undefined => DIALECTS.find((dialect) => dialect === text?.trim().toLowerCase());\n\n/**\n * Sets the Claude desktop app up to start the Surfaces server over a\n * database, by copying the command and the sign-in of a database server the\n * person already has in that app's config, or by asking for them. The sign-in\n * goes from the file to the same file (or from the keyboard, unshown, to the\n * file); it is never printed. Returns what it wrote, with no value in it.\n */\nexport async function runSetup(options: SetupOptions): Promise<{ wrote: \"sample\" | \"database\" | \"nothing\"; from?: string; dialect?: SetupDialect }> {\n const { file, version, terminal } = options;\n const { say, ask } = terminal;\n const config = readDesktopConfig(file);\n const done = (replaced: boolean) => {\n say(`${replaced ? \"Updated\" : \"Added\"} the Surfaces server in ${file}.`);\n say(\"Next: quit the Claude app fully and open it again, then start a new chat.\");\n };\n if (options.sample) {\n done(writeSurfacesEntry(file, sampleEntry(version)).replaced);\n say('Then ask: \"Use the surfaces tools to show a chart of the sample retail data.\"');\n return { wrote: \"sample\" };\n }\n\n const servers = databaseServers(config);\n let chosen: DatabaseServer | undefined;\n let manual = false;\n if (options.use) {\n chosen = servers.find((server) => server.name === options.use);\n if (!chosen) throw new Error(`There is no server named \"${options.use}\" in ${file}.${servers.length > 0 ? ` It has: ${servers.map((server) => server.name).join(\", \")}.` : \"\"}`);\n } else if (servers.length === 0) {\n say(`No database server was found in ${file}, so its details are asked for here.`);\n manual = true;\n } else {\n say(\"Servers already set up in the Claude app:\");\n servers.forEach((server, index) => say(` ${index + 1}. ${server.name}${server.dialect ? ` (${server.dialect})` : \"\"}`));\n say(` ${servers.length + 1}. A database that is not in this list`);\n say(` ${servers.length + 2}. No database: the sample data only`);\n const suggested = servers[0]!.dialect ? \"1\" : \"\";\n const answer = (await ask(`Which one should Surfaces show data from?${suggested ? \" [1]\" : \"\"} `)).trim() || suggested;\n const picked = Number(answer);\n if (!Number.isInteger(picked) || picked < 1 || picked > servers.length + 2) {\n say(\"Nothing was changed.\");\n return { wrote: \"nothing\" };\n }\n if (picked === servers.length + 2) {\n done(writeSurfacesEntry(file, sampleEntry(version)).replaced);\n return { wrote: \"sample\" };\n }\n if (picked === servers.length + 1) manual = true;\n else chosen = servers[picked - 1];\n }\n\n let dialect = asDialect(options.dialect) ?? chosen?.dialect;\n if (options.dialect && !asDialect(options.dialect)) throw new Error(`The database type must be one of ${DIALECTS.join(\", \")}, not \"${options.dialect}\".`);\n if (!dialect) {\n dialect = asDialect(await ask(`What kind of database is it? (${DIALECTS.join(\", \")}) `));\n if (!dialect) {\n say(`Surfaces works with ${DIALECTS.join(\", \")}. Nothing was changed.`);\n return { wrote: \"nothing\" };\n }\n }\n\n let command: string;\n let args: string[];\n let secret: string | undefined;\n let secretName: string | undefined;\n if (chosen) {\n ({ command, args, secretName } = chosen);\n secret = secretName ? config.mcpServers?.[chosen.name]?.env?.[secretName] : undefined;\n if (secret !== undefined) say(`The sign-in ${chosen.name} uses (${secretName}) was copied inside that file. It was not shown and went nowhere else.`);\n else if (chosen.otherNames.length > 0) say(`${chosen.name} signs in with several settings (${chosen.otherNames.join(\", \")}). Surfaces hands a database's server one connection string, so none was copied; inline views may not be able to sign in.`);\n if (secret !== undefined && chosen.otherNames.length > 0) say(`Its other settings (${chosen.otherNames.join(\", \")}) were not copied: Surfaces hands a database's server only its connection string.`);\n } else if (manual) {\n const line = (await ask(\"The command that starts that database's MCP server (for example: uvx teradata-mcp-server): \")).trim();\n const parts = [...line.matchAll(/\"([^\"]*)\"|'([^']*)'|(\\S+)/g)].map((match) => match[1] ?? match[2] ?? match[3]!);\n if (parts.length === 0) {\n say(\"Nothing was changed.\");\n return { wrote: \"nothing\" };\n }\n [command, ...args] = parts as [string, ...string[]];\n secretName = (await ask(\"The name that server reads its connection string from [DATABASE_URI]: \")).trim() || \"DATABASE_URI\";\n secret = await terminal.askHidden(\"The connection string (what you type is not shown): \");\n } else return { wrote: \"nothing\" };\n\n const found = options.findProgram(command);\n if (!found) say(`The program ${command} was not found on this computer. The entry is written all the same; install ${command}, or inline views will not reach the database.`);\n const entry = surfacesEntry({ version, dialect, command: found ?? command, args, secret, secretName });\n done(writeSurfacesEntry(file, entry).replaced);\n say('Then ask: \"Use the surfaces tools to list my tables\", and \"show <a table> as a grid\".');\n say(\"That file holds the connection string as plain text, as it does for your other servers. Keep it to yourself.\");\n return { wrote: \"database\", from: chosen?.name, dialect };\n}\n"]}
@@ -0,0 +1,27 @@
1
+ /** One request a view made for data, and where its time went. No statement, name or value is kept. */
2
+ export interface TimedRequest {
3
+ /** The data method: `execute` (rows for a view), `listTables`, and so on. */
4
+ method: string;
5
+ /** From the request reaching this server to its answer being ready, in milliseconds. */
6
+ totalMs: number;
7
+ /** Of that, the time spent waiting on the database's own MCP server (the database's work and that server's). */
8
+ databaseMs: number;
9
+ /** How many calls to the database's server the request made. None means the answer was already held here. */
10
+ databaseCalls: number;
11
+ /** The size of the answer handed to the view, in bytes of JSON. */
12
+ bytes: number;
13
+ failed: boolean;
14
+ }
15
+ /**
16
+ * Times the data requests of the views this server draws, split into the
17
+ * wait on the database's own MCP server and everything this server adds on
18
+ * top (rewriting the SQL, turning the answer into Arrow, packing it for the
19
+ * view). It keeps the last `limit` requests in memory and nothing else. What
20
+ * it cannot see: the time between the view and this server, which is the
21
+ * host app's.
22
+ */
23
+ export declare function createTiming(limit?: number): {
24
+ around: <T>(method: string, run: () => Promise<T>) => Promise<T>;
25
+ report: () => string;
26
+ requests: TimedRequest[];
27
+ };
package/dist/timing.js ADDED
@@ -0,0 +1,84 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ /** The key `@surfaces-ui/engine-mcp` looks under for a function to tell each database call's time to (`DATABASE_CALL` there). */
3
+ const DATABASE_CALL = Symbol.for("surfaces-ui.database-call");
4
+ const median = (values) => {
5
+ if (values.length === 0)
6
+ return 0;
7
+ const sorted = [...values].sort((a, b) => a - b);
8
+ const middle = Math.floor(sorted.length / 2);
9
+ return sorted.length % 2 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2;
10
+ };
11
+ const ms = (value) => `${Math.round(value)} ms`;
12
+ /**
13
+ * Times the data requests of the views this server draws, split into the
14
+ * wait on the database's own MCP server and everything this server adds on
15
+ * top (rewriting the SQL, turning the answer into Arrow, packing it for the
16
+ * view). It keeps the last `limit` requests in memory and nothing else. What
17
+ * it cannot see: the time between the view and this server, which is the
18
+ * host app's.
19
+ */
20
+ export function createTiming(limit = 500) {
21
+ const current = new AsyncLocalStorage();
22
+ const requests = [];
23
+ // The database connector reports each call's time here; it belongs to whichever request is running it.
24
+ globalThis[DATABASE_CALL] = (spent) => {
25
+ const request = current.getStore();
26
+ if (!request)
27
+ return;
28
+ request.databaseMs += spent;
29
+ request.databaseCalls += 1;
30
+ };
31
+ async function around(method, run) {
32
+ const tally = { databaseMs: 0, databaseCalls: 0 };
33
+ const start = performance.now();
34
+ let failed = false;
35
+ let bytes = 0;
36
+ try {
37
+ const result = await current.run(tally, run);
38
+ failed = result?.isError === true;
39
+ const totalMs = performance.now() - start;
40
+ // Measured after the clock stops, so the measuring is not counted.
41
+ bytes = JSON.stringify(result?.structuredContent ?? null).length;
42
+ requests.push({ method, totalMs, ...tally, bytes, failed });
43
+ return result;
44
+ }
45
+ catch (error) {
46
+ requests.push({ method, totalMs: performance.now() - start, ...tally, bytes, failed: true });
47
+ throw error;
48
+ }
49
+ finally {
50
+ if (requests.length > limit)
51
+ requests.splice(0, requests.length - limit);
52
+ }
53
+ }
54
+ /** The timings in words and numbers only, for a person or a model to read. */
55
+ function report() {
56
+ if (requests.length === 0)
57
+ return "No view has asked this server for data yet. Draw a grid or a chart, sort it or page through it, then ask again.";
58
+ const lines = [`Timings of the last ${requests.length} data requests made by views (medians). "Database" is the wait on the database's own MCP server; "added here" is what the Surfaces server adds on top.`];
59
+ const methods = [...new Set(requests.map((request) => request.method))];
60
+ for (const method of methods) {
61
+ const all = requests.filter((request) => request.method === method && !request.failed);
62
+ if (all.length === 0)
63
+ continue;
64
+ const asked = all.filter((request) => request.databaseCalls > 0);
65
+ const held = all.length - asked.length;
66
+ if (asked.length > 0) {
67
+ const total = median(asked.map((request) => request.totalMs));
68
+ const database = median(asked.map((request) => request.databaseMs));
69
+ const added = median(asked.map((request) => Math.max(0, request.totalMs - request.databaseMs)));
70
+ const share = total > 0 ? Math.round((added / total) * 100) : 0;
71
+ lines.push(`- ${method}: ${asked.length} that asked the database. Total ${ms(total)}, database ${ms(database)}, added here ${ms(added)} (${share}% of the total). ${median(asked.map((request) => request.databaseCalls))} database calls each, answer ${Math.round(median(asked.map((request) => request.bytes)) / 1024)} kB. Slowest total ${ms(Math.max(...asked.map((request) => request.totalMs)))}.`);
72
+ }
73
+ if (held > 0)
74
+ lines.push(`- ${method}: ${held} answered from what this server already held, ${ms(median(all.filter((request) => request.databaseCalls === 0).map((request) => request.totalMs)))} each.`);
75
+ }
76
+ const failures = requests.filter((request) => request.failed).length;
77
+ if (failures > 0)
78
+ lines.push(`${failures} requests failed and are left out of the medians.`);
79
+ lines.push("Not measured here: the time between the view and this server, which is the host app's. Requests that ask the database in parallel can show more database time than total.");
80
+ return lines.join("\n");
81
+ }
82
+ return { around, report, requests };
83
+ }
84
+ //# sourceMappingURL=timing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.js","sourceRoot":"","sources":["../src/timing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,iIAAiI;AACjI,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAiB9D,MAAM,MAAM,GAAG,CAAC,MAAgB,EAAE,EAAE;IAClC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GA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CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAChY,CAAC;YACJ,CAAC;YACD,IAAI,IAAI,GAAG,CAAC;gBAAE,KAAK,CAAC,IAAI,CAAC,KAAK,MAAM,KAAK,IAAI,iDAAiD,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC5M,CAAC;QACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;QACrE,IAAI,QAAQ,GAAG,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,mDAAmD,CAAC,CAAC;QAC7F,KAAK,CAAC,IAAI,CAAC,2KAA2K,CAAC,CAAC;QACxL,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\n/** The key `@surfaces-ui/engine-mcp` looks under for a function to tell each database call's time to (`DATABASE_CALL` there). */\nconst DATABASE_CALL = Symbol.for(\"surfaces-ui.database-call\");\n\n/** One request a view made for data, and where its time went. No statement, name or value is kept. */\nexport interface TimedRequest {\n /** The data method: `execute` (rows for a view), `listTables`, and so on. */\n method: string;\n /** From the request reaching this server to its answer being ready, in milliseconds. */\n totalMs: number;\n /** Of that, the time spent waiting on the database's own MCP server (the database's work and that server's). */\n databaseMs: number;\n /** How many calls to the database's server the request made. None means the answer was already held here. */\n databaseCalls: number;\n /** The size of the answer handed to the view, in bytes of JSON. */\n bytes: number;\n failed: boolean;\n}\n\nconst median = (values: number[]) => {\n if (values.length === 0) return 0;\n const sorted = [...values].sort((a, b) => a - b);\n const middle = Math.floor(sorted.length / 2);\n return sorted.length % 2 ? sorted[middle]! : (sorted[middle - 1]! + sorted[middle]!) / 2;\n};\nconst ms = (value: number) => `${Math.round(value)} ms`;\n\n/**\n * Times the data requests of the views this server draws, split into the\n * wait on the database's own MCP server and everything this server adds on\n * top (rewriting the SQL, turning the answer into Arrow, packing it for the\n * view). It keeps the last `limit` requests in memory and nothing else. What\n * it cannot see: the time between the view and this server, which is the\n * host app's.\n */\nexport function createTiming(limit = 500) {\n const current = new AsyncLocalStorage<{ databaseMs: number; databaseCalls: number }>();\n const requests: TimedRequest[] = [];\n // The database connector reports each call's time here; it belongs to whichever request is running it.\n (globalThis as { [DATABASE_CALL]?: (ms: number) => void })[DATABASE_CALL] = (spent) => {\n const request = current.getStore();\n if (!request) return;\n request.databaseMs += spent;\n request.databaseCalls += 1;\n };\n\n async function around<T>(method: string, run: () => Promise<T>): Promise<T> {\n const tally = { databaseMs: 0, databaseCalls: 0 };\n const start = performance.now();\n let failed = false;\n let bytes = 0;\n try {\n const result = await current.run(tally, run);\n failed = (result as { isError?: boolean } | undefined)?.isError === true;\n const totalMs = performance.now() - start;\n // Measured after the clock stops, so the measuring is not counted.\n bytes = JSON.stringify((result as { structuredContent?: unknown } | undefined)?.structuredContent ?? null).length;\n requests.push({ method, totalMs, ...tally, bytes, failed });\n return result;\n } catch (error) {\n requests.push({ method, totalMs: performance.now() - start, ...tally, bytes, failed: true });\n throw error;\n } finally {\n if (requests.length > limit) requests.splice(0, requests.length - limit);\n }\n }\n\n /** The timings in words and numbers only, for a person or a model to read. */\n function report(): string {\n if (requests.length === 0) return \"No view has asked this server for data yet. Draw a grid or a chart, sort it or page through it, then ask again.\";\n const lines = [`Timings of the last ${requests.length} data requests made by views (medians). \"Database\" is the wait on the database's own MCP server; \"added here\" is what the Surfaces server adds on top.`];\n const methods = [...new Set(requests.map((request) => request.method))];\n for (const method of methods) {\n const all = requests.filter((request) => request.method === method && !request.failed);\n if (all.length === 0) continue;\n const asked = all.filter((request) => request.databaseCalls > 0);\n const held = all.length - asked.length;\n if (asked.length > 0) {\n const total = median(asked.map((request) => request.totalMs));\n const database = median(asked.map((request) => request.databaseMs));\n const added = median(asked.map((request) => Math.max(0, request.totalMs - request.databaseMs)));\n const share = total > 0 ? Math.round((added / total) * 100) : 0;\n lines.push(\n `- ${method}: ${asked.length} that asked the database. Total ${ms(total)}, database ${ms(database)}, added here ${ms(added)} (${share}% of the total). ${median(asked.map((request) => request.databaseCalls))} database calls each, answer ${Math.round(median(asked.map((request) => request.bytes)) / 1024)} kB. Slowest total ${ms(Math.max(...asked.map((request) => request.totalMs)))}.`,\n );\n }\n if (held > 0) lines.push(`- ${method}: ${held} answered from what this server already held, ${ms(median(all.filter((request) => request.databaseCalls === 0).map((request) => request.totalMs)))} each.`);\n }\n const failures = requests.filter((request) => request.failed).length;\n if (failures > 0) lines.push(`${failures} requests failed and are left out of the medians.`);\n lines.push(\"Not measured here: the time between the view and this server, which is the host app's. Requests that ask the database in parallel can show more database time than total.\");\n return lines.join(\"\\n\");\n }\n\n return { around, report, requests };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surfaces-ui/mcp",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "MCP Apps delivery for Surfaces UI: tools, ui:// resources and a stdio server",
5
5
  "keywords": [
6
6
  "surfaces-ui",
@@ -51,22 +51,23 @@
51
51
  "react": "^19.3.1",
52
52
  "react-dom": "^19.3.1",
53
53
  "zod": "^4.6.7",
54
- "@surfaces-ui/agent": "0.4.0",
55
- "@surfaces-ui/components": "0.4.0",
56
- "@surfaces-ui/data": "0.4.0",
57
- "@surfaces-ui/proto": "0.4.0",
58
- "@surfaces-ui/dev-server": "0.4.0",
59
- "@surfaces-ui/spec": "0.4.0",
60
- "@surfaces-ui/tokens": "0.4.0"
54
+ "@surfaces-ui/agent": "0.6.0",
55
+ "@surfaces-ui/data": "0.6.0",
56
+ "@surfaces-ui/components": "0.6.0",
57
+ "@surfaces-ui/dev-server": "0.6.0",
58
+ "@surfaces-ui/proto": "0.6.0",
59
+ "@surfaces-ui/spec": "0.6.0",
60
+ "@surfaces-ui/tokens": "0.6.0"
61
61
  },
62
62
  "devDependencies": {
63
+ "@anthropic-ai/mcpb": "^2.1.2",
63
64
  "@types/node": "^26.6.6",
64
65
  "@types/react": "^19.3.0",
65
66
  "@types/react-dom": "^19.3.0",
66
67
  "@vitejs/plugin-react": "^6.3.0",
67
68
  "vite": "^8.3.8",
68
69
  "vite-plugin-singlefile": "^2.3.4",
69
- "@surfaces-ui/discovery": "0.4.0"
70
+ "@surfaces-ui/discovery": "0.6.0"
70
71
  },
71
72
  "publishConfig": {
72
73
  "access": "public",
@@ -75,6 +76,7 @@
75
76
  "scripts": {
76
77
  "build": "tsc -p tsconfig.build.json && vite build",
77
78
  "typecheck": "tsc -p tsconfig.json --noEmit",
78
- "test": "vitest run --passWithNoTests"
79
+ "test": "vitest run --passWithNoTests",
80
+ "pack:desktop": "node desktop/pack.mjs"
79
81
  }
80
82
  }