@@ -535,20 +535,20 @@ Tools can return resource links that reference other resources in your MCP serve
535
535
536
536
``` go
537
537
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
552
552
}
553
553
```
554
554
@@ -558,27 +558,29 @@ You can combine different content types including resource links in a single too
558
558
559
559
``` go
560
560
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
582
584
}
583
585
```
584
586
@@ -588,23 +590,22 @@ Resource links can include additional metadata through annotations:
588
590
589
591
``` go
590
592
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
608
609
}
609
610
```
610
611
0 commit comments