Skip to main content
Glama

NPM Context Agent MCP

npm-context-agent-mcp

A Model Context Protocol (MCP) server that provides comprehensive contextual information about npm packages, including README files, versions, dependencies, download statistics, and more.

šŸš€ Features

  • Fetch npm package metadata - Get detailed information about any npm package

  • Retrieve README files - Automatically fetches README from GitHub repositories with smart branch fallback

  • Search packages - Search npm registry by keyword

  • Version history - Get all available versions of a package

  • Dependencies info - View dependencies, devDependencies, and peerDependencies

  • Download statistics - Track package download trends

  • Type-safe validation - Uses Zod for runtime schema validation

  • Scoped package support - Handles scoped packages like @types/node

  • Error handling - Graceful error handling with detailed error messages

  • Zero dependencies - Lightweight implementation using native fetch API

šŸ“‹ Requirements

  • Node.js 18+ (works with Node.js 20+ recommended)

  • pnpm 10.19.0+

šŸ› ļø Installation

From npm (when published)

npm install -g npm-context-agent-mcp

From source

git clone <repository-url> cd npm-context-agent-mcp pnpm install pnpm build

šŸŽÆ Usage

As an MCP Server

This server implements the Model Context Protocol and can be used with MCP-compatible clients.

Add to your MCP configuration:

{ "mcpServers": { "npm-context-agent": { "command": "node", "args": ["path/to/npm-context-agent-mcp/build/index.js"] } } }

Available Tools

get_readme_data

Retrieves package information and README content from npm packages.

Parameters:

  • packageName (string, required): The name of the npm package

  • version (string, optional): Specific version to fetch (defaults to latest)

Example:

{ "packageName": "zustand", "version": "5.0.0" }

Response: Returns package name, version, description, repository URL, and README content.


search_packages

Search npm registry for packages by keyword.

Parameters:

  • query (string, required): Search keyword

  • limit (number, optional): Maximum number of results (default: 20)

Example:

{ "query": "state management", "limit": 10 }

Response: Returns matching packages with names, versions, descriptions, authors, and links.


get_package_versions

Get all available versions of a package.

Parameters:

  • packageName (string, required): The name of the npm package

Example:

{ "packageName": "react" }

Response: Returns list of all versions, dist tags, and latest version.


get_package_dependencies

Get dependencies and devDependencies for a package.

Parameters:

  • packageName (string, required): The name of the npm package

  • version (string, optional): Specific version to fetch (defaults to latest)

Example:

{ "packageName": "@types/node", "version": "24.0.0" }

Response: Returns dependencies, devDependencies, and peerDependencies for the specified version.


get_download_stats

Get download statistics from npm.

Parameters:

  • packageName (string, required): The name of the npm package

  • period (string, optional): Time period - "last-day", "last-week", or "last-month" (default: "last-month")

Example:

{ "packageName": "lodash", "period": "last-week" }

Response: Returns download counts and date range for the specified period.


get_package_info

Get comprehensive package metadata.

Parameters:

  • packageName (string, required): The name of the npm package

  • version (string, optional): Specific version to fetch (defaults to all versions)

Example:

{ "packageName": "express", "version": "4.18.0" }

Response: Returns comprehensive package information including keywords, license, maintainers, and repository details.


šŸ—ļø Development

Project Structure

npm-context-agent-mcp/ ā”œā”€ā”€ src/ │ └── index.ts # Main MCP server implementation ā”œā”€ā”€ build/ # Compiled JavaScript output ā”œā”€ā”€ package.json ā”œā”€ā”€ tsconfig.json └── README.md

Scripts

  • pnpm build - Compile TypeScript to JavaScript

  • pnpm inspect - Run MCP inspector for testing

Building

pnpm build

The build process compiles TypeScript and makes the output executable.

Testing with MCP Inspector

pnpm inspect

This runs the MCP inspector which allows you to test the server interactively.

šŸ›ļø Architecture

MCP Server Implementation

The server uses the @modelcontextprotocol/sdk to create a standardized MCP server that:

  1. Fetches package metadata from the npm registry API

  2. Validates the response structure using Zod schemas

  3. For README fetching: Extracts the GitHub repository URL and fetches README with branch fallback

  4. Returns formatted, structured data

Data Flow

Client Request → MCP Server → npm Registry API ↓ Validation (Zod) ↓ GitHub API (for README) ↓ Formatted Response

Error Handling

The server implements comprehensive error handling:

  • HTTP errors from npm registry

  • Invalid response structures

  • GitHub README fetch failures with branch fallback

  • Network errors

  • Scoped package handling

All errors are returned with descriptive messages and proper error flags.

README Fetching with Branch Fallback

The server intelligently fetches README files by trying multiple branches in order:

  1. Try main branch

  2. Try master branch

  3. Try default branch (no branch specification)

This ensures maximum compatibility across different repository configurations.

šŸ”’ Type Safety

The project uses Zod for runtime validation across all tools:

const NpmRegistryResponseSchema = z.object({ name: z.string(), version: z.string(), description: z.string().optional(), repository: z.object({ type: z.string(), url: z.string(), }), });

This ensures type safety and prevents runtime errors from unexpected API responses across all API endpoints.

šŸ“¦ Dependencies

  • @modelcontextprotocol/sdk - MCP SDK for server implementation

  • zod - Runtime type validation

šŸ”§ Supported Package Types

  • Regular packages: lodash, express, react

  • Scoped packages: @types/node, @babel/core, @angular/core

  • Specific versions: All endpoints support optional version parameters

šŸ¤ Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

šŸ“„ License

ISC

šŸ™ Acknowledgments

Deploy Server
-
security - not tested
F
license - not found
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Provides comprehensive contextual information about npm packages including README files, versions, dependencies, download statistics, and search functionality. Enables users to explore and analyze npm packages through natural language queries with intelligent GitHub README fetching and branch fallback.

  1. šŸš€ Features
    1. šŸ“‹ Requirements
      1. šŸ› ļø Installation
        1. From npm (when published)
        2. From source
      2. šŸŽÆ Usage
        1. As an MCP Server
        2. Available Tools
      3. šŸ—ļø Development
        1. Project Structure
        2. Scripts
        3. Building
        4. Testing with MCP Inspector
      4. šŸ›ļø Architecture
        1. MCP Server Implementation
        2. Data Flow
        3. Error Handling
        4. README Fetching with Branch Fallback
      5. šŸ”’ Type Safety
        1. šŸ“¦ Dependencies
          1. šŸ”§ Supported Package Types
            1. šŸ¤ Contributing
              1. šŸ“„ License
                1. šŸ™ Acknowledgments

                  MCP directory API

                  We provide all the information about MCP servers via our MCP API.

                  curl -X GET 'https://glama.ai/api/mcp/v1/servers/JuanSebastianGB/npm-context-agent-mcp'

                  If you have feedback or need assistance with the MCP directory API, please join our Discord server