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. 03自动控制 MSPaint
  4. 04在画布绘制答案

适用场景

  1. 01演示多步骤数学问题求解
  2. 02将计算结果绘制到 MSPaint
  3. 03探索 MCP 驱动的 Windows 应用自动化

MCP 相关

MCP 服务通过 fastmcp 暴露数学运算、校验及 MSPaint 控制工具;配套客户端连接服务并协调 Google Gemini 调用这些工具。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

基于 AI 规划算法的 MSPaint MCP 服务

本项目演示如何使用高级 AI 提示词技术,让大模型能够稳健地处理多步骤复杂数学问题。项目使用 Model Context Protocol(MCP),让由 Google Gemini 模型驱动的 AI Agent 与传统 Windows 应用(MSPaint)交互。AI Agent 使用通过 fastmcp 定义并借助 pywinauto 实现的工具来解答数学问题,然后在 Paint 画布上绘制解答。

目录

简介

本项目展示了如何使用高级 AI 提示词技术,让大模型能够稳健地处理多步骤复杂数学问题。

针对该问题陈述的结构化提示词

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 文件。

    • 将 Gemini API 密钥添加到 .env 文件中:

      GEMINI_API_KEY=YOUR_API_KEY
      

用法

  1. 运行 MCP 客户端:

    python mcp_paint_app/mcp_client.py
    

    这将启动 MCP 客户端,使其连接到 MCP 服务、初始化 AI Agent 并开始自动化流程。

工作原理

  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 Agent(Google Gemini):

    • 接收一个复杂数学表达式(例如 ((3000 - (400+552)) / 2 + 1024)。
    • 使用可用工具(在系统提示词中定义)逐步解答问题。
    • 生成函数调用(例如 FUNCTION_CALL: {"name": "add", "arguments" {"a": 400, "b": 552}})来使用这些工具。
    • 使用 verify_calculation 工具验证每次计算。
    • 使用 verify_consistency 工具确保所有步骤保持一致。
    • 得出并验证最终答案后,使用 Paint 显示结果:打开 Paint、绘制矩形并将最终答案添加为文本。
    • 通过调用 COMPLETE_RUN 命令结束运行。

关键组件

  • mcp_server.py: 包含自动化 MSPaint 的核心逻辑。open_paint、draw_rectangle 和 add_text_in_paint 函数是 AI Agent 使用的关键工具。
  • mcp_client.py: 管理 AI Agent 与 MCP 服务之间的交互。它会设置系统提示词、调用工具并处理响应。
  • requirements.txt: 列出项目所需的所有 Python 软件包。
  • .env: 存储 Google Gemini API 密钥。

故障排除

  • 权限问题: 如果遇到权限问题,请尝试以管理员身份运行脚本。
  • 坐标问题: 在 MSPaint 中用于点击的坐标可能需要根据屏幕分辨率和窗口大小进行调整。使用代码中的调试打印语句来确定正确的坐标。
  • 工具选择问题: 如果 AI Agent 未选择正确的工具,请检查系统提示词,并确保工具描述准确。
  • API 密钥问题: 确保在 .env 文件中正确设置了 Gemini API 密钥。

贡献

欢迎贡献!请提交包含更改的拉取请求。

许可证

MIT 许可证

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。