MCP 应用允许支持 MCP 的 AI 应用(也称为宿主)在对话中打开一个经过路由的 webforJ 视图。该视图仍是 Java 应用的一部分,因此它使用的组件、服务、路由和状态与在浏览器中使用时相同。
用户和 AI 可以共同操作同一个实时 UI。AI 可以在打开视图时提供输入,调用可更改当前视图的操作,并接收用户在 UI 中所做选择的上下文。用户也可以继续直接使用渲染后的 webforJ 组件。
使用 Spring AI 的 Spring Boot 是发布 MCP 应用的主要方式。该集成会发现带标记的路由,并将其添加到 Spring AI 的 MCP 服务器中。请先从 Spring Boot 设置 开始,然后通过最简已发布视图测试连接。不使用 Spring Boot 的应用可以改用标准 servlet 设置。
MCP Apps 是 MCP 规范的一项持续演进的扩展,因此各宿主采用其修订版本和安全策略的速度不尽相同。应用会声明其视图加载和连接所需的来源,允许这些来源的宿主便会渲染该视图。宿主也可能采用更严格的策略。打开工具始终会返回其文本内容,而该路由仍可作为普通浏览器页面访问。请按照测试中的步骤,验证你要面向的每个宿主。
主题
Spring Boot MCP 应用
Build and publish a routed webforJ view as an MCP App with Spring Boot and Spring AI.
测试 MCP 应用
Test a webforJ MCP App with an MCP Apps-capable host, including the Codex app, Claude Desktop, and MCPJam.
使用输入打开视图
Accept structured opening input in a routed MCP App and choose its requested display mode.
为已打开的视图添加工具
Add tools that work with an MCP App already open in the current conversation.
使用 MCP 客户端
Connect a rendered webforJ view to its MCP client.
配置 MCP 应用
Configure the public app origin, allowed embedding clients, and external browser domains.
标准 webforJ 设置
Assemble an MCP server and register webforJ MCP Apps in a standard servlet-based webforJ application.
继续学习
文章AI Java web framework: how webforJ is built for AI work
文章Spring Boot MCP server: tools plus a live UI in webforJ
文章MCP Apps in Java: show a webforJ UI inside AI chat
文章AI actions that update a Java UI: open and change webforJ views
文章MCP app in plain Java: no Spring Boot required
文章How to test a Java MCP App without an AI host