Skip to main content
Glama

detect_faces

Identify faces in images or videos to obtain face IDs for subsequent face swapping operations. Specify a confidence threshold to control detection sensitivity.

Instructions

Detect faces in an image or video. Returns face IDs that can be used for individual face swapping.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_urlYesURL or local path to the image or video to scan for faces
confidence_scoreNoConfidence threshold (0.3-0.9). Higher = stricter detection. Default varies.

Implementation Reference

  • src/index.ts:215-263 (registration)
    Complete registration of the 'detect_faces' tool using server.tool(), including name, description, input schema, and handler function
    server.tool(
      "detect_faces",
      "Detect faces in an image or video. Returns face IDs that can be used for individual face swapping.",
      {
        file_url: z
          .string()
          .describe("URL or local path to the image or video to scan for faces"),
        confidence_score: z
          .number()
          .min(0.3)
          .max(0.9)
          .optional()
          .describe(
            "Confidence threshold (0.3-0.9). Higher = stricter detection. Default varies."
          ),
      },
      async ({ file_url, confidence_score }) => {
        try {
          const result = await client.v1.faceDetection.create({
            assets: { targetFilePath: file_url },
            confidenceScore: confidence_score,
          });
    
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(
                  {
                    id: result.id,
                    message:
                      "Face detection job submitted. Use get_face_detection_result to get the detected faces.",
                  },
                  null,
                  2
                ),
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              { type: "text" as const, text: `Error: ${error.message}` },
            ],
            isError: true,
          };
        }
      }
    );
  • Input validation schema using Zod for 'detect_faces' parameters: file_url (required string) and confidence_score (optional number with min 0.3 and max 0.9)
    {
      file_url: z
        .string()
        .describe("URL or local path to the image or video to scan for faces"),
      confidence_score: z
        .number()
        .min(0.3)
        .max(0.9)
        .optional()
        .describe(
          "Confidence threshold (0.3-0.9). Higher = stricter detection. Default varies."
        ),
    },
  • Handler function that executes the face detection logic: calls client.v1.faceDetection.create() with file_url and confidence_score, returns job ID, and includes error handling
    async ({ file_url, confidence_score }) => {
      try {
        const result = await client.v1.faceDetection.create({
          assets: { targetFilePath: file_url },
          confidenceScore: confidence_score,
        });
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(
                {
                  id: result.id,
                  message:
                    "Face detection job submitted. Use get_face_detection_result to get the detected faces.",
                },
                null,
                2
              ),
            },
          ],
        };
      } catch (error: any) {
        return {
          content: [
            { type: "text" as const, text: `Error: ${error.message}` },
          ],
          isError: true,
        };
      }
    }

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/andrianthan/magic-hour-mcp'

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