Skip to content

Resolve the option param with using OpenAPI v3 for tools macro #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Hendler
Copy link
Contributor

@Hendler Hendler commented Apr 17, 2025

Adds doc and test.

#135

Motivation and Context

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • [] Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@Hendler Hendler force-pushed the user/hendler/135 branch 3 times, most recently from 2113a98 to 3ccbc64 Compare April 18, 2025 18:57
@Hendler Hendler changed the title Document OpenAPI compat issue Use OpenAPI v3 for tools macro Apr 18, 2025
@Hendler Hendler force-pushed the user/hendler/135 branch 3 times, most recently from a70f10a to 6527e83 Compare April 20, 2025 09:10
.map(|text| text.text.as_str())
.expect("Expected text content");

assert_eq!(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would think this would fail per #135

}

#[test]
fn test_optional_field_schema_generation_via_macro() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about use a more little change test .

impl Server {
    /// This tool is used to get the weather of a city.
    #[tool(name = "get-weather", description = "Get the weather of a city.", vis = )]
    pub async fn get_weather(&self, #[tool(param)] city: String) -> String {
        drop(city);
        "rain".to_string()
    }
    #[tool(description = "Empty Parameter")]
    async fn empty_param(&self) {}
    +#[tool(description = "Optional Parameter")]
    +async fn optional_param(&self, #[tool(param)] city: Option<String>) -> String {
    +    city.unwrap_or_default()
    +}
}
#[tokio::test]
async fn test_tool_macros_with_optional_param() {
    let _attr = Server::optional_param_tool_attr();
    // println!("{_attr:?}");
    let attr_type = _attr.input_schema.get("properties").unwrap().get("city").unwrap().get("type").unwrap();
    println!("_attr.input_schema: {:?}", attr_type);
    assert_eq!(attr_type, "string");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@jokemanfire
Copy link
Collaborator

Sorry for the late reply, as the questioner has not updated for a long time.

@jokemanfire jokemanfire changed the title Use OpenAPI v3 for tools macro Resolve the option param with using OpenAPI v3 for tools macro May 12, 2025
@Hendler Hendler force-pushed the user/hendler/135 branch 3 times, most recently from b5919e0 to 9642796 Compare May 13, 2025 16:42
…ld schema workaround (modelcontextprotocol#135)

test(update): added test tool macro with optional
@Hendler Hendler force-pushed the user/hendler/135 branch from 9642796 to 1cc56b2 Compare May 13, 2025 17:01
@Hendler
Copy link
Contributor Author

Hendler commented May 13, 2025

@jokemanfire feel free to approve. Maybe fixing this will fix other issues as well?
cc @4t145

I may have more time to work on this soon.

@jokemanfire jokemanfire merged commit 5d92061 into modelcontextprotocol:main May 14, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants