需求规划分析服务

一个提供19种工具的MCP服务器,用于自动化需求规划分析,包括产品/位置层次结构导航、计算准确性/偏差/FVA指标、识别根本原因并生成自包含的Reveal.js HTML演示文稿。

  • by mswastik
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 mswastik/demand-mcp

使用说明

需求计划MCP服务器

MCP服务器暴露 19工具 用于自动化需求计划分析。 LLM协调这些工具来导航产品/位置层次结构, 计算准确性/偏差/FVA指标,确定根本原因,并产生 一个自包含的Reveal.js HTML演示文稿——以及加载和编辑 一个现有的演示文稿,而无需从头开始重建。


项目结构

demand_mcp/
├── server.py          # FastMCP server entry point — 19 tools
├── data.py            # Data loading, PackContent normalization, filters
├── metrics.py         # Accuracy, bias, FVA, YoY, evolution computations
├── presentation.py    # Reveal.js + Plotly HTML builder
├── config.yaml        # Server configuration (paths, fiscal year, defaults)
├── brand.json         # Brand colors, fonts — edit to match your org
├── requirements.txt
├── prompts/
│   └── system.md      # System prompt for your LLM orchestrator
└── output/            # Generated HTML presentations go here

设置

pip install -r requirements.txt

配置

1.编辑 config.yaml

parquet_path: "path/to/your/demand.parquet"
output_dir:   "output"
brand_config: "brand.json"
fiscal_year_start_month: 1   # 1=Jan, 4=Apr, 7=Jul, 10=Oct

2.编辑 brand.json

预填充Stryker默认值。更新 colors, fonts,以及 logo_path 以匹配您组织的品牌。关键字段:

{
  "company_name": "Your Company",
  "colors": {
    "primary":   "#F4A11D",   // main accent (buttons, bars, highlights)
    "secondary": "#003087",   // headings, slide headers
    "df_color":  "#F4A11D",   // DF forecast line/bars in charts
    "stat_color":"#003087",   // Stat forecast line/bars in charts
    "actual_color":"#2E7D32"  // Actuals line/bars in charts
  },
  "fonts": {
    "heading": "Calibri, Arial, sans-serif",
    "body":    "Calibri, Arial, sans-serif"
  }
}

运行服务器

cd demand_mcp
python server.py
# or with a custom config:
python server.py --config /path/to/config.yaml

服务器启动于 127.0.0.1:8000 (可在中配置 config.yaml). 拼花地板文件已加载 一旦启动 --重新启动服务器以获取新数据。


连接您的法学硕士

配置本地LLM客户端以连接到MCP服务器。 复制以下内容 prompts/system.md 正如系统提示的那样。

使用任何支持MCP的OpenAI兼容客户端的示例:

client = YourLLMClient(
    mcp_server_url="http://127.0.0.1:8000",
    system_prompt=open("prompts/system.md").read(),
)
response = client.chat("Generate a demand planning review for last month.")

19工具

数据探索

# 工具 目的
1 get_data_info 行数、日期范围、层次结构唯一计数
2 get_hierarchy_members 列出任何层次结构级别的值(带可选过滤器)
3 get_date_range 可用月份(带可选过滤器)

指标

# 工具 目的
4 compute_accuracy_summary 精度(所有4个滞后)按任何层次组合分组
5 compute_bias_summary 偏差百分比和单位(所有4个滞后)
6 compute_fva_summary FVA=测向精度-统计精度
7 get_accuracy_trend 给定滞后的月度精度趋势
8 get_yoy_growth 与DF和Stat预测相比,销量同比增长
9 get_forecast_evolution L2 → L1 → L0 → 每月Fcst与实际值
10 get_top_offenders 按任何指标对层次结构成员进行排名(用于深入分析)

演示文稿(新建)

# 工具 目的
11 initialize_presentation 启动一个新的空白HTML演示会话
12 add_slide 附加一张幻灯片(标题/指标/图表/表格/图表表格/两个标签/评论)
13 finalize_presentation 编写HTML+sidecar .state.json;返回输出路径

高效的报告生成

# 工具 目的
14 generate_standard_report 预先计算所有9张标准幻灯片+在一次调用中返回JSON简报
15 add_commentary 在指定幻灯片上写叙述性文本(通过 slide_id)
16 get_presentation_status 列出所有幻灯片、ID和评论状态——用于重置后恢复
17 drill_down_slide 在下一个层次结构级别附加一个重点深入的幻灯片

编辑现有演示文稿

# 工具 目的
18 list_presentations 列出输出目录中保存的HTML文件;可编辑的标志
19 load_presentation 将保存的演示文稿重新加载到内存中进行编辑

时间窗口

所有度量工具都接受 window 参数:

值 描述
last_month 最近完成的一个月
last_3_months 最近完成的三个月
last_12_months 滚动12个月
ytd 1月1日至最后完成月份
YYYY-MM:YYYY-MM 显式范围,例如。 2024-01:2024-06
None 所有可用的实际历史记录

层次结构参考

位置(粗略→ fine)

Stryker Group Region → Area → Region → Country

产品(粗→ fine)

Business Sector → Business Unit → Franchise → Product Line → IBP Level 5 → IBP Level 6 → IBP Level 7 → CatalogNumber

预测水平 (用于准确性报告):

  • 东亚地区→ uses 区域 作为预测水平
  • 所有其他→ uses 区域 作为预测水平

度量定义

度量 公式 解释
准确度 1 - ΣAbsErr / ΣAct 更高=更好。目标≥70%
偏差% Σ(Act−Fcst) / ΣAct +ve=预测不足,-ve=预测过高
偏置单位 Σ(Act−Fcst) 已签署的数量差距
战车武器装备 DF Acc − Stat Acc +ve=DF增加值;−ve=定子节拍DF

所有卷系列均 包装内容物标准化 (除以装载时的包装内容物)。


输出

生成的演示文稿将保存到 output_dir 在...中指定 config.yaml. 打开 .html 任何浏览器中的文件——不需要服务器,所有依赖项都是CDN链接的。

使用箭头键或单击浏览幻灯片。演讲者笔记可以通过以下方式切换 S.

侧车状态文件

finalize_presentation() 每次写入两个文件:

output/
  demand_review_20260225_1200.html           ← the browser presentation
  demand_review_20260225_1200.html.state.json ← structured slide data (editable)

这 .state.json 存储每张幻灯片的布局、图表数据、表格数据、评论, 和 slide_id. load_presentation(filename) 读取此文件以还原完整 编辑会话--所有后续工具(add_slide, add_commentary, drill_down_slide, finalize_presentation)然后像会话一样工作 从未结束。