elicitation 0.10.0

Conversational elicitation of strongly-typed Rust values via MCP
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
//! Conversational elicitation of strongly-typed Rust values via MCP.
//!
//! The `elicitation` library provides a trait-based system for eliciting
//! strongly-typed values from users through conversational interaction via
//! the Model Context Protocol (MCP). It transforms LLM conversations into
//! type-safe Rust values with compile-time guarantees.
//!
//! # MCP Setup Required
//!
//! This library runs as an **MCP server** and requires an **MCP client**
//! (like Claude Desktop or Claude CLI) to provide the elicitation tools.
//! Your application won't work standalone - it must be invoked by an MCP client.
//!
//! See the [README](https://github.com/crumplecup/elicitation) for setup instructions.
//!
//! # Core Concepts
//!
//! ## Traits
//!
//! - [`Prompt`] - Provides prompt metadata for a type
//! - [`Elicit`] - Main trait for eliciting values
//!
//! ## Interaction Paradigms
//!
//! - [`Select`] - Choose from finite options (enum pattern)
//! - [`Affirm`] - Yes/no confirmation (bool pattern)
//! - [`Survey`] - Multi-field elicitation (struct pattern)
//! - [`Authorize`] - Permission policies (planned for v0.2.0)
//!
//! # Example
//!
//! ```rust,ignore
//! use elicitation::{Elicitation, ElicitResult};
//! use rmcp::service::{Peer, RoleClient};
//!
//! async fn example(client: &Peer<RoleClient>) -> ElicitResult<()> {
//!     // Elicit a simple integer
//!     let age: i32 = i32::elicit(communicator).await?;
//!
//!     // Elicit an optional value
//!     let nickname: Option<String> = Option::<String>::elicit(communicator).await?;
//!
//!     // Elicit a collection
//!     let scores: Vec<i32> = Vec::<i32>::elicit(communicator).await?;
//!     Ok(())
//! }
//! ```
//!
//! # Derive Macros
//!
//! The library provides derive macros for automatic implementation:
//!
//! ```rust,ignore
//! use elicitation::Elicit;
//!
//! // Enums automatically use the Select paradigm
//! #[derive(Elicit)]
//! enum Color {
//!     Red,
//!     Green,
//!     Blue,
//! }
//!
//! // Structs automatically use the Survey paradigm
//! #[derive(Elicit)]
//! struct Person {
//!     #[prompt("What is your name?")]
//!     name: String,
//!     #[prompt("What is your age?")]
//!     age: u8,
//! }
//! ```
//!
//! # MCP Integration
//!
//! The library uses the [rmcp](https://crates.io/crates/rmcp) crate - the
//! official Rust MCP SDK - for MCP client integration. All elicitation
//! happens through asynchronous MCP tool calls.

#![forbid(unsafe_code)]
#![warn(missing_docs)]
// Allow ::elicitation::... paths in proc-macro generated code inside this crate.
extern crate self as elicitation;

mod client;
mod communicator;
mod mcp_wrapper; // Generic wrapper for MCP tool outputs
mod server; // Server-side wrapper (analogous to ElicitClient)
// Unified trait for client/server communication

// Verification framework imports

mod collections;
mod complete;
mod containers;
mod default_style;
mod error;
pub mod type_spec;
pub mod verification;

pub mod type_graph;

#[cfg(feature = "prompt-tree")]
pub mod prompt_tree;
#[cfg(feature = "prompt-tree")]
pub use prompt_tree::{
    AssembledPrompt, ElicitPromptTree, PromptKind, PromptTree, collect_assembled_prompts,
};

#[cfg(feature = "cli")]
pub mod cli;

pub mod contracts;

pub mod emit_code;
pub mod mcp;
mod paradigm;
mod primitives;
mod proxy;
pub mod style;
pub mod tool;
mod tool_registry;
mod verified_workflow;

// Router macro module (declarative macro)
#[macro_use]
mod router_macro;

