Skip to content

Module resolution issues with TypeScript ESM imports #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
enkhbold470 opened this issue Mar 24, 2025 · 3 comments
Open

Module resolution issues with TypeScript ESM imports #218

enkhbold470 opened this issue Mar 24, 2025 · 3 comments

Comments

@enkhbold470
Copy link

We're experiencing issues with TypeScript module resolution when trying to import the MCP SDK in an ESM project. We've tried several approaches:

  1. Direct imports:
import { Server } from "@modelcontextprotocol/sdk/server";
import { Function, FunctionParameter } from "@modelcontextprotocol/sdk/server/mcp";
  1. Full path imports:
import { Server } from "@modelcontextprotocol/sdk/dist/esm/server/index.js";
import { Function, FunctionParameter } from "@modelcontextprotocol/sdk/dist/esm/server/mcp.js";

Both approaches result in TypeScript errors:

Cannot find module '@modelcontextprotocol/sdk/server' or its corresponding type declarations.
Cannot find module '@modelcontextprotocol/sdk/server/mcp' or its corresponding type declarations.

Our project configuration:

// package.json
{
  "type": "module",
  "dependencies": {
    "@modelcontextprotocol/sdk": "latest"
  }
}

// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "bundler",
    // ...
  }
}

Could you please provide guidance on the correct way to import the SDK in an ESM TypeScript project?

@Pdash-exceeds
Copy link

@enkhbold470 - check this patch #217

@ipenywis
Copy link

This is still an issue with latest version 1.9.0.

@https-eduardo
Copy link

This is still an issue with latest version 1.9.0.

Changing from:
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp";
To:
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";

Solved for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants