From 1f279fbb2aeaa36567ed1eec9334f07014363a20 Mon Sep 17 00:00:00 2001 From: HiranoMasaaki Date: Tue, 17 Feb 2026 03:35:24 +0000 Subject: [PATCH 1/2] refactor: replace mime-types library with minimal helper mime-types@3.0.2 (CJS) calls require("path") inside ESM bundles causing runtime errors. Replace it with a lightweight lookupMimeType helper that covers the six extensions actually used (.png, .jpg, .jpeg, .gif, .webp, .pdf). Co-Authored-By: Claude Opus 4.6 --- apps/base/package.json | 2 -- apps/base/src/lib/mime.ts | 14 ++++++++++++++ apps/base/src/tools/read-image-file.ts | 4 ++-- apps/base/src/tools/read-pdf-file.ts | 4 ++-- pnpm-lock.yaml | 11 ----------- 5 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 apps/base/src/lib/mime.ts diff --git a/apps/base/package.json b/apps/base/package.json index abbe1a85..2265b796 100644 --- a/apps/base/package.json +++ b/apps/base/package.json @@ -32,12 +32,10 @@ "@modelcontextprotocol/sdk": "^1.26.0", "@perstack/core": "workspace:*", "commander": "^14.0.3", - "mime-types": "^3.0.2", "zod": "^4.3.6" }, "devDependencies": { "@tsconfig/node22": "^22.0.5", - "@types/mime-types": "^3.0.1", "@types/node": "^25.2.3", "tsup": "^8.5.1", "typescript": "^5.9.3", diff --git a/apps/base/src/lib/mime.ts b/apps/base/src/lib/mime.ts new file mode 100644 index 00000000..c1888170 --- /dev/null +++ b/apps/base/src/lib/mime.ts @@ -0,0 +1,14 @@ +import { extname } from "node:path" + +const MIME_TYPES: Record = { + ".png": "image/png", + ".jpg": "image/jpeg", + ".jpeg": "image/jpeg", + ".gif": "image/gif", + ".webp": "image/webp", + ".pdf": "application/pdf", +} + +export function lookupMimeType(filePath: string): string | undefined { + return MIME_TYPES[extname(filePath).toLowerCase()] +} diff --git a/apps/base/src/tools/read-image-file.ts b/apps/base/src/tools/read-image-file.ts index b51bd147..c9e53310 100644 --- a/apps/base/src/tools/read-image-file.ts +++ b/apps/base/src/tools/read-image-file.ts @@ -1,8 +1,8 @@ import { existsSync } from "node:fs" import { stat } from "node:fs/promises" import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" -import mime from "mime-types" import { z } from "zod/v4" +import { lookupMimeType } from "../lib/mime.js" import { validatePath } from "../lib/path.js" import { errorToolResult, successToolResult } from "../lib/tool-result.js" @@ -14,7 +14,7 @@ export async function readImageFile(input: { path: string }) { if (!isFile) { throw new Error(`File ${path} does not exist.`) } - const mimeType = mime.lookup(validatedPath) + const mimeType = lookupMimeType(validatedPath) if (!mimeType || !["image/png", "image/jpeg", "image/gif", "image/webp"].includes(mimeType)) { throw new Error(`File ${path} is not supported.`) } diff --git a/apps/base/src/tools/read-pdf-file.ts b/apps/base/src/tools/read-pdf-file.ts index add2a4a2..14eb8a3a 100644 --- a/apps/base/src/tools/read-pdf-file.ts +++ b/apps/base/src/tools/read-pdf-file.ts @@ -1,8 +1,8 @@ import { existsSync } from "node:fs" import { stat } from "node:fs/promises" import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" -import mime from "mime-types" import { z } from "zod/v4" +import { lookupMimeType } from "../lib/mime.js" import { validatePath } from "../lib/path.js" import { errorToolResult, successToolResult } from "../lib/tool-result.js" @@ -14,7 +14,7 @@ export async function readPdfFile(input: { path: string }) { if (!isFile) { throw new Error(`File ${path} does not exist.`) } - const mimeType = mime.lookup(validatedPath) + const mimeType = lookupMimeType(validatedPath) if (mimeType !== "application/pdf") { throw new Error(`File ${path} is not a PDF file.`) } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5db2a352..0f25aa1d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,9 +65,6 @@ importers: commander: specifier: ^14.0.3 version: 14.0.3 - mime-types: - specifier: ^3.0.2 - version: 3.0.2 zod: specifier: ^4.3.6 version: 4.3.6 @@ -75,9 +72,6 @@ importers: '@tsconfig/node22': specifier: ^22.0.5 version: 22.0.5 - '@types/mime-types': - specifier: ^3.0.1 - version: 3.0.1 '@types/node': specifier: ^25.2.3 version: 25.2.3 @@ -1832,9 +1826,6 @@ packages: '@types/estree@1.0.8': resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==} - '@types/mime-types@3.0.1': - resolution: {integrity: sha512-xRMsfuQbnRq1Ef+C+RKaENOxXX87Ygl38W1vDfPHRku02TgQr+Qd8iivLtAMcR0KF5/29xlnFihkTlbqFrGOVQ==} - '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} @@ -4628,8 +4619,6 @@ snapshots: '@types/estree@1.0.8': {} - '@types/mime-types@3.0.1': {} - '@types/node@12.20.55': {} '@types/node@25.2.3': From 208e5c9c41d040f8a09550795fccd967cdf2ef8c Mon Sep 17 00:00:00 2001 From: HiranoMasaaki Date: Tue, 17 Feb 2026 03:38:24 +0000 Subject: [PATCH 2/2] chore: fix lint formatting and add empty changeset Co-Authored-By: Claude Opus 4.6 --- .changeset/warm-islands-fetch.md | 2 ++ apps/base/src/lib/mime.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 .changeset/warm-islands-fetch.md diff --git a/.changeset/warm-islands-fetch.md b/.changeset/warm-islands-fetch.md new file mode 100644 index 00000000..a845151c --- /dev/null +++ b/.changeset/warm-islands-fetch.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/apps/base/src/lib/mime.ts b/apps/base/src/lib/mime.ts index c1888170..4b0f754b 100644 --- a/apps/base/src/lib/mime.ts +++ b/apps/base/src/lib/mime.ts @@ -1,14 +1,14 @@ import { extname } from "node:path" const MIME_TYPES: Record = { - ".png": "image/png", - ".jpg": "image/jpeg", - ".jpeg": "image/jpeg", - ".gif": "image/gif", - ".webp": "image/webp", - ".pdf": "application/pdf", + ".png": "image/png", + ".jpg": "image/jpeg", + ".jpeg": "image/jpeg", + ".gif": "image/gif", + ".webp": "image/webp", + ".pdf": "application/pdf", } export function lookupMimeType(filePath: string): string | undefined { - return MIME_TYPES[extname(filePath).toLowerCase()] + return MIME_TYPES[extname(filePath).toLowerCase()] }