// Newtype wrapper macro module (declarative macros)
#[macro_use]
mod newtype_macro;

// Newtype methods macro module (declarative macros with method delegation)
#[macro_use]
mod newtype_methods_macro;

// Select trenchcoat macro: wraps foreign Select enums with JsonSchema + serde
#[macro_use]
mod select_trenchcoat_macro;

mod traits;

mod elicit_json;
pub use elicit_json::ElicitJson;
pub mod plugin;
mod plugin_registry;
pub use plugin::{
    DescriptorPlugin, ElicitPlugin, NoContext, PluginContext, PluginToolRegistration,
    StatefulPlugin, ToolDescriptor, make_descriptor, make_descriptor_ctx,
};
pub use plugin_registry::{PluginRegistry, Toolchain};

pub mod dynamic;
pub use dynamic::{
    AnyToolFactory, AnyToolSlot, DynamicToolDescriptor, DynamicToolRegistry,
    ToolFactoryRegistration, TypedSlot,
};

#[cfg(feature = "serde_json")]
mod value_impl;

#[cfg(any(feature = "chrono", feature = "time", feature = "jiff"))]
mod datetime_common;

#[cfg(feature = "chrono")]
pub mod datetime_chrono;

#[cfg(feature = "time")]
pub mod datetime_time;

#[cfg(feature = "jiff")]
pub mod datetime_jiff;

#[cfg(feature = "rand")]
pub mod rand_rng;

mod elicitation_style;

// Error types
pub use error::{ElicitError, ElicitErrorKind, ElicitResult, JsonError, RmcpError, ServiceError};
pub use verification::types::ValidationError;

// Core client and server
pub use client::ElicitClient;
pub use communicator::{ElicitCommunicator, ElicitationContext, StyleContext};
pub use mcp_wrapper::ElicitToolOutput;
pub use server::ElicitServer;

// Core traits
pub use elicitation_style::StyleMarker;
pub use traits::{
    ElicitBuilder, ElicitIntrospect, Elicitation, ElicitationPattern, Generator, PatternDetails,
    Prompt, TypeMetadata, VariantMetadata,
};

// Type graph visualization — registry always available; builder/renderers gated on `graph`
#[cfg(feature = "graph")]
pub use type_graph::{
    DotRenderer, GraphEdge, GraphNode, GraphRenderer, MermaidDirection, MermaidRenderer, NodeKind,
    TypeGraph, TypeGraphError, TypeGraphPlugin,
};
pub use type_graph::{TypeGraphKey, all_graphable_types, lookup_type_graph};

// Type spec layer (agent-browsable contracts)
pub use type_spec::{
    ElicitSpec, SpecCategory, SpecCategoryBuilder, SpecEntry, SpecEntryBuilder, TypeSpec,
    TypeSpecBuilder, TypeSpecInventoryKey, lookup_type_spec, lookup_type_spec_by_id,
    type_spec_plugin::TypeSpecPlugin,
};

// Contracts (proof-carrying composition)
pub use contracts::{
    And, Established, Implies, InVariant, Is, Prop, Refines, both, downcast, fst, snd,
};

// Completion marker — enforces all elicitation obligations at compile time
pub use complete::ElicitComplete;

// Workflow verification marker — enforces all proposition obligations
pub use verified_workflow::VerifiedWorkflow;

// Tools (contract-based MCP tools)
pub use tool::{Tool, True, both_tools, then};

// Tool registry (automatic discovery)
pub use tool_registry::{ElicitToolDescriptor, collect_all_elicit_tools};

// Interaction paradigm traits
pub use paradigm::{Affirm, Authorize, FieldInfo, Filter, Select, Survey};
pub use proxy::ElicitProxy;

// Dynamic collections
pub use collections::ChoiceSet;

// Re-export rmcp for user convenience
pub use rmcp;

// Re-export futures for derive macro (BoxFuture in ElicitPlugin blanket impls)
#[doc(hidden)]
pub use futures;

