The NPM Context Agent MCP server provides comprehensive contextual information about npm packages through various tools, resources, and prompts:
Core Tools:
Package Metadata (
get_package_info) - Retrieve detailed package information including keywords, license, maintainers, and repository detailsREADME Files (
get_readme_data) - Fetch README content from GitHub repositories with smart branch fallback (main ā master ā default)Package Search (
search_packages) - Search npm registry by keyword with customizable result limitsVersion History (
get_package_versions) - Get all available versions and distribution tagsDependencies Analysis (
get_package_dependencies) - View dependencies, devDependencies, and peerDependencies for any versionDownload Statistics (
get_download_stats) - Track package download trends for last day, week, or monthPackage Comparison (
compare_packages) - Compare two packages side-by-side with detailed metricsBundle Size Analysis (
get_package_size) - Get minified and gzipped size information from BundlephobiaQuality Metrics (
get_package_quality) - Access quality, popularity, and maintenance scores from npms.io
MCP Resources:
package://{packageName}- Access package metadata as JSONpackage://{packageName}/readme- Access README content as markdownpackage://{packageName}/dependencies- Access dependencies as JSONpackage://{packageName}/versions- Access version history as JSON
MCP Prompts:
analyze-package- Comprehensive package analysis templatecompare-packages- Compare two packages templatefind-alternatives- Find alternative packages template
Technical Features:
Type-safe validation using Zod schemas
Support for scoped packages (e.g.,
@types/node)Version-specific queries across all operations
Multiple transport modes: stdio, HTTP, or dual mode simultaneously
Structured JSON output for programmatic access
Fetches README files from GitHub repositories with intelligent branch fallback (main/master/default) to provide package documentation
Provides comprehensive tools for interacting with the npm registry, including fetching package metadata, searching packages, retrieving version history, analyzing dependencies, and accessing download statistics
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
š Package Comparison - Compare two packages side-by-side
š¦ Bundle Size - Get package bundle size information from bundlephobia
ā Quality Metrics - Get quality scores from npms.io
MCP Resources
Resources provide application-driven data access:
package://{packageName} - Package metadata as JSON resource
package://{packageName}/readme - README content as markdown resource
package://{packageName}/dependencies - Dependencies as JSON resource
package://{packageName}/versions - Version history as JSON resource
MCP Prompts
Ready-to-use prompt templates:
analyze-package - Comprehensive package analysis prompt
compare-packages - Compare two packages prompt
find-alternatives - Find alternative packages prompt
Transport Support
stdio Transport - Traditional stdio-based communication (default)
HTTP Transport - HTTP-based communication for remote access
Dual Mode - Support both transports simultaneously
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
š¤ Structured output - All tools return structured JSON for programmatic access
šØ Modern MCP SDK - Uses latest MCP SDK v1.20.2 with resources and prompts
š HTTP & stdio - Choose your transport mode based on your needs
š Requirements
Node.js 18+ (works with Node.js 20+ recommended)
pnpm 10.19.0+
š ļø Installation
From npm (when published)
From source
šÆ Usage
As an MCP Server
This server implements the Model Context Protocol and can be used with MCP-compatible clients.
Stdio Transport (Default)
Add to your MCP configuration:
HTTP Transport
To use HTTP transport, set the environment variable before starting:
Then connect to http://localhost:3000/mcp from your MCP client.
Dual Mode
To run both stdio and HTTP transports simultaneously:
Environment Variables:
TRANSPORT_MODE- Transport mode:stdio(default),http, orbothPORT- HTTP server port (default: 3000, only used for http/both modes)
Quick Start Examples
Tools:
Get README for a package:
Search for packages:
Get all versions:
Get dependencies:
Check download stats:
Compare packages:
Get bundle size:
Get quality metrics:
Resources:
Read package metadata:
Read package README:
Read package dependencies:
Read version history:
Prompts:
Analyze a package:
Compare two packages:
Find alternatives:
Available Tools
Tool | Description | Parameters |
| Get package README from GitHub |
,
|
| Search npm packages by keyword |
,
|
| Get all versions of a package |
|
| Get package dependencies |
,
|
| Get download statistics |
,
|
| Get comprehensive package info |
,
|
| Compare two packages side-by-side |
,
|
| Get bundle size information |
,
|
| Get quality metrics from npms.io |
|
get_readme_data
Retrieves package information and README content from npm packages.
Parameters:
packageName(string, required): The name of the npm packageversion(string, optional): Specific version to fetch (defaults to latest)
Example:
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 keywordlimit(number, optional): Maximum number of results (default: 20)
Example:
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:
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 packageversion(string, optional): Specific version to fetch (defaults to latest)
Example:
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 packageperiod(string, optional): Time period - "last-day", "last-week", or "last-month" (default: "last-month")
Example:
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 packageversion(string, optional): Specific version to fetch (defaults to all versions)
Example:
Response: Returns comprehensive package information including keywords, license, maintainers, and repository details.
compare_packages
Compare two packages side-by-side with detailed metrics.
Parameters:
packageName1(string, required): First package to comparepackageName2(string, required): Second package to compare
Example:
Response: Returns side-by-side comparison including versions, descriptions, download statistics, maintainers, and keywords.
get_package_size
Get bundle size information for a package from bundlephobia.
Parameters:
packageName(string, required): The name of the npm packageversion(string, optional): Specific version to check (defaults to latest)
Example:
Response: Returns minified size, gzipped size, and dependency count.
get_package_quality
Get quality metrics from npms.io for a package.
Parameters:
packageName(string, required): The name of the npm package
Example:
Response: Returns quality score, popularity score, and maintenance score.
Available Resources
Resource | Description | MIME Type |
| Package metadata |
|
| Package README content |
|
| Package dependencies |
|
| Package version history |
|
Available Prompts
Prompt | Description | Arguments |
| Comprehensive package analysis |
|
| Compare two packages |
,
|
| Find alternative packages |
,
|
šļø Development
Project Structure
Scripts
pnpm build- Compile TypeScript to JavaScriptpnpm inspect- Run MCP inspector for testing
Building
The build process compiles TypeScript and makes the output executable.
Testing with MCP Inspector
This runs the MCP inspector which allows you to test the server interactively.
šļø Architecture
MCP Server Implementation
The server uses the @modelcontextprotocol/sdk v1.20.2 to create a standardized MCP server that:
Fetches package metadata from various npm APIs
Validates all responses using Zod schemas
For README fetching: Extracts the GitHub repository URL and fetches README with branch fallback
Returns formatted, structured data with both text and JSON output
Supports Resources for application-driven data access
Supports Prompts for reusable analysis templates
Provides multiple transport options (stdio, HTTP, or both)
API Endpoints Used
npm Registry API:
https://registry.npmjs.org/- Package metadata, versions, dependenciesnpm Search API:
https://registry.npmjs.org/-/v1/search- Package search functionalitynpm Downloads API:
https://api.npmjs.org/downloads/point/- Download statisticsGitHub Raw Content:
https://raw.githubusercontent.com/- README file fetchingBundlephobia API:
https://bundlephobia.com/api/size- Bundle size informationnpms.io API:
https://api.npms.io/v2/package/- Quality metrics
Data Flow
Error Handling
The server implements comprehensive error handling:
HTTP errors from all APIs (npm registry, bundlephobia, npms.io, GitHub)
Invalid response structures
GitHub README fetch failures with branch fallback
Network errors and timeouts
Scoped package handling
Missing package or version errors
All errors are returned with descriptive messages and proper error flags in both text and structured formats.
README Fetching with Branch Fallback
The server intelligently fetches README files by trying multiple branches in order:
Try
mainbranchTry
masterbranchTry 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:
This ensures type safety and prevents runtime errors from unexpected API responses across all API endpoints.
š¦ Dependencies
@modelcontextprotocol/sdk- MCP SDK for server implementationzod- Runtime type validationexpress- HTTP server for HTTP transport mode
š¦ Supported Package Types
This server can query any npm package. Here are examples:
Regular packages:
lodash,express,reactScoped packages:
@types/node,@babel/core,@angular/coreSpecific versions: All tools support optional version parameters
š Version History
Version 2.0.0 (Current)
Major Update - MCP SDK modernization and new features
New Features:
ā MCP Resources support (4 resources)
ā MCP Prompts support (3 prompts)
ā HTTP transport mode
ā Dual transport mode (stdio + HTTP)
ā Package comparison tool
ā Bundle size tool (bundlephobia integration)
ā Quality metrics (npms.io integration)
ā Structured output for all tools
ā Modern SDK v1.20.2 with registerTool/Resource/Prompt APIs
Improvements:
ā All tools migrated to
registerTool()APIā All tools return structured content
ā Better error handling and type safety
ā Enhanced documentation
Note:
Removed security checking tool due to unavailable public API for vulnerability data
Version 1.0.0
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
MIT License
Copyright (c) 2025 Juan Sebastian Gonzalez
See LICENSE.md for full license text.
š Acknowledgments
Built with Model Context Protocol
Powered by the npm registry API
README content sourced from GitHub
Quality metrics provided by npms.io
Bundle size data from Bundlephobia