Labsco
1RB logo

MongoDB

โ˜… 15

from 1RB

Interact with MongoDB databases using natural language. Query collections, inspect schemas, and manage data.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

๐Ÿ—„๏ธ MongoDB MCP Server for LLMS

Node.js 18+ License: MIT npm version smithery badge

A Model Context Protocol (MCP) server that enables LLMs to interact directly with MongoDB databases. Query collections, inspect schemas, and manage data seamlessly through natural language.

๐Ÿ“š What is Model Context Protocol (MCP)?

The Model Context Protocol (MCP) is an open standard developed by Anthropic that creates a universal way for AI systems to connect with external data sources and tools. MCP establishes a standardized communication channel between:

  • MCP Clients: AI assistants like Claude that consume data (e.g., Claude Desktop, Cursor.ai)
  • MCP Servers: Services that expose data and functionality (like this MongoDB server)

Key benefits of MCP:

  • Universal Access: Provides a single protocol for AI assistants to query data from various sources
  • Standardized Connections: Handles authentication, usage policies, and data formats consistently
  • Sustainable Ecosystem: Promotes reusable connectors that work across multiple LLM clients

โœจ Features

  • ๐Ÿ” Collection schema inspection
  • ๐Ÿ“Š Document querying and filtering
  • ๐Ÿ“ˆ Index management
  • ๐Ÿ“ Document operations (insert, update, delete)
  • ๐Ÿ”’ Secure database access through connection strings
  • ๐Ÿ“‹ Comprehensive error handling and validation

๐ŸŽฏ Example Prompts

Try these prompts with Claude to explore the functionality:

Basic Operations

"What collections are available in the database?"
"Show me the schema for the users collection"
"Find all users in San Francisco"

Advanced Queries

"Find all electronics products that are in stock and cost less than $1000"
"Show me all orders from the user john@example.com"
"List the products with ratings above 4.5"

Index Management

"What indexes exist on the users collection?"
"Create an index on the products collection for the 'category' field"
"List all indexes across all collections"

Document Operations

"Insert a new product with name 'Gaming Laptop' in the products collection"
"Update the status of order with ID X to 'shipped'"
"Find and delete all products that are out of stock"

๐Ÿ“ Available Tools

The server provides these tools for database interaction:

Query Tools

  • listCollections: Lists available collections in the database
  • find: Queries documents with filtering and projection
  • insertOne: Inserts a single document into a collection
  • updateOne: Updates a single document in a collection
  • deleteOne: Deletes a single document from a collection

Index Tools

  • createIndex: Creates a new index on a collection
  • dropIndex: Removes an index from a collection
  • indexes: Lists indexes for a collection

๐Ÿ› ๏ธ Development

This project is built with:

  • TypeScript for type-safe development
  • MongoDB Node.js driver for database operations
  • Zod for schema validation
  • Model Context Protocol SDK for server implementation

To set up the development environment:

# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode
npm run dev

# Run tests
npm test

๐Ÿ”’ Security Considerations

When using this MCP server with your MongoDB database:

  1. Create a dedicated MongoDB user with minimal permissions needed for your use case
  2. Never use admin credentials in production environments
  3. Enable access logging for audit purposes
  4. Set appropriate read/write permissions on collections
  5. Use connection string parameters to restrict access (e.g., readPreference=secondary)
  6. Consider IP allow-listing to restrict database access

โš ๏ธ IMPORTANT: Always follow the principle of least privilege when configuring database access.

๐ŸŒ How It Works

The MongoDB MCP server:

  1. Connects to your MongoDB database using the connection string provided
  2. Exposes MongoDB operations as tools that follow the MCP specification
  3. Validates inputs using Zod for type safety and security
  4. Executes queries and returns structured data to the LLM client
  5. Manages connection pooling and proper error handling

All operations are executed with proper validation to prevent security issues such as injection attacks.

๐Ÿค Contributing

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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.