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

@sourabhshegane/mongodb-mcp-that-works

v0.1.3

Published

A MongoDB MCP server that actually works - with schema discovery, field validation, and all MongoDB operations

Readme

MongoDB That Works - MCP Server

A reliable MongoDB MCP (Model Context Protocol) server that provides seamless MongoDB integration for Claude Desktop with built-in schema discovery and field validation.

Features

  • 🔍 Schema Discovery: Automatically analyze collection structures
  • Field Validation: Prevent field name mistakes
  • 📊 Full MongoDB Support: Find, aggregate, insert, update, delete operations
  • 🚀 High Performance: Efficient connection pooling and query optimization
  • 🔐 Secure: Support for MongoDB Atlas and authentication
  • 🎯 Type-Safe: Built with TypeScript and Zod validation

Installation

Install from npm

npm install -g @sourabhshegane/mongodb-mcp-that-works

Configuration

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": ["-y", "@sourabhshegane/mongodb-mcp-that-works@latest"],
      "env": {
        "MONGODB_URI": "mongodb+srv://username:[email protected]/database",
        "MONGODB_DATABASE": "your_database_name"
      }
    }
  }
}

Configuration Options

  • MONGODB_URI: Your MongoDB connection string (required)
  • MONGODB_DATABASE: Default database name (optional)

Available Tools

1. listCollections

List all collections in the database.

// Example
mcp.listCollections({ filter: {} })

2. find

Find documents in a collection with filtering, sorting, and pagination.

// Example
mcp.find({
  collection: "users",
  filter: { status: "active" },
  sort: { createdAt: -1 },
  limit: 10
})

3. findOne

Find a single document.

// Example
mcp.findOne({
  collection: "users",
  filter: { email: "[email protected]" }
})

4. aggregate

Run aggregation pipelines.

// Example
mcp.aggregate({
  collection: "orders",
  pipeline: [
    { $match: { status: "completed" } },
    { $group: { _id: "$userId", total: { $sum: "$amount" } } }
  ]
})

5. count

Count documents matching a filter.

// Example
mcp.count({
  collection: "products",
  filter: { inStock: true }
})

6. distinct

Get distinct values for a field.

// Example
mcp.distinct({
  collection: "orders",
  field: "status"
})

7. insertOne

Insert a single document.

// Example
mcp.insertOne({
  collection: "users",
  document: { name: "John Doe", email: "[email protected]" }
})

8. updateOne

Update a single document.

// Example
mcp.updateOne({
  collection: "users",
  filter: { _id: "123" },
  update: { $set: { status: "active" } }
})

9. deleteOne

Delete a single document.

// Example
mcp.deleteOne({
  collection: "users",
  filter: { _id: "123" }
})

10. getSchema

Analyze collection structure and discover field names.

// Example
mcp.getSchema({
  collection: "users",
  sampleSize: 100
})

// Returns:
{
  "collection": "users",
  "sampleSize": 100,
  "fields": {
    "_id": {
      "types": ["ObjectId"],
      "examples": ["507f1f77bcf86cd799439011"],
      "frequency": "100/100",
      "percentage": 100
    },
    "email": {
      "types": ["string"],
      "examples": ["[email protected]"],
      "frequency": "100/100",
      "percentage": 100
    }
  }
}

Best Practices

  1. Use Schema Discovery First: Before querying, run getSchema to understand field names
  2. Handle ObjectIds: The server automatically converts string IDs to ObjectIds
  3. Use Projections: Limit returned fields to improve performance
  4. Batch Operations: Use aggregation pipelines for complex queries

Examples

Basic Usage

// Get schema first to avoid field name mistakes
const schema = await mcp.getSchema({ collection: "reports" });

// Use correct field names from schema
const reports = await mcp.find({
  collection: "reports",
  filter: { organization_id: "64ba7374f8b63db2083b2665" },
  limit: 10
});

Advanced Aggregation

const analytics = await mcp.aggregate({
  collection: "orders",
  pipeline: [
    { $match: { createdAt: { $gte: new Date("2024-01-01") } } },
    { $group: {
      _id: { $dateToString: { format: "%Y-%m", date: "$createdAt" } },
      revenue: { $sum: "$amount" },
      count: { $sum: 1 }
    }},
    { $sort: { _id: 1 } }
  ]
});

Troubleshooting

Connection Issues

  • Verify your MongoDB URI is correct
  • Check network connectivity to MongoDB Atlas
  • Ensure IP whitelist includes your current IP

Field Name Errors

  • Always use getSchema to discover correct field names
  • Remember MongoDB is case-sensitive
  • Check for typos in nested field paths (e.g., "user.profile.name")

Performance

  • Use indexes for frequently queried fields
  • Limit result sets with limit parameter
  • Use projections to return only needed fields

License

MIT License - see LICENSE file for details

Changelog

v0.1.0

  • Initial release
  • Full MongoDB CRUD operations
  • Schema discovery tool
  • Automatic ObjectId conversion
  • TypeScript support

Made out of pain since the official MongoDB MCP didn't work for me