export-dashboard-pptx.ts•4.48 kB
/**
* MCP Tool: tableau_export_dashboard_pptx
*
* Purpose: Export a Tableau dashboard/view as PowerPoint with optional filters
* Parameters:
* - viewId (required): View/dashboard identifier
* - filters (optional): Object with filter values to apply
* Returns: PowerPoint file as base64-encoded string with metadata
*/
import { z } from 'zod';
import { TableauClient } from '../tableau-client.js';
// Zod schema for input validation
export const ExportDashboardPPTXArgsSchema = z.object({
viewId: z.string().describe('View/dashboard identifier to export'),
filters: z.record(z.string()).optional().describe('Optional filter values to apply (e.g., { "Region": "West", "Year": "2024" })'),
});
export type ExportDashboardPPTXArgs = z.infer<typeof ExportDashboardPPTXArgsSchema>;
/**
* Handler for tableau_export_dashboard_pptx tool
*
* Exports a Tableau dashboard or view as a PowerPoint (PPTX) file with optional
* filter values. Returns the PowerPoint file as base64-encoded string.
*
* @param args - Tool arguments (viewId, filters)
* @param tableauClient - Initialized Tableau client instance
* @returns Formatted response with PowerPoint data or error
*/
export async function exportDashboardPPTXHandler(
args: ExportDashboardPPTXArgs,
tableauClient: TableauClient
): Promise<{ content: Array<{ type: string; text: string }> }> {
try {
// Call TableauClient to export dashboard as PowerPoint
const pptxBuffer = await tableauClient.exportDashboardPPTX(
args.viewId,
args.filters
);
// Convert Buffer to base64
const pptxBase64 = pptxBuffer.toString('base64');
const pptxSizeKB = (pptxBuffer.length / 1024).toFixed(2);
// Create a summary
const filterInfo = args.filters && Object.keys(args.filters).length > 0
? `\nFilters applied:\n${Object.entries(args.filters)
.map(([key, value]) => ` - ${key}: ${value}`)
.join('\n')}`
: '\nNo filters applied';
const summary = `PowerPoint Export Successful\n\n` +
`View/Dashboard ID: ${args.viewId}\n` +
`File Size: ${pptxSizeKB} KB\n` +
filterInfo +
`\n\nThe PowerPoint presentation has been exported and encoded as base64. ` +
`You can decode and save it using the provided base64 data. ` +
`The exported presentation contains the dashboard view as an image slide.`;
// Return summary and base64 data
// Note: For very large files, you might want to stream or provide a download URL instead
return {
content: [
{
type: 'text',
text: summary
},
{
type: 'text',
text: `\n\nBase64 PowerPoint Data (first 500 characters):\n${pptxBase64.substring(0, 500)}...\n\n[PowerPoint data truncated for display. Full size: ${pptxSizeKB} KB]`
},
{
type: 'text',
text: `\n\nFull Base64 Data:\n${pptxBase64}`
}
]
};
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
return {
content: [{
type: 'text',
text: `Error exporting dashboard to PowerPoint: ${errorMessage}\n\n` +
`Troubleshooting:\n` +
`- Verify the view ID is correct\n` +
`- Check that the view is accessible\n` +
`- Ensure filter names match dashboard filter names exactly\n` +
`- Confirm PowerPoint export is enabled for this view\n` +
`- Large dashboards may take longer or timeout`
}]
};
}
}
// Tool metadata for MCP server registration
export const exportDashboardPPTXTool = {
name: 'tableau_export_dashboard_pptx',
description: 'Export a Tableau dashboard or view as PowerPoint (PPTX) presentation with optional filters. The exported presentation contains the dashboard view as an image slide. Filters can be applied by providing a filter object with key-value pairs. Returns PowerPoint file as base64-encoded string.',
inputSchema: {
type: 'object',
properties: {
viewId: {
type: 'string',
description: 'View/dashboard identifier (GUID) to export as PowerPoint'
},
filters: {
type: 'object',
description: 'Optional: Filter values to apply before export (e.g., {"Region": "West", "Year": "2024"}). Filter names must match dashboard filter names exactly.',
additionalProperties: {
type: 'string'
}
}
},
required: ['viewId']
}
};