An MCP resource is a named, described, URI-addressable source of contextual content exposed by an MCP server. It can provide textual or binary data related to the server’s domain, allowing an application to supply structured context alongside user-generated prompts. section 7.5
Spring AI supports two implementation styles:
- Declare a resource specification in a @Bean method, describing its URI, name, description, MIME type, annotations, and read behavior. section 7.5.1
- Build the resource content from domain data, such as repository results, then return it through a ReadResourceResult. section 7.5.1
- Use an annotated service method with @McpResource when the community annotation project’s simpler declaration style is appropriate. section 7.5.2
Game List resource
A resource at games://game-list can query the game repository, format each title as a line of text, and expose the result with the name “Game List” and MIME type text/plain. MCP Inspector can list and display the returned resource. section 7.5.1
Listing 7.6 Exposing a resource using Spring configuration
@Bean
public List<McpServerFeatures.SyncResourceSpecification>
gameResources(GameRepository gameRepository) {
List<McpSchema.Role> audience = List.of(McpSchema.Role.USER);
McpSchema.Annotations annotations =
new McpSchema.Annotations(audience, 1.0);
var gameListResource = new McpSchema.Resource( #1
"games://game-list",
"Game List",
"A list of games available in the repository",
"text/plain",
annotations
);
var gameTitles = gameRepository.findAllTitles(); #2
var gameListText = new StringBuilder();
for (String title : gameTitles) {
gameListText.append("- ").append(title).append("\n");
}
var gameListResourceSpec =
new McpServerFeatures.SyncResourceSpecification( #3
gameListResource, (exchange, request) -> {
return new McpSchema.ReadResourceResult(
List.of(new McpSchema.TextResourceContents(
request.uri(),
"text/plain",
gameListText.toString())));
});
return List.of(gameListResourceSpec); #4
}
Inspect the complete Spring configuration pattern for defining a URI, metadata, repository-backed content, and a synchronous resource specification. section 7.5.1



