Angular service and provider for WebMCP tool registration. Expose AI-agent-callable tools from Angular applications using a lightweight, decorator-free service compatible with both standalone and NgModule patterns.
npm install @webmcpregistry/angular
# or
pnpm add @webmcpregistry/angularPeer dependency: @angular/core ^17.0.0 || ^18.0.0 || ^19.0.0
// app.config.ts (standalone)
import { provideWebMCP } from '@webmcpregistry/angular'
export const appConfig = {
providers: [provideWebMCP({ mode: 'auto' })],
}Or with NgModule:
// app.module.ts
import { provideWebMCP } from '@webmcpregistry/angular'
@NgModule({
providers: [provideWebMCP({ mode: 'auto' })],
})
export class AppModule {}import { Component, Inject, OnInit, OnDestroy } from '@angular/core'
import { WebMCPService } from '@webmcpregistry/angular'
@Component({
selector: 'app-search',
template: '<div>Search Page</div>',
})
export class SearchComponent implements OnInit, OnDestroy {
constructor(@Inject('WEBMCP_SERVICE') private webmcp: WebMCPService) {}
ngOnInit() {
this.webmcp.registerTool({
name: 'search_products',
description: 'Search the product catalog by keyword',
inputSchema: {
type: 'object',
properties: { query: { type: 'string', description: 'Search term' } },
required: ['query'],
},
safetyLevel: 'read',
handler: async ({ query }) => {
const res = await fetch(`/api/search?q=${query}`)
return res.json()
},
})
}
ngOnDestroy() {
this.webmcp.unregisterTool('search_products')
}
}import { getWebMCPService } from '@webmcpregistry/angular'
const service = getWebMCPService()
service.initialize({ mode: 'auto' })
service.registerTool({ name: 'my_tool', description: '...', handler: async (input) => input })Create an Angular-compatible provider that initializes the WebMCP SDK. Returns a { provide, useValue } object for Angular's DI system.
provideWebMCP({ mode: 'auto' })Parameters:
| Param | Type | Default | Description |
|---|---|---|---|
config |
WebMCPConfig |
{} |
SDK configuration |
Config options:
| Field | Type | Default | Description |
|---|---|---|---|
mode |
'auto' | 'suggest' | 'manual' |
'auto' |
SDK operating mode |
polyfill |
boolean |
— | Install polyfill if navigator.modelContext is missing |
autoDetect |
boolean |
— | Auto-detect tools from DOM |
tools |
ToolDefinition[] |
— | Pre-defined tools to register |
siteKey |
string |
— | Site key for analytics |
onRegister |
(tools: ToolDefinition[]) => void |
— | Callback when tools are registered |
onError |
(error: Error) => void |
— | Error callback |
Returns: { provide: 'WEBMCP_SERVICE', useValue: WebMCPService }
Initialization is deferred via queueMicrotask to ensure it runs after the DOM is ready.
Stateful service that wraps the core SDK. No Angular decorators -- works in any context.
| Property | Type | Description |
|---|---|---|
tools |
ToolDefinition[] |
All currently registered tools |
ready |
boolean |
Whether initialization is complete |
mode |
RegistrationMode |
The active SDK mode |
nativeAPI |
boolean |
Whether the native browser API is available |
polyfilled |
boolean |
Whether the polyfill was installed |
Manually initialize the SDK. Called automatically by provideWebMCP, but can also be called directly.
const result = service.initialize({ mode: 'auto' })Register a new tool. Updates the internal tools array.
service.registerTool({
name: 'add_to_cart',
description: 'Add a product to the cart',
inputSchema: { type: 'object', properties: { productId: { type: 'string' } } },
safetyLevel: 'write',
handler: async ({ productId }) => { /* ... */ },
})Remove a registered tool by name. Updates the internal tools array.
service.unregisterTool('add_to_cart')Get or lazily create a WebMCPService singleton. Useful for direct usage without Angular DI.
import { getWebMCPService } from '@webmcpregistry/angular'
const service = getWebMCPService()Returns: WebMCPService
The following types are re-exported from @webmcpregistry/core for convenience:
ToolDefinition-- full tool definition objectToolInputSchema-- JSON Schema for tool input parametersToolSafetyLevel--'read' | 'write' | 'danger'ToolHandler--(input: Record<string, unknown>) => unknown | Promise<unknown>WebMCPConfig-- SDK configuration optionsRegistrationMode--'auto' | 'suggest' | 'manual'
Apache-2.0 -- RAPHATECH OU