@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.
- package/dist/app.html +50 -49
- package/dist/cli.js +112 -6
- package/dist/cli.js.map +1 -1
- package/dist/server.d.ts +6 -0
- package/dist/server.js +42 -37
- package/dist/server.js.map +1 -1
- package/dist/setup.d.ts +101 -0
- package/dist/setup.js +201 -0
- package/dist/setup.js.map +1 -0
- package/dist/timing.d.ts +27 -0
- package/dist/timing.js +84 -0
- package/dist/timing.js.map +1 -0
- package/package.json +12 -10
package/dist/cli.js
CHANGED
|
@@ -3,9 +3,12 @@ import fs from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
5
5
|
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
6
|
-
import
|
|
6
|
+
import readline from "node:readline";
|
|
7
|
+
import { CONFIG_FILES, configFromEnv, findConfig, findProgram, createSurfacesServer, loadConfig, loadEnvFile, openSources, serverOptions } from "@surfaces-ui/dev-server";
|
|
7
8
|
import { installMcpServer, readAppHtml } from "./node.js";
|
|
8
9
|
import { registerSurfacesApps } from "./server.js";
|
|
10
|
+
import { desktopConfigFile, runSetup } from "./setup.js";
|
|
11
|
+
import { createTiming } from "./timing.js";
|
|
9
12
|
const args = process.argv.slice(2);
|
|
10
13
|
const flag = (name) => {
|
|
11
14
|
const at = args.indexOf(name);
|
|
@@ -22,20 +25,123 @@ try {
|
|
|
22
25
|
if (!config)
|
|
23
26
|
say(`No config found in ${dir}. Create ${CONFIG_FILES[0]} with your data sources before starting the server.`);
|
|
24
27
|
}
|
|
28
|
+
else if (args[0] === "setup") {
|
|
29
|
+
// Sets the Claude desktop app up to start this server over a database the person already has there.
|
|
30
|
+
const version = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
31
|
+
const lines = readline.createInterface({ input: process.stdin, output: process.stderr, terminal: process.stdin.isTTY === true });
|
|
32
|
+
let hidden = false;
|
|
33
|
+
// What is typed for a connection string is not echoed.
|
|
34
|
+
const output = lines;
|
|
35
|
+
const write = output._writeToOutput.bind(lines);
|
|
36
|
+
output._writeToOutput = (text) => {
|
|
37
|
+
if (!hidden)
|
|
38
|
+
write(text);
|
|
39
|
+
};
|
|
40
|
+
const ask = (question) => new Promise((resolve) => lines.question(question, resolve));
|
|
41
|
+
try {
|
|
42
|
+
await runSetup({
|
|
43
|
+
file: flag("--file") ?? desktopConfigFile(),
|
|
44
|
+
version,
|
|
45
|
+
findProgram,
|
|
46
|
+
use: flag("--use"),
|
|
47
|
+
dialect: flag("--dialect"),
|
|
48
|
+
sample: args.includes("--sample"),
|
|
49
|
+
terminal: {
|
|
50
|
+
say,
|
|
51
|
+
ask,
|
|
52
|
+
askHidden: async (question) => {
|
|
53
|
+
process.stderr.write(question);
|
|
54
|
+
hidden = true;
|
|
55
|
+
try {
|
|
56
|
+
return await ask("");
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
hidden = false;
|
|
60
|
+
process.stderr.write("\n");
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
lines.close();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
25
70
|
else {
|
|
26
|
-
|
|
71
|
+
// A project's config in the working directory, or a person's own in ~/.surfaces, for a host with no project folder.
|
|
72
|
+
const file = flag("--config") ?? findConfig();
|
|
27
73
|
// Secrets (a warehouse's host and password, a model key) come from the git-ignored .env.local beside the config, as on the dev server.
|
|
28
74
|
const secrets = loadEnvFile(path.dirname(path.resolve(file ?? CONFIG_FILES[0])));
|
|
29
75
|
if (secrets.names.length > 0)
|
|
30
76
|
say(`Read ${secrets.names.join(", ")} from ${secrets.file}.`);
|
|
31
|
-
// With no config,
|
|
32
|
-
|
|
77
|
+
// With no config file, a source named in the environment (a plugin's settings); with neither, the six sample industry models.
|
|
78
|
+
// Settings that cannot be used (a launcher that is not installed, a database type with no server named) do not stop
|
|
79
|
+
// the server: it starts on the sample data and says what is wrong through `check_setup`, where a person can act on it.
|
|
80
|
+
let fromEnv;
|
|
81
|
+
let problem;
|
|
82
|
+
if (!file) {
|
|
83
|
+
try {
|
|
84
|
+
fromEnv = configFromEnv();
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
problem = error instanceof Error ? error.message : String(error);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const { config, dir } = file ? await loadConfig(file) : { config: fromEnv ?? { seeds: true }, dir: process.cwd() };
|
|
33
91
|
const sources = await openSources(config, dir);
|
|
34
92
|
const backend = await createSurfacesServer(await serverOptions(config, sources, dir));
|
|
35
93
|
const server = new McpServer({ name: "surfaces", version: "0.0.0" });
|
|
36
|
-
|
|
94
|
+
const timing = createTiming();
|
|
95
|
+
registerSurfacesApps(server, { around: timing.around, dataSource: backend.dataSource, discovery: backend.discovery, ...(backend.pipelines ? { pipelines: backend.pipelines } : {}), appHtml: readAppHtml });
|
|
96
|
+
const set = (name) => {
|
|
97
|
+
const value = process.env[name]?.trim() ?? "";
|
|
98
|
+
return value !== "" && !value.startsWith("${") && !/^(none|sample data)$/i.test(value);
|
|
99
|
+
};
|
|
100
|
+
server.registerTool("check_setup", {
|
|
101
|
+
title: "Check the data setup",
|
|
102
|
+
description: "Says where this server's data comes from (the person's own database, a config file, or the built-in sample data), whether it can be reached right now, and what to do if not. Call it first when a data tool fails, when someone asks to connect their database, or when only sample data shows and they expected their own. It reads settings and runs one harmless listing; it never shows a password.",
|
|
103
|
+
inputSchema: {},
|
|
104
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
105
|
+
}, async () => {
|
|
106
|
+
const lines = [];
|
|
107
|
+
const own = fromEnv?.sources?.[0];
|
|
108
|
+
if (file)
|
|
109
|
+
lines.push(`Data comes from the config file ${file}: ${sources.map((s) => s.id).join(", ")}.`);
|
|
110
|
+
else if (own && own.engine === "mcp")
|
|
111
|
+
lines.push(`Data comes from the person's ${own.dialect} database, set in this plugin's settings, through ${"url" in own.server ? "a remote MCP server" : `the MCP server started by ${path.basename(own.server.command)}`}.`);
|
|
112
|
+
else
|
|
113
|
+
lines.push("Data is the built-in sample data (retail, healthcare, fraud, telco, transportation, manufacturing). No database is set up.");
|
|
114
|
+
if (problem)
|
|
115
|
+
lines.push(`The settings could not be used, so the sample data is shown instead: ${problem}`);
|
|
116
|
+
if (!file) {
|
|
117
|
+
lines.push(`Settings filled in: database type ${set("SURFACES_SOURCE_DIALECT") ? "yes" : "no"}, the database's MCP server ${set("SURFACES_SOURCE_SERVER") ? "yes" : "no"}, connection string or token ${set("SURFACES_SOURCE_SECRET") ? "yes" : "no"}.`);
|
|
118
|
+
}
|
|
119
|
+
if (own) {
|
|
120
|
+
try {
|
|
121
|
+
const { schemas } = await backend.dataSource.listSchemas({ sourceId: own.id, catalog: "" });
|
|
122
|
+
lines.push(`It works: the database answered, and ${schemas.length} ${schemas.length === 1 ? "database is" : "databases are"} visible${schemas.length > 0 ? ` (${schemas.slice(0, 8).map((x) => x.name).join(", ")}${schemas.length > 8 ? ", and more" : ""})` : ""}.`);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
// The service puts its error code in brackets in front; a person needs the words.
|
|
126
|
+
lines.push(`It does not work yet: ${(error instanceof Error ? error.message : String(error)).replace(/^\[\w+\]\s*/, "")}`);
|
|
127
|
+
lines.push("What to check, in this order: (1) the connection string in the plugin's settings, typed there and never into this conversation; (2) that this computer can reach the database's host, which often needs a VPN; (3) that the first start has had a minute, since the database's MCP server is downloaded the first time it runs. After changing a setting, start a new session.");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (!file && !problem) {
|
|
131
|
+
lines.push("This server draws inline views from a database it connects to itself, which is the advanced route. For a page over the person's own database with nothing to set up here, use the artifact-pages skill: it reads through a connector they already have. To connect this server all the same, the plugin's README lists the three settings.");
|
|
132
|
+
}
|
|
133
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
134
|
+
});
|
|
135
|
+
server.registerTool("timing_report", {
|
|
136
|
+
title: "How long views took to load",
|
|
137
|
+
description: "Says how long the views this server drew took to get their data, and how much of that was the database and how much this server added. Numbers only: no query, table name or value. Call it when someone asks whether Surfaces is slow, or to compare it with querying the database directly.",
|
|
138
|
+
inputSchema: {},
|
|
139
|
+
annotations: { readOnlyHint: true, destructiveHint: false },
|
|
140
|
+
}, async () => ({ content: [{ type: "text", text: timing.report() }] }));
|
|
37
141
|
await server.connect(new StdioServerTransport());
|
|
38
|
-
say(`Surfaces MCP server ready (${sources.map((s) => s.id).join(", ")}${file ? "" : "; sample data, no config found"}).`);
|
|
142
|
+
say(`Surfaces MCP server ready (${sources.map((s) => s.id).join(", ")}${file ? "" : fromEnv ? "; from this plugin's settings" : problem ? "; sample data, because the settings could not be used" : "; sample data, no config found"}).`);
|
|
143
|
+
if (problem)
|
|
144
|
+
say(problem);
|
|
39
145
|
const stop = () => void backend.close().then(() => process.exit(0));
|
|
40
146
|
process.on("SIGINT", stop);
|
|
41
147
|
process.on("SIGTERM", stop);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAClI,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAA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AAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;QACrL,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;QACjD,GAAG,CAAC,8BAA8B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gCAAgC,IAAI,CAAC,CAAC;QAC1H,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["#!/usr/bin/env node\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { McpServer } from \"@modelcontextprotocol/server\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/server/stdio\";\nimport { CONFIG_FILES, createSurfacesServer, loadConfig, loadEnvFile, openSources, serverOptions } from \"@surfaces-ui/dev-server\";\nimport { installMcpServer, readAppHtml } from \"./node.js\";\nimport { registerSurfacesApps } from \"./server.js\";\n\nconst args = process.argv.slice(2);\nconst flag = (name: string) => {\n const at = args.indexOf(name);\n return at === -1 ? undefined : args[at + 1];\n};\n// stdout carries the MCP protocol, so everything a person should read goes to stderr.\nconst say = (text: string) => process.stderr.write(`${text}\\n`);\n\ntry {\n if (args[0] === \"install\") {\n const dir = flag(\"--dir\") ?? process.cwd();\n const config = flag(\"--config\") ?? CONFIG_FILES.find((f) => fs.existsSync(path.resolve(dir, f)));\n const { file, replaced } = installMcpServer({ dir, config, name: flag(\"--name\") });\n say(`${replaced ? \"Updated\" : \"Added\"} the Surfaces server in ${file}.`);\n if (!config) say(`No config found in ${dir}. Create ${CONFIG_FILES[0]} with your data sources before starting the server.`);\n } else {\n const file = flag(\"--config\") ?? CONFIG_FILES.find((f) => fs.existsSync(path.resolve(f)));\n // Secrets (a warehouse's host and password, a model key) come from the git-ignored .env.local beside the config, as on the dev server.\n const secrets = loadEnvFile(path.dirname(path.resolve(file ?? CONFIG_FILES[0]!)));\n if (secrets.names.length > 0) say(`Read ${secrets.names.join(\", \")} from ${secrets.file}.`);\n // With no config, serve the six sample industry models.\n const { config, dir } = file ? await loadConfig(file) : { config: { seeds: true }, dir: process.cwd() };\n const sources = await openSources(config, dir);\n const backend = await createSurfacesServer(await serverOptions(config, sources, dir));\n const server = new McpServer({ name: \"surfaces\", version: \"0.0.0\" });\n registerSurfacesApps(server, { dataSource: backend.dataSource, discovery: backend.discovery, ...(backend.pipelines ? { pipelines: backend.pipelines } : {}), appHtml: readAppHtml });\n await server.connect(new StdioServerTransport());\n say(`Surfaces MCP server ready (${sources.map((s) => s.id).join(\", \")}${file ? \"\" : \"; sample data, no config found\"}).`);\n const stop = () => void backend.close().then(() => process.exit(0));\n process.on(\"SIGINT\", stop);\n process.on(\"SIGTERM\", stop);\n }\n} catch (error) {\n say(error instanceof Error ? error.message : String(error));\n process.exit(1);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,M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AAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,uDAAuD,CAAC,CAAC,CAAC,gCAAgC,IAAI,CAAC,CAAC;QAC1O,IAAI,OAAO;YAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC1B,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["#!/usr/bin/env node\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { McpServer } from \"@modelcontextprotocol/server\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/server/stdio\";\nimport readline from \"node:readline\";\nimport { CONFIG_FILES, configFromEnv, findConfig, findProgram, createSurfacesServer, loadConfig, loadEnvFile, openSources, serverOptions } from \"@surfaces-ui/dev-server\";\nimport { installMcpServer, readAppHtml } from \"./node.js\";\nimport { registerSurfacesApps } from \"./server.js\";\nimport { desktopConfigFile, runSetup } from \"./setup.js\";\nimport { createTiming } from \"./timing.js\";\n\nconst args = process.argv.slice(2);\nconst flag = (name: string) => {\n const at = args.indexOf(name);\n return at === -1 ? undefined : args[at + 1];\n};\n// stdout carries the MCP protocol, so everything a person should read goes to stderr.\nconst say = (text: string) => process.stderr.write(`${text}\\n`);\n\ntry {\n if (args[0] === \"install\") {\n const dir = flag(\"--dir\") ?? process.cwd();\n const config = flag(\"--config\") ?? CONFIG_FILES.find((f) => fs.existsSync(path.resolve(dir, f)));\n const { file, replaced } = installMcpServer({ dir, config, name: flag(\"--name\") });\n say(`${replaced ? \"Updated\" : \"Added\"} the Surfaces server in ${file}.`);\n if (!config) say(`No config found in ${dir}. Create ${CONFIG_FILES[0]} with your data sources before starting the server.`);\n } else if (args[0] === \"setup\") {\n // Sets the Claude desktop app up to start this server over a database the person already has there.\n const version = (JSON.parse(fs.readFileSync(new URL(\"../package.json\", import.meta.url), \"utf8\")) as { version: string }).version;\n const lines = readline.createInterface({ input: process.stdin, output: process.stderr, terminal: process.stdin.isTTY === true });\n let hidden = false;\n // What is typed for a connection string is not echoed.\n const output = lines as unknown as { _writeToOutput(text: string): void };\n const write = output._writeToOutput.bind(lines);\n output._writeToOutput = (text) => {\n if (!hidden) write(text);\n };\n const ask = (question: string) => new Promise<string>((resolve) => lines.question(question, resolve));\n try {\n await runSetup({\n file: flag(\"--file\") ?? desktopConfigFile(),\n version,\n findProgram,\n use: flag(\"--use\"),\n dialect: flag(\"--dialect\"),\n sample: args.includes(\"--sample\"),\n terminal: {\n say,\n ask,\n askHidden: async (question) => {\n process.stderr.write(question);\n hidden = true;\n try {\n return await ask(\"\");\n } finally {\n hidden = false;\n process.stderr.write(\"\\n\");\n }\n },\n },\n });\n } finally {\n lines.close();\n }\n } else {\n // A project's config in the working directory, or a person's own in ~/.surfaces, for a host with no project folder.\n const file = flag(\"--config\") ?? findConfig();\n // Secrets (a warehouse's host and password, a model key) come from the git-ignored .env.local beside the config, as on the dev server.\n const secrets = loadEnvFile(path.dirname(path.resolve(file ?? CONFIG_FILES[0]!)));\n if (secrets.names.length > 0) say(`Read ${secrets.names.join(\", \")} from ${secrets.file}.`);\n // With no config file, a source named in the environment (a plugin's settings); with neither, the six sample industry models.\n // Settings that cannot be used (a launcher that is not installed, a database type with no server named) do not stop\n // the server: it starts on the sample data and says what is wrong through `check_setup`, where a person can act on it.\n let fromEnv: ReturnType<typeof configFromEnv>;\n let problem: string | undefined;\n if (!file) {\n try {\n fromEnv = configFromEnv();\n } catch (error) {\n problem = error instanceof Error ? error.message : String(error);\n }\n }\n const { config, dir } = file ? await loadConfig(file) : { config: fromEnv ?? { seeds: true }, dir: process.cwd() };\n const sources = await openSources(config, dir);\n const backend = await createSurfacesServer(await serverOptions(config, sources, dir));\n const server = new McpServer({ name: \"surfaces\", version: \"0.0.0\" });\n const timing = createTiming();\n registerSurfacesApps(server, { around: timing.around, dataSource: backend.dataSource, discovery: backend.discovery, ...(backend.pipelines ? { pipelines: backend.pipelines } : {}), appHtml: readAppHtml });\n const set = (name: string) => {\n const value = process.env[name]?.trim() ?? \"\";\n return value !== \"\" && !value.startsWith(\"${\") && !/^(none|sample data)$/i.test(value);\n };\n server.registerTool(\n \"check_setup\",\n {\n title: \"Check the data setup\",\n description:\n \"Says where this server's data comes from (the person's own database, a config file, or the built-in sample data), whether it can be reached right now, and what to do if not. Call it first when a data tool fails, when someone asks to connect their database, or when only sample data shows and they expected their own. It reads settings and runs one harmless listing; it never shows a password.\",\n inputSchema: {},\n annotations: { readOnlyHint: true, destructiveHint: false },\n },\n async () => {\n const lines: string[] = [];\n const own = fromEnv?.sources?.[0];\n if (file) lines.push(`Data comes from the config file ${file}: ${sources.map((s) => s.id).join(\", \")}.`);\n else if (own && own.engine === \"mcp\") lines.push(`Data comes from the person's ${own.dialect} database, set in this plugin's settings, through ${\"url\" in own.server ? \"a remote MCP server\" : `the MCP server started by ${path.basename(own.server.command)}`}.`);\n else lines.push(\"Data is the built-in sample data (retail, healthcare, fraud, telco, transportation, manufacturing). No database is set up.\");\n if (problem) lines.push(`The settings could not be used, so the sample data is shown instead: ${problem}`);\n if (!file) {\n lines.push(`Settings filled in: database type ${set(\"SURFACES_SOURCE_DIALECT\") ? \"yes\" : \"no\"}, the database's MCP server ${set(\"SURFACES_SOURCE_SERVER\") ? \"yes\" : \"no\"}, connection string or token ${set(\"SURFACES_SOURCE_SECRET\") ? \"yes\" : \"no\"}.`);\n }\n if (own) {\n try {\n const { schemas } = await backend.dataSource.listSchemas({ sourceId: own.id, catalog: \"\" });\n lines.push(`It works: the database answered, and ${schemas.length} ${schemas.length === 1 ? \"database is\" : \"databases are\"} visible${schemas.length > 0 ? ` (${schemas.slice(0, 8).map((x) => x.name).join(\", \")}${schemas.length > 8 ? \", and more\" : \"\"})` : \"\"}.`);\n } catch (error) {\n // The service puts its error code in brackets in front; a person needs the words.\n lines.push(`It does not work yet: ${(error instanceof Error ? error.message : String(error)).replace(/^\\[\\w+\\]\\s*/, \"\")}`);\n lines.push(\n \"What to check, in this order: (1) the connection string in the plugin's settings, typed there and never into this conversation; (2) that this computer can reach the database's host, which often needs a VPN; (3) that the first start has had a minute, since the database's MCP server is downloaded the first time it runs. After changing a setting, start a new session.\",\n );\n }\n } else if (!file && !problem) {\n lines.push(\n\"This server draws inline views from a database it connects to itself, which is the advanced route. For a page over the person's own database with nothing to set up here, use the artifact-pages skill: it reads through a connector they already have. To connect this server all the same, the plugin's README lists the three settings.\",\n );\n }\n return { content: [{ type: \"text\" as const, text: lines.join(\"\\n\") }] };\n },\n );\n server.registerTool(\n \"timing_report\",\n {\n title: \"How long views took to load\",\n description:\n \"Says how long the views this server drew took to get their data, and how much of that was the database and how much this server added. Numbers only: no query, table name or value. Call it when someone asks whether Surfaces is slow, or to compare it with querying the database directly.\",\n inputSchema: {},\n annotations: { readOnlyHint: true, destructiveHint: false },\n },\n async () => ({ content: [{ type: \"text\" as const, text: timing.report() }] }),\n );\n await server.connect(new StdioServerTransport());\n say(`Surfaces MCP server ready (${sources.map((s) => s.id).join(\", \")}${file ? \"\" : fromEnv ? \"; from this plugin's settings\" : problem ? \"; sample data, because the settings could not be used\" : \"; sample data, no config found\"}).`);\n if (problem) say(problem);\n const stop = () => void backend.close().then(() => process.exit(0));\n process.on(\"SIGINT\", stop);\n process.on(\"SIGTERM\", stop);\n }\n} catch (error) {\n say(error instanceof Error ? error.message : String(error));\n process.exit(1);\n}\n"]}
|
package/dist/server.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export interface SurfacesAppsOptions {
|
|
|
24
24
|
catalog?: Catalog;
|
|
25
25
|
/** Most rows the app's data tool returns per request. Defaults to 1,000. */
|
|
26
26
|
maxRowsPerRequest?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Wraps each request the app page makes for data, so a host can time it
|
|
29
|
+
* (`createTiming` in `@surfaces-ui/mcp/node`). It is given the method's
|
|
30
|
+
* name and must return what `run` returns.
|
|
31
|
+
*/
|
|
32
|
+
around?: <T>(method: string, run: () => Promise<T>) => Promise<T>;
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
29
35
|
* Adds the Surfaces tools and app page to an MCP server.
|
package/dist/server.js
CHANGED
|
@@ -5,6 +5,8 @@ import { PagingSchema, RefreshKind, RunState, ViewQuerySchema } from "@surfaces-
|
|
|
5
5
|
import { analyticsCatalog, catalogDocs, catalogPrompt, fromJsonRender } from "@surfaces-ui/spec";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { APP_RESOURCE_URI, PIPELINE_RPC, PIPELINE_RPC_TOOL, RPC, RPC_TOOL, isPipelineRpcMethod, isRpcMethod } from "./protocol.js";
|
|
8
|
+
/** A tool that only reads says so both ways: a host decides what to ask a person about from these, and a directory review asks for each one. */
|
|
9
|
+
const READ_ONLY = { readOnlyHint: true, destructiveHint: false };
|
|
8
10
|
const ui = { ui: { resourceUri: APP_RESOURCE_URI } };
|
|
9
11
|
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
10
12
|
const failure = (value) => ({ ...text(value), isError: true });
|
|
@@ -54,7 +56,7 @@ export function registerSurfacesApps(server, options) {
|
|
|
54
56
|
title: "Show a table",
|
|
55
57
|
description: "Shows the rows of a SQL query in an interactive table the person can scroll and sort. Use for looking at records.",
|
|
56
58
|
inputSchema: { sql: sqlArg, sourceId: sourceArg, title: z.string().optional() },
|
|
57
|
-
annotations:
|
|
59
|
+
annotations: READ_ONLY,
|
|
58
60
|
_meta: ui,
|
|
59
61
|
}, async ({ sql, sourceId, title }) => checked({ view: "grid", sourceId: await sourceOf(sourceId), sql, title }, (rows) => `Showing a table of ${rows} rows.`));
|
|
60
62
|
registerAppTool(server, "show_chart", {
|
|
@@ -82,7 +84,7 @@ export function registerSurfacesApps(server, options) {
|
|
|
82
84
|
sourceId: sourceArg,
|
|
83
85
|
title: z.string().optional(),
|
|
84
86
|
},
|
|
85
|
-
annotations:
|
|
87
|
+
annotations: READ_ONLY,
|
|
86
88
|
_meta: ui,
|
|
87
89
|
}, async ({ sql, type, x, xGrain, xBins, y, splitBy, stacked, legend, sourceId, title }) => checked({ view: "chart", sourceId: await sourceOf(sourceId), sql, type, x, xGrain, xBins, y, splitBy, stacked, legend, title }, (rows) => `Showing a ${type} chart over ${rows} rows.`));
|
|
88
90
|
registerAppTool(server, "show_pivot_table", {
|
|
@@ -99,28 +101,28 @@ export function registerSurfacesApps(server, options) {
|
|
|
99
101
|
sourceId: sourceArg,
|
|
100
102
|
title: z.string().optional(),
|
|
101
103
|
},
|
|
102
|
-
annotations:
|
|
104
|
+
annotations: READ_ONLY,
|
|
103
105
|
_meta: ui,
|
|
104
106
|
}, async ({ sql, rows, columns, measures, sourceId, title }) => checked({ view: "pivot", sourceId: await sourceOf(sourceId), sql, rows, columns, measures, title }, (count) => `Showing a pivot table over ${count} rows.`));
|
|
105
107
|
registerAppTool(server, "show_query_result", {
|
|
106
108
|
title: "Explore a query",
|
|
107
109
|
description: "Shows a query the person can explore themselves: filters, a table and a chart of the same result, and the SQL that ran.",
|
|
108
110
|
inputSchema: { sql: sqlArg, sourceId: sourceArg, title: z.string().optional() },
|
|
109
|
-
annotations:
|
|
111
|
+
annotations: READ_ONLY,
|
|
110
112
|
_meta: ui,
|
|
111
113
|
}, async ({ sql, sourceId, title }) => checked({ view: "result", sourceId: await sourceOf(sourceId), sql, title }, (rows) => `Showing an explorable result of ${rows} rows.`));
|
|
112
114
|
registerAppTool(server, "open_sql_editor", {
|
|
113
115
|
title: "Open the SQL editor",
|
|
114
116
|
description: "Opens a SQL editor with autocomplete for the source's tables, where the person can write and run queries.",
|
|
115
117
|
inputSchema: { sql: z.string().optional().describe("SQL to start with."), sourceId: sourceArg },
|
|
116
|
-
annotations:
|
|
118
|
+
annotations: READ_ONLY,
|
|
117
119
|
_meta: ui,
|
|
118
120
|
}, async ({ sql, sourceId }) => show({ view: "editor", sourceId: await sourceOf(sourceId), sql: sql ?? "" }, "Opened the SQL editor."));
|
|
119
121
|
registerAppTool(server, "show_schema_explorer", {
|
|
120
122
|
title: "Browse tables",
|
|
121
123
|
description: "Shows a searchable tree of the source's tables and their columns.",
|
|
122
124
|
inputSchema: { sourceId: sourceArg },
|
|
123
|
-
annotations:
|
|
125
|
+
annotations: READ_ONLY,
|
|
124
126
|
_meta: ui,
|
|
125
127
|
}, async ({ sourceId }) => show({ view: "schema", sourceId: await sourceOf(sourceId) }, "Showing the tables in this source."));
|
|
126
128
|
const render = (messages) => {
|
|
@@ -133,7 +135,7 @@ export function registerSurfacesApps(server, options) {
|
|
|
133
135
|
title: "Show a custom view",
|
|
134
136
|
description: `Shows a custom layout (a dashboard, a summary) described as A2UI messages using catalog ${catalog.id}. Call get_component_docs first to learn the components.`,
|
|
135
137
|
inputSchema: { messages: z.array(z.record(z.string(), z.unknown())).min(1).describe("A2UI messages: createSurface, then updateComponents, then optionally updateDataModel.") },
|
|
136
|
-
annotations:
|
|
138
|
+
annotations: READ_ONLY,
|
|
137
139
|
_meta: ui,
|
|
138
140
|
}, async ({ messages }) => render(messages));
|
|
139
141
|
registerAppTool(server, "show_dashboard", {
|
|
@@ -146,14 +148,14 @@ export function registerSurfacesApps(server, options) {
|
|
|
146
148
|
state: z.record(z.string(), z.unknown()).optional(),
|
|
147
149
|
}),
|
|
148
150
|
},
|
|
149
|
-
annotations:
|
|
151
|
+
annotations: READ_ONLY,
|
|
150
152
|
_meta: ui,
|
|
151
153
|
}, async ({ spec }) => render(fromJsonRender(spec, catalog)));
|
|
152
154
|
server.registerTool("get_component_docs", {
|
|
153
155
|
title: "Component documentation",
|
|
154
156
|
description: "Explains how to build a custom view: the message format and every component with its props and an example. Pass a component name for just that one.",
|
|
155
157
|
inputSchema: { component: z.string().optional() },
|
|
156
|
-
annotations:
|
|
158
|
+
annotations: READ_ONLY,
|
|
157
159
|
}, async ({ component }) => {
|
|
158
160
|
if (!component)
|
|
159
161
|
return text(catalogPrompt(catalog));
|
|
@@ -171,7 +173,7 @@ export function registerSurfacesApps(server, options) {
|
|
|
171
173
|
database: z.string().optional().describe("A database or schema to list. Omit for the ones the source covers by default."),
|
|
172
174
|
search: z.string().optional().describe("Part of a table name."),
|
|
173
175
|
},
|
|
174
|
-
annotations:
|
|
176
|
+
annotations: READ_ONLY,
|
|
175
177
|
}, async ({ sourceId, database, search }) => {
|
|
176
178
|
try {
|
|
177
179
|
const { sources } = await dataSource.listSources({});
|
|
@@ -202,7 +204,7 @@ export function registerSurfacesApps(server, options) {
|
|
|
202
204
|
table: z.string().describe("The table's name, as list_tables gave it (database.table where it has a database)."),
|
|
203
205
|
sourceId: sourceArg,
|
|
204
206
|
},
|
|
205
|
-
annotations:
|
|
207
|
+
annotations: READ_ONLY,
|
|
206
208
|
}, async ({ table, sourceId }) => {
|
|
207
209
|
try {
|
|
208
210
|
const id = await sourceOf(sourceId);
|
|
@@ -230,7 +232,7 @@ export function registerSurfacesApps(server, options) {
|
|
|
230
232
|
title: "Search the catalog",
|
|
231
233
|
description: "Finds tables and columns by words or meaning, across the databases the catalog covers. Returns names, types and descriptions, never data values.",
|
|
232
234
|
inputSchema: { query: z.string().min(1).describe("What to look for, e.g. customer revenue."), sourceId: z.string().optional().describe("Search one source. Omit to search all.") },
|
|
233
|
-
annotations:
|
|
235
|
+
annotations: READ_ONLY,
|
|
234
236
|
}, async ({ query, sourceId }) => {
|
|
235
237
|
try {
|
|
236
238
|
const found = await discovery.search({ query, sourceIds: sourceId ? [sourceId] : [], pageSize: 20 });
|
|
@@ -255,31 +257,34 @@ export function registerSurfacesApps(server, options) {
|
|
|
255
257
|
title: "Surfaces data channel",
|
|
256
258
|
description: "Used by the Surfaces app page to fetch data. Not for direct use.",
|
|
257
259
|
inputSchema: { method: z.string(), request: z.record(z.string(), z.unknown()) },
|
|
258
|
-
annotations:
|
|
260
|
+
annotations: READ_ONLY,
|
|
259
261
|
_meta: { ui: { resourceUri: APP_RESOURCE_URI, visibility: ["app"] } },
|
|
260
262
|
}, async ({ method, request }) => {
|
|
261
263
|
if (!isRpcMethod(method))
|
|
262
264
|
return failure(`Unknown method ${method}.`);
|
|
263
265
|
const shape = RPC[method];
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
messages
|
|
275
|
-
|
|
266
|
+
const around = options.around ?? ((_method, run) => run());
|
|
267
|
+
return around(method, async () => {
|
|
268
|
+
try {
|
|
269
|
+
// Requests arrive as protobuf JSON; decode them so enums, 64-bit numbers and oneofs are read correctly.
|
|
270
|
+
const decoded = fromJson(shape.request, request);
|
|
271
|
+
if (method === "execute") {
|
|
272
|
+
const execute = decoded;
|
|
273
|
+
execute.query ??= create(ViewQuerySchema);
|
|
274
|
+
execute.query.page ??= create(PagingSchema);
|
|
275
|
+
execute.query.page.limit = Math.min(execute.query.page.limit || maxRows, maxRows);
|
|
276
|
+
const messages = [];
|
|
277
|
+
for await (const part of dataSource.execute(execute))
|
|
278
|
+
messages.push(toJson(shape.response, part));
|
|
279
|
+
return { ...text(`${messages.length} messages`), structuredContent: { messages } };
|
|
280
|
+
}
|
|
281
|
+
const response = await dataSource[method](decoded);
|
|
282
|
+
return { ...text("ok"), structuredContent: { messages: [toJson(shape.response, response)] } };
|
|
276
283
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return failure(message(error));
|
|
282
|
-
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
return failure(message(error));
|
|
286
|
+
}
|
|
287
|
+
});
|
|
283
288
|
});
|
|
284
289
|
}
|
|
285
290
|
/** The agent's pipeline tools as MCP tools: one implementation, so the two cannot drift. */
|
|
@@ -298,15 +303,15 @@ function registerPipelineTools(server, pipelines, show) {
|
|
|
298
303
|
const pipelineId = z.string().describe("The pipeline's id, from list_pipelines.");
|
|
299
304
|
const select = z.array(z.string()).optional().describe("Datasets to build: name alone, name+ with what reads it, +name with what it reads. Omit for all.");
|
|
300
305
|
const describe = (name) => tools.get(name).description;
|
|
301
|
-
server.registerTool("list_pipelines", { title: "List pipelines", description: describe("list_pipelines"), inputSchema: {}, annotations:
|
|
302
|
-
server.registerTool("describe_pipeline", { title: "Describe a pipeline", description: describe("describe_pipeline"), inputSchema: { pipelineId }, annotations:
|
|
303
|
-
server.registerTool("check_pipeline", { title: "Check a pipeline", description: describe("check_pipeline"), inputSchema: { pipelineId, select }, annotations:
|
|
304
|
-
server.registerTool("get_run", { title: "A pipeline run", description: describe("get_run"), inputSchema: { pipelineId, runId: z.string() }, annotations:
|
|
306
|
+
server.registerTool("list_pipelines", { title: "List pipelines", description: describe("list_pipelines"), inputSchema: {}, annotations: READ_ONLY }, call("list_pipelines"));
|
|
307
|
+
server.registerTool("describe_pipeline", { title: "Describe a pipeline", description: describe("describe_pipeline"), inputSchema: { pipelineId }, annotations: READ_ONLY }, call("describe_pipeline"));
|
|
308
|
+
server.registerTool("check_pipeline", { title: "Check a pipeline", description: describe("check_pipeline"), inputSchema: { pipelineId, select }, annotations: READ_ONLY }, call("check_pipeline"));
|
|
309
|
+
server.registerTool("get_run", { title: "A pipeline run", description: describe("get_run"), inputSchema: { pipelineId, runId: z.string() }, annotations: READ_ONLY }, call("get_run"));
|
|
305
310
|
registerAppTool(server, "show_pipeline", {
|
|
306
311
|
title: "Show a pipeline",
|
|
307
312
|
description: "Shows a pipeline live to the person: its datasets and how they feed one another, its runs, and each dataset's query, grain, key, columns and check results. The person can run it, check it, rebuild one dataset or cancel from there.",
|
|
308
313
|
inputSchema: { pipelineId },
|
|
309
|
-
annotations:
|
|
314
|
+
annotations: READ_ONLY,
|
|
310
315
|
_meta: ui,
|
|
311
316
|
}, async ({ pipelineId: id }) => {
|
|
312
317
|
try {
|
|
@@ -351,7 +356,7 @@ function registerPipelineTools(server, pipelines, show) {
|
|
|
351
356
|
}))
|
|
352
357
|
.optional(),
|
|
353
358
|
},
|
|
354
|
-
annotations:
|
|
359
|
+
annotations: READ_ONLY,
|
|
355
360
|
_meta: ui,
|
|
356
361
|
}, async (input) => {
|
|
357
362
|
try {
|