soma_gateway/
dispatch_helpers.rs1use serde_json::{json, Value};
2
3pub const GATEWAY_ERROR_SCHEMA_VERSION: &str = "mcp.gateway.error.v1";
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct GatewayStructuredError {
7 pub code: &'static str,
8 pub kind: &'static str,
9 pub tool: &'static str,
10 pub action: String,
11 pub remediation: &'static str,
12}
13
14impl GatewayStructuredError {
15 #[must_use]
16 pub fn to_json(&self) -> Value {
17 json!({
18 "isError": true,
19 "schema_version": GATEWAY_ERROR_SCHEMA_VERSION,
20 "code": self.code,
21 "kind": self.kind,
22 "tool": self.tool,
23 "action": self.action,
24 "remediation": self.remediation,
25 })
26 }
27}
28
29pub fn structured_error(
30 action: impl Into<String>,
31 code: &'static str,
32 kind: &'static str,
33 remediation: &'static str,
34) -> GatewayStructuredError {
35 GatewayStructuredError {
36 code,
37 kind,
38 tool: "gateway",
39 action: action.into(),
40 remediation,
41 }
42}
43
44#[cfg(test)]
45#[path = "dispatch_helpers_tests.rs"]
46mod tests;