MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / registerReportTools

Function registerReportTools

packages/mcp/src/tools/analytics/reports.ts:24–100  ·  view source on GitHub ↗
(
  server: McpServer,
  context: McpAuthContext,
)

Source from the content-addressed store, hash-verified

22}
23
24export function registerReportTools(
25 server: McpServer,
26 context: McpAuthContext,
27) {
28 server.tool(
29 'list_dashboards',
30 'List all dashboards for a project. Returns dashboard IDs and names. Use these IDs with list_reports to see what reports each dashboard contains.',
31 {
32 projectId: projectIdSchema(context),
33 },
34 async ({ projectId: inputProjectId }) =>
35 withErrorHandling(async () => {
36 const projectId = await resolveProjectId(context, inputProjectId);
37 const dashboards = await db.dashboard.findMany({
38 where: { projectId },
39 orderBy: { createdAt: 'desc' },
40 select: { id: true, name: true, projectId: true },
41 });
42 return dashboards.map((d) => ({
43 ...d,
44 dashboard_url: dashboardUrl(context.organizationId, projectId, d.id),
45 }));
46 }),
47 );
48
49 server.tool(
50 'list_reports',
51 'List all reports in a dashboard. Returns report IDs, names, chart types, and the events/metrics they track. Use get_report_data to execute a report and retrieve its actual data.',
52 {
53 projectId: projectIdSchema(context),
54 dashboardId: z.string().describe('The dashboard ID to list reports for'),
55 },
56 async ({ projectId: inputProjectId, dashboardId }) =>
57 withErrorHandling(async () => {
58 const projectId = await resolveProjectId(context, inputProjectId);
59 const reports = await getReportsByDashboardId(dashboardId);
60 if (reports.some((r) => r.projectId !== projectId)) {
61 throw new Error('Dashboard does not belong to this project');
62 }
63 return reports.map((r) => ({
64 id: r.id,
65 name: r.name,
66 chartType: r.chartType,
67 range: r.range,
68 interval: r.interval,
69 metric: r.metric,
70 series: r.series.map((s) =>
71 s.type === 'formula'
72 ? { type: 'formula', id: s.id, formula: s.formula }
73 : {
74 type: 'event',
75 id: s.id,
76 name: s.name,
77 displayName: s.displayName,
78 segment: s.segment,
79 },
80 ),
81 breakdowns: r.breakdowns,

Callers 1

registerAllToolsFunction · 0.90

Calls 9

projectIdSchemaFunction · 0.90
withErrorHandlingFunction · 0.90
resolveProjectIdFunction · 0.90
getReportsByDashboardIdFunction · 0.90
reportUrlFunction · 0.85
runReportFunction · 0.85
dashboardUrlFunction · 0.70
mapMethod · 0.45
someMethod · 0.45

Tested by

no test coverage detected