mcp-jdbc

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Allows querying, modifying, and creating tables in MariaDB databases via JDBC, including SELECT, INSERT, UPDATE, and DELETE operations

  • Enables inspection and manipulation of MySQL database content through SQL queries, with support for table creation and management

  • Provides access to a sample Netflix movie database for exploration and querying through the JDBC interface

JDBC 模型上下文协议服务器

该模型上下文协议 (MCP) 服务器使大型语言模型 (LLM) 能够仅通过 Java 数据库连接 (JDBC) url 来检查、查询、创建和修改数据库内容。

支持的数据库包括 PostgresSQL、Oracle、MariaDB、Sqlite

点击此处观看视频。

一般用法

  1. 安装jbang
  2. 配置您的 MCP 客户端以运行服务器(请参阅下面的Claude 桌面配置

以下是用于配置服务器的命令行示例。

从一个空数据库(内存中的 h2 数据库)开始:

jbang jdbc@quarkiverse/quarkus-mcp-servers

实时数据库(任何常见的 JDBC 兼容数据库):

jbang jdbc@quarkiverse/quarkus-mcp-servers [jdbc_url]

例如,要连接到已运行的 Oracle 数据库:

jbang jdbc@quarkiverse/quarkus-mcp-servers jdbc:oracle:thin:@localhost:1521:orcl

您还可以单独指定用户和密码,这里针对 PostgreSQL 数据库:

jbang jdbc@quarkiverse/quarkus-mcp-servers jdbc:postgresql://localhost:5432/sakila -u sakila -p p_ssW0rd

可下载的数据库

JBang 可以从网络下载文件并将其直接提供给 h2 和 sqlite 等数据库。

这是使用 %{url} 语法完成的。

下面是如何连接到 SQLite 中的 Chinook 数据库的示例,从 github 下载Chinook_Sqlite.sqlite文件。

jbang jdbc@quarkiverse/quarkus-mcp-servers jdbc:sqlite:%{https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite}

网上有一些有趣的样本数据示例,您可以用它们来探索数据。

以下是已知可与该服务器一起使用(无需额外配置)的数据库和示例 JDBC URL 的非详尽列表。

示例数据库

奇努克

样本音乐商店数据包括艺术家、专辑、曲目、发票等。

jdbc:sqlite:%{https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite}

北风

经典的 Microsoft 示例数据库,包含客户、订单、产品等。

jdbc:sqlite:%{https://github.com/jpwhite3/northwind-SQLite3/raw/refs/heads/main/dist/northwind.db}

Netflix电影

基于 Netflix 目录的电影数据样本

jdbc:sqlite:%{https://github.com/lerocha/netflixdb/releases/download/v1.0.0/netflixdb.sqlite}

支持的 JDBC 变体

数据库依赖关系
MariaDBorg.mariadb.jdbc:mariadb-java-client:发布
MySQLmysql:mysql-连接器-java:发布
PostgreSQLorg.postgresql:postgresql:发布
甲骨文com.oracle.database.jdbc:ojdbc10:RELEASE
SQL 服务器com.microsoft.sqlserver:mssql-jdbc:RELEASE
SAP 数据库com.sapcloud.db.jdbc:ngdbc:发布
Informixcom.ibm.informix:jdbc:RELEASE
火鸟org.firebirdsql.jdbc:jaybird:发布
数据库org.hsqldb:hsqldb:发布
h2com.h2database:h2:RELEASE
阿帕奇德比org.apache.derby:derby:RELEASE
SQLiteorg.xerial:sqlite-jdbc:发布

成分

以下是该服务器提供的 MCP 组件。

工具

  • read_query - 在数据库上执行 SELECT 查询
  • write_query - 在数据库上执行 INSERT、UPDATE、DELETE 查询
  • **create_table——**在数据库中创建表
  • **list_tables——**列出数据库中的所有表
  • **describe_table-**描述一个表

提示

  • jdbc_demo - 开始探索服务器的示例提示(类似于 sqllite MCP 中的提示)

Claude 桌面配置和mcp-cli

将其添加到您的claude_desktop_config.jsonserver_config.json文件中:

{ "mcpServers": { "jdbc": { "command": "jbang", "args": [ "jdbc@quarkiverse/quarkus-mcp-servers", "[jdbc_url]" ] } } }

故障排除

未找到 jbang

  • 确保已安装jbang并且它在你的 PATH 中可用
  • 或者,使用 jbang 可执行文件的完整路径(例如/Users/username/.jbang/jbang

获取更多日志

为了获得更详细的日志记录,您可以将以下参数添加到 jbang 命令行:

-Dquarkus.log.file.enable=true -Dquarkus.log.file.path=${user.home}/mcp-server-jdbc.log

例子:

jbang -Dquarkus.log.file.enable=true -Dquarkus.log.file.path=${user.home}/mcp-jdbc.log jdbc@quarkiverse/quarkus-mcp-servers jdbc:h2:mem:testdb

原生映像/可执行文件

虽然服务器可以编译为本机可执行文件,但不建议这样做,因为这样就无法动态加载相关的 JDBC 驱动程序。

当然,你也可以编译一个针对特定 JDBC 驱动程序的服务器,但这暂时留给读者练习。如果你对此感兴趣,请提交 issue 或 PR。

这是怎么做出来的?

MCP 服务器使用 Quarkus、超音速亚原子 Java 框架及其模型上下文协议支持。

如果您想了解有关 Quarkus MCP Server 支持的更多信息,请参阅此博客文章和 Quarkus MCP Server扩展文档

为了启动服务器并处理 JDBC URL 的神奇设置,它使用jbang来设置 Java 并尽可能透明地运行 .jar 文件。与uvxpipxnpmx和其他库的工作原理非常相似;只不过是针对 Java 的。

-
security - not tested
A
license - permissive license
-
quality - not tested

MCP 可访问任何可通过 JDBC 访问的数据库,例如 Postgres、Oracle、mysql、mariadb、sqlite 等。

  1. General Usage
    1. Downloadable databases
      1. Example databases
    2. Supported JDBC variants
      1. Components
        1. Tools
        2. Prompts
      2. Claude Desktop Config and mcp-cli
        1. Troubleshooting
      3. Native Image/Executable
        1. How was this made?
      ID: 2au072rrbc