MCP Apps with Java: sharing application state between the model and a live UI
One interesting part of MCP Apps is that the UI doesn’t have to be a disposable interface generated for a single model response.
I’ve been experimenting with this from the Java side using Spring Boot, Spring AI and webforJ.
The architecture is roughly:
MCP host -> tool call -> Java application -> rendered view
A routed Java view is exposed as both an MCP tool and UI resource. The same route can still run as a normal application in the browser.
The more interesting part is what happens after the view opens.
Additional MCP tools can target the rendered view associated with the same MCP session. A tool call can therefore modify the state of the application the user is currently looking at rather than returning another detached result.
Communication also goes the other way. When the user interacts with the Java UI, the application can update the model context. For example, selecting rows or changing a filter can change what information is available to the model without adding another visible chat message.
That makes the interaction roughly:
prompt -> MCP tool -> Java view -> user interaction -> model context
For example, an invoice application can expose an operation that opens its invoice route with an overdue filter. Once open, another tool can change the same view to display an aging chart. The user can then manually change the selection and make only those selected invoices available for further analysis.
The application itself remains a Java application. Spring Boot runs it, Spring AI provides the MCP server integration, and webforJ handles the UI.
I work on webforJ, for disclosure. The implementation and API are documented here:
https://docs.webforj.com/docs/integrations/mcp-apps/overview
I’m curious what people think about this interaction model. In particular, whether sharing one live application state between the human UI and model feels more useful than having the model generate a separate UI/result each time.