Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/server-mcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "bun run build:assets && bun build src/index.ts --outdir=dist --target=bun --minify",
"build:assets": "bun run --cwd ../../packages/bar-chart-widget build && mkdir -p dist/widget/bar-chart && cp ../../packages/bar-chart-widget/dist/index.html dist/widget/bar-chart/bar-chart-widget.html && mkdir -p dist/widget/get-time && cp src/widget/get-time/get-time.html dist/widget/get-time/get-time.html && mkdir -p src/widget/widget-app && cp ../../packages/bar-chart-widget/dist/index.html src/widget/bar-chart/bar-chart-widget.html",
"build": "bun run build:asset && bun build src/index.ts --outdir=dist --target=bun --minify",
"build:asset": "mkdir -p dist/widget/get-time && cp src/widget/get-time/get-time.html dist/widget/get-time/get-time.html",
"build:types": "tsc --emitDeclarationOnly",
"dev": "bun --watch run src/index.ts",
"inspector": "bun run dev & sleep 2 && npx @mcpjam/inspector@latest; kill %1",
"inspector": "npx @mcpjam/inspector@latest",
"test": "vitest run",
"type-check": "tsc --noEmit",
"clean": "git clean -xdf .cache .turbo dist node_modules"
Expand Down
100 changes: 91 additions & 9 deletions apps/server-mcp/src/widget/bar-chart/bar-chart-widget.html

Large diffs are not rendered by default.

34 changes: 6 additions & 28 deletions apps/server-mcp/src/widget/bar-chart/bar-chart.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { join as joinPath } from "node:path";
import { Effect, FileSystem, Schema } from "effect";
import { BarChartWidgetPayload } from "@repo/domain/Chart";
import { Effect, FileSystem, Path } from "effect";
import { makeUiRenderTool, makeUiResource } from "../../UiResource";

const BarChartWidgetResourceUri = "ui://bar-chart";

const BarChartWidgetHtml = Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const sourceSuffix = joinPath("widget", "bar-chart");
const path = yield* Path.Path;
const sourceSuffix = path.join("widget", "bar-chart");
const isSourcePath = import.meta.dir.endsWith(sourceSuffix);
const htmlPath = isSourcePath
? joinPath(import.meta.dir, "bar-chart-widget.html")
: joinPath(import.meta.dir, "widget/bar-chart/bar-chart-widget.html");
? path.join(import.meta.dir, "bar-chart-widget.html")
: path.join(import.meta.dir, "widget/bar-chart/bar-chart-widget.html");
return yield* fs.readFileString(htmlPath);
});

Expand All @@ -27,29 +28,6 @@ export const BarChartWidgetResourceLayer = makeUiResource(
},
);

const BarChartNumber = Schema.Union([Schema.Number, Schema.NumberFromString]);

const BarChartDatum = Schema.Struct({
category: Schema.String,
value: BarChartNumber,
});

const BarChartWidgetProps = Schema.Struct({
title: Schema.optional(Schema.String),
valueLabel: Schema.optional(Schema.String),
maxWidth: Schema.optional(BarChartNumber),
width: Schema.optional(BarChartNumber),
height: Schema.optional(BarChartNumber),
showLabels: Schema.optional(Schema.Boolean),
maxY: Schema.optional(BarChartNumber),
});

export const BarChartWidgetPayload = Schema.Struct({
data: Schema.optional(Schema.Array(BarChartDatum)),
dataUrl: Schema.optional(Schema.String),
props: Schema.optional(BarChartWidgetProps),
});

export const RenderBarChartWidgetTool = makeUiRenderTool(
BarChartWidgetResourceUri,
{
Expand Down
1 change: 0 additions & 1 deletion apps/server-mcp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
}
]
},
"references": [{ "path": "../../packages/domain" }],
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
6 changes: 6 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions packages/bar-chart-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"build": "vite build",
"dev": "vite --host --clearScreen false",
"build": "vite build && bun run build:asset",
"build:asset": "bun scripts/copy-asset.ts build",
"dev": "bun run dev:asset & vite build --watch",
"dev:asset": "bun scripts/copy-asset.ts dev --watch",
"dev:local": "vite --host --clearScreen false",
"preview": "vite preview",
"type-check": "tsc --noEmit -p tsconfig.json",
"clean": "git clean -xdf .cache dist node_modules"
},
"dependencies": {
"d3": "^7.9.0",
"@modelcontextprotocol/ext-apps": "^1.3.2",
"@observablehq/plot": "^0.6.17",
"d3": "^7.9.0",
"effect": "4.0.0-beta.43",
"framer-motion": "^12.23.6",
"react": "^19.2.4",
"react-dom": "^19.2.4"
},
"devDependencies": {
"@repo/config-typescript": "workspace:*",
"@repo/domain": "workspace:*",
"@types/d3": "^7.4.3",
"@types/node": "^25.5.0",
"@types/react": "^19.2.14",
Expand Down
60 changes: 60 additions & 0 deletions packages/bar-chart-widget/scripts/copy-asset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { existsSync, watch } from "node:fs";
import { copyFile, mkdir } from "node:fs/promises";
import path from "node:path";

const mode = process.argv[2];
const shouldWatch = process.argv.includes("--watch");

if (mode !== "build" && mode !== "dev") {
console.error("Usage: bun scripts/copy-asset.ts <build|dev> [--watch]");
process.exit(1);
}

const sourcePath = path.resolve("dist/index.html");
const destinationDir = path.resolve(
mode === "dev"
? "../../apps/server-mcp/src/widget/bar-chart"
: "../../apps/server-mcp/dist/widget/bar-chart",
);
const destinationPath = path.join(destinationDir, "bar-chart-widget.html");

const waitForSource = async () => {
if (existsSync(sourcePath)) {
return;
}

await new Promise<void>((resolve) => {
const interval = setInterval(() => {
if (existsSync(sourcePath)) {
clearInterval(interval);
resolve();
}
}, 200);
});
};

const copyOnce = async () => {
await mkdir(destinationDir, { recursive: true });
await copyFile(sourcePath, destinationPath);
};

const copyAfterBuild = async () => {
await waitForSource();
await copyOnce();
};

if (shouldWatch) {
await copyAfterBuild();

watch(
path.dirname(sourcePath),
{ persistent: true },
async (_event, file) => {
if (file === path.basename(sourcePath)) {
await copyOnce();
}
},
);
} else {
await copyAfterBuild();
}
Loading
Loading