Skip to content

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

@MartinSchlott

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

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