MCP SuperAssistant

repository·main·Indexed 25 days ago

https://github.com/srbhptl39/mcp-superassistant

A browser extension that enables web-based AI assistants, such as ChatGPT and Gemini, to interact with the Model Context Protocol (MCP). It bridges cloud-based LLMs and local or remote data sources by proxying tool calls through a local server. The project features a modular architecture including a plugin system with site adapters, a shared TypeScript utility package (@extension/shared), and a dedicated UI library (@extension/ui) integrated with Tailwind CSS and shadcn/ui.

Tokens
42.9K
Snippets
91
Records
213
Agent score
81%

What's inside mcp-superassistant

  1. Overview of Gemini Adapter Components

    main

    The Gemini Adapter provides specialized support for the Google Gemini website (https://gemini.google.com/). It enables the MCP SuperAssistant extension to interact with Gemini's interface and detect MCP tool commands within chat responses.

    Key capabilities include:

    • DOM Observation: Detecting tool commands in chat responses by observing DOM changes.
    • Markdown Processing: Extracting MCP tool commands from Gemini's markdown-formatted responses.
    • Chat Interaction: Programmatically inserting text, submitting messages, and handling file uploads.
    • Sidebar Integration: Converting detected tools into a format compatible with the extension's sidebar for displaying outputs.
  2. Overview of MCP SuperAssistant

    main

    MCP SuperAssistant is a Chrome extension that integrates the Model Context Protocol (MCP) tools with web-based AI platforms. It allows you to execute MCP tools directly within interfaces like ChatGPT, Perplexity, Google Gemini, and more, seamlessly inserting tool results back into the conversation.

    Supported Platforms include:

    • ChatGPT
    • Google Gemini & Google AI Studio
    • Perplexity
    • Grok
    • OpenRouter Chat
    • DeepSeek
    • GitHub Copilot
    • Mistral AI
    • Kimi
    • Qwen Chat
    • Z Chat
    • and others.
  3. Use Instructions component utilities

    main

    The Instructions component provides two primary utilities for managing MCP tool instructions:

    1. instructionGenerator.ts: Responsible for generating markdown-formatted instructions for using MCP tools based on the available toolset.
    2. schema_converter.ts: Provides utilities to convert between standard JSON Schema and the compact Compressed Schema Notation (CSN).
  4. Understand the MCP SuperAssistant File Structure

    main

    The project follows a modular architecture organized into specific functional directories. This structure ensures a clean separation of concerns between configuration, parsing, observation, and rendering.

    Core Directories

    • src/core/: Contains the foundation of the library.
      • config.ts: Configuration interfaces and default settings.
      • types.ts: Centralized shared type definitions used across the codebase.
    • src/parser/: Handles content parsing logic.
      • functionParser.ts: Logic for parsing function calls.
      • parameterParser.ts: Logic for extracting parameters.
      • languageParser.ts: Logic for detecting language tags.
    • src/observer/: Manages DOM observation.
      • mutationObserver.ts: Setup for MutationObservers.
      • streamObserver.ts: Logic for observing streaming content.
      • stalledStreamHandler.ts: Detects and handles stalled content streams.
    • src/renderer/: Manages UI and component rendering.
      • functionBlock.ts: Logic for rendering function blocks.
      • components.ts: UI components.
      • styles.ts: Styling definitions.
    • src/utils/: General utility functions.
      • dom.ts: DOM manipulation utilities.
      • performance.ts: Performance-related utilities.
    • src/index.ts: The main library entry point.
  5. What is the purpose of the @extension/shared package?

    main

    The @extension/shared package serves as a central repository for TypeScript types, utilities, and constants. Its primary goal is to ensure type safety and prevent code duplication across the different parts of the MCP SuperAssistant extension, including:

    • Content script components
    • Background script/service worker
    • Popup and options pages
    • Development utilities

    Specifically, it contains critical definitions like toolCall.ts which defines the structures for MCP tool calls and execution results used throughout the system.

  6. Overview of MCP-SuperAssistant Content Script Architecture

    main

    The MCP-SuperAssistant content script is a modular, event-driven system designed to interact with AI platform web pages. It manages injected UI components, executes MCP tools via site-specific adapters, maintains application state, and communicates with the background script.

    Core Architecture Components

    • Plugin Architecture (plugins/): A centralized system for managing adapters. It includes a Plugin Registry, a Base Adapter (abstract class), Site-Specific Adapters (tailored for specific AI platforms), and a Default Adapter (universal fallback).
    • State Management (stores/): Uses Zustand for domain-specific stores:
      • App Store: Global application state.
      • Connection Store: MCP server connection management.
      • UI Store: Interface state and preferences.
      • Adapter Store: Plugin and adapter state.
      • Tools Store: MCP tool execution state.
    • Event System (events/): A typed event bus for decoupled communication between modules.
    • React Hooks Integration (hooks/): Provides interfaces for components to interact with the system, including useAdapter, useStores, and useEventBus.
    • UI Components (components/): React components for the injected sidebar and website-specific overrides.
  7. Overview of available Zustand stores

    main

    The application state is partitioned into several specialized stores, each managing a distinct domain. These are composed and exported via stores/index.ts.

    Store Directory Structure

    • app.store.ts: Manages general application state.
    • adapter.store.ts: Manages plugin adapter state.
    • connection.store.ts: Manages MCP (Model Context Protocol) connection state.
    • tool.store.ts: Manages tool management state.
    • ui.store.ts: Manages UI-specific state management.
  8. Overview of Utility Modules (`utils`)

    main
    The utils directory provides small, focused, and reusable utility modules and helper functions used across the MCP-SuperAssistant content script. These modules are designed to encapsulate specific logic (such as DOM manipulation, logging, or string formatting) to keep the codebase DRY (Don't Repeat Yourself). They are typically implemented as pure functions or classes that can be easily imported into other parts of the application.
  9. Modify UI library styles

    main

    You can customize the appearance of the @extension/ui package in two ways:

    • Global Tailwind Styles: Modify the tailwind.config.ts file in the UI package to change theme settings, colors, or spacing.
    • CSS Variables: Modify the CSS variables defined in ui/lib/global.css to change the core color palette (e.g., --primary, --background, --border).
  10. How the Events Module works

    main

    The Events Module provides a decoupled, type-safe communication system for the MCP-SuperAssistant content script. It uses a central TypedEventBus to manage communication between different application parts.

    Key Components

    • event-bus.ts: The central hub (TypedEventBus) that supports typed events, wildcard listeners, event history, and error handling.
    • event-types.ts: Defines the EventMap interface, which maps event names to their specific payload types, ensuring type safety.
    • event-handlers.ts: Manages global listeners for application-wide events like errors or site changes.
    • event-system.ts: Orchestrates the lifecycle (setup and teardown) of the entire system.
  11. Emit and listen to events via the Event System

    main

    Components can communicate with other parts of the extension using the useEventBus hook. This is useful for decoupling UI interactions from core logic.

    Use the emit function to broadcast events with a payload. Common event patterns include notifying the system when a tool is requested by a user interaction.

    import { useEventBus } from '../../hooks/useEventBus';
    
    export function ToolButton({ toolId }: { toolId: string }) {
      const { emit } = useEventBus();
      
      const handleClick = () => {
        emit('tool:requested', { toolId, source: 'button' });
      };
      
      return <button onClick={handleClick}>Execute Tool</button>;
    }
  12. How the Plugin System works

    main

    The plugin system is a modular architecture designed to adapt the assistant's capabilities based on the active website.

    • PluginRegistry: The central hub that manages registration, lifecycle (initialize, activate, deactivate, cleanup), and hostname-based adapter selection.
    • BaseAdapterPlugin: An abstract class that provides a standardized implementation for lifecycle management, status tracking, and error handling.
    • PluginContext: A factory that provides plugins with access to runtime resources, including Zustand stores, a type-safe event bus, DOM utilities, Chrome APIs, and a structured logger.
    • Adapters: Site-specific implementations (like ExampleForumAdapter) that fulfill the AdapterPlugin contract to perform actions like text insertion or form submission on specific domains.