> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tryhamsa.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Test MCP Function

> Runs one function on an MCP server with the arguments you send and returns its result. A failed run (tool error, timeout, unreachable server) still returns `200`, with `data.success: false` and `data.error`.



## OpenAPI

````yaml /api-reference/openapi.json post /v2/voice-agents/web-tool/mcp/test-function
openapi: 3.0.1
info:
  title: Hamsa API
  description: >-
    The Hamsa API: voice agents and their calls, phone numbers, batch calls and
    knowledge bases; speech to text, text to speech, voices and AI content.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.tryhamsa.com
security: []
paths:
  /v2/voice-agents/web-tool/mcp/test-function:
    post:
      summary: Test an MCP function
      description: >-
        Runs one function on an MCP server with the arguments you send and
        returns its result. A failed run (tool error, timeout, unreachable
        server) still returns `200`, with `data.success: false` and
        `data.error`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - serverUrl
                - functionName
              properties:
                serverUrl:
                  type: string
                  format: uri
                  description: MCP server URL (Streamable HTTP or SSE).
                  example: https://mcp.example.com/sse
                authToken:
                  type: string
                  nullable: true
                  description: >-
                    Authorization header value with its prefix, e.g. `Bearer
                    xxx`. May use `{{secrets.NAME}}` placeholders from your
                    project secrets. `null` for none.
                  example: Bearer {{secrets.MCP_TOKEN}}
                httpHeaders:
                  type: object
                  additionalProperties:
                    type: string
                  description: >-
                    Extra headers for the MCP connection. Values may use
                    `{{secrets.NAME}}` placeholders.
                  example:
                    X-Workspace: support
                timeOut:
                  type: number
                  minimum: 1
                  maximum: 60
                  description: Timeout in seconds (1-60). Default 30.
                  example: 10
                functionName:
                  type: string
                  minLength: 1
                  description: Name of the function to run, from the discover response.
                  example: create_ticket
                arguments:
                  type: object
                  additionalProperties: true
                  description: Function arguments, matching its `inputSchema`.
                  example:
                    title: Printer is broken
            examples:
              call:
                summary: Run a function
                value:
                  serverUrl: https://mcp.example.com/sse
                  authToken: Bearer {{secrets.MCP_TOKEN}}
                  functionName: create_ticket
                  arguments:
                    title: Printer is broken
                  timeOut: 10
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      success:
                        type: boolean
                        description: >-
                          `false` when the function failed, timed out, or the
                          server was unreachable.
                        example: true
                      result:
                        anyOf:
                          - type: object
                            nullable: true
                            additionalProperties: true
                          - type: array
                            items: {}
                            nullable: true
                          - type: string
                            nullable: true
                          - type: number
                            nullable: true
                          - type: boolean
                            nullable: true
                        description: >-
                          The function's result: parsed JSON when it returns
                          JSON, otherwise the text. `null` on failure.
                        example:
                          ticketId: TICK-123
                      error:
                        type: string
                        nullable: true
                        description: Why it failed. `null` on success.
                        example: null
                      executionTime:
                        type: integer
                        description: Round trip in milliseconds.
                        example: 812
        '400':
          description: >-
            Invalid body, an unsafe server URL, a `{{secrets.NAME}}` placeholder
            with no matching secret.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '401':
          description: 'Unauthorized: missing or invalid API key.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '403':
          description: >-
            A limited key without the `tools:update` scope, or a role that can't
            edit APIs & MCPs (`ScopeNotAllowed`, `params.scope` is
            `tools:update`). Or the request uses `{{secrets.NAME}}` and your API
            key or role can't read secrets (`WebToolSecretsPermissionRequired`;
            needs the `secrets:read` scope). Requests without secret references
            don't need it.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '500':
          description: Server Side Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    ErrorSchema:
      type: object
      properties:
        code:
          type: integer
          description: >-
            Service error code: the HTTP status with a service prefix (for
            example `8404`). Missing when the service has no code for that
            status.
          example: 8404
        message:
          type: string
          description: >-
            What went wrong. Some services (calls and recordings) put the error
            key here, for example `CallNotFoundOrUnavailable`, and send no
            `messageKey`.
          example: Policy not found!
        messageKey:
          type: string
          description: >-
            Stable key for the error, safe to match on in code. Not returned by
            every service.
          example: PolicyNotFound
        params:
          type: object
          additionalProperties: true
          description: >-
            Details for some errors (for example `reason`). Not returned by
            every service.
          example:
            reason: NO_DRAFT
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Pass the API key in the Authorization header, You need to put Token
        keyword before the API key. e.g. 'Authorization: Token <api-key>'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.