The MCP Server ODBC via SQLAlchemy is a lightweight server that connects your AI models to databases through ODBC using FastAPI, pyodbc, and SQLAlchemy. It allows AI assistants to interact with databases by fetching schemas, retrieving table information, executing SQL queries, and more.
pip install uv
Or using Homebrew:
brew install uv
View installation configuration:
odbcinst -j
List available data source names:
odbcinst -q -s
Configure your ODBC Data Source Name in ~/.odbc.ini
. Example for Virtuoso DBMS:
[VOS]
Description = OpenLink Virtuoso
Driver = /path/to/virtodbcu_r.so
Database = Demo
Address = localhost:1111
WideAsUTF16 = Yes
Use the following format for Virtuoso:
virtuoso+pyodbc://user:password@VOS
Clone the repository:
git clone https://github.com/OpenLinkSoftware/mcp-sqlalchemy-server.git
cd mcp-sqlalchemy-server
Update your .env
file to override the defaults:
ODBC_DSN=VOS
ODBC_USER=dba
ODBC_PASSWORD=dba
API_KEY=xxx
For Claude Desktop users, add the following to your claude_desktop_config.json
:
{
"mcpServers": {
"my_database": {
"command": "uv",
"args": ["--directory", "/path/to/mcp-sqlalchemy-server", "run", "mcp-sqlalchemy-server"],
"env": {
"ODBC_DSN": "dsn_name",
"ODBC_USER": "username",
"ODBC_PASSWORD": "password",
"API_KEY": "sk-xxx"
}
}
}
}
Here are tested pyodbc URL examples for different database systems:
Database | URL Format |
---|---|
Virtuoso DBMS | virtuoso+pyodbc://user:password@ODBC_DSN |
PostgreSQL | postgresql://user:password@localhost/dbname |
MySQL | mysql+pymysql://user:password@localhost/dbname |
SQLite | sqlite:///path/to/database.db |
Retrieves all schema names from the connected database.
Parameters:
user
(optional): Database username (default: "demo")password
(optional): Database password (default: "demo")dsn
(optional): ODBC data source name (default: "Local Virtuoso")Returns: JSON array of schema names
Lists table information for a specified schema.
Parameters:
schema
(optional): Database schema (default: connection default)user
(optional): Database username (default: "demo")password
(optional): Database password (default: "demo")dsn
(optional): ODBC data source name (default: "Local Virtuoso")Returns: JSON with table information (catalog, schema, name, type)
Provides detailed information about a table's structure.
Parameters:
schema
(required): Database schema nametable
(required): Table name to describeuser
(optional): Database username (default: "demo")password
(optional): Database password (default: "demo")dsn
(optional): ODBC data source name (default: "Local Virtuoso")Returns: JSON with table column details (names, types, sizes, constraints)
Searches for tables containing a specific substring.
Parameters:
q
(required): Substring to search for in table namesschema
(optional): Database schema to search inuser
(optional): Database username (default: "demo")password
(optional): Database password (default: "demo")dsn
(optional): ODBC data source name (default: "Local Virtuoso")Returns: JSON with matching table information
Executes SQL queries and returns results in JSON format.
Parameters:
query
(required): SQL query to executeuser
(optional): Database username (default: "demo")password
(optional): Database password (default: "demo")dsn
(optional): ODBC data source name (default: "Local Virtuoso")Returns: Query results as JSON
For easier debugging:
Install the MCP Inspector:
npm install -g @modelcontextprotocol/inspector
Start the inspector:
npx @modelcontextprotocol/inspector uv --directory /path/to/mcp-sqlalchemy-server run mcp-sqlalchemy-server
Access the provided URL to monitor server interactions
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.