ngx-mcp-apps 0.4.0
GitHub npm Italiano
On this page

Reference

API

McpApp signals

SignalMeaning
statusconnecting, connected or standalone
connectedtrue once the handshake with the host succeeded
toolInput, toolInputPartialArguments of the tool call that opened the app (final, and while streaming)
toolResult, structuredContentResult of that tool call
toolCancelled, toolCancelReasonThe host cancelled the tool call, and why when it says so
hostContext, hostCapabilitiesWhat the host says about itself
themelight or dark, as reported by the host
displayMode, availableDisplayModes, canFullscreeninline, fullscreen, pip
eventsProtocol log, newest first, when log: true

McpApp methods

MethodMeaning
callServerTool(name, args)Call a tool of your MCP server from the UI
pollServerTool(name, { intervalMs, args, guard, injector })Signal that follows a server tool
structuredContentAs(guard)structuredContent, checked by your guard and typed
updateModelContext(text, structuredContent?)Add context for the model's next turn, without a chat message
sendMessage(text)Post a user message; resolves false if the host refuses
requestDisplayMode(mode), toggleFullscreen()Ask the host for another display mode; resolves with the mode actually set
openLink(url)Ask the host to open a link; resolves false if the host refuses
requestTeardown()Ask the host to close the app
onTeardown(handler)Run handler before the host removes the app (the host waits for it); returns a function that removes it
readServerResource(uri), listServerResources(cursor?)Read or list the resources of your MCP server, through the host
downloadFile(contents)Ask the host to save files for the user; resolves false if refused
sendLog(level, data, logger?)Send a log message to the host (notifications/message)
bridgeThe underlying McpBridge, for protocol methods not wrapped here

The methods that return a promise reject with an error when the app is not connected. requestTeardown() and sendLog() do nothing in that case, and bridge is undefined when the app runs outside a host.

Lower-level API

McpBridge, parentWindowPort(), the Methods constants and the guards are plain TypeScript and are exported too:

const bridge = new McpBridge(parentWindowPort(), { name: 'my-app', version: '1.0.0' });
bridge.onNotification(Methods.toolResult, (params) => {
  /* ... */
});
const { hostContext } = await bridge.connect();

Configuration

Options of provideMcpApp(config):

OptionDefaultMeaning
name, versionrequiredSent to the host during the handshake
autoResizetrueTell the host the content size so the iframe fits it
availableDisplayModesnot sentDisplay modes the app supports, declared to the host in the handshake
connectTimeout4000Ms to wait for the host before going standalone
requestTimeout60000Ms to wait for an answer to a request
logfalseKeep the last 50 protocol events in events (for debugging)
allowedOriginsanyTalk only to a parent window with one of these origins
portparent windowCustom transport, mainly for tests

Compatibility

Both packages support the same Angular versions.

PackageAngularPeer dependencies
ngx-mcp-apps18, 19, 20, 21, 22@angular/core >=18.0.0 <23.0.0
ngx-mcp-apps-builder18, 19, 20, 21, 22@angular/build >=18.0.0 <23.0.0, @angular-devkit/architect >=0.1800.0 <0.2300.0

Each of these versions was checked with a new application that uses the library and is built by the builder, with both the first release of the major (18.0.0, 19.0.0, ...) and its latest one: a production build, then the built page opened in a browser.

The check is repeated automatically on every change and once a week, with the latest release of each major: a new application, ng add, a component of Angular Material, the single-file build, then the page opened in a browser. Run it yourself with npm run build && npm run test:compat.

  • MCP Apps protocol 2026-01-26. A different version announced by the host is logged, and the app keeps working.
  • Automated tests run the library against the official AppBridge.
  • Hosts. Tested with Claude: claude.ai on the web and the Claude app for Android. The library follows the MCP Apps specification (protocol 2026-01-26), so other hosts that implement it should work, but they have not been tried.

Limits

  • Not wrapped yet: tools provided by the app to the host, sampling, file download, reading server resources. They are reachable through bridge.request(...) and bridge.onRequest(...).
  • Only the host context fields the library knows are validated; unknown fields are passed through as they are.
  • The single HTML file loads everything at once: lazy chunks are merged into it, and web workers are not supported (see Build one HTML file).

Acknowledgements

This is an independent, unofficial implementation. It is inspired by, and owes its design to:

"MCP", "Model Context Protocol" and "Claude" are names of their respective owners and are used only to describe compatibility and credit. This project is not affiliated with or endorsed by any of them.