Skip to main content
Integrate your databases with LangChain agents using MCP Toolbox.

Overview

MCP Toolbox for Databases is an open source MCP server for databases. It was designed with enterprise-grade and production-quality in mind. It enables you to develop tools easier, faster, and more securely by handling the complexities such as connection pooling, authentication, and more. Toolbox Tools can be seamlessly integrated with LangChain applications. For more information on getting started or configuring MCP Toolbox, see the documentation. architecture

Setup

This guide assumes you have already done the following:
  1. Installed Python 3.9+ and pip.
  2. Installed PostgreSQL 16+ and the psql command-line client.

1. Setup your Database

First, let’s set up a PostgreSQL database. We’ll create a new database, a dedicated user for MCP Toolbox, and a hotels table with some sample data. Connect to PostgreSQL using the psql command. You may need to adjust the command based on your PostgreSQL setup (e.g., if you need to specify a host or a different superuser).
Now, run the following SQL commands to create the user, database, and grant the necessary permissions:
Connect to your newly created database with the new user:
Finally, create the hotels table and insert some data:
You can now exit psql by typing \q.

2. Install MCP toolbox

Next, we will install MCP Toolbox, define our tools in a tools.yaml configuration file, and run the MCP Toolbox server. For macOS users, the easiest way to install is with Homebrew:
For other platforms, download the latest MCP Toolbox binary for your operating system and architecture. Create a tools.yaml file. This file defines the data sources MCP Toolbox can connect to and the tools it can expose to your agent. For production use, always use environment variables for secrets.
Now, in a separate terminal window, start the MCP Toolbox server. If you installed via Homebrew, you can just run toolbox. If you downloaded the binary manually, you’ll need to run ./toolbox from the directory where you saved it:
MCP Toolbox will start on http://127.0.0.1:5000 by default and will hot-reload if you make changes to your tools.yaml file.

Instantiation

Invocation

Use within an agent

Now for the fun part! We’ll install the required LangChain packages and create an agent that can use the tools we defined in MCP Toolbox.
With the packages installed, we can define our agent. We will use ChatVertexAI for the model and ToolboxClient to load our tools. The create_agent from langchain.agents creates a robust agent that can reason about which tools to call. Note: Ensure your MCP Toolbox server is running in a separate terminal before executing the code below.

Run the agent

You’ve successfully connected a LangChain agent to a local database using MCP Toolbox! 🥳

API reference

The primary class for this integration is ToolboxClient. For more information, see the following resources: MCP Toolbox has a variety of features to make developing Gen AI tools for databases seamless:

Community and support

We encourage you to get involved with the community: