excel_mcp_server/types/
responses.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize)]
5#[serde(rename_all = "snake_case")]
6pub enum Status {
7 Success,
8 Error,
9}
10
11#[derive(Debug, Serialize)]
13pub struct ToolResponse<T: Serialize> {
14 pub status: Status,
15 pub message: String,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub data: Option<T>,
18}
19
20#[derive(Debug, Serialize)]
22pub struct ErrorData {
23 pub category: ErrorCategory,
24 pub description: String,
25 pub suggestion: String,
26}
27
28#[derive(Debug, Serialize)]
30#[serde(rename_all = "snake_case")]
31pub enum ErrorCategory {
32 NotFound,
33 InvalidInput,
34 EngineUnsupported,
35 CapacityExceeded,
36 IoError,
37 ParseError,
38 Evicted,
39}
40
41pub fn success<T: Serialize>(message: &str, data: T) -> String {
43 serde_json::to_string(&ToolResponse {
44 status: Status::Success,
45 message: message.to_string(),
46 data: Some(data),
47 })
48 .expect("serialization of ToolResponse should never fail")
49}
50
51pub fn success_no_data(message: &str) -> String {
53 serde_json::to_string(&ToolResponse::<()> {
54 status: Status::Success,
55 message: message.to_string(),
56 data: None,
57 })
58 .expect("serialization of ToolResponse should never fail")
59}
60
61pub fn error(category: ErrorCategory, description: &str, suggestion: &str) -> String {
63 serde_json::to_string(&ToolResponse {
64 status: Status::Error,
65 message: description.to_string(),
66 data: Some(ErrorData {
67 category,
68 description: description.to_string(),
69 suggestion: suggestion.to_string(),
70 }),
71 })
72 .expect("serialization of ToolResponse should never fail")
73}
74
75#[derive(Debug, Serialize)]
77pub struct WorkbookInfo {
78 pub workbook_id: String,
79 pub engine: String,
80 pub sheets: Vec<SheetSummary>,
81}
82
83#[derive(Debug, Serialize)]
85pub struct SheetSummary {
86 pub name: String,
87 pub dimensions: Option<String>,
88 pub row_count: Option<u32>,
89 pub col_count: Option<u16>,
90}
91
92#[derive(Debug, Serialize)]
94pub struct ReadSheetData {
95 pub rows: Vec<Vec<serde_json::Value>>,
96 pub total_rows: u32,
97 pub page_rows: u32,
98 pub continuation_token: Option<String>,
99}
100
101#[derive(Debug, Serialize)]
103pub struct CellData {
104 pub cell: String,
105 pub value: serde_json::Value,
106 pub value_type: String,
107 pub formula: Option<String>,
108}
109
110#[derive(Debug, Serialize)]
112pub struct WriteResult {
113 pub cells_written: usize,
114 pub range_covered: String,
115}
116
117#[derive(Debug, Serialize)]
119pub struct SearchResult {
120 pub matches: Vec<SearchMatch>,
121 pub total_matches: usize,
122 pub truncated: bool,
123}
124
125#[derive(Debug, Serialize)]
127pub struct SearchMatch {
128 pub sheet: String,
129 pub cell: String,
130 pub value: serde_json::Value,
131}
132
133#[derive(Debug, Serialize)]
135pub struct WorkbookDescription {
136 pub workbook_id: String,
137 pub engine: String,
138 pub sheets: Vec<SheetDescription>,
139}
140
141#[derive(Debug, Serialize)]
143pub struct SheetDescription {
144 pub name: String,
145 pub dimensions: Option<String>,
146 pub row_count: Option<u32>,
147 pub col_count: Option<u16>,
148 pub sample_rows: Vec<Vec<serde_json::Value>>,
149}
150
151#[derive(Debug, Serialize)]
153pub struct CsvExportData {
154 pub csv: String,
155 pub total_rows: u32,
156 pub truncated: bool,
157}
158
159#[derive(Debug, Serialize, Deserialize)]
161pub struct ContinuationToken {
162 pub sheet: String,
163 pub offset: u32,
164 pub range: Option<String>,
165}