Tools for agents: Exact ray-mesh intersections

Find forward ray hits on triangle meshes, with exact positions, face indices and barycentric coordinates.

Connect with MCP

{
  "mcpServers": {
    "super-agent-tools": {
      "url": "https://app.getsupers.com/sites/agent-ray-mesh/mcp"
    }
  }
}
Streamable HTTP · No API key · Stateless

Use this URL in any client supporting remote Streamable HTTP MCP. Calls return structured JSON; inputs are processed without persistence.

Call intersect_ray_mesh

Ray equation: origin + t*direction, with t >= 0; direction need not be normalized. Parameter t is not Euclidean distance. Send integers or quoted decimal/fraction strings; JSON floats and booleans are rejected. Both face sides are tested. Edge, vertex and t=0 hits are included; shared-edge or overlapping-face hits remain separate per-face records. Barycentric weights correspond to the three vertex indices in each face. front_facing means the ray direction opposes the face normal from its index order. Degenerate triangles are reported and skipped. A ray in a triangle plane is reported as coplanar even if it misses the triangle; coplanar overlap is not resolved. isolated_hits_complete is false whenever coplanar faces exist; nearest_hit is only the nearest reported isolated hit. Empty hits alone do not prove no coplanar overlap. This is a linear scan for small meshes, not a spatially accelerated renderer or solid-containment test. Rational arithmetic: https://docs.python.org/3/library/fractions.html

