Skip to main content
Glama
DynamicEndpoints

Microsoft 365 Core MCP Server

generate_html_report

Create interactive HTML reports and dashboards with responsive design, charts, and filtering capabilities for Microsoft 365 data analysis.

Instructions

Create interactive HTML reports and dashboards with responsive design, charts, and filtering capabilities.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction: create new HTML report, get existing, or list all
fileNameNoName for the HTML file (for create action)
driveIdNoOneDrive/SharePoint drive ID (default: user's OneDrive)
folderIdNoFolder ID within the drive (default: root)
templateNoTemplate configuration for HTML report styling
sectionsNoArray of HTML sections to create
includeChartsNoEnable interactive charts with Chart.js
fileIdNoFile ID for get action
filterNoOData filter for list action
topNoNumber of results to return (for list action)

Implementation Reference

  • Tool registration in the MCP server, linking the tool name to the handler function handleHTMLReports.
      "generate_html_report",
      "Create interactive HTML reports and dashboards with responsive design, charts, and filtering capabilities.",
      htmlReportArgsSchema.shape,
      {"readOnlyHint":false,"destructiveHint":false,"idempotentHint":false},
      wrapToolHandler(async (args: HTMLReportArgs) => {
        this.validateCredentials();
        try {
          const result = await handleHTMLReports(args, this.getGraphClient());
          return { content: [{ type: 'text', text: result }] };
        } catch (error) {
          if (error instanceof McpError) {
            throw error;
          }
          throw new McpError(
            ErrorCode.InternalError,
            `Error generating HTML report: ${error instanceof Error ? error.message : 'Unknown error'}`
          );
        }
      })
    );
  • Main handler function for the generate_html_report tool. Dispatches to create/get/list actions based on args.action. The 'create' action generates the HTML report.
    export async function handleHTMLReports(
      args: HTMLReportArgs,
      graphClient: Client
    ): Promise<string> {
      try {
        switch (args.action) {
          case 'create':
            return await createHTMLReport(args, graphClient);
          case 'get':
            return await getHTMLReport(args, graphClient);
          case 'list':
            return await listHTMLReports(args, graphClient);
          default:
            throw new McpError(
              ErrorCode.InvalidRequest,
              `Unknown action: ${args.action}`
            );
        }
      } catch (error) {
        if (error instanceof McpError) throw error;
        throw new McpError(
          ErrorCode.InternalError,
          `HTML report operation failed: ${error instanceof Error ? error.message : 'Unknown error'}`
        );
      }
    }
  • Core creation logic for HTML reports. Generates HTML content using sections and template, then uploads to OneDrive/SharePoint.
    async function createHTMLReport(
      args: HTMLReportArgs,
      graphClient: Client
    ): Promise<string> {
      if (!args.fileName) {
        throw new McpError(ErrorCode.InvalidRequest, 'fileName is required for create action');
      }
    
      if (!args.template) {
        throw new McpError(ErrorCode.InvalidRequest, 'template is required for create action');
      }
    
      if (!args.sections || args.sections.length === 0) {
        throw new McpError(ErrorCode.InvalidRequest, 'At least one section is required');
      }
    
      // Determine drive location (default to user's OneDrive)
      const driveId = args.driveId || 'me';
      const folderPath = args.folderId ? `/items/${args.folderId}` : '/root';
    
      // Create HTML file
      const fileName = args.fileName.endsWith('.html') ? args.fileName : `${args.fileName}.html`;
      
      // Generate HTML content
      const htmlContent = generateHTMLContent(args.sections, args.template, args.includeCharts);
      
      const uploadedFile = await graphClient
        .api(`/drives/${driveId}${folderPath}:/${fileName}:/content`)
        .header('Content-Type', 'text/html')
        .put(Buffer.from(htmlContent, 'utf-8'));
    
      return JSON.stringify({
        success: true,
        fileId: uploadedFile.id,
        fileName: uploadedFile.name,
        webUrl: uploadedFile.webUrl,
        driveId: uploadedFile.parentReference?.driveId,
        message: `HTML report "${fileName}" created successfully with ${args.sections.length} sections`
      }, null, 2);
    }
  • Primary helper function that generates the complete HTML document from sections and template. Includes theme styles, Chart.js for interactive charts, responsive design.
    function generateHTMLContent(
      sections: HTMLSection[],
      template: HTMLTemplate,
      includeCharts?: boolean
    ): string {
      const theme = getThemeStyles(template.theme || 'modern');
      
      let html = `<!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>${escapeHtml(template.title)}</title>
      ${template.author ? `<meta name="author" content="${escapeHtml(template.author)}">` : ''}
      ${template.description ? `<meta name="description" content="${escapeHtml(template.description)}">` : ''}
      
      ${template.includeBootstrap ? '<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">' : ''}
      ${includeCharts || template.includeChartJS ? '<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.js"></script>' : ''}
      
      <style>
        ${theme}
        ${template.customCSS || ''}
      </style>
    </head>
    <body>
      <div class="container">
        <header class="report-header">
          ${template.companyLogo ? `<img src="${escapeHtml(template.companyLogo)}" alt="Company Logo" class="company-logo">` : ''}
          <h1>${escapeHtml(template.title)}</h1>
          ${template.description ? `<p class="report-description">${escapeHtml(template.description)}</p>` : ''}
          ${template.companyName ? `<p class="company-name">${escapeHtml(template.companyName)}</p>` : ''}
          <p class="report-date">Generated: ${new Date().toLocaleString()}</p>
        </header>
        
        <main class="report-content">`;
    
      // Generate sections
      sections.forEach((section, index) => {
        html += generateHTMLSection(section, index);
      });
    
      html += `
        </main>
        
        <footer class="report-footer">
          ${template.companyName ? `<p>© ${new Date().getFullYear()} ${escapeHtml(template.companyName)}</p>` : ''}
          <p>Report generated by M365 Core MCP Server</p>
        </footer>
      </div>
      
      ${includeCharts ? getChartScripts(sections) : ''}
    </body>
    </html>`;
    
      return html;
    }
  • Zod schema defining input parameters for the generate_html_report tool, including action, template, sections for structured HTML generation.
    export const htmlReportArgsSchema = z.object({
      action: z.enum(['create', 'get', 'list'])
        .describe('Action: create new HTML report, get existing, or list all'),
      fileName: z.string().optional()
        .describe('Name for the HTML file (for create action)'),
      driveId: z.string().optional()
        .describe('OneDrive/SharePoint drive ID (default: user\'s OneDrive)'),
      folderId: z.string().optional()
        .describe('Folder ID within the drive (default: root)'),
      template: htmlTemplateSchema.optional()
        .describe('Template configuration for HTML report styling'),
      sections: z.array(htmlSectionSchema).optional()
        .describe('Array of HTML sections to create'),
      includeCharts: z.boolean().optional()
        .describe('Enable interactive charts with Chart.js'),
      fileId: z.string().optional()
        .describe('File ID for get action'),
      filter: z.string().optional()
        .describe('OData filter for list action'),
      top: z.number().optional()
        .describe('Number of results to return (for list action)')
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate this is a non-read-only, non-idempotent, non-destructive tool (readOnlyHint=false, idempotentHint=false, destructiveHint=false), which the description doesn't contradict. The description adds context about the tool's capabilities (responsive design, charts, filtering) that goes beyond annotations, but it lacks details on behavioral aspects like authentication requirements, rate limits, or what happens during creation (e.g., file overwriting). With annotations covering basic safety, the description provides some added value but not rich behavioral disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose: 'Create interactive HTML reports and dashboards with responsive design, charts, and filtering capabilities.' Every word earns its place by specifying key features without redundancy or unnecessary elaboration. It's appropriately sized for a tool with a clear function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (10 parameters, nested objects, no output schema) and rich schema coverage, the description is adequate but has gaps. It outlines what the tool does but doesn't address prerequisites, error handling, or output details (e.g., what is returned after creation). With annotations covering basic behavioral hints, the description meets minimum viability but could be more complete for a multi-action tool with significant configuration options.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, meaning all parameters are well-documented in the schema itself. The description mentions 'responsive design, charts, and filtering capabilities,' which loosely maps to parameters like 'template', 'sections', and 'includeCharts', but it doesn't add meaningful semantics beyond what the schema already provides (e.g., it doesn't explain parameter interactions or usage patterns). Given the high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Create interactive HTML reports and dashboards with responsive design, charts, and filtering capabilities.' It specifies the verb ('Create') and resource ('HTML reports and dashboards') along with key features. However, it doesn't explicitly differentiate from sibling tools like 'generate_professional_report' or 'generate_word_document', which might serve similar reporting purposes but in different formats.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools or contexts where HTML reports are preferred over other formats (e.g., Word documents or PowerPoint presentations). Usage is implied only through the description's focus on HTML features, but there are no explicit when/when-not statements or named alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DynamicEndpoints/m365-core-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server