Skip to content

Commit 0fdb197

Browse files
feat: add ResourceLink type and parsing support (#407)
feat: add ResourceLink type and parsing support (#407)
1 parent d807ae7 commit 0fdb197

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

mcp/types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,22 @@ type AudioContent struct {
865865

866866
func (AudioContent) isContent() {}
867867

868+
// ResourceLink represents a link to a resource that the client can access.
869+
type ResourceLink struct {
870+
Annotated
871+
Type string `json:"type"` // Must be "resource_link"
872+
// The URI of the resource.
873+
URI string `json:"uri"`
874+
// The name of the resource.
875+
Name string `json:"name"`
876+
// The description of the resource.
877+
Description string `json:"description"`
878+
// The MIME type of the resource.
879+
MIMEType string `json:"mimeType"`
880+
}
881+
882+
func (ResourceLink) isContent() {}
883+
868884
// EmbeddedResource represents the contents of a resource, embedded into a prompt or tool call result.
869885
//
870886
// It is up to the client how best to render embedded resources for the

mcp/utils.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ func NewAudioContent(data, mimeType string) AudioContent {
222222
}
223223
}
224224

225+
// Helper function to create a new ResourceLink
226+
func NewResourceLink(uri, name, description, mimeType string) ResourceLink {
227+
return ResourceLink{
228+
Type: "resource_link",
229+
URI: uri,
230+
Name: name,
231+
Description: description,
232+
MIMEType: mimeType,
233+
}
234+
}
235+
225236
// Helper function to create a new EmbeddedResource
226237
func NewEmbeddedResource(resource ResourceContents) EmbeddedResource {
227238
return EmbeddedResource{
@@ -476,6 +487,16 @@ func ParseContent(contentMap map[string]any) (Content, error) {
476487
}
477488
return NewAudioContent(data, mimeType), nil
478489

490+
case "resource_link":
491+
uri := ExtractString(contentMap, "uri")
492+
name := ExtractString(contentMap, "name")
493+
description := ExtractString(contentMap, "description")
494+
mimeType := ExtractString(contentMap, "mimeType")
495+
if uri == "" || name == "" {
496+
return nil, fmt.Errorf("resource_link uri or name is missing")
497+
}
498+
return NewResourceLink(uri, name, description, mimeType), nil
499+
479500
case "resource":
480501
resourceMap := ExtractMap(contentMap, "resource")
481502
if resourceMap == nil {

0 commit comments

Comments
 (0)