mcp-server-with-spring-ai Details

mcp-server-with-spring-ai is a Spring Boot integrated MCP (Model Context Protocol) server example that showcases how to expose executable tools from an MCP server to clients (including LLMs) and how to wire a MCP client to consume those tools. The documentation explains MCP at a high level, outlines the three-layer MCP Java SDK architecture (Client/Server Layer, Session Layer, Transport Layer), and demonstrates two sample tools implemented in SellerAccountTools. This repo emphasizes how an MCP server can connect to external data sources (e.g., a PostgreSQL DB) and expose tools that an AI model can invoke to retrieve data, with the example illustrating tool invocation and automatic tool selection by prompts.

Use Case

Use this MCP server to enable AI models (including LLMs) to interact with external data sources via well-defined tools exposed by the server. In the example, two tools are exposed to search a SellerAccounts table by name or by owner. The MCP architecture is described as three-layer: Client/Server Layer (McpClient and McpServer), Session Layer (McpSession with DefaultMcpSession), and Transport Layer (McpTransport for JSON-RPC with multiple transports). The server exposes tools that the client can invoke, allowing the LLM to select the correct tool based on the prompt.

Code example (as provided in the docs):

@Service
public class SellerAccountTools {
private final SellerAccountRepository sellerAccountRepository;

public SellerAccountTools(SellerAccountRepository sellerAccountRepository) {
this.sellerAccountRepository = sellerAccountRepository;
}

@Tool(name = "Search Seller account by name", description = "Find all Seller Accounts by name")
public String getAccountByName(
@ToolParam(description = "Seller Account Name") String name) {
List<SellerAccount> accountList = sellerAccountRepository.findByName(name);
StringBuilder result = new StringBuilder();
for (SellerAccount account : accountList) {
result.append(account.toString()).append("\n");
}
return result.toString();
}

@Tool(description = "Find all Seller Accounts by owner")
public String getAccountByOwner(
@ToolParam(description = "Seller Account owner") String owner) {
List<SellerAccount> accountList = sellerAccountRepository.findByOwner(owner);
StringBuilder result = new StringBuilder();
for (SellerAccount account : accountList) {
result.append(account.toString()).append("\n");
}
return result.toString();
}
}

Explanation

  • Tools allows server to expose tools that can be invoked by LLM, for this example i have created two tools which will search from account table by Name and by Owner.

  • Based on the prompt AI LLM will automatocally pick the correct method but we need to write name and descrition properly
  • Available Tools (2)

    Examples & Tutorials

    @Service
    public class SellerAccountTools {
    private final SellerAccountRepository sellerAccountRepository;

    public SellerAccountTools(SellerAccountRepository sellerAccountRepository) {
    this.sellerAccountRepository = sellerAccountRepository;
    }

    @Tool(name = "Search Seller account by name", description = "Find all Seller Accounts by name")
    public String getAccountByName(
    @ToolParam(description = "Seller Account Name") String name) {
    List<SellerAccount> accountList = sellerAccountRepository.findByName(name);
    StringBuilder result = new StringBuilder();
    for (SellerAccount account : accountList) {
    result.append(account.toString()).append("\n");
    }
    return result.toString();
    }

    @Tool(description = "Find all Seller Accounts by owner")
    public String getAccountByOwner(
    @ToolParam(description = "Seller Account owner") String owner) {
    List<SellerAccount> accountList = sellerAccountRepository.findByOwner(owner);
    StringBuilder result = new StringBuilder();
    for (SellerAccount account : accountList) {
    result.append(account.toString()).append("\n");
    }
    return result.toString();
    }
    }

    Installation Guide

    Step 1 Create Postgresql DB

    Run docker-compose.yml file and run the table.sql to create table.

    Step 2 Run ollama locally

    Download ollama and run any model as per you machine capacity

    Step 3 Creating MCP Server

    Download the mcp-server project and run it.

    Important classes to note - SellerAccountTools

    Step 4 Creating MCP Client

    Download the mcp-client project and run.

    Step 5 Testing

    DB Table Data

    !image

    Frequently Asked Questions

    Is this your MCP?

    Claim ownership and get verified badge

    Repository Stats
    Important Notes

    Tools allows server to expose tools that can be invoked by LLM, for this example i have created two tools which will search from account table by Name and by Owner. Based on the prompt LLM will automatically pick the correct method and it will format the results.

    Details
    Last Updated3/17/2026
    SourceGitHub

    Compare Alternatives

    Similar MCP Tools

    6 related tools
    Anki MCP Server

    Anki MCP Server

    A Model Context Protocol (MCP) server that enables AI assistants to interact with Anki, the spaced repetition flashcard application. The Anki MCP Server allows AI models to access Anki's card data, enabling features like automated flashcard creation, review, and management.

    1MCP Agent

    1MCP Agent

    A unified Model Context Protocol server implementation that aggregates multiple MCP servers into one. The 1mcp-app/agent is an open-source project that provides a single entry point for multiple MCP servers, making it easier to manage and interact with various AI models and tools.

    Roundtable AI MCP Server

    Roundtable AI MCP Server

    Roundtable AI MCP Server is a zero-configuration local MCP server that unifies multiple AI coding assistants (Codex, Claude Code, Cursor, Gemini) through intelligent auto-discovery and a standardized interface. It coordinates specialized sub-agents from within your IDE to solve engineering problems in parallel, sharing context and synthesizing responses into a single, high-quality output. This documentation details installation, available MCP tools, integration with popular IDEs, and a broad ecosystem of specialized tools and CLIs that can be invoked as part of a roundtable-powered workflow, enabling developers to delegate tasks to the right AI for each facet of a problem without leaving their development environment.

    MCPJungle

    MCPJungle

    MCPJungle is a self-hosted MCP Gateway and Registry for AI agents. It serves as a central registry and gateway to manage Model Context Protocol (MCP) servers and the tools they expose. By consolidating MCP server registration, tool discovery, and access control, MCPJungle enables AI agents and clients to discover, group, and securely invoke tools from a single, unified gateway. The project provides a CLI, Docker-based deployment options, and enterprise-ready features such as tool grouping, access control, and observability to streamline MCP-based workflows across organizations.

    mcpmcp-server

    mcpmcp-server

    mcpmcp-server is a focused solution for discovering, setting up, and integrating MCP servers with your favorite clients to unlock AI-powered workflows. It streamlines how you connect MCP-powered servers to popular clients, enabling seamless AI-assisted interactions across your daily tools. The project emphasizes an approachable, config-driven approach to linking MCP servers with clients like Claude Desktop, while directing you to the homepage for variations across apps and platforms. This README highlights a practical JSON configuration example and notes on supported environments, helping you get started quickly and confidently.

    Imagen3-MCP

    Imagen3-MCP

    Imagen3-MCP is an image generation service based on Google's Imagen 3.0 that exposes its functionality through MCP (Model Control Protocol). The project provides a server to run a local MCP service that accesses Google Gemini-powered image generation, enabling developers to integrate advanced image synthesis into their applications. The documentation covers prerequisites (Gemini API key), installation steps for Cherry Studio, and a Cursor-based JSON configuration example for embedding the MCP server in broader tooling. This MCP is designed to be deployment-friendly, with configurable environment variables and optional proxy settings to adapt to various network environments.