safetyCheck. This
example shows the wrapper in isolation — same shape as the
weather server’s summarizer tool.
summarizer.ts
What happens on a flagged input
If the safety API flags thetext parameter:
- The wrapper doesn’t call your handler.
- It returns a structured blocked response:
- With
output_screen: true, your terminal also prints: - The active span gets
mcp.safety_check.flagged = trueplus latency and content attributes.
What happens on a clean input
The wrapper writes safety attributes (flagged: false, latency, success) to
the span, then calls your handler with the original params unchanged.
Customizing the blocked response
The blocked response usesstructuredContent.summary as the summary key. If
your tool’s outputSchema uses a different key, you’ll either:
- match the wrapper’s expectation (call your output field
summary), or - fork the wrapper for that tool.
Performance
The wrapper adds one round-trip toapi.sedata-ai.tech per call. Typical
latency: tens of milliseconds. The wrapper records this latency on the span
as mcp.safety_check.latency_ms so you can monitor it.
If the safety API is unreachable, the wrapper fails open — your handler
runs and the span attribute mcp.safety_check.success is false. Set up an
alert on mcp.safety_check.success = false rate to catch outages.
See also
Safety checks concept
Detailed flow and failure modes.
safetyCheck reference
Full function signature.