mongodb-agent-langgraph-mcp

Example MongoDB agent using Langgraph + Langchainjs MCP adapter

GitHub Stars

0

User Rating

Not Rated

Forks

1

Issues

0

Views

1

Favorites

0

README
MongoDB Agent LangGraph MCP

This project is a fork of Gaurab MCP project

This project provides a REPL to interact with a MongoDB instance using natural language, powered by LangChain.js MCP Adapter, LangGraph agent and OpenAI.

Features
  • Ask open-ended questions about your MongoDB instance
  • Uses a suite of MongoDB tools (find, aggregate, insert, update, etc.)

Prerequisites
  • Node.js (v18+ recommended)
  • npm
  • Access to an OpenAI resource (API key, deployment, etc.)
  • Access to a running MongoDB instance

Environment Variables

Ensure you have the following environment variables set:

export OPENAI_API_KEY=
export OPENAI_MODEL_NAME=gpt-3.5-turbo
export TEMPERATURE=0
export MONGO_CONNECTION_STRING=

Installation
  1. Clone the repository:
    git clone git@github.com:josmanperez/mongodb-agent-langgraph-mcp.git
    cd mongodb-agent-langgraph-mcp
    
  2. Install dependencies:
    npm install
    

Usage
  1. Ensure your MongoDB instance is running and accessible.
    • For MongoDB MCP, the default connection string is set to mongodb://localhost:27017/?directConnection=true in client.js. Change it if needed.
  2. Start the REPL:
    node client.js
    
  3. Interact with the agent:
    • Type natural language questions or commands, e.g.:
      • list all my databases
      • count documents in collection users in database mydb
      • insert a document into collection test in database mydb
    • Press Ctrl+C to exit.

Customization
  • To change the MongoDB connection string, edit the connectionString in client.js.
  • To use a different Azure OpenAI deployment/model, update the environment variables accordingly.

License

MIT

Author Information
Gaurab Aryal

Product @mongodb | prev. Product @datadog

@mongodb New York

42

Followers

49

Repositories

3

Gists

7

Total Contributions

Top Contributors

Threads