NPM Context Agent MCP

NPM Context Agent MCP

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.

Category
访问服务器

README

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

Core Capabilities

  • 📦 Package Metadata - Get detailed information about any npm package
  • 📖 README Files - Automatically fetches README from GitHub repositories with smart branch fallback
  • 🔍 Package Search - Search npm registry by keyword with customizable result limits
  • 📋 Version History - Get all available versions of a package with dist tags
  • 🔗 Dependencies Info - View dependencies, devDependencies, and peerDependencies
  • 📊 Download Statistics - Track package download trends (last day, week, or month)
  • ℹ️ Comprehensive Info - Get full package metadata including keywords, license, maintainers

Technical Features

  • 🛡️ Type-safe validation - Uses Zod for runtime schema validation
  • 🏷️ Scoped package support - Handles scoped packages like @types/node
  • 🎯 Version support - Fetch specific package versions for all operations
  • ⚡ Smart branch fallback - Automatically tries main → master → default branches
  • 🔄 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"]
    }
  }
}

Quick Start Examples

Get README for a package:

{ "packageName": "react" }

Search for packages:

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

Get all versions:

{ "packageName": "svelte" }

Get dependencies:

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

Check download stats:

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

Available Tools

Tool Description Parameters
get_readme_data Get package README from GitHub packageName, version?
search_packages Search npm packages by keyword query, limit?
get_package_versions Get all versions of a package packageName
get_package_dependencies Get package dependencies packageName, version?
get_download_stats Get download statistics packageName, period?
get_package_info Get comprehensive package info packageName, version?

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

API Endpoints Used

  • npm Registry API: https://registry.npmjs.org/ - Package metadata, versions, dependencies
  • npm Search API: https://registry.npmjs.org/-/v1/search - Package search functionality
  • npm Downloads API: https://api.npmjs.org/downloads/point/ - Download statistics
  • GitHub Raw Content: https://raw.githubusercontent.com/ - README file fetching

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

📝 Version History

Version 1.0.0 (Current)

Initial Release - Complete npm context agent MCP server

Features:

  • ✅ README fetching with branch fallback
  • ✅ Package search functionality
  • ✅ Version history retrieval
  • ✅ Dependencies analysis
  • ✅ Download statistics
  • ✅ Comprehensive package info
  • ✅ Scoped package support
  • ✅ Version-specific queries
  • ✅ Zod schema validation
  • ✅ Comprehensive error handling

🤝 Contributing

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

📄 License

ISC

🙏 Acknowledgments

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选