database_mcp_server/types.rs
1//! Request and response types for MCP tool parameters.
2//!
3//! Each struct maps to the JSON input or output schema of one MCP tool.
4
5use rmcp::schemars;
6use rmcp::schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8use serde_json::Value;
9
10/// Response for tools with no structured return data.
11#[derive(Debug, Serialize, JsonSchema)]
12pub struct MessageResponse {
13 /// Description of the completed operation.
14 pub message: String,
15}
16
17/// Response for the `list_databases` tool.
18#[derive(Debug, Serialize, JsonSchema)]
19pub struct ListDatabasesResponse {
20 /// Sorted list of database names.
21 pub databases: Vec<String>,
22}
23
24/// Request for the `create_database` tool.
25#[derive(Debug, Default, Deserialize, JsonSchema)]
26pub struct CreateDatabaseRequest {
27 /// Name of the database to create. Must contain only alphanumeric characters and underscores.
28 pub database_name: String,
29}
30
31/// Request for the `drop_database` tool.
32#[derive(Debug, Default, Deserialize, JsonSchema)]
33pub struct DropDatabaseRequest {
34 /// Name of the database to drop. Must contain only alphanumeric characters and underscores.
35 pub database_name: String,
36}
37
38/// Request for the `list_tables` tool.
39#[derive(Debug, Default, Deserialize, JsonSchema)]
40pub struct ListTablesRequest {
41 /// The database name to list tables from. Required. Use `list_databases` first to see available databases.
42 pub database_name: String,
43}
44
45/// Response for the `list_tables` tool.
46#[derive(Debug, Serialize, JsonSchema)]
47pub struct ListTablesResponse {
48 /// Sorted list of table names.
49 pub tables: Vec<String>,
50}
51
52/// Request for the `get_table_schema` tool.
53#[derive(Debug, Default, Deserialize, JsonSchema)]
54pub struct GetTableSchemaRequest {
55 /// The database name containing the table. Required. Use `list_databases` first to see available databases.
56 pub database_name: String,
57 /// The table name to inspect. Use `list_tables` first to see available tables in the database.
58 pub table_name: String,
59}
60
61/// Response for the `get_table_schema` tool.
62#[derive(Debug, Serialize, JsonSchema)]
63pub struct TableSchemaResponse {
64 /// Name of the inspected table.
65 pub table_name: String,
66 /// Column definitions keyed by column name.
67 pub columns: Value,
68}
69
70/// Request for the `read_query` and `write_query` tools.
71#[derive(Debug, Default, Deserialize, JsonSchema)]
72pub struct QueryRequest {
73 /// The SQL query to execute.
74 pub query: String,
75 /// The database to run the query against. Required. Use `list_databases` first to see available databases.
76 pub database_name: String,
77}
78
79/// Response for the `read_query`, `write_query`, and `explain_query` tools.
80#[derive(Debug, Serialize, JsonSchema)]
81pub struct QueryResponse {
82 /// Result rows, each a JSON object keyed by a column name.
83 pub rows: Value,
84}
85
86/// Request for the `explain_query` tool.
87#[derive(Debug, Default, Deserialize, JsonSchema)]
88pub struct ExplainQueryRequest {
89 /// The database to explain against. Required. Use `list_databases` first to see available databases.
90 pub database_name: String,
91 /// The SQL query to explain.
92 pub query: String,
93 /// If true, use EXPLAIN ANALYZE for actual execution statistics. In read-only mode, only allowed for read-only statements. Defaults to false.
94 #[serde(default)]
95 pub analyze: bool,
96}