Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(dashboards): preserve tile widths when reordering via MCP (#57928)

Vasco de Krijger95e5ec747530
diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.py
index d98082b80b96..c1a32614e042 100644
--- a/posthog/api/test/dashboards/test_dashboard.py
+++ b/posthog/api/test/dashboards/test_dashboard.py
@@ -3205,11 +3205,13 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
tile1.refresh_from_db()
tile2.refresh_from_db()
- # tile2 should be in position (0,0), tile1 in position (6,0)
- self.assertEqual(tile2.layouts["sm"]["x"], 0)
- self.assertEqual(tile2.layouts["sm"]["y"], 0)
- self.assertEqual(tile1.layouts["sm"]["x"], 6)
- self.assertEqual(tile1.layouts["sm"]["y"], 0)
+ # tiles with no existing layout fall back to the default 6-wide × 5-tall:
+ # tile2 lands at (0,0), tile1 packs to its right at (6,0)
+ self.assertEqual(tile2.layouts["sm"], {"x": 0, "y": 0, "w": 6, "h": 5})
+ self.assertEqual(tile1.layouts["sm"], {"x": 6, "y": 0, "w": 6, "h": 5})
+ # xs is the 1-column mobile grid; w must always be 1
+ self.assertEqual(tile1.layouts["xs"]["w"], 1)
+ self.assertEqual(tile2.layouts["xs"]["w"], 1)
def test_reorder_tiles_invalid_tile_ids(self):
dashboard = Dashboard.objects.create(team=self.team, name="Test Dashboard")
@@ -3272,10 +3274,10 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
tile1.refresh_from_db()
tile2.refresh_from_db()
- self.assertEqual(tile2.layouts["sm"]["x"], 0)
- self.assertEqual(tile2.layouts["sm"]["y"], 0)
- self.assertEqual(tile1.layouts["sm"]["x"], 6)
- self.assertEqual(tile1.layouts["sm"]["y"], 0)
+ self.assertEqual(tile2.layouts["sm"], {"x": 0, "y": 0, "w": 6, "h": 5})
+ self.assertEqual(tile1.layouts["sm"], {"x": 6, "y": 0, "w": 6, "h": 5})
+ self.assertEqual(tile1.layouts["xs"]["w"], 1)
+ self.assertEqual(tile2.layouts["xs"]["w"], 1)
def test_reorder_tiles_with_mixed_tile_types(self):
dashboard = Dashboard.objects.create(team=self.team, name="Test Dashboard")
@@ -3294,10 +3296,177 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
text_tile.refresh_from_db()
insight_tile.refresh_from_db()
- self.assertEqual(text_tile.layouts["sm"]["x"], 0)
- self.assertEqual(text_tile.layouts["sm"]["y"], 0)
- self.assertEqual(insight_tile.layouts["sm"]["x"], 6)
- self.assertEqual(insight_tile.layouts["sm"]["y"], 0)
+ self.assertEqual(text_tile.layouts["sm"], {"x": 0, "y": 0, "w": 6, "h": 5})
+ self.assertEqual(insight_tile.layouts["sm"], {"x": 6, "y": 0, "w": 6, "h": 5})
+ self.assertEqual(text_tile.layouts["xs"]["w"], 1)
+ self.assertEqual(insight_tile.layouts["xs"]["w"], 1)
+
+ def test_reorder_tiles_preserves_existing_widths_by_default(self):
+ dashboard = Dashboard.objects.create(team=self.team, name="Test Dashboard")
+ insight1 = Insight.objects.create(team=self.team, name="Insight 1")
+ insight2 = Insight.objects.create(team=self.team, name="Insight 2")
+ # Both tiles have been manually resized to full row width and a custom height
+ tile1 = DashboardTile.objects.create(
+ dashboard=dashboard,
+ insight=insight1,
+ layouts={"sm": {"x": 0, "y": 0, "w": 12, "h": 8}, "xs": {"x": 0, "y": 0, "w": 1, "h": 8}},
+ )
+ tile2 = DashboardTile.objects.create(
+ dashboard=dashboard,
+ insight=insight2,
+ layouts={"sm": {"x": 0, "y": 8, "w": 12, "h": 8}, "xs": {"x": 0, "y": 8, "w": 1, "h": 8}},
+ )
+
+ response = self.client.post(
+ f"/api/environments/{self.team.pk}/dashboards/{dashboard.pk}/reorder_tiles/",
+ {"tile_order": [tile2.pk, tile1.pk]},
+ content_type="application/json",
+ )
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+
+ tile1.refresh_from_db()
+ tile2.refresh_from_db()
+ # Widths and heights are preserved; positions are repacked in the new order
+ self.assertEqual(tile2.layouts["sm"], {"x": 0, "y": 0, "w": 12, "h": 8})
+ self.assertEqual(tile1.layouts["sm"], {"x": 0, "y": 8, "w": 12, "h": 8})
+ # xs is the 1-column mobile grid; w must always be 1 regardless of sm width
+ self.assertEqual(tile1.layouts["xs"]["w"], 1)
+ self.assertEqual(tile2.layouts["xs"]["w"], 1)
+
+ def test_reorder_tiles_preserve_packs_mixed_widths(self):
+ dashboard = Dashboard.objects.create(team=self.team, name="Test Dashboard")
+ insight1 = Insight.objects.create(team=self.team, name="Insight 1")
+ insight2 = Insight.objects.create(team=self.team, name="Insight 2")
+ insight3 = Insight.objects.create(team=self.team, name="Insight 3")
+ tile1 = DashboardTile.objects.create(
+ dashboard=dashboard,
+ insight=insight1,
+ layouts={"sm": {"x": 0, "y": 0, "w": 4, "h": 5}},
+ )
+ tile2 = DashboardTile.objects.create(
+ dashboard=dashboard,
+ insight=insight2,
+ layouts={"sm": {"x": 0, "y": 0, "w": 8, "h": 5}},
+ )
+ tile3 = DashboardTile.objects.create(
+ dashboard=dashboard,
+ insight=insight3,
+ layouts={"sm": {"x": 0, "y": 0, "w": 12, "h": 5}},
+ )
+
+ response = self.client.post(
+ f"/api/environments/{self.team.pk}/dashboards/{dashboard.pk}/reorder_tiles/",
+ {"tile_order": [tile1.pk, tile2.pk, tile3.pk]},
+ content_type="application/json",
+ )
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+
+ tile1.refresh_from_db()
+ tile2.refresh_from_db()
+ tile3.refresh_from_db()
+ # tile1 (w=4) at (0,0); tile2 (w=8) packs to its right at (4,0); tile3 (w=12) wraps to next row.
+ self.assertEqual((tile1.layouts["sm"]["x"], tile1.layouts["sm"]["y"], tile1.layouts["sm"]["w"]), (0, 0, 4))
+ self.assertEqual((tile2.layouts["sm"]["x"], tile2.layouts["sm"]["y"], tile2.layouts["sm"]["w"]), (4, 0, 8))
+ self.assertEqual((tile3.layouts["sm"]["x"], tile3.layouts["sm"]["y"], tile3.layouts["sm"]["w"]), (0, 5, 12))
+ # xs is the single-column mobile stack: tiles stack top-to-bottom in list order,
+ # accumulating each tile's height independently of the sm packing.
+ self.assertEqual(tile1.layouts["xs"], {"x": 0, "y": 0, "w": 1, "h": 5})
+ self.assertEqual(tile2.layouts["xs"], {"x": 0, "y": 5, "w": 1, "h": 5})
+ self.assertEqual(tile3.layouts["xs"], {"x": 0, "y": 10, "w": 1, "h": 5})
+
+ def test_reorder_tiles_preserve_packs_into_lowest_segment_with_uneven_heights(self):
+ dashboard = Dashboard.objects.create(team=self.team, name="Test Dashboard")
+ insight1 = Insight.objects.create(team=self.team, name="Insight 1")
+ insight2 = Insight.objects.create(team=self.team, name="Insight 2")
+ insight3 = Insight.objects.create(team=self.team, name="Insight 3")
+ # Two half-width tiles of different heights, then a third half-width tile.
+ tile1 = DashboardTile.objects.create(
+ dashboard=dashboard, insight=insight1, layouts={"sm": {"x": 0, "y": 0, "w": 6, "h": 3}}
+ )
+ tile2 = DashboardTile.objects.create(
+ dashboard=dashboard, insight=insight2, layouts={"sm": {"x": 0, "y": 0, "w": 6, "h": 5}}
+ )
+ tile3 = DashboardTile.objects.create(
+ dashboard=dashboard, insight=insight3, layouts={"sm": {"x": 0, "y": 0, "w": 6, "h": 2}}
+ )
+
+ response = self.client.post(
+ f"/api/environments/{self.team.pk}/dashboards/{dashboard.pk}/reorder_tiles/",
+ {"tile_order": [tile1.pk, tile2.pk, tile3.pk]},
+ content_type="application/json",
+ )
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+
+ tile1.refresh_from_db()
+ tile2.refresh_from_db()
+ tile3.refresh_from_db()
+ # tile1 (h=3) at (0,0); tile2 packs right at (6,0). Left column is now lower (3) than the
+ # right (5), so tile3 must slot into the lower-left segment at (0,3) rather than below tile2.
+ self.assertEqual(tile1.layouts["sm"], {"x": 0, "y": 0, "w": 6, "h": 3})
+ self.assertEqual(tile2.layouts["sm"], {"x": 6, "y": 0, "w": 6, "h": 5})
+ self.assertEqual(tile3.layouts["sm"], {"x": 0, "y": 3, "w": 6, "h": 2})
+ # xs stacks in list order accumulating each tile's own height (0, 3, then 3+5=8),
+ # independent of the lowest-segment sm packing that placed tile3 at sm y=3.
+ self.assertEqual(tile1.layouts["xs"], {"x": 0, "y": 0, "w": 1, "h": 3})
+ self.assertEqual(tile2.layouts["xs"], {"x": 0, "y": 3, "w": 1, "h": 5})
+ self.assertEqual(tile3.layouts["xs"], {"x": 0, "y": 8, "w": 1, "h": 2})
+
+ @parameterized.expand(
+ [
+ (
+ "two_column",
+ {"x": 0, "y": 0, "w": 6, "h": 5},
+ {"x": 6, "y": 0, "w": 6, "h": 5},
+ ),
+ (
+ "full_width",
+ {"x": 0, "y": 0, "w": 12, "h": 5},
+ {"x": 0, "y": 5, "w": 12, "h": 5},
+ ),
+ ]
+ )
+ def test_reorder_tiles_layout_mode_overrides_existing_widths(
+ self, layout_mode: str, expected_first: dict, expected_second: dict
+ ):
+ dashboard = Dashboard.objects.create(team=self.team, name="Test Dashboard")
+ insight1 = Insight.objects.create(team=self.team, name="Insight 1")
+ insight2 = Insight.objects.create(team=self.team, name="Insight 2")
+ tile1 = DashboardTile.objects.create(
+ dashboard=dashboard,
+ insight=insight1,
+ layouts={"sm": {"x": 0, "y": 0, "w": 4, "h": 8}},
+ )
+ tile2 = DashboardTile.objects.create(
+ dashboard=dashboard,
+ insight=insight2,
+ layouts={"sm": {"x": 4, "y": 0, "w": 4, "h": 8}},
+ )
+
+ response = self.client.post(
+ f"/api/environments/{self.team.pk}/dashboards/{dashboard.pk}/reorder_tiles/",
+ {"tile_order": [tile1.pk, tile2.pk], "layout": layout_mode},
+ content_type="application/json",
+ )
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+
+ tile1.refresh_from_db()
+ tile2.refresh_from_db()
+ self.assertEqual(tile1.layouts["sm"], expected_first)
+ self.assertEqual(tile2.layouts["sm"], expected_second)
+ self.assertEqual(tile1.layouts["xs"]["w"], 1)
+ self.assertEqual(tile2.layouts["xs"]["w"], 1)
+
+ def test_reorder_tiles_invalid_layout_returns_400(self):
+ dashboard = Dashboard.objects.create(team=self.team, name="Test Dashboard")
+ insight = Insight.objects.create(team=self.team, name="Insight 1")
+ tile = DashboardTile.objects.create(dashboard=dashboard, insight=insight)
+
+ response = self.client.post(
+ f"/api/environments/{self.team.pk}/dashboards/{dashboard.pk}/reorder_tiles/",
+ {"tile_order": [tile.pk], "layout": "stacked"},
+ content_type="application/json",
+ )
+ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_create_text_tile_adds_markdown_tile_to_dashboard(self):
dashboard = Dashboard.objects.create(team=self.team, name="Test Dashboard")
diff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.py
index 23e95ebd8aca..fe9bbf1c7011 100644
--- a/products/dashboards/backend/api/dashboard.py
+++ b/products/dashboards/backend/api/dashboard.py
@@ -3,6 +3,7 @@ import json
import uuid
from collections.abc import AsyncGenerator
from contextlib import nullcontext
+from enum import StrEnum
from typing import Any, Optional, cast
from django.conf import settings
@@ -159,12 +160,101 @@ def serialize_tile_with_context(tile, order: int, context: dict) -> tuple[int, d
return order, tile_data
+class ReorderLayout(StrEnum):
+ PRESERVE = "preserve"
+ TWO_COLUMN = "two_column"
+ FULL_WIDTH = "full_width"
+
+
+DASHBOARD_GRID_COLUMN_COUNT = 12
+DEFAULT_REORDER_TILE_WIDTH = 6
+DEFAULT_REORDER_TILE_HEIGHT = 5
+
+
+def _existing_sm_size(tile: DashboardTile, default_w: int, default_h: int) -> tuple[int, int]:
+ sm = (tile.layouts or {}).get("sm") if isinstance(tile.layouts, dict) else None
+ if not isinstance(sm, dict):
+ return default_w, default_h
+ w, h = sm.get("w"), sm.get("h")
+ return (
+ w if isinstance(w, int) and w > 0 else default_w,
+ h if isinstance(h, int) and h > 0 else default_h,
+ )
+
+
+def _apply_reorder_layout(
+ tile_order: list[int],
+ tile_map: dict[int, DashboardTile],
+ layout_mode: ReorderLayout,
+) -> None:
+ """Repack tiles. ``preserve`` keeps each tile's existing w/h and reuses the lowest-segment
+ greedy algorithm from ``frontend/src/scenes/dashboard/tileLayouts.ts``; the other modes overwrite w/h."""
+ if layout_mode == ReorderLayout.TWO_COLUMN:
+ for index, tile_id in enumerate(tile_order):
+ row, col = divmod(index, 2)
+ tile_map[tile_id].layouts = {
+ "sm": {
+ "x": col * DEFAULT_REORDER_TILE_WIDTH,
+ "y": row * DEFAULT_REORDER_TILE_HEIGHT,
+ "w": DEFAULT_REORDER_TILE_WIDTH,
+ "h": DEFAULT_REORDER_TILE_HEIGHT,
+ },
+ "xs": {"x": 0, "y": index * DEFAULT_REORDER_TILE_HEIGHT, "w": 1, "h": DEFAULT_REORDER_TILE_HEIGHT},
+ }
+ return
+
+ if layout_mode == ReorderLayout.FULL_WIDTH:
+ for index, tile_id in enumerate(tile_order):
+ y = index * DEFAULT_REORDER_TILE_HEIGHT
+ tile_map[tile_id].layouts = {
+ "sm": {"x": 0, "y": y, "w": DASHBOARD_GRID_COLUMN_COUNT, "h": DEFAULT_REORDER_TILE_HEIGHT},
+ "xs": {"x": 0, "y": y, "w": 1, "h": DEFAULT_REORDER_TILE_HEIGHT},
+ }
+ return
+
+ column_heights = [0] * DASHBOARD_GRID_COLUMN_COUNT
+ xs_y = 0
+ for tile_id in tile_order:
+ tile = tile_map[tile_id]
+ existing_w, existing_h = _existing_sm_size(tile, DEFAULT_REORDER_TILE_WIDTH, DEFAULT_REORDER_TILE_HEIGHT)
+ w = max(1, min(existing_w, DASHBOARD_GRID_COLUMN_COUNT))
+ h = max(1, existing_h)
+
+ # x=0 is the baseline candidate; scan the remaining start positions for a lower segment top,
+ # keeping the leftmost on ties (the loop only updates on a strictly lower top).
+ best_x = 0
+ best_y = max(column_heights[0:w])
+ for x in range(1, DASHBOARD_GRID_COLUMN_COUNT - w + 1):
+ segment_top = max(column_heights[x : x + w])
+ if segment_top < best_y:
+ best_x = x
+ best_y = segment_top
+
+ tile.layouts = {
+ "sm": {"x": best_x, "y": best_y, "w": w, "h": h},
+ "xs": {"x": 0, "y": xs_y, "w": 1, "h": h},
+ }
+ for k in range(best_x, best_x + w):
+ column_heights[k] = best_y + h
+ xs_y += h
+
+
class ReorderTilesRequestSerializer(serializers.Serializer):
tile_order = serializers.ListField(
child=serializers.IntegerField(),
min_length=1,
help_text="Array of tile IDs in the desired display order (top to bottom, left to right).",
)
+ layout = serializers.ChoiceField(
+ choices=[mode.value for mode in ReorderLayout],
+ default=ReorderLayout.PRESERVE.value,
+ required=False,
+ help_text=(
+ "How to size tiles when reordering. 'preserve' (default) keeps each tile's existing width and height "
+ "and only repacks positions in the new order. 'two_column' forces a 6-wide × 5-tall grid (two tiles per "
+ "row). 'full_width' forces each tile to span the full 12-column row at height 5."
+ ),
+ )
class CopyDashboardTileRequestSerializer(serializers.Serializer):
@@ -1701,6 +1791,7 @@ class DashboardsViewSet(
serializer = ReorderTilesRequestSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
tile_order: list[int] = serializer.validated_data["tile_order"]
+ layout_mode = ReorderLayout(serializer.validated_data["layout"])
if len(tile_order) != len(set(tile_order)):
return Response(
@@ -1708,9 +1799,6 @@ class DashboardsViewSet(
status=status.HTTP_400_BAD_REQUEST,
)
- tile_width = 6
- tile_height = 5
-
tiles = DashboardTile.objects.filter(dashboard=dashboard, id__in=tile_order)
tile_map = {tile.id: tile for tile in tiles}
@@ -1721,15 +1809,7 @@ class DashboardsViewSet(
status=status.HTTP_404_NOT_FOUND,
)
- for index, tile_id in enumerate(tile_order):
- tile = tile_map[tile_id]
- row = index // 2
- col = index % 2
- tile.layouts = {
- "sm": {"x": col * tile_width, "y": row * tile_height, "w": tile_width, "h": tile_height},
- # xs is single-column (full 6-col mobile grid width)
- "xs": {"x": 0, "y": index * tile_height, "w": tile_width, "h": tile_height},
- }
+ _apply_reorder_layout(tile_order, tile_map, layout_mode)
DashboardTile.objects.bulk_update(tile_map.values(), ["layouts"])
diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.ts
index 01a089a61f12..2c5fd17e5229 100644
--- a/products/dashboards/frontend/generated/api.schemas.ts
+++ b/products/dashboards/frontend/generated/api.schemas.ts
@@ -7422,12 +7422,31 @@ export interface DashboardTileApi {
transparent_background?: boolean | null
}
+/**
+ * * `preserve` - preserve
+ * `two_column` - two_column
+ * `full_width` - full_width
+ */
+export type LayoutEnumApi = (typeof LayoutEnumApi)[keyof typeof LayoutEnumApi]
+
+export const LayoutEnumApi = {
+ Preserve: 'preserve',
+ TwoColumn: 'two_column',
+ FullWidth: 'full_width',
+} as const
+
export interface ReorderTilesRequestApi {
/**
* Array of tile IDs in the desired display order (top to bottom, left to right).
* @minItems 1
*/
tile_order: number[]
+ /** How to size tiles when reordering. 'preserve' (default) keeps each tile's existing width and height and only repacks positions in the new order. 'two_column' forces a 6-wide × 5-tall grid (two tiles per row). 'full_width' forces each tile to span the full 12-column row at height 5.
+
+ * `preserve` - preserve
+ * `two_column` - two_column
+ * `full_width` - full_width */
+ layout?: LayoutEnumApi
}
/**
diff --git a/products/dashboards/frontend/generated/api.zod.ts b/products/dashboards/frontend/generated/api.zod.ts
index e3ef3fb2d837..ad447961d836 100644
--- a/products/dashboards/frontend/generated/api.zod.ts
+++ b/products/dashboards/frontend/generated/api.zod.ts
@@ -331,11 +331,20 @@ export const DashboardsMoveTilePartialUpdateBody = /* @__PURE__ */ zod
})
.describe('Serializer mixin that handles tags for objects.')
+export const dashboardsReorderTilesCreateBodyLayoutDefault = `preserve`
+
export const DashboardsReorderTilesCreateBody = /* @__PURE__ */ zod.object({
tile_order: zod
.array(zod.number())
.min(1)
.describe('Array of tile IDs in the desired display order (top to bottom, left to right).'),
+ layout: zod
+ .enum(['preserve', 'two_column', 'full_width'])
+ .describe('\* `preserve` - preserve\n\* `two_column` - two_column\n\* `full_width` - full_width')
+ .default(dashboardsReorderTilesCreateBodyLayoutDefault)
+ .describe(
+ "How to size tiles when reordering. 'preserve' (default) keeps each tile's existing width and height and only repacks positions in the new order. 'two_column' forces a 6-wide × 5-tall grid (two tiles per row). 'full_width' forces each tile to span the full 12-column row at height 5.\n\n\* `preserve` - preserve\n\* `two_column` - two_column\n\* `full_width` - full_width"
+ ),
})
/**
diff --git a/products/dashboards/mcp/tools.yaml b/products/dashboards/mcp/tools.yaml
index de244d2eec7b..eea51b06ca67 100644
--- a/products/dashboards/mcp/tools.yaml
+++ b/products/dashboards/mcp/tools.yaml
@@ -200,9 +200,9 @@ tools:
enrich_url: '{id}'
title: Reorder dashboard tiles
description: >
- Reorder tiles on a dashboard by providing an array of tile IDs in the desired display order. Computes a
- 2-column grid layout (6 columns wide, 5 rows tall per tile). First, use dashboard-get to see current tile
- IDs.
+ Reorder tiles on a dashboard by providing an array of tile IDs in the desired display order. First, use
+ dashboard-get to see current tile IDs. By default existing tile widths and heights are preserved; see the
+ layout parameter to force a 2-column or full-width grid instead.
dashboard-templates-copy-between-projects-create:
operation: dashboard_templates_copy_between_projects_create
enabled: false
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index f908aa341bf6..364954af9722 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -1110,7 +1110,7 @@
}
},
"dashboard-reorder-tiles": {
- "description": "Reorder tiles on a dashboard by providing an array of tile IDs in the desired display order. Computes a 2-column grid layout (6 columns wide, 5 rows tall per tile). First, use dashboard-get to see current tile IDs.",
+ "description": "Reorder tiles on a dashboard by providing an array of tile IDs in the desired display order. First, use dashboard-get to see current tile IDs. By default existing tile widths and heights are preserved; see the layout parameter to force a 2-column or full-width grid instead.",
"category": "Dashboards",
"feature": "dashboards",
"summary": "Reorder dashboard tiles",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 1aa37d331611..aa238d33fdc2 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -1127,7 +1127,7 @@
}
},
"dashboard-reorder-tiles": {
- "description": "Reorder tiles on a dashboard by providing an array of tile IDs in the desired display order. Computes a 2-column grid layout (6 columns wide, 5 rows tall per tile). First, use dashboard-get to see current tile IDs.",
+ "description": "Reorder tiles on a dashboard by providing an array of tile IDs in the desired display order. First, use dashboard-get to see current tile IDs. By default existing tile widths and heights are preserved; see the layout parameter to force a 2-column or full-width grid instead.",
"category": "Dashboards",
"feature": "dashboards",
"summary": "Reorder dashboard tiles",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 257d13dab0c9..21d664aeedaf 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -20768,6 +20768,20 @@ export namespace Schemas {
summary: string;
}
+ /**
+ * * `preserve` - preserve
+ * `two_column` - two_column
+ * `full_width` - full_width
+ */
+ export type LayoutEnum = typeof LayoutEnum[keyof typeof LayoutEnum];
+
+
+ export const LayoutEnum = {
+ Preserve: 'preserve',
+ TwoColumn: 'two_column',
+ FullWidth: 'full_width',
+ } as const;
+
export interface LegalDocumentCreator {
first_name: string;
email: string;
@@ -35744,6 +35758,12 @@ export namespace Schemas {
* @minItems 1
*/
tile_order: number[];
+ /** How to size tiles when reordering. 'preserve' (default) keeps each tile's existing width and height and only repacks positions in the new order. 'two_column' forces a 6-wide × 5-tall grid (two tiles per row). 'full_width' forces each tile to span the full 12-column row at height 5.
+
+ * `preserve` - preserve
+ * `two_column` - two_column
+ * `full_width` - full_width */
+ layout?: LayoutEnum;
}
export interface ScanEvidence {
diff --git a/services/mcp/src/generated/dashboards/api.ts b/services/mcp/src/generated/dashboards/api.ts
index 4e5b8b14ce23..b699a945e98e 100644
--- a/services/mcp/src/generated/dashboards/api.ts
+++ b/services/mcp/src/generated/dashboards/api.ts
@@ -236,11 +236,20 @@ export const DashboardsReorderTilesCreateQueryParams = /* @__PURE__ */ zod.objec
format: zod.enum(['json', 'txt']).optional(),
})
+export const dashboardsReorderTilesCreateBodyLayoutDefault = `preserve`
+
export const DashboardsReorderTilesCreateBody = /* @__PURE__ */ zod.object({
tile_order: zod
.array(zod.number())
.min(1)
.describe('Array of tile IDs in the desired display order (top to bottom, left to right).'),
+ layout: zod
+ .enum(['preserve', 'two_column', 'full_width'])
+ .describe('* `preserve` - preserve\n* `two_column` - two_column\n* `full_width` - full_width')
+ .default(dashboardsReorderTilesCreateBodyLayoutDefault)
+ .describe(
+ "How to size tiles when reordering. 'preserve' (default) keeps each tile's existing width and height and only repacks positions in the new order. 'two_column' forces a 6-wide × 5-tall grid (two tiles per row). 'full_width' forces each tile to span the full 12-column row at height 5.\n\n* `preserve` - preserve\n* `two_column` - two_column\n* `full_width` - full_width"
+ ),
})
/**
diff --git a/services/mcp/src/tools/generated/dashboards.ts b/services/mcp/src/tools/generated/dashboards.ts
index d5225ec86155..a17ff851367c 100644
--- a/services/mcp/src/tools/generated/dashboards.ts
+++ b/services/mcp/src/tools/generated/dashboards.ts
@@ -286,6 +286,9 @@ const dashboardReorderTiles = (): ToolBase<typeof DashboardReorderTilesSchema, W
if (params.tile_order !== undefined) {
body['tile_order'] = params.tile_order
}
+ if (params.layout !== undefined) {
+ body['layout'] = params.layout
+ }
const result = await context.api.request<Schemas.Dashboard>({
method: 'POST',
path: `/api/projects/${encodeURIComponent(String(projectId))}/dashboards/${encodeURIComponent(String(params.id))}/reorder_tiles/`,
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/dashboard-reorder-tiles.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/dashboard-reorder-tiles.json
index a881e1c770e6..3484a7ef0e09 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/dashboard-reorder-tiles.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/dashboard-reorder-tiles.json
@@ -5,6 +5,12 @@
"description": "A unique integer value identifying this dashboard.",
"type": "number"
},
+ "layout": {
+ "default": "preserve",
+ "description": "How to size tiles when reordering. 'preserve' (default) keeps each tile's existing width and height and only repacks positions in the new order. 'two_column' forces a 6-wide × 5-tall grid (two tiles per row). 'full_width' forces each tile to span the full 12-column row at height 5.\n\n* `preserve` - preserve\n* `two_column` - two_column\n* `full_width` - full_width",
+ "enum": ["preserve", "two_column", "full_width"],
+ "type": "string"
+ },
"tile_order": {
"description": "Array of tile IDs in the desired display order (top to bottom, left to right).",
"items": {