Ask your MongoDB
anything.
Mango is an open-source AI agent that turns natural language into MongoDB queries. Plug in any LLM, connect your database, and start asking questions in seconds.
Everything you need
Production-ready from day one.
Natural Language Queries
Ask questions in plain English. Mango translates them into accurate MQL queries using the LLM of your choice.
Training & Memory
Load verified examples with `mango train`. Every successful query is also auto-saved. Similar questions get faster, more accurate answers over time.
MQL Validation
Every query is validated before reaching the database โ collection names, field names, and operators are checked against the live schema.
Auto Error Recovery
When a query fails with a fixable error, Mango injects the error back into context and retries automatically โ up to 2 times.
Pluggable Architecture
Swap LLM providers, memory backends, and tools without changing your agent code. Everything is built on abstract interfaces.
SSE Streaming
See every tool call in real time via Server-Sent Events. Know exactly what queries are being executed and why.
Read-Only by Design
Only find, aggregate, count, and distinct. Write operations are rejected at the tool level โ no accidental mutations.
Schema-Aware
Mango automatically introspects your collections, inferring field types, indexes, and references from sampled documents.
How it works
Ten steps from question to answer.
Inject training examples
Gold-standard verified examples are injected first. The LLM uses them directly โ no schema exploration needed.
Pre-inject memory examples
Auto-saved past interactions are retrieved and injected as additional few-shot examples into the prompt.
Select relevant schema
Only the schema portions relevant to the current query are selected and injected โ not the full database schema.
LLM decides which tools to call
The LLM analyzes the question and selects which tools to invoke.
Auto-inject schema before run_mql
Before each run_mql call, the current schema is automatically re-injected so the LLM always has accurate field names and types at query time.
Validate MQL before execution
Every query is validated against the live schema โ collection names, fields, and operators โ before running.
Execute tools against MongoDB
Tools run queries against MongoDB and return structured results.
Auto-retry on fixable errors
If a tool fails with a fixable error, the error is injected back and the LLM corrects the query automatically (max 2 retries).
Stream natural language answer
The final response is streamed back to the caller via SSE.
Auto-save successful queries to memory
The successful interaction is automatically saved for future similar questions.
Up in 3 minutes
Connect your database and start asking questions.
No setup? No problem.
Run this quickstart instantly on your own database โ no install needed.
from mango import MangoAgent
from mango.tools import (
ToolRegistry,
ListCollectionsTool,
SearchCollectionsTool,
DescribeCollectionTool,
CollectionStatsTool,
RunMQLTool,
SaveTextMemoryTool,
DeleteLastMemoryEntryTool
)
from mango.servers.fastapi import MangoFastAPIServer
from mango.integrations.anthropic import AnthropicLlmService
from mango.integrations.mongodb import MongoRunner
from mango.integrations.chromadb import ChromaAgentMemory
# Configure your LLM
llm = AnthropicLlmService(
model="claude-sonnet-4-6",
api_key="YOUR_API_KEY",
)
# Configure your database
db = MongoRunner()
db.connect("mongodb://localhost:27017/mydb")
# Configure your agent memory
agent_memory = ChromaAgentMemory(
persist_dir="./chroma_db",
)
# Register tools
tools = ToolRegistry()
tools.register(ListCollectionsTool(db))
tools.register(SearchCollectionsTool(db))
tools.register(DescribeCollectionTool(db))
tools.register(CollectionStatsTool(db))
tools.register(RunMQLTool(db))
tools.register(SaveTextMemoryTool(agent_memory))
# Create your agent
agent = MangoAgent(
llm_service=llm,
tool_registry=tools,
db=db,
agent_memory=agent_memory,
introspect=False
)
# Wire up the delete tool AFTER agent creation so it can reference agent state
tools.register(DeleteLastMemoryEntryTool(agent_memory, lambda: agent._last_memory_entry_id))
# Run the server
server = MangoFastAPIServer(agent)
server.run() # http://localhost:8000
Works with any LLM
Swap providers with one line of code.
Anthropic Claude
mango-ai[anthropic]
OpenAI GPT
mango-ai[openai]
Google Gemini
mango-ai[gemini]
Ollama (Open Source)
mango-ai[ollama]