A ReAct agent built with LangChain & LangGraph that reasons over a Couchbase database using tools it discovers at runtime via MCP β ask questions in plain English, get answers from real data.
MCP is an open standard β a universal adapter β that standardizes how AI applications connect to external data and tools. It replaces dozens of one-off integrations with a single interface. Here, the agent never hard-codes a database function; it discovers its tools from an MCP server at runtime.
One protocol instead of N bespoke connectors. Swap the server, keep the agent.
The server decides exactly what the model can see and do β e.g. enforce read-only query mode.
The LLM doesn't just read data β it uses real tools to query and act on live systems.
LangGraph is the brain, MCP is the hands, Couchbase is the knowledge. A single clientβserver handshake turns your database into callable tools.
from langchain_mcp_adapters.client import MultiServerMCPClient from langchain_openai import ChatOpenAI from langgraph.prebuilt import create_react_agent # 1 Β· point the client at the Couchbase MCP server client = MultiServerMCPClient({ "couchbase": { "command": "mcp-server-couchbase", "transport": "stdio", "env": {"CB_CONNECTION_STRING": ..., "READ_ONLY_QUERY_MODE": "true"}, } }) # 2 Β· tools are DISCOVERED, not written by hand tools = await client.get_tools() # 3 Β· wire them into a LangGraph ReAct agent β done agent = create_react_agent(ChatOpenAI(model="gpt-4o-mini"), tools)
A ReAct agent alternates between reasoning and acting until it can answer β every tool it calls comes from the MCP server.
The LLM reads your question and decides what information it needs from the database.
It calls an MCP tool β e.g. run a N1QL query or list the collections in a bucket.
The tool's result flows back into the model's context as fresh evidence.
Once it has enough, the agent writes a natural-language answer grounded in real data.
Three commands to a chat interface over your own Couchbase data. No cluster? Load the free travel-sample bucket on Couchbase Capella.
# clone & install git clone https://github.com/tirth1263/LangGraph-MCP-Agent.git cd LangGraph-MCP-Agent pip install -r requirements.txt # configure your keys cp .env.example .env # then add OPENAI_API_KEY + CB_* values # launch the chat app streamlit run app.py
Everything is open-source under the MIT license β the Streamlit app, a step-by-step notebook, and this site.