How to Integrate Claude Context with LangChain and LangGraph: A Complete Guide
Integrate Claude Context with LangChain or LangGraph using the Model Context Protocol (MCP) — start the @zilliz/claude-context-mcp server, connect via langchain-mcp-adapters, and load semantic code search tools directly into your agent.
This guide shows you how to connect Zilliz's Claude Context repository to popular AI frameworks. Whether you're building retrieval-augmented generation (RAG) pipelines or autonomous coding agents, you'll learn to leverage Claude Context's MCP server for semantic code search within LangChain and LangGraph workflows.
What Is Claude Context?
Claude Context is an open-source semantic code search engine developed by Zilliz. It indexes codebases using abstract syntax tree (AST) parsing, generates embeddings via OpenAI, VoyageAI, or Ollama, and stores vectors in Milvus or Zilliz Cloud.
The repository provides three key components:
| Package | Purpose | Location |
|---|---|---|
@zilliz/claude-context-core |
Indexing engine, embeddings, vector DB | packages/core/ |
@zilliz/claude-context-mcp |
MCP server exposing tools to agents | packages/mcp/ |
langchain-mcp-adapters |
Bridge between MCP and LangChain | External package |
Integration Architecture
The integration follows a three-layer architecture:
LangChain/LangGraph Agent
↓
langchain-mcp-adapters (MultiServerMCPClient)
↓
┌────┴────┐
│ │
Claude-Context File-system
MCP Server MCP Server
│ │
└───────┬───────┘
↓
Milvus / Zilliz Cloud
This design lets your agent combine semantic code search (Claude Context) with file operations (read, list, search) in a unified tool interface.
Prerequisites
Before integrating, ensure you have:
- Node.js (for running the MCP server via
npx) - Python 3.9+ (for LangChain/LangGraph)
- Environment variables configured:
OPENAI_API_KEY— for embeddingsMILVUS_ADDRESS— vector database endpointMILVUS_TOKEN— authentication token
Install the required Python package:
pip install langchain-mcp-adapters
Step-by-Step Integration
Step 1: Start the Claude Context MCP Server
The MCP server runs as a stdio-based process — no network ports required. Launch it via npx:
npx @zilliz/claude-context-mcp@latest
The server exposes these tools to LangChain:
| Tool Name | Description |
|---|---|
index_codebase |
Index a directory using AST or line-based splitting |
search_code |
Semantic search over indexed code |
clear_index |
Remove all vectors for a project |
get_index_status |
Check if a project is indexed |
Step 2: Create a Multi-Server MCP Client
Use MultiServerMCPClient to bundle Claude Context with auxiliary tools. This pattern mirrors the production implementation in evaluation/retrieval/custom.py (lines 72-84):
import os
import sys
from langchain_mcp_adapters.client import MultiServerMCPClient
# Define server configurations
servers = {
"filesystem": {
"command": sys.executable,
"args": ["evaluation/servers/read_server.py"],
"transport": "stdio",
},
"claude-context": {
"command": "npx",
"args": ["-y", "@zilliz/claude-context-mcp@latest"],
"env": {
"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY"),
"MILVUS_ADDRESS": os.getenv("MILVUS_ADDRESS"),
"MILVUS_TOKEN": os.getenv("MILVUS_TOKEN"),
},
"transport": "stdio",
},
}
# Initialize the client
client = MultiServerMCPClient(servers)
Key configuration details:
- Environment variables are passed through
envso the MCP server can authenticate with OpenAI and Milvus transport: "stdio"enables process-based communication without network overhead- Optional servers like
grepcan be added for hybrid text + semantic search
Step 3: Load MCP Tools into LangChain
Convert MCP operations to LangChain Tool objects using load_mcp_tools. This implementation follows evaluation/retrieval/custom.py (lines 85-115):
from langchain_mcp_adapters.tools import load_mcp_tools
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
async def build_claude_context_agent():
"""Assemble a LangChain agent with Claude Context tools."""
async with client.session("filesystem") as fs_sess, \
client.session("claude-context") as cc_sess:
# Load tools from both servers
fs_tools = await load_mcp_tools(fs_sess)
cc_tools = await load_mcp_tools(cc_sess)
# Select the most useful Claude Context tools
search_tool = next(t for t in cc_tools if t.name == "search_code")
index_tool = next(t for t in cc_tools if t.name == "index_codebase")
# Combine all available tools
all_tools = [search_tool, index_tool] + fs_tools
# Initialize the LLM and agent
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
agent = initialize_agent(
all_tools,
llm,
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
handle_parsing_errors=True,
)
return agent
Tool selection strategy:
| Claude Context Tool | When to Use |
|---|---|
index_codebase |
One-time setup per repository; choose "ast" splitter for functions/classes, "line" for raw text |
search_code |
Every query; returns ranked code snippets with file paths and line numbers |
clear_index |
When re-indexing with different settings or after significant codebase changes |
Step 4: Execute Semantic Code Search
With the agent initialized, run natural language queries against your codebase:
import asyncio
async def main():
agent = await build_claude_context_agent()
# Step 1: Index the target repository (if not already indexed)
index_result = await agent.run(
"Index the codebase at ./my-project using the AST splitter. "
"Use project name 'my-project'."
)
print(f"Indexing complete: {index_result}")
# Step 2: Run semantic search queries
search_result = await agent.run(
"Find the function that validates user credentials "
"in the authentication module. Return the file path, "
"line numbers, and a code snippet."
)
print(f"\n🔎 Search result:\n{search_result}")
if __name__ == "__main__":
asyncio.run(main())
Alternative: Direct Core Package Integration
For scenarios requiring finer control than MCP provides, use the core Python package directly:
from zilliz.claude_context_core import Context, OpenAIEmbedding, MilvusVectorDatabase
import os
# Initialize components
embedding = OpenAIEmbedding(
api_key=os.getenv("OPENAI_API_KEY"),
model="text-embedding-3-small"
)
vector_db = MilvusVectorDatabase(
address=os.getenv("MILVUS_ADDRESS"),
token=os.getenv("MILVUS_TOKEN")
)
# Create context
ctx = Context(embedding=embedding, vector_database=vector_db)
# Index and search
async def direct_search():
await ctx.index_codebase("./my-project", splitter="ast")
results = await ctx.semantic_search(
"./my-project",
"credential validation logic",
top_k=5
)
for r in results:
print(f"{r.relative_path}:{r.start_line} - {r.content[:120]}")
This approach bypasses MCP entirely and can be wrapped into a custom LangChain tool if needed.
Key Repository Files for Reference
| File | Purpose | Lines of Interest |
|---|---|---|
evaluation/retrieval/custom.py |
Production MCP client implementation | 72-84 (server setup), 85-115 (tool loading) |
packages/mcp/README.md |
MCP server documentation and environment variables | Full file |
packages/core/README.md |
Core indexing engine API reference | Full file |
README.md (root) |
Quick-start and integration overview | LangChain/LangGraph section |
examples/basic-usage/index.ts |
TypeScript direct MCP usage | Full file |
Summary
-
Claude Context integrates with LangChain and LangGraph through the Model Context Protocol (MCP), using the
langchain-mcp-adapterspackage as the bridge. -
Three integration steps: start the
@zilliz/claude-context-mcpserver, create aMultiServerMCPClient, and load tools viaload_mcp_toolsinto your agent. -
Key tools exposed:
index_codebasefor one-time indexing,search_codefor semantic retrieval, andclear_indexfor index management. -
Production reference: the
evaluation/retrieval/custom.pyfile demonstrates the exact pattern used in Claude Context's own evaluation suite. -
Alternative path: use
@zilliz/claude-context-coredirectly for custom integrations requiring fine-grained control over embedding models and vector storage.
Frequently Asked Questions
How do I connect to a remote Milvus instance from LangChain?
Configure the MILVUS_ADDRESS and MILVUS_TOKEN environment variables in your MultiServerMCPClient server configuration. The MCP server passes these credentials to the core package, which initializes the Milvus connection. Use https:// prefix for TLS-encrypted endpoints.
Can I use Claude Context with LangGraph instead of LangChain agents?
Yes. The load_mcp_tools function returns standard LangChain Tool objects that work with both frameworks. In LangGraph, pass the tools list to your StateGraph or use create_react_agent from langgraph.prebuilt. The tool-calling interface remains identical.
What embedding models does Claude Context support?
The core package supports OpenAI (text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002), VoyageAI (voyage-code-2, voyage-2), and Ollama (local models like nomic-embed-text). Configure via the model parameter in your embedding provider constructor.
How do I index only specific file types in a large repository?
Use the index_codebase tool's include_patterns and exclude_patterns parameters. For example, include ["*.py", "*.ts"] and exclude ["**/test/**", "**/node_modules/**"]. The AST splitter automatically handles language detection based on file extensions.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →