@schemacast/mcp 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +76 -2
- package/dist/auto-visual-meta.d.ts +19 -0
- package/dist/auto-visual-meta.js +19 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +13 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.js +17 -0
- package/dist/package-version.d.ts +10 -0
- package/dist/package-version.js +18 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.js +136 -0
- package/dist/startup.d.ts +11 -0
- package/dist/startup.js +15 -0
- package/dist/ui/main.d.ts +2 -0
- package/dist/ui/main.js +113 -0
- package/dist/ui-resource.d.ts +19 -0
- package/dist/ui-resource.js +44 -0
- package/dist/ui.html +114 -0
- package/dist/visualize-report.d.ts +7 -0
- package/dist/visualize-report.js +6 -0
- package/dist/visualize-summary.d.ts +22 -0
- package/dist/visualize-summary.js +125 -0
- package/dist/with-auto-visual.d.ts +80 -0
- package/dist/with-auto-visual.js +106 -0
- package/package.json +53 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wael Zohny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@schemacast/mcp`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stdio MCP server with a `visualize_json` tool and a bundled MCP Apps UI.
|
|
4
|
+
|
|
5
|
+
**0.x — API may change.**
|
|
6
|
+
|
|
7
|
+
## Run with npx
|
|
8
|
+
|
|
9
|
+
Prefer pinning a version so hosts stay reproducible:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx -y @schemacast/mcp@0.5.1
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
(`npx -y @schemacast/mcp` also works and tracks latest.)
|
|
16
|
+
|
|
17
|
+
On start the process prints one stderr line, for example `schemacast-mcp 0.5.1 ready (stdio)`, and never writes to stdout (stdout is reserved for MCP stdio).
|
|
18
|
+
|
|
19
|
+
## Host configuration
|
|
20
|
+
|
|
21
|
+
Claude Desktop and Cursor (`mcpServers`):
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"mcpServers": {
|
|
26
|
+
"schemacast": {
|
|
27
|
+
"command": "npx",
|
|
28
|
+
"args": ["-y", "@schemacast/mcp@0.5.1"]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Claude Code:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
claude mcp add schemacast -- npx -y @schemacast/mcp@0.5.1
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
VS Code (`.vscode/mcp.json`):
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"servers": {
|
|
45
|
+
"schemacast": {
|
|
46
|
+
"type": "stdio",
|
|
47
|
+
"command": "npx",
|
|
48
|
+
"args": ["-y", "@schemacast/mcp@0.5.1"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
After updating, restart the host (Claude Desktop) or start a new request (Cursor/VS Code).
|
|
55
|
+
|
|
56
|
+
### From a clone
|
|
57
|
+
|
|
58
|
+
Build locally, then point the host at the built entry:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pnpm --filter @schemacast/mcp build
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"command": "node",
|
|
67
|
+
"args": ["/absolute/path/to/schemacast/packages/mcp/dist/main.js"]
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Library usage
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { registerAutoVisualTool } from '@schemacast/mcp';
|
|
75
|
+
|
|
76
|
+
registerAutoVisualTool(server, 'existing_report', existingToolConfig, existingHandler);
|
|
77
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result metadata key containing the generated VisualSpec.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const spec = toolResult._meta?.[AUTO_VISUAL_RESULT_META_KEY];
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare const AUTO_VISUAL_RESULT_META_KEY = "schemacast/visualSpec";
|
|
10
|
+
/**
|
|
11
|
+
* Result metadata key containing the `visualize_json` report (ranked views, bands, fields, assumptions).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const report = toolResult._meta?.[VISUALIZE_REPORT_META_KEY];
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const VISUALIZE_REPORT_META_KEY = "schemacast/report";
|
|
19
|
+
//# sourceMappingURL=auto-visual-meta.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result metadata key containing the generated VisualSpec.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const spec = toolResult._meta?.[AUTO_VISUAL_RESULT_META_KEY];
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export const AUTO_VISUAL_RESULT_META_KEY = 'schemacast/visualSpec';
|
|
10
|
+
/**
|
|
11
|
+
* Result metadata key containing the `visualize_json` report (ranked views, bands, fields, assumptions).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const report = toolResult._meta?.[VISUALIZE_REPORT_META_KEY];
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export const VISUALIZE_REPORT_META_KEY = 'schemacast/report';
|
|
19
|
+
//# sourceMappingURL=auto-visual-meta.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @schemacast/mcp
|
|
3
|
+
*
|
|
4
|
+
* MCP server integration for `@schemacast/core` VisualSpecs.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { createMcpServer } from './server.js';
|
|
9
|
+
export { registerAutoVisualTool } from './with-auto-visual.js';
|
|
10
|
+
export { AUTO_VISUAL_RESULT_META_KEY, VISUALIZE_REPORT_META_KEY } from './auto-visual-meta.js';
|
|
11
|
+
export { createVisualizeReport, getConfidenceBand } from './visualize-report.js';
|
|
12
|
+
export type { ConfidenceBand, IntentReport, ReportedView, VisualizeReport, } from './visualize-report.js';
|
|
13
|
+
export { withAutoVisual } from './with-auto-visual.js';
|
|
14
|
+
export type { AutoVisualToolHandler, AutoVisualToolMetadata, WithAutoVisualOptions, } from './with-auto-visual.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @schemacast/mcp
|
|
3
|
+
*
|
|
4
|
+
* MCP server integration for `@schemacast/core` VisualSpecs.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { createMcpServer } from './server.js';
|
|
9
|
+
export { registerAutoVisualTool } from './with-auto-visual.js';
|
|
10
|
+
export { AUTO_VISUAL_RESULT_META_KEY, VISUALIZE_REPORT_META_KEY } from './auto-visual-meta.js';
|
|
11
|
+
export { createVisualizeReport, getConfidenceBand } from './visualize-report.js';
|
|
12
|
+
export { withAutoVisual } from './with-auto-visual.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { PACKAGE_VERSION } from './package-version.js';
|
|
5
|
+
import { createMcpServer } from './server.js';
|
|
6
|
+
import { writeMcpReadyLine } from './startup.js';
|
|
7
|
+
async function main() {
|
|
8
|
+
const uiResourceHtml = await readFile(new URL('./ui.html', import.meta.url), 'utf8');
|
|
9
|
+
const server = createMcpServer(uiResourceHtml);
|
|
10
|
+
await server.connect(new StdioServerTransport());
|
|
11
|
+
writeMcpReadyLine(PACKAGE_VERSION);
|
|
12
|
+
}
|
|
13
|
+
main().catch((error) => {
|
|
14
|
+
console.error(error);
|
|
15
|
+
process.exitCode = 1;
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@schemacast/mcp` version from package.json (used by the stdio server).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* createMcpServer(html); // server reports PACKAGE_VERSION
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare const PACKAGE_VERSION: string;
|
|
10
|
+
//# sourceMappingURL=package-version.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
/**
|
|
5
|
+
* `@schemacast/mcp` version from package.json (used by the stdio server).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* createMcpServer(html); // server reports PACKAGE_VERSION
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const PACKAGE_VERSION = readPackageVersion();
|
|
13
|
+
function readPackageVersion() {
|
|
14
|
+
const packageJsonPath = join(dirname(fileURLToPath(import.meta.url)), '../package.json');
|
|
15
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
16
|
+
return packageJson.version;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=package-version.js.map
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an MCP server with `visualize_json` and its linked VisualSpec UI resource.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const server = createMcpServer(uiHtml);
|
|
8
|
+
* await server.connect(new StdioServerTransport());
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function createMcpServer(uiResourceHtml: string): McpServer;
|
|
12
|
+
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { applyViewHints, cast } from '@schemacast/core';
|
|
2
|
+
import { registerAppResource, registerAppTool, RESOURCE_MIME_TYPE, } from '@modelcontextprotocol/ext-apps/server';
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { UI_RESOURCE_URI } from './ui-resource.js';
|
|
6
|
+
import { VISUALIZE_REPORT_META_KEY } from './auto-visual-meta.js';
|
|
7
|
+
import { PACKAGE_VERSION } from './package-version.js';
|
|
8
|
+
import { createVisualizeReport } from './visualize-report.js';
|
|
9
|
+
import { formatVisualizeSummary } from './visualize-summary.js';
|
|
10
|
+
const JSON_DATA_SCHEMA = z.union([
|
|
11
|
+
z.string(),
|
|
12
|
+
z.number(),
|
|
13
|
+
z.boolean(),
|
|
14
|
+
z.null(),
|
|
15
|
+
z.array(z.unknown()),
|
|
16
|
+
z.record(z.string(), z.unknown()),
|
|
17
|
+
]);
|
|
18
|
+
const FIELD_HINTS_SCHEMA = z.object({
|
|
19
|
+
label: z.string().optional(),
|
|
20
|
+
group: z.string().optional(),
|
|
21
|
+
value: z.string().optional(),
|
|
22
|
+
x: z.string().optional(),
|
|
23
|
+
y: z.union([z.string(), z.array(z.string())]).optional(),
|
|
24
|
+
source: z.string().optional(),
|
|
25
|
+
target: z.string().optional(),
|
|
26
|
+
});
|
|
27
|
+
const PREFER_VIEW_DESCRIPTION = 'View id to show first, e.g. "bar-chart". Only views that fit the data are accepted; otherwise the reason is reported in assumptions.';
|
|
28
|
+
const FIELD_HINTS_DESCRIPTION = 'Field names that override inference: label, group, value, x, y (string or list), source, target. Unknown or non-numeric fields are ignored and explained in assumptions. Field roles by view: x = category/horizontal axis of bar-chart, line-chart, pie-chart; y or value = numeric series (value is a single y); label = card title in kanban, detail-card and timeline, and the category of bar-chart and pie-chart; group = kanban lane, or the field whose values become one line each on a line-chart (each x and group pair must be unique); source/target = node-graph edge ends. A kanban card label is not a chart category: use x for a chart category. With x or label plus y or value, a bar-chart is built even when inference rejected it. A y/value hint may name a lat/lng field, which is otherwise excluded from metrics.';
|
|
29
|
+
const VISUALIZE_JSON_DESCRIPTION = [
|
|
30
|
+
'Picks the best visual for JSON data and returns a VisualSpec rendered by the linked UI.',
|
|
31
|
+
'The data must be complete, valid JSON. Partial or streaming JSON input is not accepted.',
|
|
32
|
+
'A bare string must be sent as quoted JSON (with its double quotes), not as raw text.',
|
|
33
|
+
'An optional intent (e.g. "compare revenue by region") boosts matching views.',
|
|
34
|
+
'Supported views: line-chart, bar-chart, pie-chart, kpi-grid, data-table, kanban, timeline, node-graph, hierarchy-tree, detail-card, json-tree.',
|
|
35
|
+
'Scores (0-1) are heuristic ranking signals, not probabilities.',
|
|
36
|
+
'Each view gets a band describing its kind, not a score range: detected (a specific data shape was found), plausible (reasonable, not specific), or default (generic data-table or json-tree). Views rank by band first, then score, except that part-to-whole data (values summing to 100 or 1) lists pie-chart before bar-chart unless an intent boosted bar-chart; a valid preferView goes first and is marked preferred by caller.',
|
|
37
|
+
'Optional preferView (one view id) and fields (label, group, value, x, y, source, target) override inference when valid; invalid hints are explained in the assumptions.',
|
|
38
|
+
'Field roles by view: x = category/horizontal axis of bar-chart, line-chart, pie-chart; y or value = numeric series (value is a single y); label = card title in kanban, detail-card and timeline, and the category of bar-chart and pie-chart; group = kanban lane, or the field whose values become one line each on a line-chart (each x and group pair must be unique); source/target = node-graph edge ends. A kanban card label is not a chart category: use x for a chart category. With x or label plus y or value, a bar-chart is built even when inference rejected it. A y/value hint may name a lat/lng field, which is otherwise excluded from metrics.',
|
|
39
|
+
'Graphs: nodes by id with edges/links using source/target, from/to, src/dst, or parent/child; a bare edge list (rows with overlapping from/to values) becomes a node-graph with nodes derived from its endpoints and value/weight kept as edge weight.',
|
|
40
|
+
'The text result lists the top 3 views with reasons, the views that were checked and rejected with a reason, the fields used and ignored, and assumptions such as an unwrapped envelope, rows not aggregated, skipped non-numeric values, mixed date formats, geo coordinates, or units not confirmed by the data; the same report is in _meta["schemacast/report"].',
|
|
41
|
+
'Units (currency, %, or a plain unit such as kg) are shown only when the data or meta states them (top-level or in a meta object), never from a field name alone.',
|
|
42
|
+
].join(' ');
|
|
43
|
+
/**
|
|
44
|
+
* Creates an MCP server with `visualize_json` and its linked VisualSpec UI resource.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const server = createMcpServer(uiHtml);
|
|
49
|
+
* await server.connect(new StdioServerTransport());
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function createMcpServer(uiResourceHtml) {
|
|
53
|
+
const server = new McpServer({
|
|
54
|
+
name: 'schemacast',
|
|
55
|
+
version: PACKAGE_VERSION,
|
|
56
|
+
});
|
|
57
|
+
registerAppTool(server, 'visualize_json', {
|
|
58
|
+
title: 'Visualize JSON',
|
|
59
|
+
description: VISUALIZE_JSON_DESCRIPTION,
|
|
60
|
+
inputSchema: z.object({
|
|
61
|
+
data: JSON_DATA_SCHEMA,
|
|
62
|
+
intent: z.string().optional(),
|
|
63
|
+
preferView: z.string().optional().describe(PREFER_VIEW_DESCRIPTION),
|
|
64
|
+
fields: FIELD_HINTS_SCHEMA.optional().describe(FIELD_HINTS_DESCRIPTION),
|
|
65
|
+
}),
|
|
66
|
+
annotations: {
|
|
67
|
+
readOnlyHint: true,
|
|
68
|
+
idempotentHint: true,
|
|
69
|
+
},
|
|
70
|
+
_meta: {
|
|
71
|
+
ui: {
|
|
72
|
+
resourceUri: UI_RESOURCE_URI,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
}, async ({ data, intent, preferView, fields }) => {
|
|
76
|
+
const input = validateJsonString(data);
|
|
77
|
+
const castSpec = cast(input, {
|
|
78
|
+
...(intent === undefined ? {} : { intent }),
|
|
79
|
+
...(fields?.label === undefined ? {} : { labelField: fields.label }),
|
|
80
|
+
});
|
|
81
|
+
const hintsGiven = preferView !== undefined || fields !== undefined;
|
|
82
|
+
const hinted = hintsGiven
|
|
83
|
+
? applyViewHints(castSpec, {
|
|
84
|
+
...(preferView === undefined ? {} : { preferView }),
|
|
85
|
+
...(fields === undefined ? {} : { fields: fields }),
|
|
86
|
+
})
|
|
87
|
+
: undefined;
|
|
88
|
+
const spec = hinted?.spec ?? castSpec;
|
|
89
|
+
const report = createVisualizeReport(input, spec, { intent, hints: hinted });
|
|
90
|
+
return {
|
|
91
|
+
content: [
|
|
92
|
+
{
|
|
93
|
+
type: 'text',
|
|
94
|
+
text: formatVisualizeSummary(spec, report),
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
structuredContent: toStructuredContent(spec),
|
|
98
|
+
_meta: { [VISUALIZE_REPORT_META_KEY]: report },
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
registerAppResource(server, 'schemacast-visualizer', UI_RESOURCE_URI, { mimeType: RESOURCE_MIME_TYPE }, async () => ({
|
|
102
|
+
contents: [
|
|
103
|
+
{
|
|
104
|
+
uri: UI_RESOURCE_URI,
|
|
105
|
+
mimeType: RESOURCE_MIME_TYPE,
|
|
106
|
+
text: uiResourceHtml,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
}));
|
|
110
|
+
return server;
|
|
111
|
+
}
|
|
112
|
+
function validateJsonString(data) {
|
|
113
|
+
if (typeof data !== 'string') {
|
|
114
|
+
return data;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
JSON.parse(data);
|
|
118
|
+
return data;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
throw new Error('data must be valid JSON when provided as a string.');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function toStructuredContent(spec) {
|
|
125
|
+
return {
|
|
126
|
+
version: spec.version,
|
|
127
|
+
isStreaming: spec.isStreaming,
|
|
128
|
+
primaryView: spec.primaryView,
|
|
129
|
+
views: spec.views,
|
|
130
|
+
fields: spec.fields,
|
|
131
|
+
data: spec.data,
|
|
132
|
+
...(spec.edges === undefined ? {} : { edges: spec.edges }),
|
|
133
|
+
...(spec.meta === undefined ? {} : { meta: spec.meta }),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stderr-only startup notice so hosts can see the server is up without touching the MCP stdio stream.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* writeMcpReadyLine('0.5.1');
|
|
7
|
+
* // stderr: schemacast-mcp 0.5.1 ready (stdio)
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function writeMcpReadyLine(version: string, write?: (chunk: string) => void): void;
|
|
11
|
+
//# sourceMappingURL=startup.d.ts.map
|
package/dist/startup.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stderr-only startup notice so hosts can see the server is up without touching the MCP stdio stream.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* writeMcpReadyLine('0.5.1');
|
|
7
|
+
* // stderr: schemacast-mcp 0.5.1 ready (stdio)
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export function writeMcpReadyLine(version, write = (chunk) => {
|
|
11
|
+
process.stderr.write(chunk);
|
|
12
|
+
}) {
|
|
13
|
+
write(`schemacast-mcp ${version} ready (stdio)\n`);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=startup.js.map
|
package/dist/ui/main.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { App } from '@modelcontextprotocol/ext-apps';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { VisualSpecView } from '@schemacast/react';
|
|
5
|
+
import '@schemacast/react/styles.css';
|
|
6
|
+
import { AUTO_VISUAL_RESULT_META_KEY } from '../auto-visual-meta.js';
|
|
7
|
+
const app = new App({ name: 'schemacast', version: __SCHEMACAST_MCP_VERSION__ });
|
|
8
|
+
const appContainer = document.getElementById('schemacast-app');
|
|
9
|
+
if (appContainer === null) {
|
|
10
|
+
throw new Error('The schemacast app container is missing.');
|
|
11
|
+
}
|
|
12
|
+
const root = createRoot(appContainer);
|
|
13
|
+
root.render(_jsx("p", { role: "status", children: "Waiting for a VisualSpec\u2026" }));
|
|
14
|
+
app.addEventListener('hostcontextchanged', () => {
|
|
15
|
+
applyHostTheme(app.getHostContext()?.theme);
|
|
16
|
+
});
|
|
17
|
+
app.ontoolresult = (result) => {
|
|
18
|
+
const resultMetadata = isRecord(result._meta) ? result._meta[AUTO_VISUAL_RESULT_META_KEY] : null;
|
|
19
|
+
const visualSpec = isVisualSpec(resultMetadata) ? resultMetadata : result.structuredContent;
|
|
20
|
+
if (!isVisualSpec(visualSpec)) {
|
|
21
|
+
root.render(_jsx("p", { role: "alert", children: "The server response did not contain a valid VisualSpec." }));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
root.render(_jsx(VisualSpecView, { spec: visualSpec }));
|
|
25
|
+
};
|
|
26
|
+
app
|
|
27
|
+
.connect()
|
|
28
|
+
.then(() => {
|
|
29
|
+
applyHostTheme(app.getHostContext()?.theme);
|
|
30
|
+
})
|
|
31
|
+
.catch((error) => {
|
|
32
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
33
|
+
root.render(_jsxs("p", { role: "alert", children: ["Could not connect to the MCP host: ", message] }));
|
|
34
|
+
});
|
|
35
|
+
function applyHostTheme(theme) {
|
|
36
|
+
const documentRoot = document.documentElement;
|
|
37
|
+
if (theme === undefined) {
|
|
38
|
+
documentRoot.removeAttribute('data-theme');
|
|
39
|
+
documentRoot.style.removeProperty('color-scheme');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
documentRoot.dataset.theme = theme;
|
|
43
|
+
documentRoot.style.colorScheme = theme;
|
|
44
|
+
}
|
|
45
|
+
function isVisualSpec(value) {
|
|
46
|
+
if (!isRecord(value)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return (value.version === '1.0' &&
|
|
50
|
+
typeof value.isStreaming === 'boolean' &&
|
|
51
|
+
isViewCandidate(value.primaryView) &&
|
|
52
|
+
Array.isArray(value.views) &&
|
|
53
|
+
value.views.every(isViewCandidate) &&
|
|
54
|
+
Array.isArray(value.fields) &&
|
|
55
|
+
value.fields.every(isFieldDescriptor) &&
|
|
56
|
+
Array.isArray(value.data) &&
|
|
57
|
+
value.data.every(isRecord) &&
|
|
58
|
+
(value.edges === undefined || (Array.isArray(value.edges) && value.edges.every(isRecord))) &&
|
|
59
|
+
(value.meta === undefined || isRecord(value.meta)));
|
|
60
|
+
}
|
|
61
|
+
function isViewCandidate(value) {
|
|
62
|
+
return (isRecord(value) &&
|
|
63
|
+
typeof value.id === 'string' &&
|
|
64
|
+
isVisualArchetype(value.archetype) &&
|
|
65
|
+
typeof value.label === 'string' &&
|
|
66
|
+
typeof value.score === 'number' &&
|
|
67
|
+
typeof value.reason === 'string' &&
|
|
68
|
+
isRecord(value.bindings) &&
|
|
69
|
+
(value.data === undefined || (Array.isArray(value.data) && value.data.every(isRecord))));
|
|
70
|
+
}
|
|
71
|
+
function isFieldDescriptor(value) {
|
|
72
|
+
return (isRecord(value) &&
|
|
73
|
+
typeof value.key === 'string' &&
|
|
74
|
+
typeof value.label === 'string' &&
|
|
75
|
+
isSemanticType(value.semanticType) &&
|
|
76
|
+
typeof value.nullRatio === 'number' &&
|
|
77
|
+
typeof value.cardinality === 'number' &&
|
|
78
|
+
(value.formatHint === undefined || typeof value.formatHint === 'string'));
|
|
79
|
+
}
|
|
80
|
+
function isRecord(value) {
|
|
81
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
82
|
+
}
|
|
83
|
+
function isVisualArchetype(value) {
|
|
84
|
+
return (value === 'line-chart' ||
|
|
85
|
+
value === 'bar-chart' ||
|
|
86
|
+
value === 'pie-chart' ||
|
|
87
|
+
value === 'kpi-grid' ||
|
|
88
|
+
value === 'data-table' ||
|
|
89
|
+
value === 'kanban' ||
|
|
90
|
+
value === 'timeline' ||
|
|
91
|
+
value === 'node-graph' ||
|
|
92
|
+
value === 'hierarchy-tree' ||
|
|
93
|
+
value === 'detail-card' ||
|
|
94
|
+
value === 'json-tree');
|
|
95
|
+
}
|
|
96
|
+
function isSemanticType(value) {
|
|
97
|
+
return (value === 'timestamp' ||
|
|
98
|
+
value === 'currency' ||
|
|
99
|
+
value === 'percentage' ||
|
|
100
|
+
value === 'status' ||
|
|
101
|
+
value === 'identifier' ||
|
|
102
|
+
value === 'url' ||
|
|
103
|
+
value === 'image-url' ||
|
|
104
|
+
value === 'boolean' ||
|
|
105
|
+
value === 'number' ||
|
|
106
|
+
value === 'category' ||
|
|
107
|
+
value === 'text' ||
|
|
108
|
+
value === 'nested' ||
|
|
109
|
+
value === 'unknown' ||
|
|
110
|
+
value === 'geo-lat' ||
|
|
111
|
+
value === 'geo-lng');
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Apps resource URI linked from `visualize_json`.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* server.registerResource(UI_RESOURCE_URI, ...);
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare const UI_RESOURCE_URI = "ui://schemacast/visualize-json";
|
|
10
|
+
/**
|
|
11
|
+
* Wraps the renderer bundles in an isolated, self-contained MCP App document.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const html = createUiHtml(bundledScript, bundledStyles);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function createUiHtml(script: string, styles: string): string;
|
|
19
|
+
//# sourceMappingURL=ui-resource.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Apps resource URI linked from `visualize_json`.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* server.registerResource(UI_RESOURCE_URI, ...);
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export const UI_RESOURCE_URI = 'ui://schemacast/visualize-json';
|
|
10
|
+
/**
|
|
11
|
+
* Wraps the renderer bundles in an isolated, self-contained MCP App document.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const html = createUiHtml(bundledScript, bundledStyles);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function createUiHtml(script, styles) {
|
|
19
|
+
const safeScript = script.replace(/<\/script/gi, '<\\/script');
|
|
20
|
+
return `<!doctype html>
|
|
21
|
+
<html lang="en">
|
|
22
|
+
<head>
|
|
23
|
+
<meta charset="utf-8">
|
|
24
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
25
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; font-src data:; connect-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'">
|
|
26
|
+
<title>schemacast visualizer</title>
|
|
27
|
+
<style>
|
|
28
|
+
:root { color-scheme: light; background: #fff; }
|
|
29
|
+
:root[data-theme='dark'] { color-scheme: dark; background: #171d26; }
|
|
30
|
+
@media (prefers-color-scheme: dark) {
|
|
31
|
+
:root:not([data-theme]) { color-scheme: dark; background: #171d26; }
|
|
32
|
+
}
|
|
33
|
+
body { min-height: 100vh; margin: 0; }
|
|
34
|
+
#schemacast-app { min-height: 100vh; }
|
|
35
|
+
</style>
|
|
36
|
+
<style>${styles}</style>
|
|
37
|
+
</head>
|
|
38
|
+
<body>
|
|
39
|
+
<main id="schemacast-app"></main>
|
|
40
|
+
<script>${safeScript}</script>
|
|
41
|
+
</body>
|
|
42
|
+
</html>`;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=ui-resource.js.map
|