mcpField
M
MSPaint MCP Server with AI-based Planning Algorithms

MSPaint MCP Server with AI-based Planning Algorithms

ローカル
github.com/shettysaish20AI・エージェント182 週間前に更新

MSPaint MCP Server with AI-based Planning Algorithms について

Google Gemini、MCP ツール、MSPaint の自動操作を組み合わせ、複数段階の数式を解いて結果をキャンバスに描画するプロジェクトです。AI の計画立案やデスクトップ自動化を試す開発者向けで、計算と検証のツールを備えています。

主な機能

  1. 01数式を段階的に解く
  2. 02計算と整合性の検証
  3. 03MSPaint の操作を自動化
  4. 04答えをキャンバスに描画

活用シーン

  1. 01複数段階の数学問題の解法を実演
  2. 02計算結果を MSPaint に描画
  3. 03MCP による Windows アプリ自動化の検証

MCP 対応

MCP サーバーは fastmcp を通じて、数学演算、検証、MSPaint 操作のツールを公開します。付属クライアントがサーバーに接続し、Google Gemini によるツール呼び出しを調整します。

設定

ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。

インストール方法は未掲載です

このサーバーのパッケージやリモートエンドポイントはまだ取得できていません。プロジェクトの README の手順に従ってください。

リポジトリ

ツール

ツール一覧はまだ取得されていません

ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。

詳細

AIベースの計画アルゴリズムを備えたMSPaint MCPサーバー

このプロジェクトでは、高度なAIプロンプト技術を使って、LLMが複数の手順を要する複雑な数学の問題を確実に扱えるようにする方法を紹介します。Model Context Protocol(MCP)を使い、GoogleのGeminiモデルを搭載したAIエージェントが、レガシーなWindowsアプリケーション(MSPaint)とやり取りできるようにします。AIエージェントは、fastmcpを使って定義し、pywinautoで実装したツールを活用して数学の問題を解き、その解答をPaintのキャンバスに描画します。

目次

はじめに

このプロジェクトでは、高度なAIプロンプト技術を使って、LLMが複数の手順を要する複雑な数学の問題を確実に扱えるようにする方法を紹介します。

この問題文に対する構造化プロンプト

You are a math agent with painting skills, solving complex math expressions step-by-step.
You have access to various mathematical tools for calculations and verifications, as well as an MSPaint application to draw and present your solution on a canvas.

Available Tools:
{tools_description}

MSPaint Application Information:
- Rectangle coordinates: x1 = 763, y1 = 595, x2 = 1788, y2 = 1123

You must respond with EXACTLY ONE LINE in one of these formats (no additional text):

1. For function calls:
FUNCTION_CALL: {{"name": function_name, "arguments": {{"param1": value1, "param2": value2}}}}

2. For final answers:
FINAL_ANSWER: <NUMBER>

3. For completing the task:
COMPLETE_RUN

Instructions:
- Start by calling the show_reasoning tool ONLY ONCE with a list of all step-by-step reasoning steps explaining how you will solve the problem. Once called, NEVER CALL IT AGAIN UNDER ANY CIRCUMSTANCES.
- When reasoning, tag each step with the reasoning type (e.g., [Arithmetic], [Logical Check]).
- Use all available math tools to solve the problem step-by-step.
- When a function returns multiple values, process all of them.
- Apply BODMAS rules: start with the innermost parentheses and work outward.
- Do not skip steps — perform all calculations sequentially.
- Respond only with one line at a time.
- Call only one tool per response.
- After calculating a number, verify it by calling:
FUNCTION_CALL: {{"name": "verify_calculation", "arguments": {{"expression": <MATH_EXPRESSION>, "expected": <NUMBER>}}}}
- If verify_calculation returns False, re-evaluate your previous steps.
- Once you reach a final answer, check for consistency of all steps and calculations by calling:
FUNCTION_CALL: {{"name": "verify_consistency", "arguments": {{"steps": [[<MATH_EXPRESSION1>, <ANSWER1>], [<MATH_EXPRESSION2>, <ANSWER2>], ...]}}}} 
- If verify_consistency returns False, re-evaluate your previous steps.
- Once verify_consistency return True, submit your final result as:
FINAL_ANSWER: <NUMBER>

Paint Instructions:
- To draw in Paint, follow this sequence strictly:
1. Call open_paint to start the Paint application.
2. Verify Paint is open using verify_paint_open.
3. If verify_paint_open returns False, retry opening Paint until it succeeds.
4. After Paint is open, draw a rectangle using draw_rectangle with correct parameters.
5. Add text using add_text_in_paint, inserting your FINAL_ANSWER: <NUMBER>.

Final Step:
- After completing all calculations, verifications, and drawings, call:
COMPLETE_RUN

