Bridge to Agentia — Project Overview & Narrative
Inspiration
The web was built primarily for humans: we view a page, interpret its visual layout, click buttons, fill forms, and complete workflows. AI agents, however, require something fundamentally different—they need discoverable, structured, and actionable capabilities.
WebMCP (Web Model Context Protocol) provides a compelling foundation for solving this problem by allowing web applications to expose their capabilities directly as machine-readable tools that AI agents can discover and execute within the browser security boundary. This prompted an essential architectural question:
What happens when a website does not natively support WebMCP?
That question inspired Bridge to Agentia.
What I Built
Bridge to Agentia explores three complementary architectural paradigms for bridging AI agents with web applications:
- Native WebMCP — The web application directly exposes its capabilities as schema-validated WebMCP tools registered in the browser context via
document.modelContext. - API Adapter — An external proxy adapter translates an existing website REST API into agent-accessible WebMCP tools via a serverless edge worker (Cloudflare Worker).
- UI / Automation Adapter — An external adapter translates agent intent directly into DOM interactions and automation steps over the existing user interface.
The objective is not to replace existing web applications, but to construct a robust, unified bridge between agent intent and underlying web capabilities.
For example, the same user prompt:
“Find an indigo denim jacket under $150 and add it to my bag.”
can be executed through any of the three underlying integration mechanisms:
AI Agent Intent
│
├── Native WebMCP ─────────► In-Browser Tool Registry (34 Tools)
│
├── API Adapter ───────────► Serverless Edge Proxy ──► Storefront API
│
└── UI Adapter ────────────► Headless Automation ─────► Storefront DOM
To demonstrate this in practice, we built an in-website AI Stylist featuring both text and voice interaction, allowing shoppers to converse naturally while the agent discovers and orchestrates available WebMCP tools in real time.
Human Shopper
│
├── Natural Language Chat ───┐
│ │
└── Real-Time Voice Mic ─────┤
▼
AI Agent
▼
WebMCP Tool Registry
▼
Storefront Capabilities
This architecture enables consistent, semantic agent interactions regardless of the underlying execution layer.
How I Built It
Bridge to Agentia is architected around a declarative, tool-based interaction lifecycle:
- Discovery: The agent inspects available tools for the current session state via
document.modelContext.getTools(). - Schema Comprehension: The agent parses typed JSON Schemas defining required fields, types, enums, and numerical constraints.
- Intent Resolution & Selection: The LLM resolves user requests into appropriate tool calls and structured arguments.
- Security & Privacy Gating: Inputs are checked for prompt injection patterns; sensitive operations require user confirmation; credentials never enter model context.
- Execution & State Mutation: The tool executes against the same-origin API, updates application state, and dispatches UI synchronization events.
- Result Sanitization & Synthesis: Tool results are scrubbed of PII before return to the model for conversational summarization.
User
│ (Chat / Voice)
▼
AI Agent Controller
│
├── 1. Sanitize Prompt & Check Delimiters ([USER_MESSAGE])
├── 2. Discover Available Tools (State-Gated)
├── 3. Resolve Tool & Parameters (Gemini Function Calling)
├── 4. Request User Confirmation (if Destructive / Transactional)
▼
WebMCP Registry Execution
│
├── Validate Input Schema (Types, Enums, Integer Bounds)
├── Invoke Same-Origin Commerce API
├── Update Application State (Auth / Cart / Wishlist)
▼
Response Sanitization & Privacy Boundary
│
├── Scrub PII (Mask Emails, Redact Street Addresses & Phones)
├── Neutralize Indirect Prompt Injections in Tool Payloads
├── Record Execution to Append-Only Audit Log (/api/audit)
▼
Conversational Natural-Language / Voice Audio Response
State-Aware Capability Exposure
Tool availability dynamically reflects session state:
- Guest (Logged Out): 18 public tools active (catalog search, fashion filters, size guides, comparison matrices, shipping rates, auth status).
- Authenticated, Cart Empty: 33 tools active (cart operations, wishlist management, address updates, order history). Checkout is gated (
33/34). - Authenticated, Cart Populated: All 34 tools active, unlocking
create_order(34/34).
End-to-End Security & Privacy Guardrails
To prevent data exfiltration and credential theft:
- Auth Isolation:
loginandregistertools are omitted from LLM tool declarations; authentication occurs strictly through browser UI. - PII Scrubbing: Contact numbers and home addresses are replaced with semantic tokens (e.g.,
[Saved Address #1]), and emails are recursively masked. - Prompt Injection Defense: Inputs and tool payloads are wrapped in boundary markers, with automated detection for instruction overrides, role spoofing, and delimiter escapes.
- Human-in-the-Loop Confirmation: Destructive tools (
create_order,cancel_order,clear_cart,logout,update_shipping_address,remove_from_cart) pause execution for explicit user confirmation. - Persistent Audit Trail: Execution durations, parameters, and threat signatures are logged in memory and flushed to server-side append-only JSONL files.
What I Learned
Building Bridge to Agentia demonstrated that making a web application agent-accessible requires far more than exposing raw endpoints.
Key learnings include:
- Separation of Interface and Implementation: The semantic tool interface presented to an agent can remain identical whether backed by native browser APIs, edge API adapters, or DOM automation.
- Designing for LLM Tool Consumption: Writing descriptive tool documentation, strict parameter schemas, and clear error contracts directly dictates model planning accuracy.
- State-Aware Tool Gating: Dynamically updating available tools based on session state dramatically reduces model hallucinations and invalid function calls.
- Failure Modes and Resilient Error Contracts: Tools must return structured, machine-actionable error payloads (
code,retryable,userActionRequired) so agents can self-correct when encounters occur (out of stock, invalid coupons, unauthenticated states). - The Necessity of LLM Security Boundaries: Unchecked agent access risks prompt injection and privacy violations. Defensive prompt guards, PII scrubbers, and confirmation gates are essential for trustworthy agentic commerce.
Challenges
- Bridging the Paradigm Gap: Native WebMCP provides optimal latency and security, but requires website-level implementation. API adaptation avoids visual dependency but requires backend schema knowledge. UI automation requires no backend access but introduces brittle DOM coupling. Balancing these trade-offs across edge runtimes was a primary architectural challenge.
- Dynamic State Synchronization: Ensuring that an action performed by an AI agent (such as adding an item to the cart or logging in) immediately synchronizes React UI context, cart counts, and native tool availability without causing stale closures or infinite re-renders.
- Full-Duplex Voice Control: Implementing natural speech recognition and Text-to-Speech playback while providing instantaneous cancellation (mute toggles, sound wave stop controls, and drawer close events) to prevent background audio runaway during asynchronous multi-turn tool loops.
- Rigorous Failure Handling: Constructing deterministic tests to validate that the system fails safely and predictably across wrong argument types, negative integers, execution order errors, out-of-stock items, and network interruptions.
Why Bridge to Agentia?
Bridge to Agentia envisions a web where humans and AI agents interact with applications through a common, capability-oriented interface.
Instead of asking:
“Does this website support WebMCP?”
we explore the broader, forward-looking question:
“How can any web capability become discoverable, secure, and actionable for an AI agent?”
By unifying native browser WebMCP, edge API adaptation, and DOM-level automation with comprehensive security guardrails, Bridge to Agentia provides a practical blueprint for the agentic web.
Different architectures, same destination: making web capabilities discoverable and actionable by AI agents.
Built With
- agent
- ai
- chatgpt
- chrome
- codex
- mcp
- netlify
- next.js
- node.js
- react
- render
- typescript
- vercel
- webmcp

Log in or sign up for Devpost to join the conversation.