package com.ankurm.mcpapps; import java.io.IOException; import java.nio.charset.StandardCharsets; import org.springframework.ai.mcp.annotation.McpResource; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; /** The HTML views, served as ordinary MCP resources under the ui:// scheme. */ @Component public class UiResources { private final boolean unsafeRender; public UiResources(@Value("${app.unsafe-render:false}") boolean unsafeRender) { this.unsafeRender = unsafeRender; } @McpResource(uri = UiMeta.BOARD_URI, name = "inventory_board", description = "Stock board view", mimeType = UiMeta.MIME_TYPE, metaProvider = UiMeta.BoardResource.class) public String board() throws IOException { // app.unsafe-render=true switches the view to innerHTML, to demonstrate script injection. Never ship that. return load("ui/board.html").replace("__UNSAFE_RENDER__", Boolean.toString(unsafeRender)); } @McpResource(uri = UiMeta.SDK_URI, name = "inventory_board_sdk", description = "Stock board view (ext-apps SDK)", mimeType = UiMeta.MIME_TYPE, metaProvider = UiMeta.SdkResource.class) public String sdkBoard() throws IOException { return load("ui/board-sdk.html"); } private static String load(String path) throws IOException { return new ClassPathResource(path).getContentAsString(StandardCharsets.UTF_8); } }