npm package: @htoo-tw/report-transformer
Description: An XMCP application with tool syntax
Latest version: 0.1.1

### MCP D3 Data Transformer

A tool for generating D3 compatible data formats for report-generator MCP.

## Sample data

```json
{
  "result": [
    {
      "year": "2023",
      "month": "Jan",
      "month_year": "2023-01",
      "total_revenue": "92756492.61",
      "transaction_count": 126
    },
    {
      "year": "2023",
      "month": "Feb",
      "month_year": "2023-02",
      "total_revenue": "93128528.57",
      "transaction_count": 127
    },
    {
      "year": "2023",
      "month": "Mar",
      "month_year": "2023-03",
      "total_revenue": "95699029.84",
      "transaction_count": 131
    },
    {
      "year": "2023",
      "month": "Apr",
      "month_year": "2023-04",
      "total_revenue": "103647077.57",
      "transaction_count": 139
    },
    {
      "year": "2023",
      "month": "May",
      "month_year": "2023-05",
      "total_revenue": "106332107.74",
      "transaction_count": 143
    },
    {
      "year": "2023",
      "month": "Jun",
      "month_year": "2023-06",
      "total_revenue": "108860799.22",
      "transaction_count": 146
    },
    {
      "year": "2023",
      "month": "Jul",
      "month_year": "2023-07",
      "total_revenue": "109433081.04",
      "transaction_count": 148
    },
    {
      "year": "2023",
      "month": "Aug",
      "month_year": "2023-08",
      "total_revenue": "112792542.28",
      "transaction_count": 152
    },
    {
      "year": "2023",
      "month": "Sep",
      "month_year": "2023-09",
      "total_revenue": "115500529.13",
      "transaction_count": 157
    },
    {
      "year": "2023",
      "month": "Oct",
      "month_year": "2023-10",
      "total_revenue": "116752780.76",
      "transaction_count": 159
    },
    {
      "year": "2023",
      "month": "Nov",
      "month_year": "2023-11",
      "total_revenue": "118907494.08",
      "transaction_count": 163
    },
    {
      "year": "2023",
      "month": "Dec",
      "month_year": "2023-12",
      "total_revenue": "120319528.24",
      "transaction_count": 168
    }
  ],
  "row_count": 12,
  "columns": [
    "year",
    "month",
    "month_year",
    "total_revenue",
    "transaction_count"
  ],
  "execution_time": 0.01
}
```

## Schema Overview

The D3 Transformer MCP tool uses a two-part schema structure for generating data
visualization reports:

Inputs:

data (DataInputSchema):
- columns (string[]): Column names for the dataset
- result (object[]): Array of data records as key-value pairs
- options (ChartOptionsSchema, optional): Chart configuration options including:
  - title (string, optional): Chart title
  - description (string, optional): Chart description
  - xAxisLabel (string, optional): X-axis label
  - yAxisLabel (string, optional): Y-axis label
  - showGrid (boolean, default: true): Whether to display grid lines
  - showLegend (boolean, default: false): Whether to show chart legend
  - barChart (object, optional): Bar chart specific options
      - orientation (enum: 'vertical'|'horizontal', default: 'vertical'): Bar orientation
  - lineChart (object, optional): Line chart specific options
      - curved (boolean, default: false): Whether to use curved lines
    - showPoints (boolean, default: true): Whether to show data points
    - showArea (boolean, default: false): Whether to fill area under line

charts (ChartsConfigSchema):
- Array of chart configurations, each containing:
  - type (enum: 'bar'|'line'): Chart type to generate
  - xColumn (string): Column name for x-axis data (categories, dates, or labels). Used
for grouping/categorizing data points. Examples: "date", "month", "department",
"product_category"
  - yColumn (string): Column name for y-axis data (numeric values to be
measured/plotted). Should contain numbers for chart visualization. Examples: "revenue",
"count", "temperature", "score"

## Expected LLM Input
```json
{
  "data": {
    "result": [...],
    "columns": [...],
  },
  "charts": [
    { "type": "line", "xColumn": "amount", "yColumn": "total_revenue" },
    { "type": "bar", "xColumn": "month", "yColumn": "transaction_count" },
    ...
  ]
}
```

## Development

```bash
pnpm dev
```

This will start the MCP server with the STDIO as the transport method in which `dist/stdio.js` is generated.

For interactive testing and debugging, the [MCP inspector](https://github.com/modelcontextprotocol/inspector) is recommended to use

Run the inspector by

```bash
npx @modelcontextprotocol/inspector
```

and add the command:

```
node /PATH/mcp/d3-transformer/dist/stdio.js
```

## Production

Build by using

```bash
pnpm build
```

---

This project was created with [create-xmcp-app](https://github.com/basementstudio/xmcp).