diff --git a/jest.config.ts b/jest.config.ts index 1f34ab9..a6e20cf 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -4,6 +4,9 @@ const config: Config = { clearMocks: true, coverageProvider: "v8", testEnvironment: "node", + moduleNameMapper: { + "^(\\.{1,2}/.*)\\.js$": "$1", + }, transform: { "^.+.tsx?$": ["ts-jest", {}], }, diff --git a/package.json b/package.json index 7fc7101..9dfeabb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "fastify-mcp", "version": "2.1.0", + "type": "module", "packageManager": "yarn@4.7.0", "author": { "name": "Kshitij Chauhan", @@ -17,14 +18,18 @@ "ai", "anthropic" ], - "main": "dist/index.js", - "types": "dist/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, "files": [ "dist" ], "scripts": { "lint": "eslint .", - "test": "jest", + "test": "NODE_OPTIONS=--experimental-vm-modules jest", "build": "tsc", "format": "prettier --write .", "format:check": "prettier --check ." diff --git a/src/index.ts b/src/index.ts index 1f7133e..67e7c55 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -export { fastifyMCPSSE } from "./mcp-sse-plugin"; -export { Sessions } from "./session-storage"; -export { streamableHttp } from "./streamable-http"; +export { fastifyMCPSSE } from "./mcp-sse-plugin.js"; +export { Sessions } from "./session-storage.js"; +export { streamableHttp } from "./streamable-http.js"; diff --git a/src/mcp-sse-plugin.ts b/src/mcp-sse-plugin.ts index 15007c4..4de8b7f 100644 --- a/src/mcp-sse-plugin.ts +++ b/src/mcp-sse-plugin.ts @@ -1,7 +1,7 @@ import type { Server } from "@modelcontextprotocol/sdk/server/index.js"; import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js"; import { FastifyPluginCallback, FastifyRequest } from "fastify"; -import { Sessions } from "./session-storage"; +import { Sessions } from "./session-storage.js"; type MCPSSEPluginOptions = { server: Server; @@ -39,7 +39,7 @@ export const fastifyMCPSSE: FastifyPluginCallback = ( sessions.remove(sessionId); }); - fastify.log.info("Starting new session", { sessionId }); + fastify.log.info({ sessionId }, "Starting new session"); await server.connect(transport); }); diff --git a/src/session-storage.test.ts b/src/session-storage.test.ts index 178efde..662458c 100644 --- a/src/session-storage.test.ts +++ b/src/session-storage.test.ts @@ -1,3 +1,4 @@ +import { jest } from "@jest/globals"; import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js"; import { Sessions } from "./session-storage"; import { setTimeout } from "node:timers/promises"; diff --git a/src/session-storage.ts b/src/session-storage.ts index fe9299a..5101a75 100644 --- a/src/session-storage.ts +++ b/src/session-storage.ts @@ -1,4 +1,4 @@ -import type { Transport } from "@modelcontextprotocol/sdk/shared/transport"; +import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js"; import { EventEmitter } from "node:events"; type SessionEvents = { diff --git a/src/streamable-http.ts b/src/streamable-http.ts index ec65858..7d79161 100644 --- a/src/streamable-http.ts +++ b/src/streamable-http.ts @@ -3,7 +3,7 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/ import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js"; import { FastifyPluginAsync, FastifyReply } from "fastify"; import { randomUUID } from "node:crypto"; -import { Sessions } from "./session-storage"; +import { Sessions } from "./session-storage.js"; type StreamableHttpPluginOptions = | StatefulStreamableHttpPluginOptions diff --git a/tsconfig.json b/tsconfig.json index 2218081..a745d1e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,7 @@ { "compilerOptions": { - "target": "es2016", - "module": "commonjs", - "esModuleInterop": true, + "target": "es2022", + "module": "nodenext", "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true,