Back to guides
beginner12 min2026-04-30

04 | cwprep and cwtwb Basic Cases: Script + MCP

Learn the roles and collaboration pattern of cwprep and cwtwb through two minimal hands-on cases.

cwprepcwtwbpythonmcpexamples

What You Will Learn

  • The minimum script pattern for direct usage
  • The minimum MCP prompt pattern in AI clients
  • Clear division of responsibilities between cwprep and cwtwb

Prerequisites

  • MCP setup and connectivity check completed
  • A demo-ready data source (table or CSV)

Case A: cwprep (Data Flow)

cwprep generates Tableau Prep flows (.tfl/.tflx).

Script Pattern

flow = {
  "flow_name": "orders_filter_demo",
  "connection": {"type": "database", "host": "localhost", "db_class": "mysql", "username": "root", "dbname": "demo"},
  "nodes": [
    {"type": "input_table", "name": "orders", "table": "orders"},
    {"type": "filter", "name": "sales_filter", "parent": "orders", "expression": "[sales] > 100"},
  ]
}

MCP Prompt Pattern

Use cwprep:
1) input table orders
2) filter sales > 100
3) output tfl to local output/demo.tfl

Case B: cwtwb (Workbook)

cwtwb generates Tableau workbooks (.twb/.twbx).

Script Pattern

Core actions are usually:

  • Create workbook
  • Connect data source
  • Create worksheet
  • Configure chart
  • Save as .twb/.twbx

MCP Prompt Pattern

Use cwtwb:
1) load superstore data
2) create a Sales by Category bar chart worksheet
3) save to output/sales_by_category.twb

How They Work Together

  • Use cwprep first to clean and shape data
  • Use cwtwb second to build dashboards on top of that data

Validation Checklist

  • One .tfl/.tflx generated successfully
  • One .twb/.twbx generated successfully
  • You can explain why cwprep -> cwtwb is the default order

First-Practice Tips

  • Start from minimal cases, not full dashboards
  • Keep prompts and outputs for reproducibility
  • If it fails, isolate first: script command first, MCP config second