use elicitation::{Elicit, ElicitToolOutput, Prompt, Select};
use elicitation_macros::elicit_tools;
use rmcp::model::{ServerCapabilities, ServerInfo};
use rmcp::service::RoleServer;
use rmcp::{ServerHandler, tool, tool_router};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Elicit)]
#[serde(rename_all = "snake_case")]
pub enum Priority {
Low,
Medium,
High,
Critical,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Elicit)]
pub enum Status {
Pending,
InProgress { progress: u8 },
Completed { result: String },
Failed { error: String },
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Elicit)]
pub struct Task {
pub name: String,
pub priority: Priority,
pub status: Status,
}
pub struct EnumTestServer;
#[elicit_tools(Priority, Status, Task)]
#[tool_router]
impl EnumTestServer {
}
impl ServerHandler for EnumTestServer {
fn get_info(&self) -> ServerInfo {
ServerInfo {
capabilities: ServerCapabilities::builder().enable_tools().build(),
..Default::default()
}
}
}
#[test]
fn test_enum_wrapper_structs_generated() {
let _priority_wrapper = ElicitToolOutput::new(Priority::High);
let _status_wrapper = ElicitToolOutput::new(Status::Pending);
let _task_wrapper = ElicitToolOutput::new(Task {
name: "Test".to_string(),
priority: Priority::High,
status: Status::Pending,
});
}
#[test]
fn test_enum_wrapper_serialization() {
use serde_json;
let wrapper = ElicitToolOutput::new(Priority::High);
let json = serde_json::to_value(&wrapper).expect("Serialize wrapper");
assert!(json.is_object());
assert!(json.get("value").is_some());
assert_eq!(json["value"], "high");
}
#[test]
fn test_enum_wrapper_schema_is_object() {
use schemars::schema_for;
let schema = schema_for!(ElicitToolOutput<Priority>);
assert!(schema.as_object().is_some(), "Schema should be an object");
let obj = schema.as_object().unwrap();
assert!(
obj.get("properties").is_some(),
"Should have properties field"
);
}
#[test]
fn test_status_wrapper_schema_is_object() {
use schemars::schema_for;
let schema = schema_for!(ElicitToolOutput<Status>);
assert!(schema.as_object().is_some(), "Schema should be an object");
}
#[test]
fn test_server_compiles() {
let server = EnumTestServer;
let _info = server.get_info();
}
#[test]
fn test_tool_methods_exist() {
let _: fn(rmcp::service::Peer<RoleServer>) -> _ = EnumTestServer::elicit_priority;
let _: fn(rmcp::service::Peer<RoleServer>) -> _ = EnumTestServer::elicit_status;
let _: fn(rmcp::service::Peer<RoleServer>) -> _ = EnumTestServer::elicit_task;
}
#[test]
fn test_wrapper_derives() {
fn assert_serde<T: Serialize + for<'de> Deserialize<'de>>() {}
fn assert_schema<T: JsonSchema>() {}
assert_serde::<ElicitToolOutput<Priority>>();
assert_serde::<ElicitToolOutput<Status>>();
assert_serde::<ElicitToolOutput<Task>>();
assert_schema::<ElicitToolOutput<Priority>>();
assert_schema::<ElicitToolOutput<Status>>();
assert_schema::<ElicitToolOutput<Task>>();
}
#[test]
fn test_nested_enum_in_struct() {
let task = Task {
name: "Deploy".to_string(),
priority: Priority::Critical,
status: Status::InProgress { progress: 75 },
};
let wrapper = ElicitToolOutput::new(task);
let json = serde_json::to_value(&wrapper).expect("Serialize");
assert!(json.is_object());
assert!(json["value"].is_object());
assert_eq!(json["value"]["name"], "Deploy");
}