Skip to content

Bug Report: Incorrect exports Configuration Prevents Import of Submodules #70

Closed

Description

@MartinSchlott

Summary:
The exports configuration in @modelcontextprotocol/sdk's package.json causes import issues for submodules like @modelcontextprotocol/sdk/client. This results in TypeScript being unable to resolve the module without additional paths configuration in tsconfig.json.


Steps to Reproduce:

  1. Create a new project:
    mkdir temp-test
    cd temp-test
    npm init -y
    npm install @modelcontextprotocol/sdk
  2. Add a minimal tsconfig.json:
    {
      "compilerOptions": {
        "module": "ESNext",
        "target": "ES6",
        "moduleResolution": "node",
        "strict": true
      }
    }
  3. Create a test.ts file:
    import { Client } from "@modelcontextprotocol/sdk/client";
    
    console.log("test");
  4. Compile the project:
    npx tsc

Expected Behavior:

The submodule @modelcontextprotocol/sdk/client should resolve correctly without requiring additional TypeScript configuration.


Actual Behavior:

TypeScript fails with the following error:

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

The issue can be worked around by adding the following to tsconfig.json:

"paths": {
  "@modelcontextprotocol/sdk/*": ["node_modules/@modelcontextprotocol/sdk/dist/*"]
},
"baseUrl": ".",

However, this should not be necessary.


Root Cause Analysis:

The package.json of @modelcontextprotocol/sdk includes the following exports configuration:

"exports": {
  "./*": "./dist/*"
}

It does not explicitly map @modelcontextprotocol/sdk/client. As a result, TypeScript cannot resolve the submodule.


Suggested Fix:

Update the exports field in package.json to include explicit mappings for submodules. For example:

"exports": {
  "./*": "./dist/*",
  "./client": "./dist/client/index.js",
  "./client/stdio": "./dist/client/stdio/index.js"
}

Environment:

  • Node.js: v16.0.0+
  • TypeScript: v4.9.0+
  • OS: OSX

Activity

  1. jspahrsummers commented on Nov 27, 2024

    @jspahrsummers
    Member

    Thanks for the report! We'd be happy to review a PR fixing this issue, if you want to submit one. 🙏

  2. MartinSchlott commented on Nov 27, 2024

    @MartinSchlott
    Author

    I’m closing this bug report because the issue was entirely on my side. I forgot to set "type": "module" in my package.json, which caused the ES module imports to fail. My punishment is my embarrassment.

    Thank you for your work on this library, and I apologize for any confusion caused!

  3. added a commit that references this issue on May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions