How junjiem/dify-plugin-agent-mcp_sse works
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.