ChromaDB & Vector Search: Connecting Semantic Memory to AI Agents via MCP
Learn how to integrate ChromaDB vector store into your AI agents using an MCP server, establishing persistent semantic memory and custom RAG retrieval logic.
Generate & Test ChromaDB Vector MCP Server Config
One-click export with environment variables & path locators for Claude Desktop, Cursor, Windsurf, and OpenAI Codex CLI.
ChromaDB & Vector Search: Connecting Semantic Memory to AI Agents
Giving AI agents long-term semantic memory requires a vector database. ChromaDB is a popular, lightweight open-source vector store. By wrapping ChromaDB in an MCP server, your agent can dynamically query, insert, and update embeddings to perform Retrieval-Augmented Generation (RAG) on the fly.
Prerequisites
- βΈNode.js 18+ installed on your host machine.
- βΈA running instance of ChromaDB. The easiest way is via Docker:
bash
docker run -p 8000:8000 chromadb/chroma - βΈAn embedding model (like OpenAI's
text-embedding-3-smallor local HuggingFace models) configured in your Chroma client.
Architecture Flow
graph LR
Agent[AI Agent / LLM] -->|Search query| MCPServer[ChromaDB MCP Server]
MCPServer -->|Embed text using local model / API| Embeddings[Vector Embeddings]
MCPServer -->|Query database| Chroma[(ChromaDB Instance)]
Chroma -->|Relevant documents| MCPServer
MCPServer -->|Context-enriched text| AgentServer Configuration Example
To run a ChromaDB MCP server, write a lightweight Node.js wrapper that exposes query_collection as an MCP tool:
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
import { ChromaClient } from 'chromadb';
const chroma = new ChromaClient({ path: process.env.CHROMA_URL || '' });
const server = new Server(
{ name: 'chromadb-mcp', version: '1.0.0' },
{ capabilities: { tools: {} } }
);
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: 'query_collection',
description: 'Query a ChromaDB collection for semantically matching documents.',
inputSchema: {
type: 'object',
properties: {
collectionName: { type: 'string' },
queryText: { type: 'string' },
limit: { type: 'number', default: 5 }
},
required: ['collectionName', 'queryText']
}
}
]
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
if (name === 'query_collection') {
const colName = String(args.collectionName);
const query = String(args.queryText);
const limit = Number(args.limit || 5);
const collection = await chroma.getCollection({ name: colName });
const results = await collection.query({
queryTexts: [query],
nResults: limit
});
return {
content: [{ type: 'text', text: JSON.stringify(results, null, 2) }]
};
}
throw new Error(`Unknown tool: ${name}`);
});
const transport = new StdioServerTransport();
await server.connect(transport);Best Practices
- βΈChunking: When allowing the agent to insert documents into ChromaDB via MCP, ensure the server middleware enforces maximum chunk sizes. Dumping a 50-page PDF into a single vector embedding will destroy retrieval accuracy.
- βΈMetadata Filtering: When designing your MCP tools, expose metadata filters (like
author,date, orcategory) so the LLM can narrow down the vector search space before calculating cosine similarity.
Troubleshooting
- βΈDimension Mismatch Error: If the MCP server throws an error when inserting or querying vectors, ensure the embedding model used by your Chroma instance exactly matches the dimensions of the model used to create the collection.
- βΈConnection Refused: Ensure your
CHROMA_URLenvironment variable is correctly set and that the Docker container is exposing port 8000.
Using with OpenAI Codex
To use this MCP server with the OpenAI Codex CLI, you can add it to your configuration using the codex mcp add command:
codex mcp add --name chromadb-vector --command "npx @modelcontextprotocol/server-chromadb-vector"(Note: Depending on the server, you may need to append arguments or use --env flags for environment variables as described in the configuration section above)
Build your full agent toolstack in the Visual Generator
Combine ChromaDB & Vector Search: Connecting Semantic Memory to AI Agents via MCP with databases, search APIs, and memory graphs in a single configuration file.
Related Guides
How to Use the MySQL MCP Server for Database Queries
Connect MySQL databases to your AI agent for querying, schema exploration, and data analysis using the MySQL MCP server.
DatabasesHow to Connect PostgreSQL to AI Agents Using MCP
Step-by-step guide to setting up the PostgreSQL MCP server. Give your AI agent read-only access to query your PostgreSQL databases safely.
DatabasesHow to Use the SQLite MCP Server for Local Database Analysis
Learn how to connect SQLite databases to your AI agent for local data analysis, querying, and schema exploration using the MCP protocol.