{"slug": "make-your-angular-app-agent-ready-with-webmcp", "title": "Make Your Angular App Agent-Ready with WebMCP", "summary": "A developer published a guide showing how to expose Angular 22 web apps to browser AI agents using WebMCP, a W3C Community Group draft that adds a modelContext object to the document so pages can register named tools with JSON Schema inputs. The demo todo app registers seven tools, including one generated automatically from a Signal Form, and calls the same store as the UI so agents cannot perform actions the interface cannot. The author notes Chrome ships WebMCP as an early preview and Angular labels its support experimental, advising against production use for now.", "body_md": "*Originally published on [my blog](https://anastasios.theodosiou.me/blog/angular-webmcp-agent-ready-apps).*\n\nVersion note: I wrote this against Angular 22.3 and the WebMCP draft as of November 2026. Every API shown here is experimental, and I will update the post after Angular 22.4 if anything changes.\n\nBrowser AI agents can already book a table or fill in a form for someone, but they do it the hard way. They take screenshots, read the DOM, guess which button is the right one, click, and hope. That is slow and expensive in tokens, and it breaks the moment you rename a CSS class or move a button.\n\nWebMCP turns this around. Your page publishes a small contract of tools: named functions with a description and a JSON Schema for their input. The agent reads the contract and calls the function directly.\n\nAngular 22 ships experimental support for it. In this article we build a small todo app that exposes seven tools to agents. One of them is a Signal Form that turns into a tool with no extra code. We also build a small \"agent console\" so you can test everything in a normal browser today.\n\nThe full demo is on GitHub: [angular-webmcp-todo](https://github.com/atheodosiou/angular-webmcp-todo). You can also [try the live demo](https://atheodosiou.github.io/angular-webmcp-todo/).\n\nWebMCP is a [W3C Community Group draft](https://webmachinelearning.github.io/webmcp/) that adds a `modelContext` object to the document. A page registers tools on it:\n\n```\nawait document.modelContext.registerTool({\n  name: 'add_todo',\n  description: 'Creates a new todo with the given title.',\n  inputSchema: { type: 'object', properties: { title: { type: 'string' } }, required: ['title'] },\n  execute: ({ title }) => ({ content: [{ type: 'text', text: `Added ${title}` }] }),\n});\n```\n\nAn agent in the browser calls `getTools()` to discover what the page offers and `executeTool()` to run one. Think of it as MCP, but the server is your web page and the tools run in the user's own session, with the user's own auth.\n\nHere is the difference for a simple request like *\"add 'buy milk' to my todos\"*:\n\n| Without WebMCP | With WebMCP | \n|---|---|\n| Screenshot the page, find the input, click it, type, find the Add button, click, screenshot again to check | `add_todo({ title: 'buy milk' })` | \n\nAs of today, Chrome ships WebMCP as an [early preview](https://venturebeat.com/infrastructure/google-chrome-ships-webmcp-in-early-preview-turning-every-website-into-a), and Angular marks its support as experimental. The [Angular docs](https://angular.dev/ai/webmcp) say the APIs may change even outside major versions. I would use it for learning and prototypes for now, and keep it out of production architecture.\n\nCreate an Angular 22 app and add the W3C polyfill so the API exists in any browser:\n\n```\nnpx @angular/cli@22 new angular-webmcp-todo\ncd angular-webmcp-todo\nnpm install @w3c/webmcp-polyfill\n```\n\nInstall the polyfill before bootstrapping, because Angular registers tools while the application initialises:\n\n``` js\n// src/main.ts\nimport { bootstrapApplication } from '@angular/platform-browser';\nimport { installWebMCP } from '@w3c/webmcp-polyfill';\nimport { appConfig } from './app/app.config';\nimport { App } from './app/app';\n\n// Never replaces a native implementation, so it is safe to leave in.\ninstallWebMCP();\n\nbootstrapApplication(App, appConfig).catch((err) => console.error(err));\n```\n\nWebMCP only exists in a secure context, so serve the app from `localhost` or HTTPS.\n\nBefore writing any tools, decide where the logic lives. My rule is that tools call the same store the UI calls. That way an agent can never do something the UI cannot, and you never maintain two versions of \"add a todo\".\n\n```\n// src/app/todos/todo-store.ts\n@Injectable({ providedIn: 'root' })\nexport class TodoStore {\n  private readonly _todos = signal<Todo[]>(load());\n  readonly filter = signal<TodoFilter>('all');\n\n  readonly todos = this._todos.asReadonly();\n  readonly remaining = computed(() => this._todos().filter((t) => !t.done).length);\n\n  constructor() {\n    effect(() => localStorage.setItem(STORAGE_KEY, JSON.stringify(this._todos())));\n  }\n\n  add(title: string): Todo { /* ... */ }\n  setDone(id: string, done: boolean): Todo | undefined { /* ... */ }\n  remove(id: string): boolean { /* ... */ }\n  clearCompleted(): number { /* ... */ }\n}\n```\n\nBecause the state lives in signals, anything an agent changes shows up in the UI straight away. With OnPush now the default in Angular 22, signals are also what keeps rendering cheap. I wrote more about that in [Optimizing Angular Change Detection with OnPush](https://anastasios.theodosiou.me/blog/improve-angular-performance-with-onpush-change-detection).\n\n`provideExperimentalWebMcpTools`\n`provideExperimentalWebMcpTools` takes an array of tool descriptors and returns environment providers. The tools are registered when the injector initialises and unregistered when it is destroyed.\n\n``` js\n// src/app/todos/todo-tools.ts\nimport { inject, provideExperimentalWebMcpTools } from '@angular/core';\nimport { TodoStore } from './todo-store';\n\nexport const provideTodoTools = () =>\n  provideExperimentalWebMcpTools([\n    {\n      name: 'list_todos',\n      title: 'List todos',\n      description:\n        'Returns every todo with its id, title and done state. Call this first to find the id of a todo.',\n      annotations: { readOnlyHint: true },\n      execute: () => {\n        const store = inject(TodoStore);\n        return json({ remaining: store.remaining(), todos: store.todos() });\n      },\n    },\n    {\n      name: 'add_todo',\n      title: 'Add a todo',\n      description: 'Creates a new todo with the given title. Returns the created todo.',\n      inputSchema: {\n        type: 'object',\n        properties: {\n          title: { type: 'string', description: 'What needs to be done, 1 to 200 characters.' },\n        },\n        required: ['title'],\n      },\n      execute: ({ title }) => {\n        if (typeof title !== 'string' || !title.trim() || title.length > 200) {\n          return error('title must be a non-empty string of at most 200 characters.');\n        }\n        return json(inject(TodoStore).add(title));\n      },\n    },\n    // complete_todo, delete_todo, clear_completed ...\n  ]);\n\nconst json = (value: unknown) => ({ content: [{ type: 'text', text: JSON.stringify(value) }] });\nconst error = (message: string) => ({ isError: true, content: [{ type: 'text', text: message }] });\n```\n\nRegister it like any other provider:\n\n``` js\n// src/app/app.config.ts\nexport const appConfig: ApplicationConfig = {\n  providers: [provideBrowserGlobalErrorListeners(), provideTodoTools()],\n};\n```\n\nSome details in that code:\n\n`inject()` works inside `execute`. Angular runs the callback in the injection context of the injector that registered the tool, so you use your services exactly as you would anywhere else.`{ title: string }` from `inputSchema`. This only affects TypeScript, which matters later in the security section.`readOnlyHint: true` says the tool only reads. `consequentialHint: true`, which I put on `delete_todo` and `clear_completed`, says the effect is significant or hard to undo, so a well-behaved agent should confirm with the user first.\nSome tools only make sense on one screen. A \"filter the list\" tool is useless when the list is hidden. `declareExperimentalWebMcpTool` registers a single tool from the current injection context and removes it automatically when that context is destroyed:\n\n```\n// src/app/todos/todo-list.ts\nexport class TodoList {\n  protected readonly store = inject(TodoStore);\n\n  constructor() {\n    declareExperimentalWebMcpTool({\n      name: 'set_filter',\n      title: 'Filter the visible todos',\n      description: 'Changes which todos the list shows to the user: all, active or completed.',\n      inputSchema: {\n        type: 'object',\n        properties: { filter: { type: 'string', enum: ['all', 'active', 'completed'] } },\n        required: ['filter'],\n      },\n      execute: ({ filter }) => {\n        if (!FILTERS.includes(filter as TodoFilter)) {\n          return { isError: true, content: [{ type: 'text', text: `filter must be one of ${FILTERS.join(', ')}.` }] };\n        }\n        this.store.filter.set(filter as TodoFilter);\n        return { content: [{ type: 'text', text: `Showing ${filter} todos.` }] };\n      },\n    });\n  }\n}\n```\n\nUnder the hood, Angular passes an `AbortSignal` to `registerTool` and aborts it from the component's `DestroyRef`. The demo has a checkbox that hides the list. Untick it and `set_filter` disappears from `getTools()`; tick it and it comes back.\n\nThat suggests declaring tools per route or per feature, so the agent sees what the user sees and the tool list stays short. It is the same modular approach I described in [Building Scalable and Maintainable Front-End Applications](https://anastasios.theodosiou.me/blog/front-end-architecture), with an agent as one more consumer.\n\nThis is my favourite part. Signal Forms are stable in Angular 22, and a form can register itself as a WebMCP tool.\n\nFirst, enable it once in the app config:\n\n``` js\n// src/app/app.config.ts\nimport { provideExperimentalWebMcpForms } from '@angular/forms/signals';\n\nproviders: [provideBrowserGlobalErrorListeners(), provideTodoTools(), provideExperimentalWebMcpForms()],\n```\n\nThen add `experimentalWebMcpTool` to the options of any form:\n\n```\n// src/app/todos/todo-list.ts\nprivate readonly newTodo = signal({ title: '' });\n\nprotected readonly todoForm = form(\n  this.newTodo,\n  (p) => {\n    required(p.title, { message: 'Title is required.' });\n    pattern(p.title, /\\S/, { message: 'Title cannot be only spaces.' });\n    maxLength(p.title, 200, { message: 'Title must be at most 200 characters.' });\n  },\n  {\n    experimentalWebMcpTool: {\n      name: 'new_todo_form',\n      description: 'Fills in and submits the \"new todo\" form shown on the page.',\n    },\n    submission: {\n      action: async (f) => {\n        this.store.add(f.title().value());\n        this.newTodo.set({ title: '' });\n        return undefined;\n      },\n    },\n  },\n);\nphp\n<!-- src/app/todos/todo-list.html -->\n<form [formRoot]=\"todoForm\">\n  <input [formField]=\"todoForm.title\" placeholder=\"What needs to be done?\" />\n  <button type=\"submit\">Add</button>\n</form>\n```\n\nThat is the whole tool. Angular does the rest:\n\n`{ title: '' }` becomes `{ type: 'object', properties: { title: { type: 'string' } }, required: ['title'], additionalProperties: false }`. The `required` list comes from your `required()` rule.`submit()`, so your normal `submission.action` runs.`{ title: '   ' }` returns:\n\n```\nForm submission failed:\ntitle: Title cannot be only spaces.\n```\n\nThe agent can read that and retry, and you only wrote the rules once.\n\nThere are limits. The schema is inferred from the current value, so a model with `null`, `undefined` or an empty array cannot be inferred and Angular throws. Fields get no per-field descriptions, so put the guidance in the tool description. A failed submission comes back as plain text without `isError`, so check the text if you build your own agent tooling.\n\nSo when do you pick a form tool over a hand-written one? Use a form tool when the action already exists as a form and you want the agent to go through exactly the same rules as the user. Write a tool by hand when you need rich descriptions per argument, structured results (like returning the created todo's id), or an action that has no form at all.\n\nAngular does not validate agent input against `inputSchema`. The schema produces TypeScript types and tells the agent what to send, but nothing at runtime stops an agent from sending `{ title: 42 }`.\n\nSo every hand-written tool validates its own arguments and returns an error the agent can act on:\n\n``` js\nexecute: ({ id, done }) => {\n  const store = inject(TodoStore);\n  if (typeof id !== 'string' || !store.find(id)) {\n    return error(`No todo with id \"${String(id)}\". Call list_todos to get valid ids.`);\n  }\n  if (done !== undefined && typeof done !== 'boolean') {\n    return error('done must be a boolean.');\n  }\n  return json(store.setDone(id, done ?? true));\n},\n```\n\nThe error message tells the agent what to do next. If you like making invalid states impossible at compile time, [exhaustive checks](https://anastasios.theodosiou.me/blog/exhaustive-checks) pair nicely with this runtime layer.\n\nMy checklist for every tool:\n\n`isError: true` and a next step.`consequentialHint`.\nThe polyfill works in unit tests too. jsdom is not a secure context, so mark it as one before installing:\n\n```\n// src/app/app.spec.ts\nObject.defineProperty(window, 'isSecureContext', { value: true });\ninstallWebMCP();\n\nconst call = async (name: string, input: object = {}) => {\n  const tool = (await document.modelContext!.getTools()).find((t) => t.name === name);\n  if (!tool) throw new Error(`tool ${name} is not registered`);\n  return JSON.parse(await document.modelContext!.executeTool(tool, input));\n};\n\nit('rejects invalid input instead of trusting the schema', async () => {\n  const res = await call('add_todo', { title: 42 });\n  expect(res.isError).toBe(true);\n  expect(TestBed.inject(TodoStore).todos().length).toBe(0);\n});\n```\n\nThe demo has four Vitest tests: all seven tools register, an agent call reaches the store, bad input is rejected, and the Signal Form tool submits through its validators.\n\nFor manual testing, the demo includes an agent console: a component that knows nothing about `TodoStore` and only uses `getTools()` and `executeTool()`, exactly like a real agent. Pick a tool, edit the JSON arguments, call it, and watch the list update.\n\nOnce that works, try it with a real browser agent that supports WebMCP.\n\nNot to production yet. WebMCP is a draft, browser support is an early preview, and Angular's APIs are explicitly experimental. Still, the design fits Angular well: tools can use DI, registration follows component lifecycles, and a Signal Form becomes a tool with one option.\n\nFor internal tools and prototypes I would start now. Put your features in store methods the UI and an agent can share, keep tools next to the components they belong to, and validate every call.\n\nThe complete demo is on GitHub: [angular-webmcp-todo](https://github.com/atheodosiou/angular-webmcp-todo). Try it live at [atheodosiou.github.io/angular-webmcp-todo](https://atheodosiou.github.io/angular-webmcp-todo/).\n\nWhat tools would your app expose? Tell me in the comments.\n\n*This article was originally published on [anastasios.theodosiou.me](https://anastasios.theodosiou.me/blog/angular-webmcp-agent-ready-apps). Read it there for the latest updates.*", "url": "https://wpnews.pro/news/make-your-angular-app-agent-ready-with-webmcp", "canonical_source": "https://dev.to/atheodosiou/make-your-angular-app-agent-ready-with-webmcp-3epa", "published_at": "2026-11-29 22:32:24+00:00", "updated_at": "2026-11-29 22:46:00.898456+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "developer-tools", "ai-tools", "artificial-intelligence"], "entities": ["Angular", "WebMCP", "W3C", "Chrome", "Google", "GitHub"], "also_reported_by": [], "takeaway": "Registering page tools on document.modelContext with a name, description and JSON Schema lets browser agents call functions directly instead of screenshotting and clicking the DOM, and routing those tools through the same store as the UI prevents agents from doing anything the interface cannot.", "recommendation": {"advice": "Expose app actions as WebMCP tools backed by the same store the UI uses, and install the @w3c/webmcp-polyfill before bootstrap so tools register during Angular initialisation.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/make-your-angular-app-agent-ready-with-webmcp", "markdown": "https://wpnews.pro/news/make-your-angular-app-agent-ready-with-webmcp.md", "text": "https://wpnews.pro/news/make-your-angular-app-agent-ready-with-webmcp.txt", "jsonld": "https://wpnews.pro/news/make-your-angular-app-agent-ready-with-webmcp.jsonld"}}