Input and output schemas
{
  "name": "intersect_ray_mesh",
  "title": "Exact ray-mesh intersections",
  "description": "Intersect a forward ray origin+t*direction, t>=0, with both sides of indexed triangles. Return exact fraction-string hits sorted by ray parameter; flag degenerate and coplanar faces separately.",
  "inputSchema": {
    "properties": {
      "vertices": {
        "items": {
          "maxItems": 3,
          "minItems": 3,
          "prefixItems": [
            {
              "anyOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            },
            {
              "anyOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            },
            {
              "anyOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          ],
          "type": "array"
        },
        "title": "Vertices",
        "type": "array"
      },
      "triangles": {
        "items": {
          "maxItems": 3,
          "minItems": 3,
          "prefixItems": [
            {
              "type": "integer"
            },
            {
              "type": "integer"
            },
            {
              "type": "integer"
            }
          ],
          "type": "array"
        },
        "title": "Triangles",
        "type": "array"
      },
      "origin": {
        "maxItems": 3,
        "minItems": 3,
        "prefixItems": [
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          }
        ],
        "title": "Origin",
        "type": "array"
      },
      "direction": {
        "maxItems": 3,
        "minItems": 3,
        "prefixItems": [
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          }
        ],
        "title": "Direction",
        "type": "array"
      }
    },
    "required": [
      "vertices",
      "triangles",
      "origin",
      "direction"
    ],
    "title": "intersect_ray_meshArguments",
    "type": "object"
  },
  "outputSchema": {
    "additionalProperties": true,
    "title": "intersect_ray_meshDictOutput",
    "type": "object"
  },
  "icons": null,
  "annotations": {
    "title": null,
    "readOnlyHint": true,
    "destructiveHint": false,
    "idempotentHint": true,
    "openWorldHint": false
  },
  "meta": null,
  "execution": null
}

Run the example to see the actual result.

HTTP alternative

POST https://app.getsupers.com/sites/agent-ray-mesh/call
Content-Type: application/json

{
  "vertices": [
    [
      0,
      0,
      0
    ],
    [
      2,
      0,
      0
    ],
    [
      0,
      2,
      0
    ]
  ],
  "triangles": [
    [
      0,
      1,
      2
    ]
  ],
  "origin": [
    "1/2",
    "1/2",
    2
  ],
  "direction": [
    0,
    0,
    -2
  ]
}

The HTTP and MCP interfaces execute the same implementation. Validation errors are returned explicitly. See the tool notes above for its supported inputs and behavior.

Ray-mesh intersections: parameter, barycentric weights and completeness

Read the explanation

The saved ray starts at one half, one half, two and points along zero, zero, minus two. Its position is origin plus t times direction. At the triangle plane z equals zero, two minus two t equals zero, so t equals one. The hit point is one half, one half, zero. Yet the ray travels two coordinate units, not one: distance equals t times the length of direction, which is two. The normal cross-section uses one hundred forty pixels per coordinate unit. Double the direction to minus four and the same hit occurs at t equals one half, with the same two-unit distance. Normalization is not required. This is a derivation from the saved input and documented contract, not an actual remote tool response. Look down onto the triangle with vertices zero, zero; two, zero; and zero, two in the z equals zero plane. The hit at one half, one half lies inside it. Its barycentric weights in vertex index order are one half, one quarter and one quarter. They sum to one and reconstruct the point: one quarter times two contributes one half to x and the other quarter contributes one half to y. All weights are nonnegative, so this point is inside. The plan view uses one hundred forty pixels per coordinate unit on both axes. An intersection with the triangle plane is not sufficient by itself; an isolated hit must also lie within the face. Edge and vertex hits are included, and shared-edge hits remain separate records for each face. The face order zero, one, two gives a normal along positive z. The downward ray opposes that normal, so the hit is front facing. Reverse the face order and the normal reverses; the same geometric hit becomes back facing, because both sides are tested. Degenerate faces are reported and skipped. Coplanar rays require another distinction: a ray in a triangle plane is reported as coplanar even if it misses the triangle, and the tool does not resolve coplanar overlap. When any coplanar face exists, isolated hits complete is false. Nearest hit means only the nearest reported isolated hit; an empty hit list alone cannot prove no coplanar overlap. The implementation is documented as a linear scan for small meshes, not a renderer acceleration structure or solid-containment test. Offline input preservation can be checked, but the shared app script is absent and no HTTP or MCP execution is performed.

Exact Ray-Triangle Intersections via Rational Arithmetic

How does intersect_ray_mesh compute exact intersection points and barycentric coordinates without floating-point inaccuracies?

The intersect_ray_mesh tool performs exact forward ray-triangle intersection queries using scalar triple products (Möller–Trumbore formulation) evaluated entirely over rational arithmetic. Instead of IEEE 754 floating-point numbers, coordinates and ray parameters are parsed as exact fractions via Python's fractions module. This avoids precision loss, epsilon tolerance tuning, and rounding artifacts along triangle boundaries.

The implementation performs an exhaustive linear scan O(N) over indexed triangles, rather than using bounding volume hierarchies (BVH) or spatial partitioning. Rays coplanar with a triangle plane are flagged in coplanar_faces without computing 2D polygon overlap segments, setting isolated_hits_complete to false. Furthermore, parameter t represents the scaling multiplier of the given direction vector, not Euclidean metric distance unless direction is normalized.

Try a worked example

Consider the default triangle with vertices (0,0,0), (2,0,0), and (0,2,0), with a ray starting at origin (1/2, 1/2, 2) pointing downwards along (0, 0, -2). In the ray equation origin + t*direction, substituting t = 1 yields the point (1/2, 1/2, 0) lying directly on the triangle plane. Submitting 'Run tool' executes the linear intersection test, reporting hit count 1 with ray parameter t = '1', exact point ['1/2', '1/2', '0'], barycentric coordinates ['1/2', '1/4', '1/4'], and front_facing as true.

Algorithmic Formulation and Rational Evaluation

The tool computes edge vectors e1 = B - A and e2 = C - A for each triangle face. Using vector cross and dot products, the determinant det = dot(e1, cross(d, e2)) is derived. When det is non-zero, solving the linear system yields barycentric coordinates u and v along with ray parameter t. By maintaining coordinates as exact instances of Python's Fraction type, calculations remain fully exact without floating-point error accumulation. fractions — Rational numbers — Python documentation

An intersection is recorded as a valid isolated hit when t >= 0, u >= 0, v >= 0, and u + v <= 1. Degenerate triangles (zero area cross-product) and coplanar rays (det == 0 and coplanar origin offset) are isolated and returned as dedicated diagnostic arrays rather than causing unhandled division errors. fractions — Rational numbers — Python documentation

Sources and further reading