fix(mcp): read version from package.json instead of hardcoding (#431)

This commit is contained in:
Oliver Ratzesberger 2026-04-05 22:44:35 +02:00 committed by GitHub
parent 1ad3388132
commit 021236378b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,8 @@
import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
import { randomUUID } from "node:crypto";
import { readFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "url";
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@ -80,6 +82,16 @@ function formatSearchSummary(results: SearchResultItem[], query: string): string
return lines.join('\n');
}
function getPackageVersion(): string {
try {
const pkgPath = join(dirname(fileURLToPath(import.meta.url)), "../../package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
return pkg.version ?? "unknown";
} catch {
return "unknown";
}
}
// =============================================================================
// MCP Server
// =============================================================================
@ -157,7 +169,7 @@ async function buildInstructions(store: QMDStore): Promise<string> {
*/
async function createMcpServer(store: QMDStore): Promise<McpServer> {
const server = new McpServer(
{ name: "qmd", version: "0.9.9" },
{ name: "qmd", version: getPackageVersion() },
{ instructions: await buildInstructions(store) },
);