// Re-export serde_json for derive macro (needed in elicit_checked)
#[doc(hidden)]
pub use serde_json;

// Re-export paste for macro usage
#[doc(hidden)]
pub use paste;

// Re-export inventory for derive macro usage
#[doc(hidden)]
pub use inventory;

// Re-export async_trait for derive macro and trait impls
#[doc(hidden)]
pub use async_trait;

// Re-export proc_macro2 so generated code can use elicitation::proc_macro2
// instead of requiring proc_macro2 as a direct dep of downstream crates.
#[doc(hidden)]
pub use proc_macro2;
#[doc(hidden)]
pub use quote;

// Re-export derive macros with user-friendly names
pub use elicitation_derive::{Elicit, ElicitPlugin, elicit_tool};
// Prop derive macro (trait lives at elicitation::contracts::Prop; both can coexist)
pub use elicitation_derive::Prop;
// ToCodeLiteral derive (trait lives at elicitation::emit_code::ToCodeLiteral)
pub use elicitation_derive::ToCodeLiteral;

// Re-export verification contract types at crate level (for kani_proofs imports)
// EXPLICIT exports - no globs (helps compiler show what's missing)
pub use verification::Contract;

pub use verification::types::{
    ArcNonNull,
    ArcSatisfies,
    ArrayAllSatisfy,
    BTreeMapNonEmpty,
    BTreeSetNonEmpty,
    BoolFalse,
    // Bools
    BoolTrue,
    BoxNonNull,
    BoxSatisfies,
    // Chars
    CharAlphabetic,
    CharAlphanumeric,
    CharNumeric,
    DurationNonZero,
    // Durations
    DurationPositive,
    F32Finite,
    F32NonNegative,
    // Floats
    F32Positive,
    F64Finite,
    F64NonNegative,
    F64Positive,
    HashMapNonEmpty,
    HashSetNonEmpty,
    I8NonNegative,
    I8NonZero,
    I8NonZeroStyle,
    // Integers - i8 family
    I8Positive,
    I8Range,
    I8RangeStyle,
    I16NonNegative,
    I16NonZero,
    I16NonZeroStyle,
    // i16 family
    I16Positive,
    I16Range,
    I16RangeStyle,
    I32NonNegative,
    I32NonZero,
    // i32 family
    I32Positive,
    I32Range,
    I32RangeStyle,
    I64NonNegative,
    I64NonZero,
    // i64 family
    I64Positive,
    I64Range,
    I64RangeStyle,
    I128NonNegative,
    I128NonZero,
    // i128 family
    I128Positive,
    I128Range,
    I128RangeStyle,
    // Networks
    IpPrivate,
    IpPublic,
    IpV4,
    IpV6,
    Ipv4Loopback,
    Ipv6Loopback,
    IsizeNonNegative,
    IsizeNonZero,
    // isize family
    IsizePositive,
    IsizeRange,
    IsizeRangeStyle,
    LinkedListNonEmpty,
    OptionSome,
    // Paths
    PathBufExists,
    PathBufIsDir,
    PathBufIsFile,
    PathBufReadable,
    RcNonNull,
    RcSatisfies,
    ResultOk,
    // Strings
    StringNonEmpty,
    // Tuples
    Tuple2,
    Tuple3,
    Tuple4,
    U8NonZero,
    // u8 family
    U8Positive,
    U8Range,
    U8RangeStyle,
    U16NonZero,
    // u16 family
    U16Positive,
    U16Range,
    U16RangeStyle,
    U32NonZero,
    // u32 family
    U32Positive,
    U32Range,
    U32RangeStyle,
    U64NonZero,
    // u64 family
    U64Positive,
    U64Range,
    U64RangeStyle,
    U128NonZero,
    // u128 family
    U128Positive,
    U128Range,
    U128RangeStyle,
    UsizeNonZero,
    // usize family
    UsizePositive,
    UsizeRange,
    UsizeRangeStyle,
    VecAllSatisfy,
    VecDequeNonEmpty,
    // Collections
    VecNonEmpty,
};

