gitai/server/tools/
releasenotes.rs

1//! MCP release notes tool implementation
2//!
3//! This module provides the MCP tool for generating release notes.
4
5use crate::config::Config as PilotConfig;
6use crate::debug;
7use crate::features::changelog::ReleaseNotesGenerator;
8use crate::git::GitRepo;
9use crate::server::tools::utils::{
10    PilotTool, apply_custom_instructions, create_text_result, parse_detail_level, resolve_git_repo,
11    validate_repository_parameter,
12};
13
14use rmcp::handler::server::tool::cached_schema_for_type;
15use rmcp::model::{CallToolResult, Tool};
16use rmcp::schemars;
17
18use serde::{Deserialize, Serialize};
19use std::borrow::Cow;
20use std::sync::Arc;
21
22/// Release notes tool for generating comprehensive release notes
23#[derive(Debug, Deserialize, Serialize, schemars::JsonSchema)]
24pub struct ReleaseNotesTool {
25    /// Starting reference (commit hash, tag, or branch name)
26    pub from: String,
27
28    /// Ending reference (commit hash, tag, or branch name). Defaults to HEAD if not specified.
29    #[serde(default)]
30    pub to: String,
31
32    /// Level of detail for the release notes
33    #[serde(default)]
34    pub detail_level: String,
35
36    /// Custom instructions for the AI
37    #[serde(default)]
38    pub custom_instructions: String,
39
40    /// Repository path (local) or URL (remote). Required.
41    pub repository: String,
42
43    /// Explicit version name to use (optional)
44    #[serde(default)]
45    pub version_name: String,
46}
47
48impl ReleaseNotesTool {
49    /// Returns the tool definition for the release notes tool
50    pub fn get_tool_definition() -> Tool {
51        Tool {
52            name: Cow::Borrowed("gitai_release_notes"),
53            description: Some(Cow::Borrowed(
54                "Generate comprehensive release notes between two Git references",
55            )),
56            input_schema: cached_schema_for_type::<Self>(),
57            annotations: None,
58            icons: None,
59            output_schema: None,
60            title: None,
61        }
62    }
63}
64
65#[async_trait::async_trait]
66impl PilotTool for ReleaseNotesTool {
67    /// Execute the release notes tool with the provided repository and configuration
68    async fn execute(
69        &self,
70        git_repo: Arc<GitRepo>,
71        config: PilotConfig,
72    ) -> Result<CallToolResult, anyhow::Error> {
73        debug!("Generating release notes with: {:?}", self);
74
75        // Validate repository parameter
76        validate_repository_parameter(&self.repository)?;
77        let git_repo = resolve_git_repo(Some(self.repository.as_str()), git_repo)?;
78        debug!("Using repository: {}", git_repo.repo_path().display());
79
80        // Parse detail level using shared utility
81        let detail_level = parse_detail_level(&self.detail_level);
82
83        // Set up config with custom instructions if provided
84        let mut config = config.clone();
85        apply_custom_instructions(&mut config, &self.custom_instructions);
86
87        // Default to HEAD if to is empty
88        let to = if self.to.trim().is_empty() {
89            "HEAD".to_string()
90        } else {
91            self.to.clone()
92        };
93
94        // Generate the release notes using the generator
95        let content = ReleaseNotesGenerator::generate(
96            git_repo.clone(),
97            &self.from,
98            &to,
99            &config,
100            detail_level,
101            if self.version_name.is_empty() {
102                None
103            } else {
104                Some(self.version_name.clone())
105            },
106        )
107        .await?;
108
109        // Create and return the result using shared utility
110        Ok(create_text_result(content))
111    }
112}