Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ This new format clearly shows what parameters each tool accepts, making it easie
2. Start the proxy server, which implements the MCP protocol
3. When a tool is called, parameters are passed as environment variables to the script/command
4. The script/command's output is returned as the tool response
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.


#### Example Scripts and Commands

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

**Generating a QR Code**

This example requires a tool like `qrencode` to be installed.

```bash
# Register a tool to generate a QR code
mcp proxy tool qrcode "Generates a QR code" "text:string" \
-e 'echo -e "data:image/png;base64,$(qrencode -t png -o - "$text" | base64 -w 0)"'
```

**Inline Command Example:**

```bash
Expand Down
2 changes: 1 addition & 1 deletion cmd/mcptools/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var Version = "dev"

// getHomeDirectory returns the user's home directory
// Tries HOME first, then falls back to USERPROFILE for Windows
// Tries HOME first, then falls back to USERPROFILE for Windows.
func getHomeDirectory() string {
homeDir := os.Getenv("HOME")
if homeDir == "" {
Expand Down
18 changes: 18 additions & 0 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,24 @@ func (s *Server) handleToolCall(params map[string]interface{}) (map[string]inter
s.log(fmt.Sprintf("Script output: %s", output))

// Return the output in the correct format for the MCP protocol
// Check if the output is a base64-encoded PNG image
// https://modelcontextprotocol.io/specification/2025-06-18/server/prompts#image-content
if strings.HasPrefix(output, "data:image/png;base64,") {
base64Data := strings.TrimPrefix(output, "data:image/png;base64,")
return map[string]interface{}{
"content": []map[string]interface{}{
{
"type": "text",
"text": "generated PNG image",
},
{
"type": "image",
"data": base64Data,
"mimeType": "image/png",
},
},
}, nil
}
return map[string]interface{}{
"content": []map[string]interface{}{
{
Expand Down