cwprep-mcp
cwprep - Text-to-PrepFlow 引擎
cwprep 是一个基于 Python 的引擎,支持 Text-to-PrepFlow(文本转 Prep 流)生成。
通过对 .tfl JSON 结构进行逆向工程并提供内置的 MCP (Model Context Protocol) 服务器,cwprep 充当了 LLM(如 Claude、Gemini)与 Tableau Prep 之间的桥梁。现在,你无需打开 GUI,只需通过自然语言对话或 Python 脚本即可生成、修改和构建数据清洗流!
作者: Cooper Wenhua imgwho@gmail.com
安装
pip install cwprepRelated MCP server: cwtwb
快速开始
from cwprep import TFLBuilder, TFLPackager
# Create builder
builder = TFLBuilder(flow_name="My Flow")
# Add database connection
conn_id = builder.add_connection(
host="localhost",
username="root",
dbname="mydb"
)
# Add input tables
orders = builder.add_input_table("orders", "orders", conn_id)
customers = builder.add_input_table("customers", "customers", conn_id)
# Join tables
joined = builder.add_join(
name="Orders + Customers",
left_id=orders,
right_id=customers,
left_col="customer_id",
right_col="customer_id",
join_type="left"
)
# Add output
builder.add_output_server("Output", joined, "My_Datasource")
# Build and save
flow, display, meta = builder.build()
TFLPackager.save_tfl("./my_flow.tfl", flow, display, meta)默认情况下,SDK 和 MCP 都只输出最终的 .tfl/.tflx 归档文件。仅当你明确需要展开的文件夹以进行检查时,才使用 save_to_folder()。
功能特性
功能 | 方法 | 描述 |
数据库连接 |
| 连接到 MySQL/PostgreSQL/SQL Server |
文件连接 |
| 连接到 Excel (.xlsx/.xls) 或 CSV 文件 |
SQL 输入 |
| 自定义 SQL 查询输入 |
表输入 |
| 直接表连接 |
Excel 输入 |
| 从 Excel 工作表读取 |
CSV 输入 |
| 从 CSV 文件读取 |
CSV 合并 |
| 合并多个 CSV 文件 |
连接 (Join) |
| 左/右/内/全连接(单列或多列) |
合并 (Union) |
| 合并多个表 |
筛选 |
| 基于表达式的筛选 |
值筛选 |
| 按值保留/排除 |
仅保留 |
| 选择列 |
删除列 |
| 删除列 |
重命名 |
| 重命名列 |
计算 |
| Tableau 公式字段 |
快速计算 |
| 快速清洗(小写/大写/修剪/移除) |
更改类型 |
| 更改列数据类型 |
复制列 |
| 复制列 |
聚合 |
| 带 SUM/AVG/COUNT 的 GROUP BY |
行转列 |
| 行转列 |
列转行 |
| 列转行 |
输出 |
| 发布到 Tableau Server |
TFLX 打包 |
| 生成包含嵌入数据文件的 .tflx |
SQL 转换 |
| 将 TFL 流转换为等效的 ANSI SQL |
示例
查看 examples/ 目录获取完整演示:
demo_basic.py- 输入、连接、输出demo_cleaning.py- 筛选、计算、重命名demo_field_operations.py- 快速计算、更改类型、复制列demo_aggregation.py- 合并、聚合、行转列demo_comprehensive.py- 所有功能组合prompts.md- 8 个即用型 MCP 提示词模板,用于 AI 驱动的流生成
MCP 服务器
cwprep 包含一个内置的 Model Context Protocol 服务器,使 AI 客户端(Claude Desktop、Cursor、Gemini CLI 等)能够直接生成 TFL 文件。
前置要求
方法 | 要求 |
| 安装 uv — 它会在隔离环境中自动下载 |
| Python ≥ 3.8 + |
快速开始
# Local (stdio)
cwprep-mcp
# Remote (Streamable HTTP)
cwprep-mcp --transport streamable-http --port 8000[!TIP] 升级? 如果你之前使用过旧版本的
uvx,请清除缓存以获取最新版本:uv cache clean cwprep
客户端配置
以下所有客户端均使用 uvx 方法(推荐)。如果你更喜欢本地 pip install,请将 uvx 替换为 cwprep-mcp。
编辑配置文件:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"cwprep": {
"command": "uvx",
"args": ["--from", "cwprep", "cwprep-mcp"]
}
}
}设置 → MCP → 添加新的 MCP 服务器,或编辑 ~/.cursor/mcp.json:
{
"mcpServers": {
"cwprep": {
"command": "uvx",
"args": ["--from", "cwprep", "cwprep-mcp"]
}
}
}在项目根目录创建 .vscode/mcp.json:
{
"servers": {
"cwprep": {
"command": "uvx",
"args": ["--from", "cwprep", "cwprep-mcp"]
}
}
}编辑 ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"cwprep": {
"command": "uvx",
"args": ["--from", "cwprep", "cwprep-mcp"]
}
}
}claude mcp add cwprep -- uvx --from "cwprep" cwprep-mcp编辑 ~/.gemini/settings.json:
{
"mcpServers": {
"cwprep": {
"command": "uvx",
"args": ["--from", "cwprep", "cwprep-mcp"]
}
}
}编辑 ~/.continue/config.yaml:
mcpServers:
- name: cwprep
command: uvx
args:
- --from
- cwprep
- cwprep-mcp启动服务器:
cwprep-mcp --transport streamable-http --port 8000然后使用端点配置你的客户端:http://your-server-ip:8000/mcp
可用的 MCP 功能
类型 | 名称 | 描述 |
🔧 工具 |
| 从流定义生成 .tfl/.tflx 文件 |
🔧 工具 |
| 将流定义或 .tfl 文件转换为 ANSI SQL |
🔧 工具 |
| 列出所有支持的节点类型 |
🔧 工具 |
| 在生成前验证流定义 |
📖 资源 |
| SDK API 参考 |
📖 资源 |
| Tableau Prep 计算语法 |
📖 资源 |
| 常见陷阱和流设计规则 |
💬 提示词 |
| 交互式流设计助手 |
💬 提示词 |
| TFL 文件结构说明 |
AI 技能支持
本项目包含一个专门的 AI 技能,供 Claude 或 Gemini 等助手使用,以帮助你构建流。
位置:
.agents/skills/tfl-generator/功能: 带有回退 SDK 使用指南的 MCP 服务器索引。详细的 API 和语法参考通过
src/cwprep/references/中的 MCP 资源提供。
目录结构
cwprep/
├── .agents/skills/ # AI Agent skills (MCP index)
├── src/cwprep/ # SDK source code
│ ├── builder.py # TFLBuilder class
│ ├── packager.py # TFLPackager class
│ ├── translator.py # SQLTranslator class
│ ├── expression_translator.py # ExpressionTranslator class
│ ├── config.py # Configuration utilities
│ ├── mcp_server.py # MCP Server (Tools, Resources, Prompts)
│ └── references/ # MCP Resource documents (.md)
├── examples/ # Demo scripts
├── docs/ # Documentation
└── tests/ # Unit tests配置
创建 config.yaml 以设置默认配置:
# MySQL (default)
database:
host: localhost
port: 3306
dbname: mydb
type: mysql
# SQL Server (Windows Authentication)
# database:
# host: localhost
# type: sqlserver
# authentication: sspi
# schema: dbo
# PostgreSQL
# database:
# host: localhost
# port: 5432
# dbname: mydb
# type: postgres
tableau_server:
url: http://your-server
default_project: Default更新日志
查看 changelog.md 获取版本历史。
许可证
AGPL-3.0 许可证
This server cannot be deployed
Maintenance
Related MCP Connectors
Generate Tableau .twb/.twbx workbooks: 47 tools for charts, dashboards, rules, CSV pipelines.
Automate production-ready PDF, Word, Excel and PowerPoint documents from templates and JSON data
Preflight and convert 450+ file types for AI workflows via TweekIT MCP & SDK (Equilibrium).
Postgres + Kafka Stack Generator
Related MCP Servers
- FlicenseNot gradedqualityNot gradedmaintenanceEnables discovery, querying, and exporting of Tableau Cloud dashboards and data sources. Supports searching workbooks, filtering data, and exporting views as PDF, PNG, PowerPoint, CSV, or JSON.-
- AGPL 3.0
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to programmatically read, modify, and query Tableau workbook files (.twb and .twbx) on the local filesystem via 80 tools.9MIT
- AlicenseNot gradedqualityCmaintenanceA local MCP server that allows LLMs to inspect and safely edit Tableau Desktop workbooks (.twb) via XML, including creating native calculated fields using Tableau formula syntax.MIT