Skip to content

Missing constructors for Root and ListRootsResult after #[non_exhaustive] in 1.x #734

@ianlet

Description

@ianlet

Root and ListRootsResult were made #[non_exhaustive] in 1.x but no constructors were added, making it impossible to implement ClientHandler::list_roots without going through serde_json::from_value:

// This no longer compiles
let root = Root { uri: "file:///project".into(), name: None };

// Current workaround
let root: Root = serde_json::from_value(json!({ "uri": "file:///project" })).unwrap();

Same for ListRootsResult: the only way to return a non-empty result from list_roots is to deserialize it.

Most types affected by the #[non_exhaustive] change got ::new() + builder methods (e.g. CallToolRequestParams, ServerInfo). These two seem to have been missed, likely because the library's own code only deserializes them (roots flow from client to server over the wire).

Would be great to have something like:

Root::new(uri: impl Into<String>)  // name defaults to None
ListRootsResult::new(roots: Vec<Root>)

Neither type appears in the migration guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-coreCore library changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions