mcp-go
mcp-go copied to clipboard
Pointer to anonymous structure [refactor?]
Looking at https://github.com/mark3labs/mcp-go/blob/main/mcp/types.go#L647, it looks as though Annotations is a pointer to an anonymous structure, and the only way I can create that is with this, which is slightly awkward:
textContent := TextContent{
Type: "text",
Text: "Hello, world!",
Annotated: Annotated{
Annotations: &struct {
Audience []Role `json:"audience,omitempty"`
Priority float64 `json:"priority,omitempty"`
}{
Audience: []Role{"user"},
},
},
}
I wonder if the Annotations can be pulled out into its own type:
type Annotations struct {
// Describes who the intended customer of this object or data is.
// ...
Audience []Role `json:"audience,omitempty"`
// Describes how important this data is for operating the server.
// ...
Priority float64 `json:"priority,omitempty"`
}
// Refactor Annotated to use the named struct
// Annotated is the base for objects that include optional annotations for the
// client. The client can use annotations to inform how objects are used or
// displayed
type Annotated struct {
Annotations *Annotations `json:"annotations,omitempty"`
}
Happy to provide a PR with this change, if folks think it's worth it ?
I think it might make the implementation of WithTemplateAnnotations marginally simpler with less duplication too: https://github.com/mark3labs/mcp-go/blob/013c0472999e4cf5092a5c59966e081c0f8a9ea3/mcp/resources.go#L94
I prefer a type compared to introducing a new function