Skip to content

Commit dcb737d

Browse files
committed
feat: add desc about resource link in docs
Signed-off-by: FanOne <294350394@qq.com>
1 parent 0e457af commit dcb737d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

mcp/types_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,6 @@ func TestCallToolResultWithResourceLink(t *testing.T) {
135135
assert.Equal(t, "resource_link", resourceLink.Type)
136136
assert.Equal(t, "file:///example/test.pdf", resourceLink.URI)
137137
assert.Equal(t, "Test Document", resourceLink.Name)
138+
assert.Equal(t, "A test document", resourceLink.Description)
139+
assert.Equal(t, "application/pdf", resourceLink.MIMEType)
138140
}

www/docs/pages/servers/tools.mdx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func handleGetResourceLinkTool(ctx context.Context, req mcp.CallToolRequest) (*m
542542

543543
// Create a resource link pointing to an existing resource
544544
uri := fmt.Sprintf("file://documents/%s", resourceID)
545-
resourceLink := mcp.NewResourceLink(uri, "name", "resource name", "file")
545+
resourceLink := mcp.NewResourceLink(uri, "Document", "The requested document", "application/pdf")
546546
return &mcp.CallToolResult{
547547
Content: []mcp.Content{
548548
mcp.NewTextContent("Found the requested document:"),
@@ -573,8 +573,21 @@ func handleSearchDocumentsTool(ctx context.Context, req mcp.CallToolRequest) (*m
573573
// Add resource links for each found document
574574
for _, doc := range foundDocs {
575575
uri := fmt.Sprintf("file://documents/%s", doc)
576-
docType := strings.Split(doc, ".")
577-
resourceLink := mcp.NewResourceLink(uri, docType[0], "file", docType[1])
576+
parts := strings.SplitN(doc, ".", 2)
577+
name := parts[0]
578+
mimeType := "application/octet-stream" // default
579+
if len(parts) > 1 {
580+
// Map extension to MIME type (simplified)
581+
switch parts[1] {
582+
case "pdf":
583+
mimeType = "application/pdf"
584+
case "txt":
585+
mimeType = "text/plain"
586+
case "md":
587+
mimeType = "text/markdown"
588+
}
589+
}
590+
resourceLink := mcp.NewResourceLink(uri, name, fmt.Sprintf("Document: %s", doc), mimeType)
578591
content = append(content, resourceLink)
579592
}
580593

@@ -598,7 +611,7 @@ func handleGetAnnotatedResourceTool(ctx context.Context, req mcp.CallToolRequest
598611
},
599612
}
600613
url := "file://documents/test.pdf"
601-
resourceLink := mcp.NewResourceLink(url, "test", "doc", docType)
614+
resourceLink := mcp.NewResourceLink(url, "Test Document", fmt.Sprintf("A %s document", docType), "application/pdf")
602615
resourceLink.Annotated = annotated
603616
return &mcp.CallToolResult{
604617
Content: []mcp.Content{

0 commit comments

Comments
 (0)