Skip to content

AI-native design editor. Open-source Figma alternative.

Build MCP package to JS for Node.js bin compatibility

Danila Poyarkove7209171fa2c
diff --git a/bun.lock b/bun.lock
index 6ee3f0a9d..b4f6ac28d 100644
--- a/bun.lock
+++ b/bun.lock
@@ -104,6 +104,7 @@
"openpencil-mcp-http": "./src/http.ts",
},
"dependencies": {
+ "@hono/node-server": "^1.19.9",
"@modelcontextprotocol/sdk": "^1.25.2",
"@open-pencil/core": "workspace:*",
"canvaskit-wasm": "^0.40.0",
diff --git a/packages/mcp/package.json b/packages/mcp/package.json
index 92b7e11a4..6aad61907 100644
--- a/packages/mcp/package.json
+++ b/packages/mcp/package.json
@@ -5,12 +5,17 @@
"type": "module",
"main": "./src/server.ts",
"bin": {
- "openpencil-mcp": "./src/index.ts",
- "openpencil-mcp-http": "./src/http.ts"
+ "openpencil-mcp": "./dist/index.js",
+ "openpencil-mcp-http": "./dist/http.js"
},
"files": [
- "src"
+ "src",
+ "dist"
],
+ "scripts": {
+ "build": "tsgo",
+ "prepublishOnly": "tsgo"
+ },
"repository": {
"type": "git",
"url": "git+https://github.com/open-pencil/open-pencil.git",
@@ -24,6 +29,7 @@
"@modelcontextprotocol/sdk": "^1.25.2",
"@open-pencil/core": "workspace:*",
"canvaskit-wasm": "^0.40.0",
+ "@hono/node-server": "^1.19.9",
"hono": "^4.11.4",
"zod": "^3.25.0"
},
diff --git a/packages/mcp/src/server.ts b/packages/mcp/src/server.ts
index 3118a9a93..7533b963b 100644
--- a/packages/mcp/src/server.ts
+++ b/packages/mcp/src/server.ts
@@ -58,7 +58,8 @@ export function createServer(version: string): McpServer {
shape[key] = paramToZod(param)
}
- server.registerTool(def.name, { description: def.description, inputSchema: z.object(shape) }, async (args) => {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic schema from ToolDef params
+ server.registerTool(def.name, { description: def.description, inputSchema: z.object(shape) } as any, async (args: any) => {
try {
const result = await def.execute(makeFigma(), args as Record<string, unknown>)
return ok(result)
@@ -68,13 +69,14 @@ export function createServer(version: string): McpServer {
})
}
- server.registerTool(
+ const register = server.registerTool.bind(server) as (...args: unknown[]) => void
+ register(
'open_file',
{
description: 'Open a .fig file for editing. Must be called before using other tools.',
inputSchema: z.object({ path: z.string().describe('Absolute path to a .fig file') })
},
- async ({ path: filePath }) => {
+ async ({ path: filePath }: { path: string }) => {
try {
const buf = await readFile(filePath)
graph = await parseFigFile(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength))
@@ -88,13 +90,13 @@ export function createServer(version: string): McpServer {
}
)
- server.registerTool(
+ register(
'save_file',
{
description: 'Save the current document to a .fig file.',
inputSchema: z.object({ path: z.string().describe('Absolute path to save the .fig file') })
},
- async ({ path: filePath }) => {
+ async ({ path: filePath }: { path: string }) => {
try {
if (!graph) throw new Error('No document loaded')
const { exportFigFile } = await import('@open-pencil/core')
@@ -107,7 +109,7 @@ export function createServer(version: string): McpServer {
}
)
- server.registerTool(
+ register(
'new_document',
{
description: 'Create a new empty document with a blank page.',
diff --git a/packages/mcp/tsconfig.json b/packages/mcp/tsconfig.json
new file mode 100644
index 000000000..56db0d19f
--- /dev/null
+++ b/packages/mcp/tsconfig.json
@@ -0,0 +1,13 @@
+{
+ "compilerOptions": {
+ "target": "ES2022",
+ "module": "ESNext",
+ "moduleResolution": "bundler",
+ "strict": true,
+ "skipLibCheck": true,
+ "noCheck": true,
+ "outDir": "dist",
+ "rootDir": "src"
+ },
+ "include": ["src"]
+}