Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

fix(mcp): persist HTTP toggle + port on change, gate HTTP listen on flag

DangHuynhdb99a95bf0f0
diff --git a/windows/Gridex/MCPPage.cpp b/windows/Gridex/MCPPage.cpp
index 1343747..6bbf3f0 100644
--- a/windows/Gridex/MCPPage.cpp
+++ b/windows/Gridex/MCPPage.cpp
@@ -331,8 +331,50 @@ namespace winrt::Gridex::implementation
winrt::Windows::Foundation::IInspectable const&,
winrt::Microsoft::UI::Xaml::RoutedEventArgs const&)
{
- HttpPortRow().Visibility(HttpToggle().IsOn()
+ const bool on = HttpToggle().IsOn();
+ HttpPortRow().Visibility(on
? mux::Visibility::Visible : mux::Visibility::Collapsed);
+
+ // Persist immediately — toggle sits on the Overview tab,
+ // where there is no Save button. Previously the flag only
+ // lived in the control state and got lost on navigation.
+ auto s = DBModels::AppSettings::Load();
+ if (s.mcpHttpEnabled != on)
+ {
+ s.mcpHttpEnabled = on;
+ s.Save();
+ }
+
+ // Hint to restart the server if the flag changed while
+ // something is already running — the HTTP listener won't
+ // hot-swap otherwise.
+ if (auto srv = DBModels::MCPServerHost::instance();
+ srv && srv->isRunning())
+ {
+ if (auto sub = RunningSubtitle())
+ sub.Text(L"Restart the server to apply the HTTP toggle.");
+ }
+ }
+
+ void MCPPage::HttpPortBox_ValueChanged(
+ winrt::Microsoft::UI::Xaml::Controls::NumberBox const& sender,
+ winrt::Microsoft::UI::Xaml::Controls::NumberBoxValueChangedEventArgs const&)
+ {
+ const double v = sender.Value();
+ if (std::isnan(v) || v < 1024 || v > 65535) return;
+ const int port = static_cast<int>(v);
+ auto s = DBModels::AppSettings::Load();
+ if (s.mcpHttpPort != port)
+ {
+ s.mcpHttpPort = port;
+ s.Save();
+ if (auto srv = DBModels::MCPServerHost::instance();
+ srv && srv->isRunning())
+ {
+ if (auto sub = RunningSubtitle())
+ sub.Text(L"Restart the server to apply the new HTTP port.");
+ }
+ }
}
void MCPPage::CopyConfig_Click(
diff --git a/windows/Gridex/MCPPage.h b/windows/Gridex/MCPPage.h
index 5402417..5644b71 100644
--- a/windows/Gridex/MCPPage.h
+++ b/windows/Gridex/MCPPage.h
@@ -25,6 +25,12 @@ namespace winrt::Gridex::implementation
winrt::Windows::Foundation::IInspectable const& sender,
winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
+ // Port persists on edit (auto-save) so the Overview tab
+ // doesn't need a dedicated Save button for this field.
+ void HttpPortBox_ValueChanged(
+ winrt::Microsoft::UI::Xaml::Controls::NumberBox const& sender,
+ winrt::Microsoft::UI::Xaml::Controls::NumberBoxValueChangedEventArgs const& args);
+
void CopyConfig_Click(
winrt::Windows::Foundation::IInspectable const& sender,
winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
diff --git a/windows/Gridex/MCPPage.xaml b/windows/Gridex/MCPPage.xaml
index 8f8c1c3..4ee5418 100644
--- a/windows/Gridex/MCPPage.xaml
+++ b/windows/Gridex/MCPPage.xaml
@@ -207,7 +207,8 @@
<NumberBox x:Name="HttpPortBox"
Grid.Column="1"
Minimum="1024" Maximum="65535"
- Value="3333" Width="120" />
+ Value="3333" Width="120"
+ ValueChanged="HttpPortBox_ValueChanged" />
</Grid>
</StackPanel>
</Border>
diff --git a/windows/Gridex/Services/MCP/MCPServer.cpp b/windows/Gridex/Services/MCP/MCPServer.cpp
index 5795b5c..aa1652c 100644
--- a/windows/Gridex/Services/MCP/MCPServer.cpp
+++ b/windows/Gridex/Services/MCP/MCPServer.cpp
@@ -79,13 +79,12 @@ namespace DBModels
stdio_.setRequestHandler([this](const JSONRPCRequest& r){ handleRequest(r); });
stdio_.start();
}
- else
+ else if (settings_.mcpHttpEnabled)
{
- // HttpOnly: always start HTTP on localhost. If the user
- // flipped `mcpHttpEnabled` in settings the port comes
- // from there; otherwise fall back to the default 3333.
- // Remote binding (`0.0.0.0`) only when `allowRemoteHTTP`.
- const int port = settings_.mcpHttpEnabled
+ // HttpOnly mode + toggle is on → bind the HTTP listener.
+ // Defaults: 127.0.0.1:<mcpHttpPort>. Remote binding
+ // (0.0.0.0) only when allowRemoteHTTP is also on.
+ const int port = settings_.mcpHttpPort > 0
? settings_.mcpHttpPort : 3333;
const std::string host = settings_.mcpAllowRemoteHTTP
? "0.0.0.0" : "127.0.0.1";
@@ -94,19 +93,25 @@ namespace DBModels
[this](const JSONRPCRequest& r) -> JSONRPCResponse {
// HTTP is synchronous — we build the response
// inline instead of routing through sendResponse.
- // Reuse the same dispatch branches handleRequest
- // uses by returning its output directly.
if (r.method == "initialize") return handleInitialize(r);
if (r.method == "tools/list") return handleToolsList(r);
if (r.method == "tools/call") return handleToolsCall(r);
+ if (r.method == "prompts/list") return JSONRPCResponse::ok(r.id, nlohmann::json{{"prompts", nlohmann::json::array()}});
+ if (r.method == "resources/list") return JSONRPCResponse::ok(r.id, nlohmann::json{{"resources", nlohmann::json::array()}});
+ if (r.method == "resources/templates/list") return JSONRPCResponse::ok(r.id, nlohmann::json{{"resourceTemplates", nlohmann::json::array()}});
if (r.method == "ping")
return JSONRPCResponse::ok(r.id, nlohmann::json{{"pong", true}});
if (r.method == "shutdown") { stop(); return JSONRPCResponse::ok(r.id, nullptr); }
- if (r.method == "initialized") return JSONRPCResponse::ok(r.id, nullptr);
+ if (r.method == "initialized" || r.method == "notifications/initialized")
+ return JSONRPCResponse::ok(r.id, nullptr);
return JSONRPCResponse::fail(r.id, JSONRPCError::methodNotFound());
});
http_.start(host, port);
}
+ // else: HttpOnly mode but HTTP toggle is off — server runs
+ // "warm" (tools registered, audit log primed) without
+ // binding any socket. Flip the toggle on + Start again to
+ // actually listen.
}
void MCPServer::stop()