cap
Expose MCP tools from your Artifact UI
You can expose MCP tools from your Artifact UI to allow the AI to call into your UI. The overall building process is the same as building an MCP server, except that this time you’re building an MCP server in the frontend.@nuwa-ai/ui-kit uses a customized MCP transport PostMessageMCPTransport, which allows you to expose MCP tools from your Artifact UI.
hooks/useArtifactMCP.ts
What does useNuwaMCP do?
Building MCP in the frontend can be a weird experience as the MCP server is usually not a React component. You have to handle mount and unmount, as well as the possibility of multiple instances of the same MCP server. The useNuwaMCP hook is a React hook that you can use to stablized the MCP instance. It will automatically handle the mount and unmount, as well as using refs to ensure there’s only one active MCP server at a time. It also handles the transport connection to the Nuwa Client.
Call Nuwa Client in MCP Tool execution
You can also call the Nuwa Client functions in the MCP tool execution.hooks/useArtifactMCP.ts

