MAGI MCP Server

Integrations

  • Enables containerized deployment of the MAGI MCP Server, allowing for portable and consistent code review environments with configurable gateway connections.

  • Provides a standardized interface for submitting Python code for review through the MAGI system, with support for analysis by Melchior, Balthasar, and Casper agents.

MAGI MCP サーバー

MAGIコードレビューシステム用のMCPサーバー実装。このサーバーは、モデルコンテキストプロトコル(MCP)を使用してコードレビューを送信し、その進捗状況を監視するための標準化されたインターフェースを提供します。

特徴

  • コード提出とレビューのオーケストレーション
  • 分散コードレビューのためのMAGIゲートウェイとの統合
  • Melchior、Balthasar、Casper エージェントを使用したマルチエージェント レビュー システム
  • コード品質評価のための多数決による意思決定

はじめる

前提条件

  • Python 3.11以上
  • MAGIゲートウェイへのアクセス(デフォルト:ws://127.0.0.1:8000/ws)
  • Docker(オプション、コンテナ化されたデプロイメント用)

インストール

  1. リポジトリをクローンする
  2. 依存関係をインストールします:
    pip install -r requirements.txt

使用法

このプロジェクトは、次の 2 つの主要コンポーネントで構成されています。

  1. MCP サーバー ( src/server.py ) - コードレビュー用の MCP プロトコルを実装します
  2. テストクライアント ( src/client.py ) - サーバーの機能をテストするためのシンプルなクライアント

サーバーの実行

python -m src.server

デフォルトでは、サーバーはws://127.0.0.1:8000/wsにあるMAGIゲートウェイに接続します。この設定は、 MAGI_URL環境変数を設定することで上書きできます。

MAGI_URL=ws://your-magi-gateway.com/ws python -m src.server

注: MAGI System の公式ゲートウェイを使用できます: ws://magisystem.ai/ws

Docker デプロイメント

Docker を使用して MAGI MCP SSE サーバーをデプロイすることもできます。

  1. Docker イメージをビルドします。
    docker build -t magi-mcp-server .
  2. コンテナを実行します。
    docker run -p 8080:8080 magi-mcp-server
  3. 特定の MAGI ゲートウェイに接続するには:
    docker run -p 8080:8080 -e MAGI_URL=ws://your-magi-gateway.com/ws magi-mcp-server
  4. デバッグモードで実行するには:
    docker run -p 8080:8080 -e DEBUG=1 magi-mcp-server

クライアントとのテスト

client.pyスクリプトは、MCP Server の機能を検証するためのテストツールとして提供されています。本番環境での使用を意図したものではありません。

python -m src.client --file path/to/your/code.py

クライアントオプション

  • --file , -f : レビューするPythonファイルへのパス
  • --magi-url : MAGIゲートウェイWebSocket URL(デフォルト: ws://127.0.0.1:8000/ws)
  • --server-script : サーバースクリプトへのパス (デフォルト: src/server.py)
  • --timeout : レビューのタイムアウト(秒)(デフォルト: 300)
  • --output , -o : 結果をJSONファイルに保存する
  • --debug : デバッグモードを有効にする

ファイルが提供されない場合、クライアントはテストにサンプル コード スニペットを使用します。

# Review a specific Python file python -m src.client --file my_code.py # Save review results to a file python -m src.client --file my_code.py --output review_results.json # Use a custom MAGI Gateway python -m src.client --file my_code.py --magi-url ws://custom-gateway:8000/ws

(base) ➜ mcp-magi git:(main) ✗ python src/client.py 2025-03-03 03:24:45,320 - magi-client - INFO - Creating MAGIClient... 2025-03-03 03:24:45,321 - magi-client - INFO - Using server script: /workspace/mcp-magi/src/server.py 2025-03-03 03:24:45,321 - magi-client - INFO - MAGI URL: ws://127.0.0.1:8000/ws 🚀 Starting MAGI Code Review... 2025-03-03 03:24:45,321 - magi-client - INFO - Starting code review... 2025-03-03 03:24:45,321 - magi-client - INFO - Starting stdio client... 2025-03-03 03:24:45,327 - magi-client - INFO - Initializing client session... 2025-03-03 03:24:45,564 - magi-client - INFO - Session initialized successfully 2025-03-03 03:24:45,565 - magi-client - INFO - Calling code_review tool... INFO:mcp.server.lowlevel.server:Processing request of type CallToolRequest WARNING:__main__:Received response for different request ID: None WARNING:__main__:Received response for different request ID: None 2025-03-03 03:24:55,501 - magi-client - INFO - Code review completed successfully 2025-03-03 03:24:55,555 - magi-client - INFO - Review completed, printing results... ================================================== MAGI CODE REVIEW RESULTS ================================================== 🎯 Final Decision: NEGATIVE ✅ Passed: False 📝 Detailed Reviews: -------------------------------------------------- Reviewer melchior: I'll analyze this code from an architectural perspective. Architectural Review: 1. Code Organization: - The code follows a basic modular structure with separate function definitions - There's a clear entry point with the `if __name__ == "__main__"` idiom - Functions have single responsibilities, which aligns with SOLID principles 2. Design Patterns: - The code implements a simple procedural pattern - While basic, it demonstrates separation of concerns between calculation and program execution 3. Component Interactions: - Clear data flow between functions - Simple and predictable function interfaces - Low coupling between components 4. Scalability & Maintainability: - The code is easily maintainable due to its simplicity - The `calculate_sum` function is reusable and independent - Could benefit from type hints for better maintainability - No error handling mechanisms in place Recommendations: 1. Add type hints: \```python def calculate_sum(numbers: list[int]) -> int: \``` 2. Consider adding input validation 3. Could be enhanced with a proper exception handling strategy 4. Consider implementing an interface or class structure for more complex scenarios <decision>POSITIVE</decision> While the code is very basic, it follows good architectural principles: - Clear separation of concerns - Single responsibility principle - Good modularization - Clean interface between components The code provides a solid foundation that could be easily extended while maintaining its architectural integrity. The simplicity here is actually a strength, as it doesn't over-engineer a straightforward solution. Reviewer balthasar: I'll analyze this Python code from a security and stability perspective: Security Analysis: 1. Input Validation: - No input validation is performed on the 'numbers' parameter - Could potentially accept non-numeric values leading to TypeErrors - No bounds checking for potential integer overflow 2. Error Handling: - No exception handling mechanisms - Could crash if invalid input is provided - No logging of errors or unexpected behavior 3. Data Protection: - No sensitive data handling concerns in this simple example - Variables are appropriately scoped 4. Stability Issues: - No type hints to ensure correct input types - No protection against large input arrays that could cause memory issues Recommended Improvements: \```python from typing import List, Union import logging def calculate_sum(numbers: List[Union[int, float]]) -> Union[int, float]: try: if not numbers: return 0 if not all(isinstance(x, (int, float)) for x in numbers): raise TypeError("All elements must be numbers") return sum(numbers) except Exception as e: logging.error(f"Error in calculate_sum: {str(e)}") raise def main() -> None: try: numbers = [1, 2, 3, 4, 5] result = calculate_sum(numbers) print(f"The sum is: {result}") except Exception as e: print(f"An error occurred: {str(e)}") \``` While the original code is functional for basic use cases, it lacks important security and stability features that would make it production-ready. <decision>NEGATIVE</decision> Reasons for negative decision: 1. Missing input validation 2. No error handling 3. No type checking 4. No logging mechanism 5. Potential for uncaught exceptions The code needs significant improvements to meet security and stability standards for production use. While it may work for simple cases, it's not robust enough for handling edge cases or potential misuse. Reviewer casper: I'll review this Python code focusing on functionality, implementation, and user experience aspects. Code Review: 1. Functionality and Completeness: - The code successfully implements a basic sum calculation function - The main structure is properly organized with separate functions - Includes proper `if __name__ == "__main__":` entry point - Basic functionality is complete for the intended purpose 2. User Experience: - Output message is clear and descriptive ("The sum is: ") - However, lacks input validation for non-numeric values - No error handling for empty lists or invalid inputs - Could benefit from user interaction rather than hardcoded values 3. Performance and Efficiency: - The implementation is simple and straightforward - For small lists, the performance is acceptable - Could use built-in `sum()` function for better performance - Memory usage is minimal and efficient 4. Implementation Best Practices: - Good function naming conventions - Clear code structure - Missing docstrings for function documentation - No type hints which could improve code clarity Suggestions for Improvement: \```python def calculate_sum(numbers: list[float]) -> float: """Calculate the sum of numbers in a list. Args: numbers: List of numbers to sum Returns: float: Sum of all numbers Raises: ValueError: If list is empty or contains non-numeric values """ if not numbers: raise ValueError("List cannot be empty") return sum(numbers) def main(): try: numbers = [float(x) for x in input("Enter numbers separated by space: ").split()] result = calculate_sum(numbers) print(f"The sum is: {result}") except ValueError as e: print(f"Error: {e}") if __name__ == "__main__": main() \``` <decision>POSITIVE</decision> The code is fundamentally sound and achieves its basic purpose. While there's room for improvement in terms of error handling, user interaction, and documentation, the current implementation is functional and follows basic programming principles. The positive decision is based on the code's correct functionality and clear structure, though implementing the suggested improvements would make it more robust and user-friendly. 🤖 MAGI Agents State: -------------------------------------------------- 🔹 MELCHIOR: Decision: NEGATIVE Content: I'll analyze this code from an architectural perspective. Architectural Review: 1. Code Organization: - The code follows a basic modular structure with separate function definitions - There's a clea... 🔹 BALTHASAR: Decision: NEGATIVE Content: I'll analyze this Python code from a security and stability perspective: Security Analysis: 1. Input Validation: - No input validation is performed on the 'numbers' parameter - Could potentially acce... 🔹 CASPER: Decision: NEGATIVE Content: I'll review this Python code focusing on functionality, implementation, and user experience aspects. Code Review: 1. Functionality and Completeness: - The code successfully implements a basic sum ca... ✨ Review completed successfully!

建築

サーバーは、MCP クライアントと MAGI ゲートウェイ間のブリッジとして機能します。

Test Client <-> MCP Server <-> MAGI Gateway <-> Review Agents (Melchior, Balthasar, Casper)

レビュープロセス:

  1. クライアントがMCPサーバーにコードを送信する
  2. サーバーはコードをMAGIゲートウェイに転送します
  3. MAGI Gatewayはコードを3つのレビューエージェントに配布します
  4. 各エージェントはコードをレビューし、肯定的または否定的な決定を下します。
  5. 最終決定は多数決に基づきます(承認には少なくとも 2 件の肯定的なレビューが必要です)
  6. 結果がクライアントに返されます

発達

開発目的でデバッグ ログを有効にすることができます。

DEBUG=1 python -m src.server

またはクライアントを使用する場合:

python -m src.client --file my_code.py --debug

ライセンス

MITライセンス

-
security - not tested
F
license - not found
-
quality - not tested

Melchior、Balthasar、Casper エージェントを含むマルチエージェント システムを使用してコード レビューを調整するための Model Context Protocol (MCP) を実装するサーバー。

  1. Features
    1. Getting Started
      1. Prerequisites
      2. Installation
    2. Usage
      1. Running the Server
      2. Docker Deployment
      3. Testing with the Client
      4. Example
      5. Example
    3. Architecture
      1. Development
        1. License
          ID: naunhpm1jr