[Lldb-commits] [lldb] [lldb-mcp] Replace byte forwarding with a protocol-aware multiplexer (PR #208506)
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Thu Jul 9 14:50:20 PDT 2026
================
@@ -0,0 +1,170 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Multiplexer.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/JSON.h"
+
+using namespace llvm;
+using namespace lldb_protocol::mcp;
+using namespace lldb_mcp;
+
+namespace {
+
+/// Server identity reported to the client during initialization.
+/// @{
+constexpr llvm::StringLiteral kServerName = "lldb-mcp";
+constexpr llvm::StringLiteral kServerVersion = "0.1.0";
+/// @}
+
+/// Client-facing tool names.
+/// @{
+constexpr llvm::StringLiteral kToolCommand = "command";
+constexpr llvm::StringLiteral kToolSessionsList = "sessions_list";
+/// @}
+
+/// Backend tool names, as exposed by the LLDB MCP server.
+/// @{
+constexpr llvm::StringLiteral kBackendToolCommand = "command";
+constexpr llvm::StringLiteral kBackendToolDebuggerList = "debugger_list";
+/// @}
+
+} // namespace
+
+Multiplexer::Multiplexer(std::unique_ptr<MCPTransport> client_transport,
+ LogCallback log_callback)
+ : m_client_transport(std::move(client_transport)),
+ m_client_binder(std::make_unique<MCPBinder>(*m_client_transport)),
+ m_log_callback(std::move(log_callback)) {
+ m_client_binder->Bind<InitializeResult, InitializeParams>(
+ "initialize", &Multiplexer::HandleInitialize, this);
+ m_client_binder->Bind<ListToolsResult, void>(
+ "tools/list", &Multiplexer::HandleToolsList, this);
+ m_client_binder->BindAsync<CallToolResult, CallToolParams>(
+ "tools/call", &Multiplexer::HandleToolsCall, this);
+ m_client_binder->BindAsync<ListResourcesResult, void>(
+ "resources/list", &Multiplexer::HandleResourcesList, this);
+ m_client_binder->BindAsync<ReadResourceResult, ReadResourceParams>(
+ "resources/read", &Multiplexer::HandleResourcesRead, this);
+ m_client_binder->Bind<void>("notifications/initialized", [this]() {
+ Log("client initialization complete");
+ });
+}
+
+void Multiplexer::AddBackend(std::unique_ptr<Client> backend) {
+ m_backends.push_back(std::move(backend));
+}
+
+llvm::Error Multiplexer::Run() {
+ m_client_binder->OnDisconnect(&Multiplexer::HandleDisconnect, this);
----------------
bulbazord wrote:
Since this is supposed to run only _after_ you've added backends, could we add some kind of error or other runtime signal that would suggest we've done something in an unintended way?
https://github.com/llvm/llvm-project/pull/208506
More information about the lldb-commits
mailing list