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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mongo-agent-hub

v0.2.1

Published

AI-powered, secure hub for MongoDB and connected knowledge sources

Readme

mongo-agent-hub

Build a secure AI chat service across multiple MongoDB databases. AgentHub connects aliases such as CRM, finance, and support; creates namespaced read tools; asks your chosen LLM to plan and call those tools; then returns the final answer.

Node.js 20+ and ESM are required.

Install

npm install mongo-agent-hub mongodb

The core package is provider-neutral. Add the official SDK for OpenAI, Anthropic, Google, or Azure separately and adapt it through AIProvider.

Use it

import { MongoClient } from 'mongodb';
import { AgentHub } from 'mongo-agent-hub';
import type { AIProvider } from '@dheerajatoria/providers';

const provider: AIProvider = {
  name: 'openai',
  async complete({ messages, tools, signal }) {
    // Call the vendor SDK using messages/tools, then map native calls to:
    // { text: string, toolCalls: [{ id, name, input }] }
    return { text: 'Adapter not configured', toolCalls: [] };
  }
};

const hub = new AgentHub({
  databases: {
    crm: process.env.CRM_DB!,
    finance: process.env.FINANCE_DB!,
    support: process.env.SUPPORT_DB!
  },
  clientFactory: (uri) => new MongoClient(uri),
  provider: 'openai',
  providers: [provider],
  maxSteps: 8
});

await hub.initialize();
const result = await hub.chat(
  'Which clients have overdue invoices and open support tickets?',
  { sessionId: 'user-42', roles: ['read'] }
);

initialize() connects every database and registers <alias>_find and <alias>_aggregate tools. chat() continues tool planning until the provider returns an answer or maxSteps is exceeded. Reuse a sessionId to retain history; call clearSession(sessionId) to remove it.

Configure MongoDB

await hub.connectMongo('analytics', {
  uri: process.env.ANALYTICS_DB!,
  database: 'reporting',
  readOnly: true
});

const collections = await hub.getCollections('analytics');
const schema = await hub.discoverSchema('analytics', 'invoices');

Schema discovery samples up to 100 documents and reports fields, types, nullability, and example values. Safe reads are capped at 500 results. $where, $function, $accumulator, $out, and $merge are rejected, but you must also use MongoDB users with read-only, least-privilege permissions.

Add tools

hub.tools.register({
  name: 'billing_get_status',
  description: 'Returns invoice status for a customer ID.',
  inputSchema: { type: 'object', required: ['customerId'] },
  permission: 'read',
  async execute(input) {
    return { customerId: input.customerId, status: 'overdue' };
  }
});

Tool names use lowercase snake case. read, write, and admin permissions are checked against roles supplied to chat; callers with admin may access every tool. hub.tools.discover(roles), execute(), and health() provide tool metadata, execution, and monitoring.

Production checklist

  • Authenticate before calling chat; pass trusted roles, never browser-supplied roles.
  • Use @dheerajatoria/auth JWT/rate-limit/audit primitives with durable storage.
  • Keep MongoDB credentials in a secret manager and enforce database-level read-only roles.
  • Validate HTTP bodies, rate limit principals, restrict CORS, and pass an abort signal for request timeouts.
  • Review tool outputs before exposing sensitive data and persist audit events.

Related packages

  • @dheerajatoria/react-chat supplies <AgentChat endpoint="/api/chat" theme="dark" />; the endpoint accepts { message } and returns { answer }.
  • @dheerajatoria/rag provides vector-store/document-loader contracts. TextLoader supports TXT/Markdown; add PDF/DOCX and Qdrant/Pinecone/Chroma adapters as needed.
  • @dheerajatoria/mcp, providers, mongo, and auth can also be used independently.

The complete source, architecture notes, and contribution guide are at https://github.com/mongo-agent-hub/mongo-agent-hub.