techne_mcp/server/
content.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub enum Content<T = serde_json::Value> {
5 #[serde(rename = "content")]
6 Unstructured(Vec<Unstructured>),
7 #[serde(rename = "structuredContent")]
8 Structured(T),
9}
10
11impl<T> From<Unstructured> for Content<T> {
12 fn from(content: Unstructured) -> Self {
13 Content::Unstructured(vec![content])
14 }
15}
16
17impl<T> From<String> for Content<T> {
18 fn from(text: String) -> Self {
19 Content::Unstructured(vec![Unstructured::Text { text }])
20 }
21}
22
23impl<T> From<u32> for Content<T> {
24 fn from(number: u32) -> Self {
25 Content::Unstructured(vec![Unstructured::Text {
26 text: number.to_string(),
27 }])
28 }
29}
30
31impl From<serde_json::Value> for Content {
32 fn from(json: serde_json::Value) -> Self {
33 Content::Structured(json)
34 }
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(tag = "type", rename_all = "camelCase")]
39pub enum Unstructured {
40 Text {
41 text: String,
42 },
43 Image {
44 data: Base64,
45 mime_type: String,
46 },
47 Audio {
48 data: Base64,
49 mime_type: String,
50 },
51 ResourceLink {
52 uri: String,
53 name: String,
54 description: String,
55 mime_type: String,
56 },
57 Resource {
58 uri: String,
59 title: String,
60 mime_type: String,
61 text: String,
62 },
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct Base64(String);