Reasoning agent Β· live database Β· zero custom tools

Give an LLM a live database
through the Model Context Protocol

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.

LangChain LangGraph create_react_agent MCP langchain-mcp-adapters Couchbase Streamlit
The core idea

What is the Model Context Protocol?

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.

πŸ”Œ

Standardized

One protocol instead of N bespoke connectors. Swap the server, keep the agent.

πŸ”’

Secure by design

The server decides exactly what the model can see and do β€” e.g. enforce read-only query mode.

πŸ› οΈ

Actionable

The LLM doesn't just read data β€” it uses real tools to query and act on live systems.

Under the hood

Architecture

LangGraph is the brain, MCP is the hands, Couchbase is the knowledge. A single client–server handshake turns your database into callable tools.

πŸ§‘ You
plain English
β†’
ReAct Agent
LangGraph
β†’
MCP Adapter
get_tools()
β†’
MCP Server
couchbase
β†’
πŸ—„οΈ Couchbase
N1QL
agent.py β€” the whole thing in ~12 lines
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)
The ReAct loop

How the agent thinks

A ReAct agent alternates between reasoning and acting until it can answer β€” every tool it calls comes from the MCP server.

Reason

The LLM reads your question and decides what information it needs from the database.

Act

It calls an MCP tool β€” e.g. run a N1QL query or list the collections in a bucket.

Observe

The tool's result flows back into the model's context as fresh evidence.

Answer

Once it has enough, the agent writes a natural-language answer grounded in real data.

Run it yourself

Quickstart

Three commands to a chat interface over your own Couchbase data. No cluster? Load the free travel-sample bucket on Couchbase Capella.

terminal
# 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
Ready to explore

Dive into the code & the tutorial

Everything is open-source under the MIT license β€” the Streamlit app, a step-by-step notebook, and this site.