Excel任务与图表生成服务

一个通过标记单元格将任务和PlantUML图表写入Excel模板的服务,支持代码捕获和自动文档生成。

  • by bobaonhan123
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 bobaonhan123/mcp_lab

使用说明

复制MCP Excel任务服务器

此项目公开了一个简单的MCP服务器,该服务器使用标记单元格将编号的主要/支持任务写入Excel模板(marker[main_task] 和 marker[support_task]).它还支持生成PlantUML图并将其嵌入Excel文件中。包含一个Copilot就绪提示,用于自动生成任务并调用MCP工具。

先决条件

  • Python 3.11+推荐
  • Windows shell示例使用 powershell;调整其他壳的路径
  • 虚拟环境(推荐): python -m venv venv
  • 对于PlantUML:Docker已安装并正在运行

安装依赖项

.\venv\Scripts\Activate
pip install -r requirements.txt

运行PlantUML服务器(Docker)

在使用PlantUML功能之前,请启动PlantUML服务器:

docker run -d -p 8080:8080 plantuml/plantuml-server:jetty

这将运行PlantUML服务器http://localhost:8080.

运行MCP服务器

从repo根目录:

.\venv\Scripts\python -m src.app

这将启动中定义的FastMCP服务器 src/app/app.py.

默认文件位置

  • 模板: templates/template.xlsx (包含任务的标记单元格)
  • PlantUML模板: templates/plantuml_template.xlsx (包含图表的标记单元格)
  • 输出: output/tasks.xlsx (由工具创建/覆盖)
  • PlantUML输出: output/plantuml_diagram.xlsx

MCP工具

任务工具

  • write_task_list(main_tasks, support_tasks, template_path?, output_path?)
    • 在标记列下写入编号的任务,保留每个标记下的行样式。

PlantUML工具

  • write_plantuml_to_excel(puml_code, template_path?, output_path?, server_url?, image_width?, image_height?)

    • 使用标记单元格将PlantUML代码和渲染图像写入Excel(marker[plantuml], marker[plantuml_image])
  • write_plantuml_image(puml_code, excel_path, output_path?, cell_anchor?, sheet_name?, server_url?, image_width?, image_height?)

    • 将PlantUML图像写入任何Excel文件中的特定单元格(不需要标记)
  • generate_plantuml_png(puml_code, output_path?, server_url?)

    • 生成PlantUML图作为独立的PNG文件

代码捕获工具

  • capture_code_block(file_path, start_line, end_line?)

    • 从具有行号(1-索引)的源文件中捕获代码块
    • 返回带文件路径、行号和语法突出显示的格式化代码
    • end_line 是可选的;如果省略,则捕获单行
  • capture_multiple_blocks(file_path, ranges)

    • 从同一文件中捕获多个代码块
    • ranges:[start_line,end_line]对列表(1索引)
    • 返回包含所有捕获块的格式化文档

Excel工具代码

  • write_code_to_excel(file_path, ranges, output_path?, title?)

    • 捕获代码块并使用格式化的行号写入Excel
    • 创建包含所有代码块的单页
  • write_code_and_diagram_to_excel(file_path, ranges, puml_code, output_path?, server_url?)

    • 使用创建Excel 2张:
      • 表1“代码块”:带行号的捕获代码
      • 表2“序列图”:PlantUML代码和渲染图图像

基于AST的代码捕获工具(Python)

这些工具使用Python的AST模块 自动检测 函数、类和方法-不需要手动行号!

  • analyze_python_file(file_path)

    • 分析Python文件并返回所有代码元素(函数、类、方法)
    • 每个元素包括:名称、类型、开始/结束行、docstring、装饰器
  • capture_function(file_path, function_name)

    • 通过自动行检测按名称捕获函数
    • 返回带有行号和语法突出显示的格式化代码
  • capture_class(file_path, class_name, include_methods?)

    • 按名称捕获类,可选地包括其所有方法
    • 默认值:包括方法
  • capture_method(file_path, class_name, method_name)

    • 从类中捕获特定方法
  • capture_by_names(file_path, names)

    • 在一次调用中按名称捕获多个元素
    • 支持混合函数和类
  • capture_all_functions(file_path, include_classes?)

    • 捕获文件中的所有函数(以及可选的类)
    • 非常适合全面的文档

MCP提示

任务提示

  • random_task_list -要求模型发明任务并调用 write_task_list.

PlantUML提示

  • draw_plantuml -要求模型根据描述创建PlantUML图。

    • 参数: diagram_description, diagram_type (序列/类/用例/活动/状态)
  • plantuml_from_code -要求模型分析源代码并生成PlantUML图。

    • 参数: source_code, diagram_type

代码捕获提示

  • capture_code -要求模型从文件中捕获并记录代码块。

    • 参数: file_path, description (可选)
    • 提取带有行号的相关代码段
  • analyze_code_structure -要求模型分析整体代码结构和架构。

    • 参数: file_path
    • 识别组件、关系和设计模式

代码转换为Excel提示

  • capture_code_to_excel -捕获代码块并保存到Excel文件。

    • 参数: file_path, description (可选)
    • 创建带有行号的格式化Excel
  • document_code_with_diagram -使用代码块和序列图创建Excel(2张)。

    • 参数: file_path, diagram_description (可选)
    • 表1:带行号的代码块
    • 表2:PlantUML序列图及渲染图像

AST代码捕获提示

  • auto_capture_code -按名称自动分析和捕获代码元素。
    • 参数: file_path, element_names (可选逗号分隔)
    • 使用AST检测没有行号的函数/类

与GitHub Copilot/MCP客户端一起使用

  1. 启动PlantUML服务器: docker run -d -p 8080:8080 plantuml/plantuml-server:jetty
  2. 启动MCP服务器(python -m src.app).
  3. 在启用MCP的客户端(例如Copilot Chat)中,选择服务器并选择提示:
    • random_task_list 用于生成任务
    • draw_plantuml 用于创建图表
  4. 该模型将生成内容并调用相应的工具。

定制

  • 通过传递更改模板/输出路径 template_path/output_path 通过工具或编辑提示文本。
  • 任务计数可以通过提示参数进行调整(main_count, support_count).
  • PlantUML服务器URL可以通过以下方式更改 server_url 参数(默认值:http://localhost:8080).

提示文件

  • prompts/copilot_random_task_prompt.txt -准备粘贴任务生成提示
  • prompts/copilot_plantuml_prompt.txt -准备粘贴PlantUML图生成提示
  • prompts/copilot_capture_code_prompt.txt -准备粘贴代码捕获提示
  • prompts/copilot_document_with_diagram_prompt.txt -准备将代码+图表粘贴到Excel提示符

例子

捕获代码块

User: Use the capture_code prompt on src/helpers/code.py to document the capture_code_block function
AI: Captures lines with the function definition and explains its purpose

分析代码结构

User: Use analyze_code_structure prompt on src/app/app.py
AI: Identifies all tools and prompts, captures relevant sections, explains the architecture

创建图表

User: Use draw_plantuml to create a sequence diagram showing how code capture works
AI: Generates PlantUML diagram and saves it to Excel

基于AST的代码捕获(新增!)

User: Capture the detect_language function from src/helpers/code.py
AI: Uses capture_function tool - no line numbers needed!
    Returns formatted code with automatic line detection
User: Analyze src/helpers/code.py and capture all functions
AI: Uses analyze_python_file to get file summary, then capture_all_functions
    Creates comprehensive documentation of all code elements