fix(mcp): report package.json version in the MCP handshake

The McpServer metadata version was a separate hardcoded string that
never matched the published version (stuck at 0.1.2, then 0.3.0 while
npm shipped 0.2.x). Read it from package.json at startup instead —
works from both src/ (tsx) and dist/ (published build).
This commit is contained in:
dayuan.jiang
2026-07-12 19:53:00 +09:00
parent d99b0cf9d1
commit 4ea4944bb9

View File

@@ -36,6 +36,7 @@ class XMLSerializerPolyfill {
}
;(globalThis as any).XMLSerializer = XMLSerializerPolyfill
import { createRequire } from "node:module"
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
import open from "open"
@@ -89,10 +90,17 @@ let currentSession: {
lastSeenXml: string
} | null = null
// Create MCP server
// Create MCP server. The version reported in the MCP handshake is read from
// package.json so it can never drift from the published npm version again
// (it sat hardcoded at stale values for most of this package's history).
// Both src/ (tsx dev) and dist/ (published build) live one level below the
// package root, so the relative path works in either runtime.
const require = createRequire(import.meta.url)
const packageVersion: string = require("../package.json").version
const server = new McpServer({
name: "next-ai-drawio",
version: "0.3.0",
version: packageVersion,
})
// Shared Zod schema fragment for page-targeting parameters.