()
| 64 | ) |
| 65 | |
| 66 | func getCompiledToolSchemas() (map[string]toolSchemaEntry, error) { |
| 67 | compiledToolSchemasOnce.Do(func() { |
| 68 | var tools []struct { |
| 69 | Name string `json:"name"` |
| 70 | InputSchema json.RawMessage `json:"inputSchema"` |
| 71 | } |
| 72 | if err := json.Unmarshal([]byte(safeOutputsToolsJSONContent), &tools); err != nil { |
| 73 | compiledToolSchemasErr = fmt.Errorf("failed to parse safe_outputs_tools.json for samples validation: %w", err) |
| 74 | return |
| 75 | } |
| 76 | out := make(map[string]toolSchemaEntry, len(tools)) |
| 77 | for _, t := range tools { |
| 78 | if len(t.InputSchema) == 0 { |
| 79 | continue |
| 80 | } |
| 81 | schemaURL := fmt.Sprintf("inmem://safe-outputs-tools/%s.json", t.Name) |
| 82 | schema, err := compileSchema(string(t.InputSchema), schemaURL) |
| 83 | if err != nil { |
| 84 | compiledToolSchemasErr = fmt.Errorf("failed to compile inputSchema for tool %q: %w", t.Name, err) |
| 85 | return |
| 86 | } |
| 87 | var rawMap map[string]any |
| 88 | if err := json.Unmarshal(t.InputSchema, &rawMap); err != nil { |
| 89 | compiledToolSchemasErr = fmt.Errorf("failed to parse inputSchema for tool %q: %w", t.Name, err) |
| 90 | return |
| 91 | } |
| 92 | out[t.Name] = toolSchemaEntry{raw: rawMap, compiled: schema} |
| 93 | } |
| 94 | samplesValidationLog.Printf("Compiled %d safe-outputs tool schemas for sample validation", len(out)) |
| 95 | compiledToolSchemas = out |
| 96 | }) |
| 97 | return compiledToolSchemas, compiledToolSchemasErr |
| 98 | } |
| 99 | |
| 100 | // validateSafeOutputsSamples validates every `samples` entry on every |
| 101 | // enabled safe-output handler against the corresponding MCP tool's inputSchema. |
no test coverage detected