Get the FREE Ultimate OpenClaw Setup Guide →

java -sql

A very simple MCP (Model Context Protocol) server written in Java for querying and inspecting SQL databases

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio dgdev91-java-mcp-sql-server java -jar C:\path\to\java-mcp-sql-server-1.0.0.jar \
  --env JMCP_MODE="stdio" \
  --env JMCP_JDBC_URL="jdbc:postgresql://localhost:5432/mydb" \
  --env JMCP_HTTP_PORT="3000" \
  --env JMCP_DB_PASSWORD="password" \
  --env JMCP_DB_USERNAME="postgres" \
  --env JMCP_QUERY_SELECT_ONLY="true"

How to use

This Java MCP SQL Server provides a lightweight way to query and inspect SQL databases from the MCP protocol. It supports multiple database engines (PostgreSQL, Oracle, SQL Server, MySQL, MariaDB, and SQLite) and offers tools to list schemas, list tables, inspect table structures, and execute queries. There are two connection modes: Stdio (direct subprocess launch) and HTTP/SSE (remote connection). In stdio mode, you run the server as a child process and communicate via JSON-RPC over stdin/stdout. In HTTP mode, the server exposes an HTTP SSE endpoint at /mcp to which MCP clients connect. The available tools include list_schemas, list_tables, get_table_structure, query_table, and execute_query. By default, only SELECT queries are allowed (JMCP_QUERY_SELECT_ONLY=true). You can set JMCP_MODE to http to enable remote connections and JMCP_HTTP_PORT to choose the port. To connect in HTTP mode, configure your client to point at http://<host>:<port>/mcp and use the provided tools to interact with the database. The README also explains how to configure popular editors (Claude Desktop, VS Code Copilot) to launch the server or connect via HTTP.

How to install

Prerequisites:

  • Java 21 or higher
  • Maven 3.6+ (for building the server from source)
  • Access to a supported database (PostgreSQL, Oracle, SQL Server, MySQL, MariaDB, or SQLite)

Install and build the server:

# Clone the repository (example)
git clone https://github.com/dgdev91-java-mcp-sql-server.git
cd dgdev91-java-mcp-sql-server

# Build the project
mvn clean package

Run in Stdio mode (default, direct launch):

export JMCP_JDBC_URL=jdbc:postgresql://localhost:5432/mydb
export JMCP_DB_USERNAME=postgres
export JMCP_DB_PASSWORD=password
export JMCP_MODE=stdio
java -jar target/java-mcp-sql-server-1.0.0.jar

Run in HTTP/SSE mode (remote connection):

export JDBC_URL=jdbc:postgresql://localhost:5432/mydb
export DB_USERNAME=postgres
export DB_PASSWORD=password
export MCP_MODE=http
export MCP_HTTP_PORT=3000
java -jar target/java-mcp-sql-server-1.0.0.jar

Alternatively, use the prebuilt scripts provided in the project (if available) such as run_http.sh or run_http.ps1 to start the HTTP server.

Configure a client to connect in the chosen mode (stdio or HTTP) as described in the README.

Additional notes

Tips and notes:

  • Environment variables to control behavior:
    • JMCP_JDBC_URL, JMCP_DB_USERNAME, JMCP_DB_PASSWORD: required to connect to the database.
    • JMCP_MODE: stdio (default) or http to enable HTTP/SSE mode.
    • JMCP_HTTP_PORT: port used in http mode (default 3000).
    • JMCP_QUERY_SELECT_ONLY: when true (default), only SELECT queries are allowed; set to false to permit INSERT, UPDATE, DELETE, etc.
  • The server supports querying and inspecting schema details across many database engines; ensure the JDBC URL is correct for your target database.
  • When using HTTP mode, ensure your firewall allows the configured port and configure clients to point to /mcp.
  • In stdio mode, the MCP client must manage the JSON-RPC framing and lifecycle of the server process.
  • For production deployments, consider securing HTTP endpoints and managing credentials outside of environment variable dumps.
  • If you encounter connection errors, verify that the database allows connections from the host running the MCP server and that the JDBC URL, username, and password are correct.

Related MCP Servers

Sponsor this space

Reach thousands of developers