MCPSERV.CLUB
lucasdengcn

Spring AI MCP Server

MCP Server

Real‑time AI context server with SSE support

Stale(50)
0stars
1views
Updated Mar 25, 2025

About

A Spring Boot implementation of the Model Context Protocol (MCP) server, providing WebFlux and WebMvc SSE endpoints for AI tools and proposals. It integrates Spring AI, Ollama models, PGVector, and H2 for a full AI workflow.

Capabilities

Resources
Access data sources
Tools
Execute functions
Prompts
Pre-built templates
Sampling
AI model interactions

Spring AI Example in Action

Overview

The Spring AI Example MCP server demonstrates how a modern Java framework can expose rich, AI‑powered capabilities to external assistants. By leveraging Spring Boot and the Spring AI ecosystem, the server implements the Model Context Protocol (MCP) with both WebFlux and traditional WebMvc support for Server‑Sent Events (SSE). This dual‑stack design allows developers to choose the reactive or imperative style that best fits their application while still providing a single, well‑defined MCP endpoint for AI clients such as Claude or GPT‑based assistants.

At its core, the server solves a common pain point: how to turn existing business logic into AI‑accessible tools without rewriting the codebase. Using Spring’s annotation, any ordinary method can be exposed as an AI tool. The server automatically serializes the method signature into a JSON schema, registers it with the MCP catalog, and handles incoming tool calls. Developers can further customize the serialization through classes or inject contextual information via . This pattern keeps the codebase clean, encourages reuse of existing services, and ensures that tool definitions remain in sync with their Java implementations.

Key features include:

  • Method‑as‑Tool: Annotate any service method with to expose it instantly. Parameters can be described with , providing clear documentation for the AI client.
  • Custom Result Conversion: Implement a converter to shape tool outputs into any desired JSON format, enabling seamless integration with downstream AI workflows.
  • Contextual Awareness: Inject to access request metadata, user identity, or other contextual data during tool execution.
  • SSE Support: Both WebFlux and WebMvc SSE implementations allow the server to stream real‑time updates, which is essential for conversational agents that need to push incremental responses or status changes.
  • Integrated AI Back‑end: The project bundles an Ollama model, a PGVector vector store for semantic search, and an H2 database for rapid prototyping. This stack demonstrates how to combine language models with structured data and vector embeddings in a single MCP service.

Real‑world scenarios that benefit from this architecture include:

  • Automated Proposal Generation: The companion module showcases how an MCP client can call the server’s tools to fetch customer data, compute pricing, and assemble a proposal document—all orchestrated by an AI assistant.
  • Dynamic FAQ or Knowledge Base: By exposing search and retrieval tools, a chatbot can answer user queries using up‑to‑date information stored in the vector index.
  • Workflow Automation: Tools that trigger alarms, schedule events, or update databases can be invoked directly from an AI conversation, turning a chat interface into a lightweight workflow engine.

By abstracting tool registration and execution behind MCP, developers can focus on business logic while still offering AI clients a rich, discoverable API surface. The Spring AI Example serves as both a reference implementation and a starting point for building production‑grade MCP servers that blend reactive streams, vector search, and model inference into a single cohesive service.