7fa204d755
scripts/build-bundle.sh cross-builds whatsapp-mcp + whatsapp-bridge (stripped, darwin/arm64) into the Neuron app's bundled connector-servers dir. tools.go: default API_BASE_URL to http://localhost:8080/api (was a hardcoded LAN IP) so the MCP finds the connector-launched loopback bridge. Validated: stripped bundled whatsapp-mcp exposes 14 tools incl send_message. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package helpers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log/slog"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
var apiBaseURL = readApiBaseURL()
|
|
|
|
func readApiBaseURL() string {
|
|
// Default to the local bridge. The connector launches the bridge on loopback :8080; a dev/LAN
|
|
// override can still be supplied via API_BASE_URL.
|
|
if v := ReadEnv("API_BASE_URL", "http://localhost:8080/api"); v != "" {
|
|
return v
|
|
}
|
|
const fallback = "http://localhost:8080/api"
|
|
slog.Warn("api_base_url not set, using default", "fallback", fallback)
|
|
return fallback
|
|
}
|
|
|
|
const apiTimeout = 25 * time.Second
|
|
|
|
// OkResult return proper ok result for mcp tool
|
|
func OkResult(v any) *mcp.CallToolResult {
|
|
b, err := json.Marshal(v)
|
|
if err != nil {
|
|
return &mcp.CallToolResult{
|
|
IsError: true,
|
|
Content: []mcp.Content{
|
|
&mcp.TextContent{Text: "Failed to encode JSON: " + err.Error()},
|
|
},
|
|
}
|
|
}
|
|
|
|
return &mcp.CallToolResult{
|
|
IsError: false,
|
|
Content: []mcp.Content{
|
|
&mcp.TextContent{Text: string(b)},
|
|
},
|
|
}
|
|
}
|
|
|
|
// ErrResult return error result for mcp tool
|
|
func ErrResult(msg string) *mcp.CallToolResult {
|
|
return &mcp.CallToolResult{
|
|
IsError: true,
|
|
Content: []mcp.Content{
|
|
&mcp.TextContent{Text: msg},
|
|
},
|
|
}
|
|
}
|
|
|
|
// ReadEnv read return value for an env
|
|
func ReadEnv(key, fallback string) string {
|
|
if value, ok := os.LookupEnv(key); ok {
|
|
return value
|
|
}
|
|
return fallback
|
|
}
|