# junjiem/dify-plugin-agent-mcp_sse architecture

> Architecture diagram of the GitHub repository junjiem/dify-plugin-agent-mcp_sse, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/junjiem/dify-plugin-agent-mcp_sse
- Repository: https://github.com/junjiem/dify-plugin-agent-mcp_sse

## Overview

##### Main Components
- Plugin Entry Point: The main script (main.py) and related manifest (manifest.yaml) serve as the entry into the plugin, where initialization and configuration occur.
- Provider Module: Under the “provider” directory, agent.py (and its YAML counterpart) is the key component that likely acts as a bridge between the agent’s logic and the strategies.
- Strategy Components: The “strategies” directory holds different strategy implementations (e.g., ReAct.py with ReAct.yaml and function_calling.py with its YAML). These encapsulate the core decision-making logic for how the agent interacts with MCP servers and available tools.
- Prompt Management: The “prompt” directory contains template.py, which is used to generate or manage the prompts being sent to the agent.
- Output Parsing: The “output_parser” directory, with files like cot_output_parser.py, handles parsing of outputs (likely handling chain-of-thought or other structured responses).
- Utility Classes: The “utils” directory with mcp_client.py is responsible for the actual connection and communication with MCP servers, handling the SSE connections and configurations.

##### Relationships and Data Flow
- The Plugin Entry Point (main.py) initializes the Agent by loading configurations (from manifest.yaml and possibly .env/example).
- The Provider module (agent.py) acts as the orchestrator, loading and choosing among various strategies based on scenarios defined in the YAML strategy configurations.
- When a tool/action is required, the Provider uses one of the strategies (from the “strategies” folder) to make decisions and prepare requests.
- The prompt module builds the communication templates that the agent uses to generate questions/answers.
- The agent’s output is sent to the output parser, which interprets the chain-of-thought or structured responses.
- Lastly, the MCP Client (from the “utils” directory) takes care of communicating with external MCP servers – using configurations (as shown in the README examples) to manage connections and tool calls.

##### Architectural Patterns and Key Technologies
- Strategy Pattern: Clearly visible in the “strategies” folder, where different strategies are implemented as separate modules (each coupled with a YAML configuration).
- Plugin/Extension Architecture: The design supports dynamic installations via GitHub, promoting extensibility.
- Separation of Concerns: Each directory (provider, strategies, prompt, output_parser, utils) encapsulates a distinct aspect of the overall functionality, ensuring modular design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Initialization"
        A["Plugin Entry (main.py & manifest.yaml)"]:::core
    end

    subgraph "Core Modules"
        B["Agent Provider (provider/agent.py, provider/agent.yaml)"]:::core
        C["Strategy Module – ReAct (strategies/ReAct.py, strategies/ReAct.yaml)"]:::core
        D["Strategy Module – Function Calling (strategies/function_calling.py, strategies/function_calling.yaml)"]:::core
        E["Prompt Handler (prompt/template.py)"]:::core
        F["Output Parser (output_parser/cot_output_parser.py)"]:::core
        G["MCP Client Utility (utils/mcp_client.py)"]:::core
    end

    subgraph "External Services"
        H["External MCP Servers"]:::external
    end

    A -->|"initializes"| B
    B -->|"selects_strategy"| C
    B -->|"selects_strategy"| D
    B -->|"sends_prompt"| E
    C -->|"returns_decision"| B
    D -->|"returns_decision"| B
    B -->|"processes_output"| F
    B -->|"communicates_with"| G
    G -->|"SSE_connection"| H

    click A "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/main.py"
    click A "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/manifest.yaml"
    click B "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/provider/agent.py"
    click B "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/provider/agent.yaml"
    click C "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/strategies/ReAct.py"
    click C "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/strategies/ReAct.yaml"
    click D "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/strategies/function_calling.py"
    click D "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/strategies/function_calling.yaml"
    click E "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/prompt/template.py"
    click F "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/output_parser/cot_output_parser.py"
    click G "https://github.com/junjiem/dify-plugin-agent-mcp_sse/blob/main/utils/mcp_client.py"

    classDef core fill:#d0e7ff,stroke:#1f78b4,stroke-width:2px;
    classDef external fill:#dfffcf,stroke:#33a02c,stroke-width:2px,stroke-dasharray: 5 5;
```
