Skip to main content
Glama
Noosbai
by Noosbai

Analyser un mesh 3D

analyze_mesh

Analyze STL or 3MF files to check dimensions, volume, surface area, overhang percentage, fine detail detection, and manifold verification for 3D printing preparation.

Instructions

Analyse un fichier STL ou 3MF et retourne : dimensions, volume, surface, pourcentage d'overhangs, détection de détails fins, et vérification manifold.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesChemin absolu vers le fichier STL ou 3MF

Implementation Reference

  • Main handler function that executes the analyze_mesh tool logic - validates file path, parses STL/3MF files, calls analyzeMesh helper, and formats results with dimensions, volume, surface area, overhangs, fine details, and manifold status
    async ({ file_path }) => {
      try {
        if (!existsSync(file_path)) {
          return {
            isError: true,
            content: [{ type: "text" as const, text: `Fichier non trouvé : ${file_path}` }],
          };
        }
    
        const lower = file_path.toLowerCase();
        if (!lower.endsWith(".stl") && !lower.endsWith(".3mf")) {
          return {
            isError: true,
            content: [{ type: "text" as const, text: "Formats supportés : STL, 3MF" }],
          };
        }
    
        console.error(`[analyze_mesh] Parsing ${file_path}...`);
        const mesh = await parseModel(file_path);
        console.error(`[analyze_mesh] Parsed ${mesh.triangles.length} triangles, analyzing...`);
        const analysis = analyzeMesh(mesh);
    
        const bb = analysis.boundingBox;
        const lines = [
          `## Analyse Mesh : ${mesh.name}`,
          "",
          `**Dimensions (XYZ)** : ${bb.size.x.toFixed(2)} × ${bb.size.y.toFixed(2)} × ${bb.size.z.toFixed(2)} mm`,
          `**Volume** : ${analysis.volume.toFixed(2)} mm³ (${(analysis.volume / 1000).toFixed(2)} cm³)`,
          `**Surface** : ${analysis.surfaceArea.toFixed(2)} mm²`,
          `**Triangles** : ${analysis.triangleCount.toLocaleString()}`,
          "",
          `### Overhangs`,
          `- Faces en overhang (>45°) : **${analysis.overhangPercent.toFixed(1)}%** (${analysis.overhangTriangles} triangles)`,
          analysis.overhangPercent > 5
            ? `- Supports probablement nécessaires`
            : `- Peu d'overhangs — pas de support nécessaire a priori`,
          "",
          `### Détails fins`,
          `- Petits triangles : ${analysis.smallDetailPercent.toFixed(1)}%`,
          analysis.hasSmallDetails
            ? `- Détails fins détectés — layer height fine recommandée`
            : `- Pas de détails fins critiques`,
          "",
          `### Manifold`,
          analysis.isManifold
            ? `- Mesh manifold (fermé, prêt pour l'impression)`
            : `- Mesh non-manifold (${analysis.nonManifoldEdges} arêtes problématiques) — repair recommandé`,
        ];
    
        return {
          content: [{ type: "text" as const, text: lines.join("\n") }],
        };
      } catch (error) {
        return {
          isError: true,
          content: [{
            type: "text" as const,
            text: `Erreur d'analyse : ${error instanceof Error ? error.message : String(error)}`,
          }],
        };
      }
    },
  • Input schema definition using zod - defines that the tool accepts a single 'file_path' string parameter
    inputSchema: {
      file_path: z.string().describe("Chemin absolu vers le fichier STL ou 3MF"),
    },
  • Tool registration function that registers 'analyze_mesh' with the MCP server, including title, description, input schema, and handler callback
    export function registerAnalyzeMesh(server: McpServer) {
      server.registerTool(
        "analyze_mesh",
        {
          title: "Analyser un mesh 3D",
          description:
            "Analyse un fichier STL ou 3MF et retourne : dimensions, volume, surface, " +
            "pourcentage d'overhangs, détection de détails fins, et vérification manifold.",
          inputSchema: {
            file_path: z.string().describe("Chemin absolu vers le fichier STL ou 3MF"),
          },
        },
        async ({ file_path }) => {
          try {
            if (!existsSync(file_path)) {
              return {
                isError: true,
                content: [{ type: "text" as const, text: `Fichier non trouvé : ${file_path}` }],
              };
            }
    
            const lower = file_path.toLowerCase();
            if (!lower.endsWith(".stl") && !lower.endsWith(".3mf")) {
              return {
                isError: true,
                content: [{ type: "text" as const, text: "Formats supportés : STL, 3MF" }],
              };
            }
    
            console.error(`[analyze_mesh] Parsing ${file_path}...`);
            const mesh = await parseModel(file_path);
            console.error(`[analyze_mesh] Parsed ${mesh.triangles.length} triangles, analyzing...`);
            const analysis = analyzeMesh(mesh);
    
            const bb = analysis.boundingBox;
            const lines = [
              `## Analyse Mesh : ${mesh.name}`,
              "",
              `**Dimensions (XYZ)** : ${bb.size.x.toFixed(2)} × ${bb.size.y.toFixed(2)} × ${bb.size.z.toFixed(2)} mm`,
              `**Volume** : ${analysis.volume.toFixed(2)} mm³ (${(analysis.volume / 1000).toFixed(2)} cm³)`,
              `**Surface** : ${analysis.surfaceArea.toFixed(2)} mm²`,
              `**Triangles** : ${analysis.triangleCount.toLocaleString()}`,
              "",
              `### Overhangs`,
              `- Faces en overhang (>45°) : **${analysis.overhangPercent.toFixed(1)}%** (${analysis.overhangTriangles} triangles)`,
              analysis.overhangPercent > 5
                ? `- Supports probablement nécessaires`
                : `- Peu d'overhangs — pas de support nécessaire a priori`,
              "",
              `### Détails fins`,
              `- Petits triangles : ${analysis.smallDetailPercent.toFixed(1)}%`,
              analysis.hasSmallDetails
                ? `- Détails fins détectés — layer height fine recommandée`
                : `- Pas de détails fins critiques`,
              "",
              `### Manifold`,
              analysis.isManifold
                ? `- Mesh manifold (fermé, prêt pour l'impression)`
                : `- Mesh non-manifold (${analysis.nonManifoldEdges} arêtes problématiques) — repair recommandé`,
            ];
    
            return {
              content: [{ type: "text" as const, text: lines.join("\n") }],
            };
          } catch (error) {
            return {
              isError: true,
              content: [{
                type: "text" as const,
                text: `Erreur d'analyse : ${error instanceof Error ? error.message : String(error)}`,
              }],
            };
          }
        },
      );
  • src/index.ts:42-42 (registration)
    Registration call in main server initialization - invokes registerAnalyzeMesh to add the tool to the MCP server
    registerAnalyzeMesh(server);
  • Core analysis helper function that computes mesh geometry: triangle count, bounding box, volume (via signed tetrahedron method), surface area, overhang detection (>45° faces), fine detail detection, and manifold edge checking
    export function analyzeMesh(stl: StlData): MeshAnalysis {
      const { triangles } = stl;
      const n = triangles.length;
    
      if (n === 0) {
        return {
          triangleCount: 0,
          boundingBox: { min: { x: 0, y: 0, z: 0 }, max: { x: 0, y: 0, z: 0 }, size: { x: 0, y: 0, z: 0 } },
          volume: 0,
          surfaceArea: 0,
          overhangPercent: 0,
          overhangTriangles: 0,
          hasSmallDetails: false,
          smallDetailPercent: 0,
          isManifold: false,
          nonManifoldEdges: 0,
        };
      }
    
      // Single pass for volume, surface area, bounding box, overhangs, triangle areas
      let volume = 0;
      let surfaceArea = 0;
      let overhangCount = 0;
      const areas: number[] = new Array(n);
    
      const bbMin: Vec3 = { x: Infinity, y: Infinity, z: Infinity };
      const bbMax: Vec3 = { x: -Infinity, y: -Infinity, z: -Infinity };
    
      for (let i = 0; i < n; i++) {
        const t = triangles[i];
    
        // Bounding box
        updateBB(bbMin, bbMax, t.v1);
        updateBB(bbMin, bbMax, t.v2);
        updateBB(bbMin, bbMax, t.v3);
    
        // Signed volume (tetrahedron with origin)
        volume += signedTetraVolume(t.v1, t.v2, t.v3);
    
        // Surface area via cross product
        const area = triangleArea(t.v1, t.v2, t.v3);
        surfaceArea += area;
        areas[i] = area;
    
        // Overhang detection: face normal Z component < cos(45°) ≈ -0.707
        // If the normal points downward (nz < 0) beyond 45°, it's an overhang.
        // We compute the actual normal from vertices for accuracy.
        const normal = computeNormal(t.v1, t.v2, t.v3);
        if (normal.z < -0.707) {
          overhangCount++;
        }
      }
    
      // Small detail detection: triangles with area < 10% of median area
      const sortedAreas = [...areas].sort((a, b) => a - b);
      const medianArea = sortedAreas[Math.floor(n / 2)];
      const smallThreshold = medianArea * 0.1;
      let smallDetailCount = 0;
      for (let i = 0; i < n; i++) {
        if (areas[i] < smallThreshold && areas[i] > 0) {
          smallDetailCount++;
        }
      }
    
      // Manifold check: each edge must be shared by exactly 2 triangles
      const { isManifold, nonManifoldEdges } = checkManifold(triangles);
    
      const size: Vec3 = {
        x: bbMax.x - bbMin.x,
        y: bbMax.y - bbMin.y,
        z: bbMax.z - bbMin.z,
      };
    
      return {
        triangleCount: n,
        boundingBox: { min: bbMin, max: bbMax, size },
        volume: Math.abs(volume),
        surfaceArea,
        overhangPercent: (overhangCount / n) * 100,
        overhangTriangles: overhangCount,
        hasSmallDetails: smallDetailCount > n * 0.05,
        smallDetailPercent: (smallDetailCount / n) * 100,
        isManifold,
        nonManifoldEdges,
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool returns analysis results but doesn't cover critical aspects like performance (e.g., processing time for large files), error handling (e.g., invalid file formats), or side effects (e.g., whether it modifies the file). For a tool with no annotation coverage, this is a significant gap in transparency.

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

Conciseness4/5

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

The description is concise and front-loaded, starting with the core action and listing outputs in a single sentence. Every element (e.g., dimensions, volume) serves to clarify the purpose without redundancy. However, it could be slightly more structured by grouping outputs or adding brief context, but overall it's efficient with minimal waste.

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 has no annotations and no output schema, the description is moderately complete for a simple analysis tool. It specifies the file types and analysis outputs, but lacks details on return format, error cases, or integration with sibling tools. For a tool in a complex 3D printing server with many siblings, this leaves gaps in understanding how it fits into broader workflows.

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?

The input schema has 100% description coverage, with 'file_path' clearly documented as an absolute path to STL or 3MF files. The description doesn't add any parameter-specific details beyond what the schema provides, such as file size limits or format specifics. Since schema coverage is high, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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 verb 'Analyse' and the resource 'un fichier STL ou 3MF', specifying it analyzes 3D mesh files. It lists specific outputs like dimensions, volume, surface, etc., making the purpose concrete. However, it doesn't explicitly differentiate from sibling tools like 'check_printability' or 'diagnose_print', which might have overlapping functions in a 3D printing context.

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 prerequisites, such as needing a valid file path, or compare it to siblings like 'check_printability' for printability checks or 'diagnose_print' for diagnostic analysis. This lack of context leaves the agent guessing about the appropriate use case.

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/Noosbai/PrusaMCP'

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