Skip to content

Commit 0e457af

Browse files
committed
feat:add desc about ResourceLink in doc
1 parent 7537a3a commit 0e457af

File tree

1 file changed

+53
-52
lines changed

1 file changed

+53
-52
lines changed

www/docs/pages/servers/tools.mdx

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -535,20 +535,20 @@ Tools can return resource links that reference other resources in your MCP serve
535535

536536
```go
537537
func handleGetResourceLinkTool(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
538-
resourceID, err := req.RequireString("resource_id")
539-
if err != nil {
540-
return mcp.NewToolResultError(err.Error()), nil
541-
}
542-
543-
// Create a resource link pointing to an existing resource
544-
resourceLink := mcp.NewResourceLink(fmt.Sprintf("file://documents/%s", resourceID))
545-
546-
return &mcp.CallToolResult{
547-
Content: []mcp.Content{
548-
mcp.NewTextContent("Found the requested document:"),
549-
resourceLink,
550-
},
551-
}, nil
538+
resourceID, err := req.RequireString("resource_id")
539+
if err != nil {
540+
return mcp.NewToolResultError(err.Error()), nil
541+
}
542+
543+
// Create a resource link pointing to an existing resource
544+
uri := fmt.Sprintf("file://documents/%s", resourceID)
545+
resourceLink := mcp.NewResourceLink(uri, "name", "resource name", "file")
546+
return &mcp.CallToolResult{
547+
Content: []mcp.Content{
548+
mcp.NewTextContent("Found the requested document:"),
549+
resourceLink,
550+
},
551+
}, nil
552552
}
553553
```
554554

@@ -558,27 +558,29 @@ You can combine different content types including resource links in a single too
558558

559559
```go
560560
func handleSearchDocumentsTool(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
561-
query, err := req.RequireString("query")
562-
if err != nil {
563-
return mcp.NewToolResultError(err.Error()), nil
564-
}
565-
566-
// Simulate document search
567-
foundDocs := []string{"doc1.pdf", "doc2.txt", "doc3.md"}
568-
569-
content := []mcp.Content{
570-
mcp.NewTextContent(fmt.Sprintf("Found %d documents matching '%s':", len(foundDocs), query)),
571-
}
572-
573-
// Add resource links for each found document
574-
for _, doc := range foundDocs {
575-
resourceLink := mcp.NewResourceLink(fmt.Sprintf("file://documents/%s", doc))
576-
content = append(content, resourceLink)
577-
}
578-
579-
return &mcp.CallToolResult{
580-
Content: content,
581-
}, nil
561+
query, err := req.RequireString("query")
562+
if err != nil {
563+
return mcp.NewToolResultError(err.Error()), nil
564+
}
565+
566+
// Simulate document search
567+
foundDocs := []string{"doc1.pdf", "doc2.txt", "doc3.md"}
568+
569+
content := []mcp.Content{
570+
mcp.NewTextContent(fmt.Sprintf("Found %d documents matching '%s':", len(foundDocs), query)),
571+
}
572+
573+
// Add resource links for each found document
574+
for _, doc := range foundDocs {
575+
uri := fmt.Sprintf("file://documents/%s", doc)
576+
docType := strings.Split(doc, ".")
577+
resourceLink := mcp.NewResourceLink(uri, docType[0], "file", docType[1])
578+
content = append(content, resourceLink)
579+
}
580+
581+
return &mcp.CallToolResult{
582+
Content: content,
583+
}, nil
582584
}
583585
```
584586

@@ -588,23 +590,22 @@ Resource links can include additional metadata through annotations:
588590

589591
```go
590592
func handleGetAnnotatedResourceTool(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
591-
docType := req.GetString("type", "general")
592-
593-
// Create resource link with annotations
594-
resourceLink := &mcp.ResourceLink{
595-
URI: "file://documents/important.pdf",
596-
Annotations: &mcp.Annotations{
597-
Audience: []mcp.Role{mcp.RoleUser},
598-
Priority: mcp.PriorityHigh,
599-
},
600-
}
601-
602-
return &mcp.CallToolResult{
603-
Content: []mcp.Content{
604-
mcp.NewTextContent("Here's the important document you requested:"),
605-
resourceLink,
606-
},
607-
}, nil
593+
docType := req.GetString("type", "general")
594+
// Create resource link with annotations
595+
annotated := mcp.Annotated{
596+
Annotations: &mcp.Annotations{
597+
Audience: []mcp.Role{mcp.RoleUser},
598+
},
599+
}
600+
url := "file://documents/test.pdf"
601+
resourceLink := mcp.NewResourceLink(url, "test", "doc", docType)
602+
resourceLink.Annotated = annotated
603+
return &mcp.CallToolResult{
604+
Content: []mcp.Content{
605+
mcp.NewTextContent("Here's the important document you requested:"),
606+
resourceLink,
607+
},
608+
}, nil
608609
}
609610
```
610611

0 commit comments

Comments
 (0)