Strictly follow the above guidelines.
Your entire response should always be a single line starting with either FUNCTION_CALL:, FINAL_ANSWER: or COMPLETE_RUN.

ChatGPTによる構造化プロンプトの評価結果

{
  "explicit_reasoning": true,
  "structured_output": true,
  "tool_separation": true,
  "conversation_loop": true,
  "instructional_framing": true,
  "internal_self_checks": true,
  "reasoning_type_awareness": true,
  "fallbacks": true,
  "overall_clarity": "Extremely strong prompt — it carefully enforces step-by-step reasoning, structured outputs, error handling, and tool use separation. Very minor improvements could be to give a short worked-out example, but even without it, the robustness is excellent."
}

プロジェクト構成

├── MSPaint-MCP-Server/
│ ├── mcp_server.py # Defines the MCP server with tools for Paint automation 
│ ├── mcp_client.py # Defines the MCP client that interacts with the server and AI model 
│ ├── requirements.txt # Lists the project dependencies 
│ └── .env # Stores the Gemini API key 
├── README.md # This file

要件

  • Python 3.11+
  • Conda(環境管理に推奨)
  • Google Gemini APIキー
  • pywin32
  • pywinauto
  • fastmcp
  • python-dotenv
  • google-genai
  • rich

セットアップ

  1. Conda環境を作成します:

    conda create -n eagenv python=3.11
    conda activate eagenv
    
  2. 依存関係をインストールします:

    pip install -r requirements.txt
    
  3. Gemini APIキーを設定します:

    • ディレクトリに.envファイルを作成します。

    • .envファイルにGemini APIキーを追加します:

      GEMINI_API_KEY=YOUR_API_KEY
      

使い方

  1. MCPクライアントを実行します:

    python mcp_paint_app/mcp_client.py
    

    これによりMCPクライアントが起動し、MCPサーバーに接続してAIエージェントを初期化し、自動化処理を開始します。

仕組み

  1. MCPサーバー(mcp_server.py):

    • MSPaintとやり取りするツール(例:open_paint、draw_rectangle、add_text_in_paint)と、さまざまな数学演算(例:add、subtract、multiply、divide、verify_calculation、verify_consistency)を定義します。
    • pywinautoを使ってMSPaintアプリケーションを操作します。
    • fastmcpライブラリを介してこれらのツールを公開します。
  2. MCPクライアント(mcp_client.py):

    • MCPサーバーに接続します。
    • Google Geminiモデルを使って指示を生成し、与えられた数式を解きます。
    • モデルの出力を解析し、呼び出すツールを特定します。
    • 必要なパラメーターを指定して、MCPサーバー上の適切なツールを呼び出します。
    • ツールからの応答を処理し、次の手順に向けてモデルに返します。
    • 最終的な答えをMSPaintに描画する処理を調整します。
  3. AIエージェント(Google Gemini):

    • 複雑な数式(例:((3000 - (400+552)) / 2 + 1024)を受け取ります。
    • 利用可能なツール(システムプロンプトで定義)を使って、問題を手順ごとに解きます。
    • ツールを使うための関数呼び出し(例:FUNCTION_CALL: {"name": "add", "arguments" {"a": 400, "b": 552}})を生成します。
    • verify_calculationツールを使って各計算を検証します。
    • verify_consistencyツールを使ってすべての手順の整合性を確認します。
    • 最終的な答えを得て検証した後、Paintを開き、長方形を描画して最終的な答えをテキストとして追加し、結果を表示します。
    • COMPLETE_RUNコマンドを呼び出して実行を完了します。

主なコンポーネント

  • mcp_server.py: MSPaint を自動化するためのコアロジックが含まれています。open_paint、draw_rectangle、add_text_in_paint 関数は、AI エージェントが使用する主要なツールです。
  • mcp_client.py: AI エージェントと MCP サーバー間のやり取りを管理します。システムプロンプトを設定し、ツールを呼び出して、応答を処理します。
  • requirements.txt: プロジェクトに必要なすべての Python パッケージを一覧表示します。
  • .env: Google Gemini API キーを保存します。

トラブルシューティング

  • 権限の問題: 権限の問題が発生した場合は、スクリプトを管理者として実行してみてください。
  • 座標の問題: MSPaint でのクリックに使用する座標は、画面の解像度やウィンドウサイズに応じて調整が必要な場合があります。コード内のデバッグ用の print 文を使って、正しい座標を確認してください。
  • ツール選択の問題: AI エージェントが正しいツールを選択しない場合は、システムプロンプトを見直し、ツールの説明が正確であることを確認してください。
  • API キーの問題: Gemini API キーが .env ファイルに正しく設定されていることを確認してください。

コントリビューション

コントリビューションを歓迎します!変更を加えたプルリクエストを送信してください。

ライセンス

MIT ライセンス

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。