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
//! `ToSqlxArgs` — bridge trait for converting any [`Elicitation`] type into
//! positional SQL arguments.
//!
//! # How it works
//!
//! Any type `T` that derives [`Elicitation`] (which implies `Serialize +
//! DeserializeOwned + JsonSchema`) automatically implements [`ToSqlxArgs`] via
//! a blanket impl. The impl serializes `T` to JSON and extracts the field
//! values in declaration order as a flat `Vec<serde_json::Value>`.
//!
//! The resulting vector can be passed directly as `args` to any driver plugin
//! tool that accepts positional parameters:
//!
//! ```text
//! my_type__to_sqlx_args { target: { name: "Alice", age: 30 } }
//! → { result: ["Alice", 30] }
//!
//! pg__execute { pool_id: "…", sql: "INSERT INTO users(name,age) VALUES($1,$2)",
//! args: ["Alice", 30] }
//! → { rows_affected: 1 }
//! ```
//!
//! # Field ordering
//!
//! Fields are emitted in the order they appear in the JSON serialization of
//! `T`. For types that derive `serde::Serialize`, this matches the struct
//! declaration order. Renamed or skipped fields follow serde attribute rules.
//!
//! For non-object JSON values (e.g. a newtype wrapping a single scalar),
//! the scalar itself is wrapped in a single-element `Vec`.
//!
//! # Factory usage
//!
//! Register a user type at server startup to get a typed binding tool:
//!
//! ```rust,ignore
//! prime_to_sqlx_args::<CreateUser>();
//! registry.register_type::<CreateUser>("create_user");
//! // Agent can now call: create_user__to_sqlx_args { target: { … } }
//! ```
use reflect_trait;
use Serialize;
/// Convert `self` into a flat list of positional SQL argument values.
///
/// Implemented automatically for all types that derive [`Elicitation`].
/// The return value is suitable for direct use as the `args` field in
/// `*__execute`, `*__fetch_all`, `*__fetch_one`, and `*__fetch_optional`
/// driver tools.
/// Expose [`ToSqlxArgs`] as an agent-callable MCP tool factory.
///
/// For each registered type `T`, contributes one tool:
/// - `{prefix}__to_sqlx_args` — convert a `T` value into positional SQL args
///
/// The `target` parameter must be the JSON representation of the `T` value.
/// The output `Vec<serde_json::Value>` can be passed directly as `args` to
/// any driver plugin execute or fetch tool.