Skip to content

Commit a068ed2

Browse files
authored
[lldb][mcp] Fix unix domain socket protocol server addresses (#146603)
When starting an MCP protocol server that uses unix sockets as the transport, a local `'[0.0.0.0]:0'` file is used instead of the supplied socket path, e.g: ``` (lldb) protocol-server start MCP accept:///tmp/some/path.sock MCP server started with connection listeners: unix-connect://[0.0.0.0]:0 (lldb) shell ls '[*' [0.0.0.0]:0 ``` This change makes it so that the URI path is used if the socket protocol is `ProtocolUnixDomain`: ``` (lldb) protocol-server start MCP accept:///tmp/some/path.sock MCP server started with connection listeners: unix-connect:///tmp/some/path.sock ```
1 parent f01017c commit a068ed2

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

lldb/source/Commands/CommandObjectProtocolServer.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ class CommandObjectProtocolServerStart : public CommandObjectParsed {
7575

7676
ProtocolServer::Connection connection;
7777
connection.protocol = protocol_and_mode->first;
78-
connection.name =
79-
formatv("[{0}]:{1}", uri->hostname.empty() ? "0.0.0.0" : uri->hostname,
80-
uri->port.value_or(0));
78+
if (connection.protocol == Socket::SocketProtocol::ProtocolUnixDomain)
79+
connection.name = uri->path;
80+
else
81+
connection.name = formatv(
82+
"[{0}]:{1}", uri->hostname.empty() ? "0.0.0.0" : uri->hostname,
83+
uri->port.value_or(0));
8184

8285
if (llvm::Error error = server->Start(connection)) {
8386
result.AppendErrorWithFormatv("{0}", llvm::fmt_consume(std::move(error)));
@@ -90,6 +93,7 @@ class CommandObjectProtocolServerStart : public CommandObjectParsed {
9093
result.AppendMessageWithFormatv(
9194
"{0} server started with connection listeners: {1}", protocol,
9295
address);
96+
result.SetStatus(eReturnStatusSuccessFinishNoResult);
9397
}
9498
}
9599
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
import tempfile
3+
import unittest
4+
5+
from lldbsuite.test.decorators import *
6+
from lldbsuite.test.lldbtest import *
7+
8+
# To be safe and portable, Unix domain socket paths should be kept at or below
9+
# 108 characters on Linux, and around 104 characters on macOS:
10+
MAX_SOCKET_PATH_LENGTH = 104
11+
12+
13+
class MCPUnixSocketCommandTestCase(TestBase):
14+
@skipIfWindows
15+
@no_debug_info_test
16+
def test_unix_socket(self):
17+
"""
18+
Test if we can start an MCP protocol-server accepting unix sockets
19+
"""
20+
21+
temp_directory = tempfile.TemporaryDirectory()
22+
socket_file = os.path.join(temp_directory.name, "mcp.sock")
23+
24+
if len(socket_file) >= MAX_SOCKET_PATH_LENGTH:
25+
self.skipTest(
26+
f"Socket path {socket_file} exceeds the {MAX_SOCKET_PATH_LENGTH} character limit"
27+
)
28+
29+
self.expect(
30+
f"protocol-server start MCP accept://{socket_file}",
31+
startstr="MCP server started with connection listeners:",
32+
substrs=[f"unix-connect://{socket_file}"],
33+
)

0 commit comments

Comments
 (0)