GitHub Stars
0
User Rating
Not Rated
Favorites
0
Views
18
Forks
0
Issues
0
Spring AI MCP Database Schema Server
A Model Context Protocol (MCP) server built with Spring Boot and Spring AI that provides tools to inspect a PostgreSQL database schema. This server is designed to work with Cursor and other MCP clients that support SSE transport.
Features
- Get schema (columns, types) for a specific table (
getTableSchematool) - Get outgoing foreign key dependencies for a table (
getTableDependenciestool) - Get incoming foreign key references to a table (
getTableReferencedBytool) - Execute arbitrary SQL SELECT queries (
executeSqltool) - USE WITH EXTREME CAUTION! - Uses Server-Sent Events (SSE) for communication.
Prerequisites
- Java 17 or higher
- Maven 3.6 or higher
- PostgreSQL database accessible from where the server runs
- An MCP Client that supports SSE transport (e.g., Cursor)
Configuration
- Database Connection: Update the database connection details (URL, username, password) in
src/main/resources/application.yml.
Security Warning: It is strongly recommended to configure a read-only database user inapplication.ymlif you intend to use theexecuteSqltool, to minimize potential damage from unintended queries.
Building the Server
To build the server, run:
mvn clean package
This will create an executable JAR file in the target directory (e.g., mcp-weather-spring-1.0-SNAPSHOT.jar).
Running the Server
Run the server using the standard Spring Boot command:
java -jar target/mcp-weather-spring-1.0-SNAPSHOT.jar
The server will start on port 8080 by default and attempt to connect to the configured database.
Configuring Cursor
- Ensure the server is running.
- Open your Cursor MCP configuration file:
- Project Specific:
.cursor/mcp.jsonin your project root. - Global:
~/.cursor/mcp.jsonin your home directory.
- Project Specific:
- Add or update the server configuration to use SSE:
{
"mcpServers": {
"PostgresSchemaServer": {
"transport": "sse",
"url": "http://localhost:8080/sse"
}
// Add other servers here if needed
}
}
- Restart Cursor.
Usage Examples in Cursor
Once the server is running, connected to the database, and Cursor is configured and restarted:
- Open the chat or use the Agent (
Cmd+K/Ctrl+K). - The tools
getTableSchema,getTableDependencies,getTableReferencedBy, andexecuteSqlfromPostgresSchemaServershould be available. - Ask questions like:
- "Use PostgresSchemaServer to get the schema for the 'users' table."
- "What are the dependencies of the 'orders' table?"
- "Which tables reference the 'products' table?"
- (Use with Caution!) "Execute the SQL query 'SELECT first_name, email FROM customers WHERE customer_id = 1' using the executeSql tool."
- (Use with Caution!) "First get the schema for the customers table, then execute a SQL query to select the email for the customer named Alice Smith."
WARNING: The executeSql tool allows running SQL queries provided by the LLM. This is inherently risky. Only use this tool if you understand the risks and have appropriate security measures in place (like a read-only database user).
Troubleshooting
- Server Connection Issues:
- Verify the server is running (check the terminal output).
- Ensure the
urlin.cursor/mcp.jsonmatches the server's address and port (default:http://localhost:8080/sse). - Check for firewall issues blocking the connection between Cursor and the server.
- Database Connection Errors:
- Check the server startup logs for errors related to database connection.
- Verify the database credentials and URL in
application.ymlare correct. - Ensure the PostgreSQL server is running and accessible.
- Tool Not Found/Working:
- Restart Cursor after configuring
mcp.json. - Check the server logs for errors when a tool is called (e.g., table not found, SQL errors).
- Restart Cursor after configuring
- executeSql Errors:
- The tool currently only allows queries starting with
SELECT(case-insensitive). - Check server logs for detailed SQL execution errors from the database driver.
- The tool currently only allows queries starting with
0
Followers
0
Repositories
0
Gists
0
Total Contributions
discord-mcp is a Java-based application that integrates with Discord servers to provide functionalities utilizing the Model Context Protocol (MCP). Users can retrieve server information through APIs and leverage tools that enhance communication efficiency. It serves as a valuable resource, especially for developers and community managers.