
Spring Ai Mcp Server Patterns
Implement Spring Boot MCP servers with @Tool handlers, resources, prompts, and stdio/HTTP/SSE transports for agent function calling.
Overview
Spring AI MCP Server Patterns is an agent skill for the Build phase that implements MCP servers in Spring Boot with tools, prompt templates, and stdio/HTTP/SSE transports.
Install
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill spring-ai-mcp-server-patternsWhat is this skill?
- @EnableMcpServer with @Tool and @ToolParam for AI-callable methods
- @PromptTemplate and @PromptParam for reusable prompt resources
- stdio, HTTP, and SSE transport patterns with Spring AI security
- Production-oriented handler layout for function and tool calling
- Quick-reference table of core MCP annotations and transport use cases
Adoption & trust: 1.2k installs on skills.sh; 271 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need agents to call your Spring services through MCP but lack consistent patterns for tools, resources, transports, and security.
Who is it for?
Solo builders on Spring Boot who want first-class MCP tool exposure instead of bespoke REST shims for each agent.
Skip if: Non-JVM stacks, read-only doc generation, or teams that only consume MCP clients without hosting a server.
When should I use this skill?
building MCP servers with Spring AI, implementing AI tools, custom function calling, or MCP transport configuration
What do I get? / Deliverables
You ship a Spring AI MCP server with documented tool handlers and transport config ready for MCP client integration.
- MCP server module with @Tool and @PromptTemplate handlers
- Transport and security configuration for chosen MCP clients
Recommended Skills
Journey fit
Exposing MCP tools from your product backend happens while building integrations agents can call. Integrations is the right shelf for protocol servers that bridge Spring services to Claude, Cursor, and other MCP clients.
How it compares
Spring Boot server implementation patterns—not a hosted MCP marketplace listing or a Node-only MCP quickstart.
Common Questions / FAQ
Who is spring-ai-mcp-server-patterns for?
Indie and small-team developers using Spring AI who need to author MCP servers with tools, prompts, and transports for AI clients.
When should I use spring-ai-mcp-server-patterns?
During Build while adding MCP servers, Spring AI function calling, custom tool handlers, resource endpoints, or transport configuration for agent integration.
Is spring-ai-mcp-server-patterns safe to install?
Check the Security Audits panel on this page; the skill allows file and shell edits—review generated server code and secrets handling before deploy.
SKILL.md
READMESKILL.md - Spring Ai Mcp Server Patterns
# Spring AI MCP Server Implementation Patterns Implements MCP servers with Spring AI for AI function calling, tool handlers, and MCP transport configuration. ## Overview Production-ready MCP server patterns: `@Tool` functions, `@PromptTemplate` resources, and stdio/HTTP/SSE transports with Spring AI security. ## When to Use MCP servers, Spring AI function calling, AI tools, tool calling, custom tool handlers, Spring Boot MCP, resource endpoints, or MCP transport configuration. ## Quick Reference ### Core Annotations | Annotation | Target | Purpose | |-----------|--------|---------| | `@EnableMcpServer` | Class | Enable MCP server auto-configuration | | `@Tool(description)` | Method | Declare AI-callable tool | | `@ToolParam(value)` | Parameter | Document tool parameter for AI | | `@PromptTemplate(name)` | Method | Declare reusable prompt template | | `@PromptParam(value)` | Parameter | Document prompt parameter | ### Transport Types | Transport | Use Case | Config | |-----------|----------|--------| | `stdio` | Local process / Claude Desktop | Default | | `http` | Remote HTTP clients | `port`, `path` | | `sse` | Real-time streaming clients | `port`, `path` | ### Key Dependencies ```xml <!-- Maven --> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-mcp-server</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-starter-model-openai</artifactId> <version>1.0.0</version> </dependency> ``` ```gradle // Gradle implementation 'org.springframework.ai:spring-ai-mcp-server:1.0.0' implementation 'org.springframework.ai:spring-ai-starter-model-openai:1.0.0' ``` ## Instructions ### 1. Project Setup Add Spring AI MCP dependencies (see Quick Reference above), configure the AI model in `application.properties`, and enable MCP with `@EnableMcpServer`: ```java @SpringBootApplication @EnableMcpServer public class MyMcpApplication { public static void main(String[] args) { SpringApplication.run(MyMcpApplication.class, args); } } ``` ```properties spring.ai.openai.api-key=${OPENAI_API_KEY} spring.ai.mcp.enabled=true spring.ai.mcp.transport.type=stdio ``` ### 2. Define Tools Annotate methods with `@Tool` inside `@Component` beans. Use `@ToolParam` to document parameters: ```java @Component public class WeatherTools { @Tool(description = "Get current weather for a city") public WeatherData getWeather(@ToolParam("City name") String city) { return weatherService.getCurrentWeather(city); } @Tool(description = "Get 5-day forecast for a city") public ForecastData getForecast( @ToolParam("City name") String city, @ToolParam(value = "Unit: celsius or fahrenheit", required = false) String unit) { return weatherService.getForecast(city, unit != null ? unit : "celsius"); } } ``` See [references/implementation-patterns.md](references/implementation-patterns.md) for database tools, API integration tools, and the `FunctionCallback` low-level pattern. ### 3. Create Prompt Templates ```java @Component public class CodeReviewPrompts { @PromptTemplate( name = "java-code-review", description = "Review Java code for best practices and issues" ) public Prompt createCodeReviewPrompt( @PromptParam("code") String code, @PromptParam(value = "focusAreas", required = false) List<S