Skip to content

Commit ca0de7e

Browse files
authored
Merge pull request #65 from k255/feature/proxy-image-content
Basic support for ImageContent (png) in proxy mode
2 parents 6dbbc7e + 1ffa3a1 commit ca0de7e

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ This new format clearly shows what parameters each tool accepts, making it easie
581581
2. Start the proxy server, which implements the MCP protocol
582582
3. When a tool is called, parameters are passed as environment variables to the script/command
583583
4. The script/command's output is returned as the tool response
584+
5. If the script's output is a base64-encoded PNG image (prefixed with `data:image/png;base64,`), it is returned as an [ImageContent](https://modelcontextprotocol.io/specification/2025-06-18/server/prompts#image-content) object.
585+
584586

585587
#### Example Scripts and Commands
586588

@@ -599,6 +601,16 @@ result=$(($a + $b))
599601
echo "The sum of $a and $b is $result"
600602
```
601603

604+
**Generating a QR Code**
605+
606+
This example requires a tool like `qrencode` to be installed.
607+
608+
```bash
609+
# Register a tool to generate a QR code
610+
mcp proxy tool qrcode "Generates a QR code" "text:string" \
611+
-e 'echo -e "data:image/png;base64,$(qrencode -t png -o - "$text" | base64 -w 0)"'
612+
```
613+
602614
**Inline Command Example:**
603615

604616
```bash

cmd/mcptools/commands/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
var Version = "dev"
1212

1313
// getHomeDirectory returns the user's home directory
14-
// Tries HOME first, then falls back to USERPROFILE for Windows
14+
// Tries HOME first, then falls back to USERPROFILE for Windows.
1515
func getHomeDirectory() string {
1616
homeDir := os.Getenv("HOME")
1717
if homeDir == "" {

pkg/proxy/proxy.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,24 @@ func (s *Server) handleToolCall(params map[string]interface{}) (map[string]inter
501501
s.log(fmt.Sprintf("Script output: %s", output))
502502

503503
// Return the output in the correct format for the MCP protocol
504+
// Check if the output is a base64-encoded PNG image
505+
// https://modelcontextprotocol.io/specification/2025-06-18/server/prompts#image-content
506+
if strings.HasPrefix(output, "data:image/png;base64,") {
507+
base64Data := strings.TrimPrefix(output, "data:image/png;base64,")
508+
return map[string]interface{}{
509+
"content": []map[string]interface{}{
510+
{
511+
"type": "text",
512+
"text": "generated PNG image",
513+
},
514+
{
515+
"type": "image",
516+
"data": base64Data,
517+
"mimeType": "image/png",
518+
},
519+
},
520+
}, nil
521+
}
504522
return map[string]interface{}{
505523
"content": []map[string]interface{}{
506524
{

0 commit comments

Comments
 (0)