mcp -with-spring-ai
Build your own mcp server with spring ai
claude mcp add --transport stdio kuldeepsingh99-mcp-server-with-spring-ai java -jar mcp-server-with-spring-ai.jar \ --env SPRING_PROFILES_ACTIVE="Spring profile (e.g., default)"
How to use
This MCP server provides a Spring Boot-based MCP implementation that exposes tools for interacting with a Postgres-backed dataset via the MCP protocol. It extends the MCP Java SDK with Spring integration, offering both client and server capabilities so you can connect an LLM-driven client to the server and invoke server-side tools. The example in the repository showcases two tools, defined in SellerAccountTools: a method to search seller accounts by name and another to search by owner. These tools are annotated and exposed to the MCP runtime so that an LLM can dynamically choose the appropriate tool based on the user prompt and the tool descriptions. To use it, run the server, connect an MCP client, and prompt the LLM to call the tool names (or descriptions) such as "Search Seller account by name" or "Find all Seller Accounts by owner". The server will execute the requested operation against the Postgres data and return results in a structured text payload.
How to install
Prerequisites:
- Java JDK 11+ and Maven installed on your machine
- Docker (optional, for local Postgres DB via docker-compose)
- Access to the MCP client you plan to use (Java-based or any compatible client)
Step 1: Prepare the database (optional, if using the example)
- Follow the repository's guidance to bring up PostgreSQL and initialize tables using docker-compose:
docker-compose up -d
# In a separate step, execute the provided SQL schema (table.sql) to create tables
Step 2: Build the MCP server
- Clone the repository and navigate to the server module
git clone <repository-url>
cd mcp-server-with-spring-ai
mvn -e -DskipTests package
Step 3: Run the MCP server
- Start the server with Java (using the generated jar):
java -jar target/mcp-server-with-spring-ai.jar
Step 4: Run the MCP client (example)
- Ensure your MCP client is configured to connect to the server's transport (stdio, SSE, or HTTP as supported by your setup) and start the client.
- Prompt the LLM with queries that reference the available tools, e.g., "Search Seller account by name: Acme" or "Find all Seller Accounts by owner: John Doe".
Step 5: Optional tooling and model runtime
- If you want to run models locally, install Ollama or any compatible LLM runtime as shown in the project README and configure the client to use it for tool selection and invocation.
Additional notes
Notes and tips:
- The server exposes two sample tools under SellerAccountTools. The LLM selects the appropriate tool based on the prompt and the tool annotations (name/description).
- Ensure your database credentials and connection URL are configured in the Spring Boot application properties (e.g., application.properties or environment variables) to allow the server to query Postgres.
- When running locally, you can use docker-compose to bring up the Postgres instance and seed data before starting the MCP server.
- If you modify tools or add new ones, ensure proper tool annotations (@Tool, @ToolParam) so the MCP runtime can expose them to clients cleanly.
- For transport, MCP supports stdio and SSE; choose the one that fits your deployment scenario (local processes vs. HTTP-based services).
- Monitor logs for tool invocations to debug tool selection and results formatting.
Related MCP Servers
mesh
One secure endpoint for every MCP server. Deploy anywhere.
Remote
A type-safe solution to remote MCP communication, enabling effortless integration for centralized management of Model Context.
quarkus-workshop-langchain4j
Quarkus Langchain4J Workshop
mcp-zap
A Spring Boot application exposing OWASP ZAP as an MCP (Model Context Protocol) server. It lets any MCP‑compatible AI agent (e.g., Claude Desktop, Cursor) orchestrate ZAP actions—spider, active scan, import OpenAPI specs, and generate reports.
mcpx-py
Python client library for https://mcp.run - call portable & secure tools for your AI Agents and Apps
google-scholar
An MCP server for Google Scholar written in TypeScript with Streamable HTTP