systemprompt_identifiers/
mcp.rs1use crate::error::IdValidationError;
4use crate::{DbValue, ToDbValue};
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7use std::fmt;
8
9#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
10#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
11#[cfg_attr(feature = "sqlx", sqlx(transparent))]
12#[serde(transparent)]
13pub struct AiToolCallId(String);
14
15impl AiToolCallId {
16 pub fn new(id: impl Into<String>) -> Self {
17 Self(id.into())
18 }
19
20 pub fn as_str(&self) -> &str {
21 &self.0
22 }
23}
24
25impl fmt::Display for AiToolCallId {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 write!(f, "{}", self.0)
28 }
29}
30
31impl From<String> for AiToolCallId {
32 fn from(s: String) -> Self {
33 Self(s)
34 }
35}
36
37impl From<&str> for AiToolCallId {
38 fn from(s: &str) -> Self {
39 Self(s.to_string())
40 }
41}
42
43impl AsRef<str> for AiToolCallId {
44 fn as_ref(&self) -> &str {
45 &self.0
46 }
47}
48
49impl ToDbValue for AiToolCallId {
50 fn to_db_value(&self) -> DbValue {
51 DbValue::String(self.0.clone())
52 }
53}
54
55impl ToDbValue for &AiToolCallId {
56 fn to_db_value(&self) -> DbValue {
57 DbValue::String(self.0.clone())
58 }
59}
60
61#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
62#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
63#[cfg_attr(feature = "sqlx", sqlx(transparent))]
64#[serde(transparent)]
65pub struct McpExecutionId(String);
66
67impl McpExecutionId {
68 pub fn new(id: impl Into<String>) -> Self {
69 Self(id.into())
70 }
71
72 pub fn generate() -> Self {
73 Self(uuid::Uuid::new_v4().to_string())
74 }
75
76 pub fn as_str(&self) -> &str {
77 &self.0
78 }
79}
80
81impl fmt::Display for McpExecutionId {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83 write!(f, "{}", self.0)
84 }
85}
86
87impl From<String> for McpExecutionId {
88 fn from(s: String) -> Self {
89 Self(s)
90 }
91}
92
93impl From<&str> for McpExecutionId {
94 fn from(s: &str) -> Self {
95 Self(s.to_string())
96 }
97}
98
99impl AsRef<str> for McpExecutionId {
100 fn as_ref(&self) -> &str {
101 &self.0
102 }
103}
104
105impl ToDbValue for McpExecutionId {
106 fn to_db_value(&self) -> DbValue {
107 DbValue::String(self.0.clone())
108 }
109}
110
111impl ToDbValue for &McpExecutionId {
112 fn to_db_value(&self) -> DbValue {
113 DbValue::String(self.0.clone())
114 }
115}
116
117#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
118#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
119#[cfg_attr(feature = "sqlx", sqlx(transparent))]
120#[serde(transparent)]
121pub struct McpServerId(String);
122
123impl McpServerId {
124 pub fn try_new(id: impl Into<String>) -> Result<Self, IdValidationError> {
125 let id = id.into();
126 if id.is_empty() {
127 return Err(IdValidationError::empty("McpServerId"));
128 }
129 Ok(Self(id))
130 }
131
132 #[allow(clippy::expect_used)]
133 pub fn new(id: impl Into<String>) -> Self {
134 Self::try_new(id).expect("MCP server ID cannot be empty")
135 }
136
137 pub fn from_env() -> Result<Self, IdValidationError> {
138 let id = std::env::var("MCP_SERVICE_ID").map_err(|_| {
139 IdValidationError::invalid("McpServerId", "MCP_SERVICE_ID environment variable not set")
140 })?;
141 Self::try_new(id)
142 }
143
144 pub fn as_str(&self) -> &str {
145 &self.0
146 }
147}
148
149impl fmt::Display for McpServerId {
150 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151 write!(f, "{}", self.0)
152 }
153}
154
155impl TryFrom<String> for McpServerId {
156 type Error = IdValidationError;
157
158 fn try_from(s: String) -> Result<Self, Self::Error> {
159 Self::try_new(s)
160 }
161}
162
163impl TryFrom<&str> for McpServerId {
164 type Error = IdValidationError;
165
166 fn try_from(s: &str) -> Result<Self, Self::Error> {
167 Self::try_new(s)
168 }
169}
170
171impl std::str::FromStr for McpServerId {
172 type Err = IdValidationError;
173
174 fn from_str(s: &str) -> Result<Self, Self::Err> {
175 Self::try_new(s)
176 }
177}
178
179impl AsRef<str> for McpServerId {
180 fn as_ref(&self) -> &str {
181 &self.0
182 }
183}
184
185impl ToDbValue for McpServerId {
186 fn to_db_value(&self) -> DbValue {
187 DbValue::String(self.0.clone())
188 }
189}
190
191impl ToDbValue for &McpServerId {
192 fn to_db_value(&self) -> DbValue {
193 DbValue::String(self.0.clone())
194 }
195}