From 8ffabe86dd320880736c691e45e71611988ceb38 Mon Sep 17 00:00:00 2001 From: Alexandre Perez Date: Tue, 1 Jul 2025 14:19:45 -0700 Subject: [PATCH 1/3] [lldb][mcp] Fix unix domain socket protocol server addresses --- lldb/source/Commands/CommandObjectProtocolServer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lldb/source/Commands/CommandObjectProtocolServer.cpp b/lldb/source/Commands/CommandObjectProtocolServer.cpp index 55bd42ed1a533..4cafd2266e235 100644 --- a/lldb/source/Commands/CommandObjectProtocolServer.cpp +++ b/lldb/source/Commands/CommandObjectProtocolServer.cpp @@ -75,9 +75,12 @@ class CommandObjectProtocolServerStart : public CommandObjectParsed { ProtocolServer::Connection connection; connection.protocol = protocol_and_mode->first; - connection.name = - formatv("[{0}]:{1}", uri->hostname.empty() ? "0.0.0.0" : uri->hostname, - uri->port.value_or(0)); + if (connection.protocol == Socket::SocketProtocol::ProtocolUnixDomain) + connection.name = uri->path; + else + connection.name = formatv( + "[{0}]:{1}", uri->hostname.empty() ? "0.0.0.0" : uri->hostname, + uri->port.value_or(0)); if (llvm::Error error = server->Start(connection)) { result.AppendErrorWithFormatv("{0}", llvm::fmt_consume(std::move(error))); From 42150df6829d641756aa5bfc060ac579447c0391 Mon Sep 17 00:00:00 2001 From: Alexandre Perez Date: Wed, 2 Jul 2025 10:14:09 -0700 Subject: [PATCH 2/3] Add test --- .../Commands/CommandObjectProtocolServer.cpp | 1 + .../commands/protocol/TestMCPUnixSocket.py | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 lldb/test/API/commands/protocol/TestMCPUnixSocket.py diff --git a/lldb/source/Commands/CommandObjectProtocolServer.cpp b/lldb/source/Commands/CommandObjectProtocolServer.cpp index 4cafd2266e235..f11e27f01c8a8 100644 --- a/lldb/source/Commands/CommandObjectProtocolServer.cpp +++ b/lldb/source/Commands/CommandObjectProtocolServer.cpp @@ -93,6 +93,7 @@ class CommandObjectProtocolServerStart : public CommandObjectParsed { result.AppendMessageWithFormatv( "{0} server started with connection listeners: {1}", protocol, address); + result.SetStatus(eReturnStatusSuccessFinishNoResult); } } }; diff --git a/lldb/test/API/commands/protocol/TestMCPUnixSocket.py b/lldb/test/API/commands/protocol/TestMCPUnixSocket.py new file mode 100644 index 0000000000000..6f5405b82666d --- /dev/null +++ b/lldb/test/API/commands/protocol/TestMCPUnixSocket.py @@ -0,0 +1,23 @@ +import os +import tempfile + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class MCPUnixSocketCommandTestCase(TestBase): + @skipIfWindows + @no_debug_info_test + def test_unix_socket(self): + """ + Test if we can start an MCP protocol-server accepting unix sockets + """ + + temp_directory = tempfile.TemporaryDirectory() + socket_file = os.path.join(temp_directory.name, "mcp.sock") + + self.expect( + f"protocol-server start MCP accept://{socket_file}", + startstr="MCP server started with connection listeners:", + substrs=[f"unix-connect://{socket_file}"], + ) From 93a27307c78b6c49db630aec4080c02447e9b55e Mon Sep 17 00:00:00 2001 From: Alexandre Perez Date: Wed, 2 Jul 2025 10:42:50 -0700 Subject: [PATCH 3/3] Make sure we don't test with sockets over 104 chars --- lldb/test/API/commands/protocol/TestMCPUnixSocket.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lldb/test/API/commands/protocol/TestMCPUnixSocket.py b/lldb/test/API/commands/protocol/TestMCPUnixSocket.py index 6f5405b82666d..de0aec040695f 100644 --- a/lldb/test/API/commands/protocol/TestMCPUnixSocket.py +++ b/lldb/test/API/commands/protocol/TestMCPUnixSocket.py @@ -1,9 +1,14 @@ import os import tempfile +import unittest from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * +# To be safe and portable, Unix domain socket paths should be kept at or below +# 108 characters on Linux, and around 104 characters on macOS: +MAX_SOCKET_PATH_LENGTH = 104 + class MCPUnixSocketCommandTestCase(TestBase): @skipIfWindows @@ -16,6 +21,11 @@ def test_unix_socket(self): temp_directory = tempfile.TemporaryDirectory() socket_file = os.path.join(temp_directory.name, "mcp.sock") + if len(socket_file) >= MAX_SOCKET_PATH_LENGTH: + self.skipTest( + f"Socket path {socket_file} exceeds the {MAX_SOCKET_PATH_LENGTH} character limit" + ) + self.expect( f"protocol-server start MCP accept://{socket_file}", startstr="MCP server started with connection listeners:",