elicit_egui 0.11.1

Elicitation-enabled egui widget tools — dual-mode MCP tools with code emission
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
//! Dual-mode container creation tools.
//!
//! Each tool returns a [`ContainerJson`] variant describing a layout container.

use elicitation::elicit_tool;
use rmcp::ErrorData;
use rmcp::model::{CallToolResult, Content};
use schemars::JsonSchema;
use serde::Deserialize;
use tracing::instrument;

use crate::serde_types::{
    ColorJson, ContainerJson, CornerRadiusJson, MarginJson, StrokeJson, Vec2Json,
};

// ---------------------------------------------------------------------------
// Helper
// ---------------------------------------------------------------------------

fn container_result(container: &ContainerJson) -> CallToolResult {
    match serde_json::to_string(container) {
        Ok(s) => CallToolResult::success(vec![Content::text(s)]),
        Err(e) => CallToolResult::error(vec![Content::text(format!("serialize error: {e}"))]),
    }
}

/// Empty params for tools that take no arguments.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct EmptyContainerParams {}

// ---------------------------------------------------------------------------
// Window
// ---------------------------------------------------------------------------

/// Parameters for `container_window`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct WindowParams {
    /// Window title.
    pub title: String,
    /// Initial position (x, y).
    pub default_pos: Option<Vec2Json>,
    /// Initial size (width, height).
    pub default_size: Option<Vec2Json>,
    /// Whether the window is resizable.
    #[serde(default = "default_true")]
    pub resizable: bool,
    /// Whether the window is collapsible.
    #[serde(default = "default_true")]
    pub collapsible: bool,
    /// Whether to enable scrolling.
    #[serde(default)]
    pub scroll: bool,
    /// Whether to show the title bar.
    #[serde(default = "default_true")]
    pub title_bar: bool,
}

fn default_true() -> bool {
    true
}

/// Create a floating window container.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_window",
    description = "Create a floating window. Returns ContainerJson::Window."
)]
#[instrument(skip_all)]
async fn container_window(p: WindowParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::Window {
        title: p.title,
        default_pos: p.default_pos,
        default_size: p.default_size,
        resizable: p.resizable,
        collapsible: p.collapsible,
        scroll: p.scroll,
        title_bar: p.title_bar,
    };
    Ok(container_result(&c))
}

// ---------------------------------------------------------------------------
// Panels
// ---------------------------------------------------------------------------

/// Parameters for `container_left_panel`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct LeftPanelParams {
    /// Panel identifier.
    pub id: String,
    /// Default panel width.
    pub default_width: Option<f32>,
    /// Whether the panel is resizable.
    #[serde(default = "default_true")]
    pub resizable: bool,
    /// Minimum panel width.
    pub min_width: Option<f32>,
    /// Maximum panel width.
    pub max_width: Option<f32>,
}

/// Create a left side panel.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_left_panel",
    description = "Create a left side panel. Returns ContainerJson::LeftPanel."
)]
#[instrument(skip_all)]
async fn container_left_panel(p: LeftPanelParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::LeftPanel {
        id: p.id,
        default_width: p.default_width,
        resizable: p.resizable,
        min_width: p.min_width,
        max_width: p.max_width,
    };
    Ok(container_result(&c))
}

/// Parameters for `container_right_panel`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct RightPanelParams {
    /// Panel identifier.
    pub id: String,
    /// Default panel width.
    pub default_width: Option<f32>,
    /// Whether the panel is resizable.
    #[serde(default = "default_true")]
    pub resizable: bool,
}

/// Create a right side panel.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_right_panel",
    description = "Create a right side panel. Returns ContainerJson::RightPanel."
)]
#[instrument(skip_all)]
async fn container_right_panel(p: RightPanelParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::RightPanel {
        id: p.id,
        default_width: p.default_width,
        resizable: p.resizable,
    };
    Ok(container_result(&c))
}

/// Parameters for `container_top_panel`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct TopPanelParams {
    /// Panel identifier.
    pub id: String,
    /// Default panel height.
    pub default_height: Option<f32>,
    /// Whether the panel is resizable.
    #[serde(default)]
    pub resizable: bool,
}

/// Create a top panel.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_top_panel",
    description = "Create a top panel. Returns ContainerJson::TopPanel."
)]
#[instrument(skip_all)]
async fn container_top_panel(p: TopPanelParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::TopPanel {
        id: p.id,
        default_height: p.default_height,
        resizable: p.resizable,
    };
    Ok(container_result(&c))
}

/// Parameters for `container_bottom_panel`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct BottomPanelParams {
    /// Panel identifier.
    pub id: String,
    /// Default panel height.
    pub default_height: Option<f32>,
    /// Whether the panel is resizable.
    #[serde(default)]
    pub resizable: bool,
}

/// Create a bottom panel.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_bottom_panel",
    description = "Create a bottom panel. Returns ContainerJson::BottomPanel."
)]
#[instrument(skip_all)]
async fn container_bottom_panel(p: BottomPanelParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::BottomPanel {
        id: p.id,
        default_height: p.default_height,
        resizable: p.resizable,
    };
    Ok(container_result(&c))
}

