npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@eliware/mcp-server

v1.1.1

Published

A Node.js server for the Model Context Protocol (MCP) with dynamic tool loading, HTTP API, and authentication.

Downloads

100

Readme

eliware.org

@eliware/mcp-server npm versionlicensebuild status

A Node.js server for the Model Context Protocol (MCP) with dynamic tool loading, HTTP API, and authentication. Easily extendable with custom tools for AI and automation workflows. Supports both CommonJS and ESM.


Table of Contents

Features

  • Model Context Protocol (MCP) server implementation for Node.js
  • Dynamic tool loading from a directory (tools/)
    • Loads .mjs files in ESM mode, .cjs files in CommonJS mode
  • HTTP API with authentication (Bearer token or custom async callback)
  • Express-based, easy to extend
  • Utility helpers for tool responses and BigInt-safe serialization
  • TypeScript type definitions included
  • Supports both CommonJS and ESM usage

Installation

npm install @eliware/mcp-server

Usage

ESM Example

// Example for ESM (module JS) usage
import { mcpServer } from '@eliware/mcp-server';

(async () => {
  const { app, httpInstance } = await mcpServer({
    // port: 1234, // You can change the port as needed
    // authToken: 'your-secret-token', // You can still use this for static token auth
    // toolsDir: './tools', // Path to your tools directory
    // name: 'Example MCP Server', // Set your server name
    // version: '1.0.0', // Set your server version
    // // Example: custom async auth callback
    // authCallback: async (token) => {
    //  // Replace with your own logic, e.g. check token in DB or against a list
    //  return token === 'your-secret-token';
    // },
    // context: { example: 'context' } // Optional context to pass to tools _extra (db, redis, etc.)
  });
  console.log('MCP Server started!');
})();

CommonJS Example

// Example for CommonJS usage
const { mcpServer } = require('@eliware/mcp-server');

(async () => {
  const { app, httpInstance } = await mcpServer({
    // port: 1234, // You can change the port as needed
    // authToken: 'your-secret-token', // You can still use this for static token auth
    // toolsDir: './tools', // Path to your tools directory
    // name: 'Example MCP Server', // Set your server name
    // version: '1.0.0', // Set your server version
    // // Example: custom async auth callback
    // authCallback: async (token) => {
    //  // Replace with your own logic, e.g. check token in DB or against a list
    //  return token === 'your-secret-token';
    // },
    // context: { example: 'context' } // Optional context to pass to tools _extra (db, redis, etc.)
  });
  console.log('MCP Server started!');
})();

Note:

  • In ESM mode, tools must be .mjs files and use the ESM export signature.
  • In CommonJS mode, tools must be .cjs files and use the CommonJS export signature.

Custom Tool Example (ESM)

To add your own tool for ESM, create a file in the tools/ directory (e.g., tools/echo.mjs):

import { z, buildResponse } from '@eliware/mcp-server';

export default async function ({ mcpServer, toolName, log }) {
  mcpServer.tool(
    toolName,
    "Echo Tool",
    { echoText: z.string() },
    async (_args, _extra) => {
      log.debug(`${toolName} Request`, { _args });
      const response = {
        message: "echo-reply",
        data: {
          text: _args.echoText
        }
      };
      log.debug(`${toolName} Response`, { response });
      return buildResponse(response);
    }
  );
}

Custom Tool Example (CommonJS)

To add your own tool for CommonJS, create a file in the tools/ directory (e.g., tools/echo.cjs):

const { z, buildResponse } = require('@eliware/mcp-server');

module.exports = async function ({ mcpServer, toolName, log }) {
  mcpServer.tool(
    toolName,
    "Echo Tool",
    { echoText: z.string() },
    async (_args, _extra) => {
      log.debug(`${toolName} Request`, { _args });
      const response = {
        message: "echo-reply",
        data: {
          text: _args.echoText
        }
      };
      log.debug(`${toolName} Response`, { response });
      return buildResponse(response);
    }
  );
};

API

`async mcpServer(options): Promise<{ app, httpInstance, mcpServer, transport }>```

Starts the MCP + HTTP server. Options:

  • log (optional): Logger instance (default: @eliware/log)
  • toolsDir (optional): Path to tools directory (default: ./tools relative to the entry file)
  • port (optional): Port for HTTP server (default: 1234 or process.env.MCP_PORT)
  • authToken (optional): Bearer token for authentication (default: process.env.MCP_TOKEN)
  • authCallback (optional): Custom async callback for authentication. Receives (token) and returns true/false or a Promise.
  • name (optional): Name for the MCP server
  • version (optional): Version for the MCP server
  • context (optional): Context object to attach to the MCP server and pass to tools (e.g. database, redis, etc.)

Returns an object with:

  • app: Express application instance
  • httpInstance: HTTP server instance
  • mcpServer: MCP server instance
  • transport: HTTP transport instance

convertBigIntToString(value)

Recursively converts all BigInt values in an object to strings.

buildResponse(data)

Wraps a plain JS object into the standard tool response payload.

z

Re-exports zod for schema validation.

TypeScript

Type definitions are included:

export interface McpServerOptions {
  log?: any;
  toolsDir?: string;
  port?: number | string;
  authToken?: string;
  authCallback?: (token?: string) => boolean | Promise<boolean>;
  name?: string;
  version?: string;
  context?: any;
}

export interface McpServerResult {
  app: import('express').Application;
  httpInstance: import('http').Server;
  mcpServer: any;
  transport: any;
}

export function mcpServer(options?: McpServerOptions): Promise<McpServerResult>;
export function convertBigIntToString(value: any): any;
export function buildResponse(data: any): { content: { type: 'text'; text: string }[] };
export { z };

Support

For help, questions, or to chat with the author and community, visit:

Discordeliware.org

eliware.org on Discord

License

MIT © 2025 Eli Sterling, eliware.org

Links