// UUIDs (feature-gated on uuid)
#[cfg(feature = "uuid")]
pub use verification::types::{UuidNonNil, UuidV4};

#[cfg(feature = "uuid")]
pub use primitives::uuid::{UuidGenerationMode, UuidGenerator};

// SystemTime (standard library)
pub use primitives::systemtime::{SystemTimeGenerationMode, SystemTimeGenerator};

// Duration (standard library)
pub use primitives::duration::{DurationGenerationMode, DurationGenerator};

// String style variants
pub use primitives::StringStyle;

// Unit structs (standard library)
pub use primitives::unit_structs::{Formatter, Parser, Validator};

// Error generators (for testing)
pub use primitives::errors::{IoErrorGenerationMode, IoErrorGenerator};

#[cfg(feature = "serde_json")]
pub use primitives::errors::{JsonErrorGenerationMode, JsonErrorGenerator};

// DateTime generators (feature-gated)
#[cfg(feature = "chrono")]
pub use datetime_chrono::{
    DateTimeUtcGenerationMode, DateTimeUtcGenerator, NaiveDateTimeGenerationMode,
    NaiveDateTimeGenerator,
};

#[cfg(feature = "time")]
pub use datetime_time::{
    InstantGenerationMode, InstantGenerator, OffsetDateTimeGenerationMode, OffsetDateTimeGenerator,
};

#[cfg(feature = "jiff")]
pub use datetime_jiff::{TimestampGenerationMode, TimestampGenerator};

// DateTimes (feature-gated on chrono/time/jiff)
#[cfg(feature = "chrono")]
pub use verification::types::{DateTimeUtcAfter, DateTimeUtcBefore, NaiveDateTimeAfter};

#[cfg(feature = "time")]
pub use verification::types::{OffsetDateTimeAfter, OffsetDateTimeBefore};

#[cfg(feature = "jiff")]
pub use verification::types::{TimestampAfter, TimestampBefore};

// Values (JSON - feature-gated)
#[cfg(feature = "serde_json")]
pub use verification::types::{ValueArray, ValueNonNull, ValueObject};

// URLs (feature-gated)
#[cfg(feature = "url")]
pub use verification::types::{UrlCanBeBase, UrlHttp, UrlHttps, UrlValid, UrlWithHost};

// Regexes (feature-gated)
#[cfg(feature = "regex")]
pub use verification::types::{
    RegexCaseInsensitive, RegexMultiline, RegexSetNonEmpty, RegexSetValid, RegexValid,
};

// Mechanisms
pub use verification::mechanisms::{
    AffirmReturnsBoolean, InputNonEmpty, MechanismWithType, NumericReturnsValid,
    SurveyReturnsValidVariant, TextReturnsNonEmpty, TextReturnsString,
};

// Reqwest HTTP types (feature-gated)
#[cfg(feature = "reqwest")]
pub use primitives::http::{
    ClientStyle, HeaderMapStyle, MethodStyle, RequestBuilderStyle, ResponseStyle, StatusCodeStyle,
    VersionStyle,
};

#[cfg(feature = "reqwest")]
pub use verification::types::StatusCodeValid;

// clap types (feature-gated on clap-types)
#[cfg(feature = "clap-types")]
pub use primitives::clap_types::{
    ArgActionStyle, ArgGroupStyle, ArgStyle, ColorChoiceStyle, CommandStyle, ErrorKindStyle,
    IdStyle, PossibleValueStyle, ValueHintStyle, ValueRangeStyle, ValueSourceStyle,
};

