Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/llm/ollama/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package ollama

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"strings"

"github.com/charmbracelet/log"
"github.com/mark3labs/mcp-go/mcp"
"github.com/ollama/ollama/api"

"github.com/mark3labs/mcphost/pkg/history"
"github.com/mark3labs/mcphost/pkg/llm"
api "github.com/ollama/ollama/api"
)

func boolPtr(b bool) *bool {
Expand Down Expand Up @@ -63,10 +66,21 @@ func (p *Provider) CreateMessage(
// Handle tool responses
if msg.IsToolResponse() {
var content string
imageContent := make([]api.ImageData, 0)

// Handle HistoryMessage format
if historyMsg, ok := msg.(*history.HistoryMessage); ok {
for _, block := range historyMsg.Content {
for _, c := range block.Content.([]mcp.Content) {
if image, ok := c.(mcp.ImageContent); ok {
// ImageContent returned from tool is base64-encoded
imageDataRaw, err := base64.StdEncoding.DecodeString(image.Data)
if err != nil {
continue
}
imageContent = append(imageContent, api.ImageData(imageDataRaw))
}
}
if block.Type == "tool_result" {
content = block.Text
break
Expand All @@ -86,6 +100,7 @@ func (p *Provider) CreateMessage(
ollamaMsg := api.Message{
Role: "tool",
Content: content,
Images: imageContent,
}
ollamaMessages = append(ollamaMessages, ollamaMsg)
continue
Expand Down