#![cfg_attr(coverage_nightly, coverage(off))]
use crate::cli::registry::{CommandMetadata, CommandRegistry, ValueType};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
pub struct McpSchemaGenerator {
registry: CommandRegistry,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct McpToolDefinition {
pub name: String,
pub description: String,
#[serde(rename = "inputSchema")]
pub input_schema: Value,
#[serde(skip_serializing_if = "Option::is_none")]
pub annotations: Option<McpToolAnnotations>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct McpToolAnnotations {
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(rename = "readOnlyHint", skip_serializing_if = "Option::is_none")]
pub read_only_hint: Option<bool>,
#[serde(rename = "destructiveHint", skip_serializing_if = "Option::is_none")]
pub destructive_hint: Option<bool>,
#[serde(rename = "idempotentHint", skip_serializing_if = "Option::is_none")]
pub idempotent_hint: Option<bool>,
#[serde(rename = "openWorldHint", skip_serializing_if = "Option::is_none")]
pub open_world_hint: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SchemaError {
MissingSchemaProperty {
tool: String,
property: String,
},
TypeMismatch {
tool: String,
property: String,
expected: String,
actual: String,
},
DuplicateToolName {
tool_name: String,
command1: String,
command2: String,
},
}
impl std::fmt::Display for SchemaError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::MissingSchemaProperty { tool, property } => {
write!(
f,
"Tool '{}' missing required property '{}'",
tool, property
)
}
Self::TypeMismatch {
tool,
property,
expected,
actual,
} => {
write!(
f,
"Tool '{}' property '{}' type mismatch: expected {}, got {}",
tool, property, expected, actual
)
}
Self::DuplicateToolName {
tool_name,
command1,
command2,
} => {
write!(
f,
"Duplicate MCP tool name '{}' in commands '{}' and '{}'",
tool_name, command1, command2
)
}
}
}
}
impl std::error::Error for SchemaError {}
include!("mcp_schema_generator_impl.rs");
include!("mcp_schema_generator_tests.rs");