Back to Skills

spring-ai-mcp-server-patterns

Provides Spring Boot MCP server patterns that create Model Context Protocol servers with Spring AI by defining tool handlers, exposing resources, configuring prompt templates, and setting up transports for AI function calling and tool calling. Use when building MCP servers to extend AI capabilities with Spring's official AI framework, implementing AI tools, custom function calling, or MCP client integration.

312stars37forksUpdated 7/30/2026

Security Assessment

Safe(90/100)
Security Score90/100

About spring-ai-mcp-server-patterns

This skill provides production-ready patterns for building Model Context Protocol (MCP) servers with Spring Boot and Spring AI. It solves the problem of exposing Java application capabilities as AI-callable tools, resources, and prompt templates by documenting the canonical annotations, transport configuration, and architectural patterns for AI function/tool calling using Spring's official AI framework.

The skill covers core annotations (@EnableMcpServer, @Tool, @ToolParam, @PromptTemplate, @PromptParam), the three transport types (stdio for local/Claude Desktop, http, and sse for streaming), and Maven/Gradle dependency setup. Step-by-step instructions show project setup with API keys pulled from environment variables, defining @Tool methods inside @Component beans, and building reusable prompt templates. A rich set of reference files goes further into advanced patterns — dynamic runtime tool registration, multi-model selection across OpenAI and Anthropic, caching with Spring's cache abstraction, and security. Notably, the security-oriented examples demonstrate a SecureToolExecutor that authenticates and authorizes callers via Spring Security before running a tool, Bean Validation on tool inputs, and defensive argument checks, alongside examples.md, migration-guide.md, api-reference.md, and testing-guide.md.

It targets Java and Spring developers building MCP servers to extend AI assistants with custom tools, implementing function calling, or integrating MCP clients. The advanced dynamic-registration examples include dispatching to Groovy scripts, Spring beans, or HTTP endpoints, which are legitimate extensibility patterns but warrant care when the registration inputs are externally controlled; the reference pairs them with authentication, authorization, and input-validation guidance.

FAQ

What does this skill help me build?

MCP (Model Context Protocol) servers using Spring Boot and Spring AI — defining tool handlers with @Tool, exposing resources, configuring @PromptTemplate prompt templates, and setting up stdio/HTTP/SSE transports for AI function and tool calling.

What are the core building blocks?

Annotations like @EnableMcpServer to enable the server, @Tool/@ToolParam to declare AI-callable methods and document parameters, and @PromptTemplate/@PromptParam for reusable prompts, all inside Spring @Component beans.

How are API keys handled?

The examples reference model API keys from environment variables (e.g. spring.ai.openai.api-key=${OPENAI_API_KEY}, or System.getenv for OpenAI/Anthropic keys), keeping secrets out of source.

Does it address securing tool execution?

Yes. Advanced patterns include a SecureToolExecutor that checks Spring Security authentication and per-tool permissions before execution, Bean Validation (@Valid) on tool inputs, argument validation, and audit logging.

What transports are supported?

stdio for local processes and Claude Desktop, http for remote HTTP clients, and sse for real-time streaming clients, configured via port and path.

All Files

8 files
references/advanced-patterns.md10.6 KB
View
references/templates/tool-template.java11.6 KB
View
references/examples.md58.5 KB
View
SKILL.md10.4 KB
View
references/migration-guide.md4.4 KB
View
references/api-reference.md35.8 KB
View
references/testing-guide.md7.6 KB
View
references/implementation-patterns.md11.1 KB
View

Install spring-ai-mcp-server-patterns

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill