Agentic Browser

AI agent for web automation and scraping, designed to plan, execute, and verify actions across any website

System architecture

Introduction#

How the React extension, Python MCP server, FastAPI backend, and tools fit together. MCP for tool transport, FastAPI for REST, shared LLM layer for providers.

Project structure#

Layout:

  • Extension: A Chromium extension built with React and TypeScript, implementing background and content scripts for browser automation and messaging.
  • Backend: A Python application exposing both an MCP server and a FastAPI HTTP API.
  • Core: Shared configuration and LLM abstraction.
  • Services: Business logic and orchestration for domain capabilities.
  • Tools: Modular, reusable tools consumed by agents and services.
  • Agents: Orchestrated reasoning graphs using LangGraph and LangChain tools.
  • Routers: FastAPI route handlers delegating to services.

Core components#

  • CLI entrypoint: main.py / agentic-api-run starts FastAPI. agentic-mcp starts stdio MCP. HTTP MCP is mounted at /mcp.
  • FastAPI backend: Exposes HTTP endpoints under a unified router registry.
  • MCP server: Implements MCP protocol tools for LLM generation, GitHub Q&A, and website content conversion.
  • LLM abstraction: Provider-agnostic configuration supporting multiple LLM providers.
  • React agent service: Orchestrates agent workflows, integrates context, and coordinates tools.
  • Agent graph: LangGraph-based reasoning pipeline with tool invocation.
  • Browser-use tool: Structured tool for generating browser action plans.
  • Extension background/content scripts: Manage extension lifecycle, inject content scripts, and coordinate actions.

Architecture overview#

Agentic Browser separates concerns across three primary channels:

  • Browser extension messaging: Background script handles extension commands and delegates actions to content scripts or the MCP server.
  • MCP protocol: The extension communicates with the Python MCP server to execute tools (e.g., LLM generation, website markdown extraction).
  • HTTP API: The extension can also call the FastAPI backend for domain-specific routes (e.g., React agent).

Detailed component analysis#

CLI entrypoint#

python main.py and agentic-api-run start FastAPI with MCP at /mcp. agentic-mcp starts stdio MCP.

MCP protocol tools and execution#

The MCP server exposes tools for LLM generation, GitHub Q&A, and website content conversion. Tool execution delegates to the LLM abstraction and utility functions.

FastAPI backend and route composition#

The FastAPI app composes routers for health, GitHub, website, YouTube, Google Search, Gmail, Calendar, PyJiIT, React agent, validator, agent, and file upload. The React agent router delegates to the React agent service.

React agent orchestration#

The React agent service constructs a LangGraph workflow, normalizes messages, injects page context when provided, and invokes the compiled graph. The agent graph uses a tool node to execute structured tools.

Browser-Use tool integration#

The browser-use tool defines a structured tool for generating browser action plans. It is consumed by the agent graph during tool execution.

Extension messaging and action execution#

The extension’s background script listens for messages from the UI and content scripts, handles tab management, and executes actions by injecting content scripts and sending messages. It supports dynamic Gemini requests and action-plan execution.

Dependency analysis#

  • The CLI depends on the MCP server and FastAPI entrypoints.
  • The FastAPI app depends on routers, which depend on services.
  • Services depend on the agent graph and tools.
  • The agent graph depends on the LLM abstraction and tools.
  • The MCP server depends on the LLM abstraction and website utilities.
  • The extension depends on background and content scripts for messaging and automation.

Performance considerations#

  • Model selection and provider routing: The LLM abstraction chooses providers and defaults, minimizing cold starts by caching clients.
  • Tool execution batching: The agent graph executes tools asynchronously; ensure tool implementations avoid blocking operations.
  • HTTP API throughput: Use asynchronous FastAPI handlers and keep route logic lightweight; delegate heavy work to services.
  • Extension responsiveness: Avoid long-running injected scripts; prefer background-worker coordination and short-lived content-script interactions.
  • Caching: Reuse compiled agent graphs and compiled LLM clients where feasible.

Security and transparency#

  • Guardrails and prompt injection: Dedicated prompt injection validator and explicit system prompts guide the agent toward safe, transparent behavior.
  • API key management: LLM provider configuration reads keys from environment variables; avoid embedding secrets in code.
  • Extension permissions: The extension interacts with tabs and content scripts; maintain minimal permissions and sanitize injected content.
  • Transparency: The React agent service logs messages and context; expose logs for auditing while avoiding sensitive data leakage.
  • MCP tool scope: Limit MCP tools to necessary capabilities and validate inputs rigorously.

Monitoring and observability#

  • Logging: Centralized logger configuration supports development and production logging levels.
  • Endpoint visibility: Health routers and standardized responses enable readiness/liveness checks.
  • Agent tracing: Log message counts and final outputs to track agent behavior and detect anomalies.

Infrastructure requirements and deployment topology#

  • Runtime environments:
  • Python runtime for the MCP server and FastAPI backend.
  • Chromium-based browser for the extension.
  • Networking:
  • Localhost binding controlled by configuration; adjust host/port for containerized deployments.
  • Scalability:
  • Stateless FastAPI routes scale horizontally behind a reverse proxy.
  • MCP server runs as a single process; consider process isolation per tenant if needed.
  • Tool-heavy workloads benefit from caching and asynchronous processing.
  • Containerization:
  • Package the Python backend and serve via a containerized FastAPI app; run the MCP server alongside or separately.
  • Secrets management:
  • Store API keys and base URLs in environment variables; mount secrets securely in containers.

Troubleshooting guide#

  • MCP tool errors: The MCP server wraps tool execution in try/catch and returns error text; verify tool names and arguments.
  • LLM initialization failures: Provider configuration requires API keys or base URLs; check environment variables and model names.
  • Extension action failures: Confirm content script injection and tab permissions; validate selectors and action parameters.
  • React agent errors: Inspect chat history normalization and page-context injection; ensure HTML-to-markdown conversion succeeds.

Conclusion#

Extension, MCP, and FastAPI stay separate on purpose. LangGraph runs the agent; the extension runs the browser. Guardrails and logs cut across both.