Skip to content

Commit 1f02487

Browse files
jbasamthanawalla
authored andcommitted
mcp: dedup wire type for image and audio (#149)
Factor out the wire type into a top-level struct.
1 parent 4f4b66a commit 1f02487

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

mcp/content.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,7 @@ func (c *ImageContent) MarshalJSON() ([]byte, error) {
6363
if data == nil {
6464
data = []byte{}
6565
}
66-
wire := struct {
67-
Type string `json:"type"`
68-
MIMEType string `json:"mimeType"`
69-
Data []byte `json:"data"`
70-
Meta Meta `json:"_meta,omitempty"`
71-
Annotations *Annotations `json:"annotations,omitempty"`
72-
}{
66+
wire := imageAudioWire{
7367
Type: "image",
7468
MIMEType: c.MIMEType,
7569
Data: data,
@@ -100,13 +94,7 @@ func (c AudioContent) MarshalJSON() ([]byte, error) {
10094
if data == nil {
10195
data = []byte{}
10296
}
103-
wire := struct {
104-
Type string `json:"type"`
105-
MIMEType string `json:"mimeType"`
106-
Data []byte `json:"data"`
107-
Meta Meta `json:"_meta,omitempty"`
108-
Annotations *Annotations `json:"annotations,omitempty"`
109-
}{
97+
wire := imageAudioWire{
11098
Type: "audio",
11199
MIMEType: c.MIMEType,
112100
Data: data,
@@ -123,6 +111,15 @@ func (c *AudioContent) fromWire(wire *wireContent) {
123111
c.Annotations = wire.Annotations
124112
}
125113

114+
// Custom wire format to ensure required fields are always included, even when empty.
115+
type imageAudioWire struct {
116+
Type string `json:"type"`
117+
MIMEType string `json:"mimeType"`
118+
Data []byte `json:"data"`
119+
Meta Meta `json:"_meta,omitempty"`
120+
Annotations *Annotations `json:"annotations,omitempty"`
121+
}
122+
126123
// ResourceLink is a link to a resource
127124
type ResourceLink struct {
128125
URI string

0 commit comments

Comments
 (0)