Writing JavaScript Interceptors
To inject a custom Goja interceptor onto any specific Provider API Route, you utilize the Data Transformation UI block securely nested within the Provider Tool configuration page.
The Interceptor Interface
All JavaScript logic inside HasMCP must structurally adhere to a strict interface. You must implement a single global function exactly namedintercept(response) for Response Interceptors, or intercept(request) for Request Interceptors.
[!NOTE] Interceptor Availability: Request Interceptors can strictly be attached toPOST,PUT, andPATCHmethods to modify outgoing bodies or arguments. Response Interceptors are universally available to all HTTP methods uniformly.
Execution Behavior
- The originating MCP client asks the HasMCP Server to trigger a tool.
- HasMCP negotiates the upstream HTTP execution accurately against the external third-party API.
- The target API returns an HTTP response payload.
- HasMCP buffers the response and inherently executes your
intercept(response)function locally physically. - The LLM exclusively receives the modified stringified response intelligently, completely unaware of the physical interception step.
[!IMPORTANT] Execution Timeouts: Both GoJA and JMESPath interceptors have a strict 100ms execution timeout on HasMCP Cloud versions to prevent runaway scripts. Enterprise on-prem deployments can explicitly define custom timeout limits on their own hosted infrastructure.