Skip to content

ESM / CommonJS module resolution collision in MCP server dynamically loaded tool plugins #23

Description

@LorrdRazzy

Environment

  • OS: Linux x64 / macOS / Windows
  • Runtime / Node: Node.js v20.x, npm / pnpm
  • TypeScript Version: ^5.x
  • atomic-agent version: v0.4.x (main branch)

Summary

When attempting to dynamically import external Model Context Protocol (MCP) server modules or user-defined tool plugins configured via atomic.config.ts, the module loader fails with an ERR_REQUIRE_ESM or ERR_UNKNOWN_FILE_EXTENSION error.

This happens because the dynamic import pipeline in src/mcp/loader.ts assumes all plugin dependencies follow ES Modules ("type": "module"), failing when encountering legacy CommonJS packages or TypeScript files compiled to standard CJS formats.


Steps to Reproduce

  1. Define a custom local tool or install a third-party CJS-formatted MCP tool package.
  2. Register the tool in your configuration file:
    // atomic.config.ts
    export default {
      tools: [
        {
          name: 'custom-tool',
          path: './plugins/my-cjs-tool.js'
        }
      ]
    };

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