use std::sync::Arc;
use elicitation::{Elicit, ElicitClient, ElicitResult, Elicitation};
use rmcp::ServiceExt;
#[derive(Debug, Elicit)]
struct Person {
name: String,
age: u8,
email: String,
}
#[derive(Debug, Elicit)]
#[prompt("Let's configure your account:")]
struct Account {
#[prompt("What username would you like?")]
username: String,
#[prompt("Enter your email address:")]
email: String,
#[prompt("How old are you?")]
age: u8,
#[prompt("Would you like to receive notifications?")]
notifications_enabled: bool,
}
#[derive(Debug, Elicit)]
struct Profile {
#[prompt("What's your full name?")]
name: String,
#[prompt("What's your preferred nickname?")]
nickname: Option<String>,
#[prompt("What's your bio?")]
bio: Option<String>,
#[prompt("How old are you?")]
age: u8,
}
#[derive(Debug, Default, Elicit)]
struct Task {
#[prompt("What's the task title?")]
title: String,
#[prompt("Describe the task:")]
description: String,
#[skip]
created_at: String,
#[skip]
id: u64,
}
#[tokio::main]
async fn main() -> ElicitResult<()> {
tracing_subscriber::fmt()
.with_env_filter("structs=debug,elicitation=debug")
.init();
tracing::info!("Starting struct elicitation example");
let service = ().serve(rmcp::transport::stdio()).await.expect("Failed to create MCP client");
let peer = service.peer();
let client = ElicitClient::new(Arc::new(peer.clone()));
tracing::info!("=== Eliciting Person ===");
let person = Person::elicit(&client).await?;
tracing::info!(person = ?person, "Created person");
tracing::info!("=== Eliciting Account ===");
let account = Account::elicit(&client).await?;
tracing::info!(account = ?account, "Created account");
tracing::info!("=== Eliciting Profile ===");
let profile = Profile::elicit(&client).await?;
tracing::info!(profile = ?profile, "Created profile");
tracing::info!("=== Eliciting Task ===");
let task = Task::elicit(&client).await?;
tracing::info!(task = ?task, "Created task");
tracing::info!("=== Summary ===");
tracing::info!("Person: {:?}", person);
tracing::info!("Account: {:?}", account);
tracing::info!("Profile: {:?}", profile);
tracing::info!("Task: {:?}", task);
println!("\n=== Field Access Demo ===");
println!(
"Person's name: {}, age: {}, email: {}",
person.name, person.age, person.email
);
println!(
"Account username: {}, email: {}, age: {}, notifications: {}",
account.username, account.email, account.age, account.notifications_enabled
);
println!(
"Profile name: {}, nickname: {:?}, bio: {:?}, age: {}",
profile.name, profile.nickname, profile.bio, profile.age
);
println!(
"Task title: {}, description: {}, created_at: {}, id: {}",
task.title, task.description, task.created_at, task.id
);
Ok(())
}