Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 83 additions & 4 deletions crates/goose/src/agents/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use once_cell::sync::Lazy;
use rmcp::model::Tool;
use rmcp::service::ClientInitializeError;
use rmcp::ServiceError as ClientError;
use serde::Deserializer;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tracing::warn;
Expand Down Expand Up @@ -216,6 +217,7 @@ pub enum ExtensionConfig {
/// The name used to identify this extension
name: String,
#[serde(default)]
#[serde(deserialize_with = "deserialize_null_with_default")]
#[schema(required)]
description: String,
uri: String,
Expand All @@ -237,6 +239,7 @@ pub enum ExtensionConfig {
/// The name used to identify this extension
name: String,
#[serde(default)]
#[serde(deserialize_with = "deserialize_null_with_default")]
#[schema(required)]
description: String,
cmd: String,
Expand All @@ -257,6 +260,7 @@ pub enum ExtensionConfig {
/// The name used to identify this extension
name: String,
#[serde(default)]
#[serde(deserialize_with = "deserialize_null_with_default")]
#[schema(required)]
description: String,
display_name: Option<String>, // needed for the UI
Expand All @@ -271,7 +275,7 @@ pub enum ExtensionConfig {
Platform {
/// The name used to identify this extension
name: String,
#[serde(default)]
#[serde(deserialize_with = "deserialize_null_with_default")]
#[schema(required)]
description: String,
#[serde(default)]
Expand All @@ -284,7 +288,7 @@ pub enum ExtensionConfig {
StreamableHttp {
/// The name used to identify this extension
name: String,
#[serde(default)]
#[serde(deserialize_with = "deserialize_null_with_default")]
#[schema(required)]
description: String,
uri: String,
Expand All @@ -307,7 +311,7 @@ pub enum ExtensionConfig {
Frontend {
/// The name used to identify this extension
name: String,
#[serde(default)]
#[serde(deserialize_with = "deserialize_null_with_default")]
#[schema(required)]
description: String,
/// The tools provided by the frontend
Expand All @@ -324,7 +328,7 @@ pub enum ExtensionConfig {
InlinePython {
/// The name used to identify this extension
name: String,
#[serde(default)]
#[serde(deserialize_with = "deserialize_null_with_default")]
#[schema(required)]
description: String,
/// The Python code to execute
Expand Down Expand Up @@ -544,6 +548,15 @@ impl ExtensionInfo {
}
}

fn deserialize_null_with_default<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
T: Default + Deserialize<'de>,
D: Deserializer<'de>,
{
let opt = Option::deserialize(deserializer)?;
Ok(opt.unwrap_or_default())
}
Comment on lines +551 to +558
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deserialize_null_with_default function lacks documentation explaining its purpose and behavior. Consider adding a doc comment that clarifies it handles both null values and missing fields by defaulting to the type's default value, which is particularly important for the description String field that should default to an empty string.

Copilot uses AI. Check for mistakes.

/// Information about the tool used for building prompts
#[derive(Clone, Debug, Serialize, ToSchema)]
pub struct ToolInfo {
Expand All @@ -568,3 +581,69 @@ impl ToolInfo {
}
}
}

#[cfg(test)]
mod tests {
use crate::agents::*;

#[test]
fn test_deserialize_missing_description() {
let config: ExtensionConfig = serde_yaml::from_str(
"enabled: true
type: builtin
name: developer
display_name: Developer
timeout: 300
bundled: true
available_tools: []",
)
.unwrap();
if let ExtensionConfig::Builtin { description, .. } = config {
assert_eq!(description, "")
} else {
panic!("unexpected result of deserialization: {}", config)
}
}

#[test]
fn test_deserialize_null_description() {
let config: ExtensionConfig = serde_yaml::from_str(
"enabled: true
type: builtin
name: developer
display_name: Developer
description: null
timeout: 300
bundled: true
available_tools: []
",
)
.unwrap();
if let ExtensionConfig::Builtin { description, .. } = config {
assert_eq!(description, "")
} else {
panic!("unexpected result of deserialization: {}", config)
}
}

#[test]
fn test_deserialize_normal_description() {
let config: ExtensionConfig = serde_yaml::from_str(
"enabled: true
type: builtin
name: developer
display_name: Developer
description: description goes here
timeout: 300
bundled: true
available_tools: []
",
)
.unwrap();
if let ExtensionConfig::Builtin { description, .. } = config {
assert_eq!(description, "description goes here")
} else {
panic!("unexpected result of deserialization: {}", config)
}
}
}