fix(mcp): add default address and warning for TCP transport (#332)
* fix(io): apply gofmt formatting to local/client.go Remove extra blank line before closing parenthesis in import block. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(mcp): add default address and warning for TCP transport NewTCPTransport now properly handles edge cases: - Sets default address to 127.0.0.1:9100 when empty string is passed - Prints security warning to stderr when binding to 0.0.0.0 (all interfaces) This fixes TestNewTCPTransport_Defaults and TestNewTCPTransport_Warning tests that were causing CI failures in PRs #298 and #313. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <developers@lethean.io> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
bb74f87e30
commit
d34053e21d
2 changed files with 17 additions and 1 deletions
|
|
@ -7,7 +7,6 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
)
|
||||
|
||||
// Medium is a local filesystem storage backend.
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ package mcp
|
|||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"github.com/modelcontextprotocol/go-sdk/jsonrpc"
|
||||
|
|
@ -20,9 +23,23 @@ type TCPTransport struct {
|
|||
listener net.Listener
|
||||
}
|
||||
|
||||
// DefaultTCPAddr is the default address for the MCP TCP transport.
|
||||
const DefaultTCPAddr = "127.0.0.1:9100"
|
||||
|
||||
// NewTCPTransport creates a new TCP transport listener.
|
||||
// It listens on the provided address (e.g. "localhost:9100").
|
||||
// If addr is empty, it defaults to 127.0.0.1:9100.
|
||||
// A warning is printed to stderr if binding to 0.0.0.0 (all interfaces).
|
||||
func NewTCPTransport(addr string) (*TCPTransport, error) {
|
||||
if addr == "" {
|
||||
addr = DefaultTCPAddr
|
||||
}
|
||||
|
||||
// Warn if binding to all interfaces
|
||||
if strings.HasPrefix(addr, "0.0.0.0:") {
|
||||
fmt.Fprintln(os.Stderr, "WARNING: MCP TCP server binding to all interfaces (0.0.0.0). This may expose the service to the network.")
|
||||
}
|
||||
|
||||
listener, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue