Securing a Spring Boot MCP server
Secure a Spring AI MCP server by adding the community mcp-server-security module with Spring Security, configuring the OAuth 2.0 resource server with your issuer URL, and protecting individual tools with method security. Check the protocol, endpoint path and any permit-all matchers before deploying. Spring documents the module as community-driven and work in progress.
Facts read on .
How do you add authentication to a Spring AI MCP server?
Add the mcp-server-security module, Spring Security and, for OAuth 2.0, the OAuth2 resource server starter, then configure the MCP resource server with your authorization server's issuer URI. The Spring AI reference lists org.springaicommunity:mcp-server-security, spring-boot-starter-security and spring-boot-starter-oauth2-resource-server as the dependencies, and shows a security filter chain that applies the MCP OAuth configurer with the issuer URL as the required setting.
The module also supports API key authentication in a basic form. Prefer OAuth for anything beyond a single trusted caller, because the MCP authorization specification is built on OAuth 2.1.
Sources: Spring AI reference: MCP Security; MCP specification: Authorization (2025-11-25).
Which settings expose the server?
The protocol, the endpoint path and the request matchers decide what is reachable. The server starter selects the transport with spring.ai.mcp.server.protocol, where STREAMABLE enables streamable HTTP, and the streamable endpoint defaults to /mcp.
Read every matcher in your filter chain. A permitAll rule on the MCP path in a copied sample opens the tools to anyone who can reach it, and the OWASP guidance is to require authentication whenever a remote endpoint exposes non-public tools or data. The reference also notes that using MCP Inspector may need CSRF and CORS protection disabled; treat that as a development setting and keep it out of deployed configuration.
If the server is meant only for local clients, keep it off public interfaces: the MCP transport specification says local servers should bind only to localhost and must validate the Origin header on HTTP connections.
Sources: Spring AI reference: Streamable-HTTP MCP Servers; Spring AI reference: MCP Security; OWASP MCP Security Cheat Sheet; MCP specification: Transports (2025-11-25).
How do you protect individual tools?
Annotate tool methods with Spring Security's method security so each tool checks the caller. The reference shows an @PreAuthorize annotation on an @McpTool method with isAuthenticated() as the expression.
Go further than authenticated: use authorities or scopes per tool, so a read tool and a delete tool need different grants. This matches the specification's scope minimization guidance and OWASP's advice to request narrow scopes.
Test the result with a token that is missing the required authority. The call should fail with an authorization error and the tool body should never run, and that test belongs in the build so a refactor cannot remove an annotation unnoticed.
Sources: Spring AI reference: MCP Security; MCP specification: Security Best Practices (2025-11-25); OWASP MCP Security Cheat Sheet.
What does the module leave to you?
The module covers authentication and tool authorization; it does not review your tool code. Validate every tool argument as untrusted, avoid building shell commands or file paths from raw input, and restrict outbound URLs.
Spring documents the module as community-driven and not yet endorsed by Spring AI or the MCP project, compatible with WebMVC-based servers only, so check the project repository for the Spring AI version it supports before upgrading.
Keep the authorization server separate from the MCP server where you can. The module family includes an authorization server component, but a shared identity provider with audit trails and revocation is easier to operate and review.
Sources: Spring AI reference: MCP Security; OWASP MCP Security Cheat Sheet.
How do you disable operations you do not need?
Turn off what the deployment does not use. The streamable-HTTP properties include a disallow-delete setting, which defaults to false, and the stateless protocol option avoids server-held sessions entirely.
The MCP security best practices say servers must not use sessions for authentication, so whichever mode you pick, verify the token on each request.
Sources: Spring AI reference: Streamable-HTTP MCP Servers; MCP specification: Security Best Practices (2025-11-25).
Sources
- Spring AI reference: MCP Security (docs.spring.io), read
- Spring AI reference: Streamable-HTTP MCP Servers (docs.spring.io), read
- MCP specification: Authorization (2025-11-25) (modelcontextprotocol.io), read
- MCP specification: Security Best Practices (2025-11-25) (modelcontextprotocol.io), read
- OWASP MCP Security Cheat Sheet (cheatsheetseries.owasp.org), read
- MCP specification: Transports (2025-11-25) (modelcontextprotocol.io), read