mcp-go
mcp-go copied to clipboard
PDF content
Hey, how to add a pdf content? tried a lot of stuff like
callToolResult.Content = append(callToolResult.Content, mcp.ImageContent{
Type: "pdf",
Data: base64.StdEncoding.EncodeToString(pdfBytes),
MIMEType: "application/pdf",
})
also this
callToolResult.Content = append(callToolResult.Content, mcp.EmbeddedResource{
Type: "resource",
Resource: mcp.BlobResourceContents{
URI: "file://" + pdfPath,
MIMEType: "application/pdf",
Blob: base64.StdEncoding.EncodeToString(pdfBytes),
},
})
responds with Unsupported image type: application/pdf
my mcp inspector prints this
{
"uri": "file:///Users/loeffel/Google Drive/My Drive/Gewerbe/Steuer/Steuer 2025/Februar/N26/google.com/6382285305241639-10.pdf",
"mimeType": "application/pdf",
"blob": "{base64content}"
}
i can open the uri in my browser do i need to add s.AddResources or something - i am stuck 😄
its a simple tool call
s.AddTool(n26ToolGet, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
id, err := uuid.Parse(request.Params.Arguments["id"].(string))
if err != nil {
return mcp.NewToolResultError("Invalid id format"), nil
}
transaction, ok := transactions[id.String()]
if !ok {
return mcp.NewToolResultError("Transaction not found"), nil
}
result := &ResultGet{
Id: id,
Transaction: transaction,
}
resultBytes, err := json.Marshal(result)
if err != nil {
return mcp.NewToolResultError("Error marshalling transactions"), nil
}
callToolResult := &mcp.CallToolResult{
Content: []mcp.Content{
mcp.TextContent{
Type: "text",
Text: "Full transaction",
},
mcp.NewEmbeddedResource(
mcp.TextResourceContents{
MIMEType: "application/json",
Text: string(resultBytes),
},
),
},
IsError: false,
}
pdfPath, ok := strings.CutPrefix(transaction.Info, "output/")
if !ok {
return callToolResult, nil
}
pdfPath = dir + "/" + pdfPath
_, err = os.Stat(pdfPath)
if errors.Is(err, os.ErrNotExist) {
return callToolResult, nil
}
pdfBytes, err := os.ReadFile(pdfPath)
if err != nil {
return mcp.NewToolResultError("Error reading pdf file"), nil
}
log.Printf("pdfPath: %s", "file://"+pdfPath)
callToolResult.Content = append(callToolResult.Content, mcp.NewEmbeddedResource(
mcp.BlobResourceContents{
URI: "file://" + pdfPath,
MIMEType: "application/pdf",
Blob: base64.StdEncoding.EncodeToString(pdfBytes),
},
))
return callToolResult, nil
})
Claude should be also has access to the files
I'm on Linux and don't have access to Claude Desktop, anyone else having issues with this and willing to debug?