Sponsored by Deepsite.site

NPMJS Model Context Protocol (MCP) Server

Created By
yiannis-spyridakis7 months ago
Content

NPMJS Model Context Protocol (MCP) Server

1. Project Purpose

The primary objective of this project is to create a lightweight, TypeScript-based Model Context Protocol (MCP) server. This server is dedicated to providing structured information about npmjs packages—such as version details, download statistics, publish dates, descriptions, and licenses—in a simple, standardized JSON format. This format is suitable for consumption by Large Language Models (LLMs) and AI-driven development tools.

The server aims to simplify access to npm package metadata by abstracting away direct interactions with multiple npmjs API endpoints.

2. Setup Instructions

  1. Clone the repository (if applicable):
    git clone <repository-url>
    cd npmjs-mcp
    
  2. Install dependencies:
    npm install
    

3. Running the Server

Development Environment

To run the server in a development environment with automatic restarts on file changes:

npm run dev

The server will start and listen for MCP requests via standard input/output.

Building for Production

To compile the TypeScript code to JavaScript for production:

npm run build

This will create a dist directory with the compiled files.

Production Environment

To run the compiled server in a production environment:

npm start

4. Available MCP Tools

This server provides tools that can be called using an MCP client.

Tool: get_npm_package_summary

  • Description: Provides essential package details: name, latest version, description, publish date of the latest version, license, homepage, and repository URL.
  • Input Schema:
    {
      "type": "object",
      "properties": {
        "packageName": {
          "type": "string",
          "description": "The name of the npm package (e.g., 'express', 'react')"
        }
      },
      "required": ["packageName"]
    }
    

Tool: get_npm_package_versions

  • Description: Lists all available package versions along with their respective publish dates.
  • Input Schema:
    {
      "type": "object",
      "properties": {
        "packageName": {
          "type": "string",
          "description": "The name of the npm package"
        }
      },
      "required": ["packageName"]
    }
    

Tool: get_npm_package_downloads

  • Description: Provides download statistics. Can fetch for a specific period or all default periods (last-day, last-week, last-month) if period is omitted.
  • Input Schema:
    {
      "type": "object",
      "properties": {
        "packageName": {
          "type": "string",
          "description": "The name of the npm package"
        },
        "period": {
          "type": "string",
          "description": "Optional: 'last-day', 'last-week', 'last-month'. If omitted, all are fetched.",
          "enum": ["last-day", "last-week", "last-month"]
        }
      },
      "required": ["packageName"]
    }
    

Tool: get_npm_package_details

  • Description: Offers a comprehensive set of information including summary details plus maintainers and keywords.
  • Input Schema:
    {
      "type": "object",
      "properties": {
        "packageName": {
          "type": "string",
          "description": "The name of the npm package"
        }
      },
      "required": ["packageName"]
    }
    

5. Example Tool Usage and Responses

The following examples illustrate how to call a tool (conceptual, actual client usage may vary) and the expected data portion of the successful MCP CallToolResponse. The MCP SDK handles the full response envelope (version, timestamp, etc.).

Example: Calling get_npm_package_summary

Tool Call Arguments:

{
  "packageName": "express"
}

Expected data in MCP Response:

{
{
  "name": "express",
  "latestVersion": "5.1.0",
  "description": "Fast, unopinionated, minimalist web framework",
  "publishDateLatest": "2025-03-31T14:01:22.509Z",
  "license": "MIT",
  "homepage": "http://expressjs.com/",
  "repository": "https://github.com/expressjs/express",
  "source": "https://registry.npmjs.org/express"
}

Example: Calling get_npm_package_versions

Tool Call Arguments:

{
  "packageName": "express"
}

Expected data in MCP Response:

{
  "versions": {
    "1.0.0": "2010-12-29T19:38:25.450Z",
    "1.0.1": "2010-12-29T19:38:25.450Z",
    "4.19.2": "2024-03-25T14:30:36.103Z",
    "5.1.0": "2025-03-31T14:01:22.509Z"
    // ... potentially many more versions
  },
  "source": "https://registry.npmjs.org/express"
}

Example: Calling get_npm_package_downloads (all default periods)

Tool Call Arguments:

{
  "packageName": "express"
}

Expected data in MCP Response:

{
  "downloads": {
    "last-day": 7895822,
    "last-week": 37439130,
    "last-month": 162348160
  },
  "package": "express",
  "source": "https://api.npmjs.org/downloads/point"
}

Example: Calling get_npm_package_details

Tool Call Arguments:

{
  "packageName": "express"
}

Expected data in MCP Response:

{
{
  "name": "express",
  "latestVersion": "5.1.0",
  "description": "Fast, unopinionated, minimalist web framework",
  "publishDateLatest": "2025-03-31T14:01:22.509Z",
  "license": "MIT",
  "homepage": "https://expressjs.com/",
  "repository": "https://github.com/expressjs/express",
  "maintainers": [
    { "name": "wesleytodd", "email": "wes@wesleytodd.com" },
    { "name": "jonchurch", "email": "npm@jonchurch.com" }
  ],
  "keywords": [
    "express",
    "framework",
    "web"
  ],
  "source": "https://registry.npmjs.org/express"
}

Error Handling

If a tool call fails (e.g., package not found, invalid arguments), the MCP server will return a standard MCP error response. The error object within this response will contain a message detailing the issue.

Example MCP Error Response (conceptual):

{
  "version": "0.2.0", // SDK version
  "id": "response-id",
  "type": "CallToolResponse",
  "timestamp": "YYYY-MM-DDTHH:mm:ss.sssZ",
  "result": {
    "error": {
      "type": "ToolError", // Or similar error type from SDK
      "message": "Package 'nonexistent-pkg' not found on npmjs."
      // Potentially other fields like 'toolName'
    }
  }
}

If a required argument like packageName is missing, the tool handler will throw an error, resulting in a similar MCP error response.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Serper MCP ServerA Serper MCP Server
DeepChatYour AI Partner on Desktop
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Tavily Mcp
WindsurfThe new purpose-built IDE to harness magic
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
ChatWiseThe second fastest AI chatbot™
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Amap Maps高德地图官方 MCP Server
Playwright McpPlaywright MCP server
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
CursorThe AI Code Editor