Skip to main content
Glama
devashishkumar

OpenRouter LangChain MCP Server

OpenRouter LangChain MCP Server

A small command-line chatbot that lets an OpenRouter model query MongoDB through a Model Context Protocol (MCP) server.

The project has two processes:

  • server.js exposes MongoDB query tools over MCP stdio transport.

  • client.js connects to the server, binds its tools to a LangChain OpenRouter model, and provides an interactive chat prompt.

Requirements

Related MCP server: mcp-mongo

Setup

  1. Install dependencies:

    npm install
  2. Create a .env file in the project root:

    OPENROUTER_API_KEY=your_openrouter_api_key
    MONGODB_URI=mongodb://localhost:27017

    MONGODB_URI is optional and defaults to mongodb://localhost:27017.

  3. Start the interactive client:

    npm start

The client starts server.js automatically over stdio, so the MCP server does not need to be started separately.

First run

The server uses the chatbot_db database. If both the users and orders collections are missing, it creates them and inserts sample records. Existing collections are left unchanged.

The sample data includes:

  • users: user IDs, names, email addresses, and statuses

  • orders: order IDs, user IDs, products, and amounts

Available MCP tools

get_collections

Lists the collections in the configured MongoDB database.

query_collection

Runs a MongoDB find query. It accepts:

  • collection (required): collection name, such as users or orders

  • filter (optional): MongoDB filter object

  • limit (optional): maximum number of documents to return; defaults to 10

Examples of questions to ask the chatbot:

Which users are active?
Show orders over $100.
What products did user 1 order?
List the available collections.

Type exit to close the client.

Configuration

The client currently uses the OpenRouter model identifier:

nvidia/nemotron-3-ultra-550b-a55b:free

To use another OpenRouter-supported model, change the model value in client.js.

Project structure

.
├── client.js   # Interactive LangChain client
├── server.js   # MCP server and MongoDB tools
├── package.json
└── README.md

Notes

  • Keep .env out of version control because it contains your API key.

  • The MCP server logs connection and seeding messages to stderr so they do not interfere with the stdio protocol.

  • The npm start script runs client.js, which starts the MCP server automatically over stdio.

Chatbot

Chatbot Chatbot

Users Collection

Chatbot

Orders Collection

Chatbot

Web application

The webapp/ directory contains a browser-based version of the chatbot. It runs an Express server, serves the UI from webapp/public/index.html, and exposes the chat endpoint at POST /api/chat.

The webapp runs the MCP server and client in the same Node.js process using an in-memory transport. The browser can therefore use the same MongoDB tools as the command-line client without starting a separate MCP process.

Run the webapp

  1. Install the webapp dependencies:

    cd webapp
    npm install
  2. Create a .env file in the webapp/ directory:

    OPENROUTER_API_KEY=your_openrouter_api_key
    MONGODB_URI=mongodb://localhost:27017
    PORT=3000

    MONGODB_URI defaults to mongodb://localhost:27017, and PORT defaults to 3000.

  3. Start the server:

    node server.js
  4. Open http://localhost:3000 in a browser.

Webapp behavior

  • The UI accepts natural-language questions about the MongoDB database.

  • Tool calls made by the model are displayed in the conversation.

  • The final model response is displayed after the tool calls complete.

  • Press Enter to send a message, or use the Send button.

  • The API returns { reply, steps } for successful requests and { error } for failures.

Example request:

curl -X POST http://localhost:3000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"message":"Show me active users"}'

Webapp project structure

webapp/
├── public/
│   └── index.html   # Browser chat interface
├── package.json
└── server.js        # Express app, MCP tools, and chat API

The webapp uses the same chatbot_db database and sample users and orders collections described above. Keep the .env file out of version control because it contains the OpenRouter API key.

Webapp

Chatbot Chatbot

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    F
    maintenance
    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.
    28 npm
    175
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to query and introspect MongoDB databases through find, aggregate, and schema discovery operations. Supports read-only default mode with optional write capabilities and works with any MCP-compatible client via stdio or HTTP transports.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables CRUD operations on MongoDB databases and collections, including listing databases and collections, via MCP tools.
    12 npm
    Apache 2.0
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to interact with MongoDB databases through natural language, supporting document CRUD, aggregation, collection listing, and statistics.
    139,525 npm
    Apache 2.0