/// Create a central panel (fills remaining space).
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_central_panel",
    description = "Create a central panel that fills remaining space. Returns ContainerJson::CentralPanel."
)]
#[instrument(skip_all)]
async fn container_central_panel(p: EmptyContainerParams) -> Result<CallToolResult, ErrorData> {
    let _ = p;
    Ok(container_result(&ContainerJson::CentralPanel))
}

// ---------------------------------------------------------------------------
// Scroll area
// ---------------------------------------------------------------------------

/// Parameters for `container_scroll_area`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ScrollAreaParams {
    /// Enable vertical scrolling.
    #[serde(default = "default_true")]
    pub vertical: bool,
    /// Enable horizontal scrolling.
    #[serde(default)]
    pub horizontal: bool,
    /// Maximum height before scrolling.
    pub max_height: Option<f32>,
    /// Maximum width before scrolling.
    pub max_width: Option<f32>,
    /// Whether to auto-shrink to content.
    #[serde(default)]
    pub auto_shrink: bool,
    /// Whether to always show scroll bars.
    #[serde(default)]
    pub always_show_scroll: bool,
}

/// Create a scrollable region.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_scroll_area",
    description = "Create a scrollable region. Returns ContainerJson::ScrollArea."
)]
#[instrument(skip_all)]
async fn container_scroll_area(p: ScrollAreaParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::ScrollArea {
        vertical: p.vertical,
        horizontal: p.horizontal,
        max_height: p.max_height,
        max_width: p.max_width,
        auto_shrink: p.auto_shrink,
        always_show_scroll: p.always_show_scroll,
    };
    Ok(container_result(&c))
}

// ---------------------------------------------------------------------------
// Collapsing, group, frame
// ---------------------------------------------------------------------------

/// Parameters for `container_collapsing`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct CollapsingParams {
    /// Header text.
    pub text: String,
    /// Whether the section starts open.
    #[serde(default)]
    pub default_open: bool,
}

/// Create a collapsible section.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_collapsing",
    description = "Create a collapsible section with header. Returns ContainerJson::CollapsingHeader."
)]
#[instrument(skip_all)]
async fn container_collapsing(p: CollapsingParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::CollapsingHeader {
        text: p.text,
        default_open: p.default_open,
    };
    Ok(container_result(&c))
}

/// Create a visual grouping (box around content).
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_group",
    description = "Create a visual grouping box around content. Returns ContainerJson::Group.",
    emit = None
)]
#[instrument(skip_all)]
async fn container_group(p: EmptyContainerParams) -> Result<CallToolResult, ErrorData> {
    let _ = p;
    Ok(container_result(&ContainerJson::Group))
}

/// Parameters for `container_frame`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct FrameParams {
    /// Optional fill colour.
    pub fill: Option<ColorJson>,
    /// Optional border stroke.
    pub stroke: Option<StrokeJson>,
    /// Optional corner rounding.
    pub corner_radius: Option<CornerRadiusJson>,
    /// Optional inner margin.
    pub inner_margin: Option<MarginJson>,
    /// Optional outer margin.
    pub outer_margin: Option<MarginJson>,
}

/// Create a framed region with custom styling.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_frame",
    description = "Create a framed region with fill, stroke, and margins. Returns ContainerJson::Frame."
)]
#[instrument(skip_all)]
async fn container_frame(p: FrameParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::Frame {
        fill: p.fill,
        stroke: p.stroke,
        corner_radius: p.corner_radius,
        inner_margin: p.inner_margin,
        outer_margin: p.outer_margin,
    };
    Ok(container_result(&c))
}

// ---------------------------------------------------------------------------
// Menu & tooltip
// ---------------------------------------------------------------------------

/// Create a menu bar container.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_menu_bar",
    description = "Create a menu bar. Returns ContainerJson::MenuBar.",
    emit = None
)]
#[instrument(skip_all)]
async fn container_menu_bar(p: EmptyContainerParams) -> Result<CallToolResult, ErrorData> {
    let _ = p;
    Ok(container_result(&ContainerJson::MenuBar))
}

/// Parameters for `container_menu`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct MenuParams {
    /// Menu title.
    pub title: String,
}

/// Create a menu within a menu bar.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_menu",
    description = "Create a menu within a menu bar. Returns ContainerJson::Menu."
)]
#[instrument(skip_all)]
async fn container_menu(p: MenuParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::Menu { title: p.title };
    Ok(container_result(&c))
}

/// Parameters for `container_tooltip`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct TooltipParams {
    /// Tooltip text.
    pub text: String,
}

/// Create a tooltip container.
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_tooltip",
    description = "Create a tooltip. Returns ContainerJson::Tooltip."
)]
#[instrument(skip_all)]
async fn container_tooltip(p: TooltipParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::Tooltip { text: p.text };
    Ok(container_result(&c))
}

/// Parameters for `container_popup`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct PopupParams {
    /// Popup identifier.
    pub id: String,
}

/// Create a popup area (context menu, dropdown).
#[elicit_tool(
    plugin = "egui_containers",
    name = "container_popup",
    description = "Create a popup area. Returns ContainerJson::Popup."
)]
#[instrument(skip_all)]
async fn container_popup(p: PopupParams) -> Result<CallToolResult, ErrorData> {
    let c = ContainerJson::Popup { id: p.id };
    Ok(container_result(&c))
}