// sqlx types (feature-gated on sqlx-types)
#[cfg(feature = "sqlx-types")]
pub use primitives::sqlx_types::{
    AnyQueryResultStyle, AnyTypeInfoStyle, ColumnDescriptorStyle, ColumnEntryStyle, RowDataStyle,
};
#[cfg(feature = "sqlx-types")]
pub use primitives::sqlx_types::{
    AnyTypeInfoKindStyle, ColumnValueStyle, DriverKindStyle, SqlTypeKindStyle, SqlxErrorKindStyle,
};
#[cfg(feature = "sqlx-types")]
pub use primitives::sqlx_types::{
    ColumnDescriptor, ColumnEntry, ColumnValue, DriverKind, RowData, SqlTypeKind,
};

// accesskit types (feature-gated on accesskit)
#[cfg(feature = "accesskit")]
pub use primitives::accesskit_types::{
    ActionStyle, AriaCurrentStyle, AutoCompleteStyle, HasPopupStyle, InvalidStyle, ListStyleStyle,
    LiveStyle, OrientationStyle, RoleStyle, ScrollHintStyle, ScrollUnitStyle, SortDirectionStyle,
    TextAlignStyle, TextDecorationStyleStyle, TextDirectionStyle, ToggledStyle,
    VerticalOffsetStyle,
};

// egui types (feature-gated on egui-types)
#[cfg(feature = "egui-types")]
pub use primitives::egui_types::{
    // Select trenchcoat wrappers
    AlignSelect,
    // Select enum styles
    AlignStyle,
    CursorIconSelect,
    CursorIconStyle,
    DirectionSelect,
    DirectionStyle,
    // Composite struct wrappers
    EguiColor32,
    EguiColor32Style,
    EguiCornerRadius,
    EguiCornerRadiusStyle,
    EguiFontId,
    EguiFontIdStyle,
    EguiMargin,
    EguiMarginStyle,
    EguiPos2,
    EguiPos2Style,
    EguiRect,
    EguiRectStyle,
    EguiShadow,
    EguiShadowStyle,
    EguiStroke,
    EguiStrokeStyle,
    EguiVec2,
    EguiVec2Style,
    FontFamilySelect,
    FontFamilyStyle,
    KeySelect,
    KeyStyle,
    OrderSelect,
    OrderStyle,
    PointerButtonSelect,
    PointerButtonStyle,
    TextStyleSelect,
    TextStyleStyle,
    TextWrapModeSelect,
    TextWrapModeStyle,
    TextureFilterSelect,
    TextureFilterStyle,
    TextureWrapModeSelect,
    TextureWrapModeStyle,
    ThemePreferenceSelect,
    ThemePreferenceStyle,
    ThemeSelect,
    ThemeStyle,
    TouchPhaseSelect,
    TouchPhaseStyle,
    UiKindSelect,
    UiKindStyle,
    WidgetTypeSelect,
    WidgetTypeStyle,
};

// ratatui types (feature-gated on ratatui)
#[cfg(feature = "ratatui")]
pub use primitives::ratatui_types::{
    // Trenchcoat wrappers (add JsonSchema for ElicitComplete)
    AlignmentSelect,
    // Select enum styles
    AlignmentStyle,
    BorderTypeSelect,
    BorderTypeStyle,
    BordersSelect,
    ColorSelect,
    ColorStyle,
    RatatuiDirectionSelect,
    RatatuiDirectionStyle,
    // Composite struct wrappers
    RatatuiMargin,
    RatatuiMarginStyle,
    RatatuiPadding,
    RatatuiPaddingStyle,
    RatatuiStyle,
    RatatuiStyleStyle,
    ScrollbarOrientationSelect,
};

// geo-types (feature-gated on geo-types)
#[cfg(feature = "geo-types")]
pub use primitives::geo_types::{
    GeoCoord, GeoCoordStyle, GeoLine, GeoLineStyle, GeoRect, GeoRectStyle,
};

// palette (feature-gated on palette)
#[cfg(feature = "palette")]
pub use primitives::palette_types::{PaletteSrgb, PaletteSrgbStyle};