7#include <imgui/imgui.h>
8#include <imgui_widgets/tooltips.h>
19auto format_timestamp(std::chrono::system_clock::time_point tp) -> std::string
21 const auto time = std::chrono::system_clock::to_time_t(tp);
24 localtime_s(&local_tm, &time);
26 localtime_r(&time, &local_tm);
28 std::ostringstream oss;
29 oss << std::put_time(&local_tm,
"%H:%M:%S");
50 show_request_ =
false;
52 ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size * 0.45f, ImGuiCond_Once);
60 if(ImGui::Begin(
name, &show_))
76 const auto endpoint = mcp.get_endpoint_url();
77 const auto health = mcp.get_health_url();
79 ImGui::TextUnformatted(
"Status");
92 ImGui::BeginTable(
"##mcp_info", 2, ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_NoSavedSettings);
93 ImGui::TableSetupColumn(
"label", ImGuiTableColumnFlags_WidthFixed, 110.0f);
94 ImGui::TableSetupColumn(
"value", ImGuiTableColumnFlags_WidthStretch);
96 ImGui::TableNextRow();
97 ImGui::TableSetColumnIndex(0);
98 ImGui::TextUnformatted(
"Endpoint");
99 ImGui::TableSetColumnIndex(1);
100 ImGui::TextUnformatted(endpoint.c_str());
104 ImGui::SetClipboardText(endpoint.c_str());
106 ImGui::SetItemTooltipEx(
"Copy MCP endpoint URL");
108 ImGui::TableNextRow();
109 ImGui::TableSetColumnIndex(0);
110 ImGui::TextUnformatted(
"Health");
111 ImGui::TableSetColumnIndex(1);
112 ImGui::TextUnformatted(health.c_str());
114 ImGui::TableNextRow();
115 ImGui::TableSetColumnIndex(0);
116 ImGui::TextUnformatted(
"Bind");
117 ImGui::TableSetColumnIndex(1);
118 ImGui::Text(
"%s:%d (localhost only)", mcp.get_host(), mcp.get_port());
120 ImGui::TableNextRow();
121 ImGui::TableSetColumnIndex(0);
122 ImGui::TextUnformatted(
"Tools");
123 ImGui::TableSetColumnIndex(1);
124 ImGui::Text(
"%zu registered", mcp.get_tool_count());
126 ImGui::TableNextRow();
127 ImGui::TableSetColumnIndex(0);
128 ImGui::TextUnformatted(
"Requests");
129 ImGui::TableSetColumnIndex(1);
130 ImGui::Text(
"%llu | tool calls: %llu | errors: %llu",
131 static_cast<unsigned long long>(mcp.get_request_count()),
132 static_cast<unsigned long long>(mcp.get_tool_call_count()),
133 static_cast<unsigned long long>(mcp.get_error_count()));
155 mcp.clear_activity();
158 ImGui::Checkbox(
"Auto-scroll", &auto_scroll_);
161 ImGui::TextUnformatted(
"Activity");
163 const auto activity = mcp.snapshot_activity();
164 ImGui::BeginChild(
"##mcp_activity", ImVec2(0, 0), ImGuiChildFlags_Borders, ImGuiWindowFlags_HorizontalScrollbar);
168 ImGui::TextDisabled(
"No MCP activity yet. Connect a client to %s", endpoint.c_str());
172 ImGuiListClipper clipper;
173 clipper.Begin(
static_cast<int>(activity.size()));
174 while(clipper.Step())
176 for(
int i = clipper.DisplayStart; i < clipper.DisplayEnd; ++i)
178 const auto&
entry = activity[
static_cast<size_t>(
i)];
181 const ImVec4
color =
entry.is_error ? ImVec4(0.95f, 0.45f, 0.4f, 1.0f)
182 : ImVec4(0.85f, 0.85f, 0.85f, 1.0f);
183 ImGui::TextColored(ImVec4(0.55f, 0.55f, 0.6f, 1.0f),
"%s", format_timestamp(
entry.timestamp).c_str());
185 ImGui::TextColored(ImVec4(0.45f, 0.7f, 0.95f, 1.0f),
"[%s]",
entry.category.c_str());
187 ImGui::TextColored(
color,
"%s",
entry.message.c_str());
193 if(auto_scroll_ && ImGui::GetScrollY() >= ImGui::GetScrollMaxY() - 1.0f)
195 ImGui::SetScrollHereY(1.0f);
auto is_running() const -> bool
void deinit(rtti::context &ctx)
void init(rtti::context &ctx)
mcp_panel(imgui_panels *parent)
void on_frame_ui_render(rtti::context &ctx, const char *name)
#define ICON_MDI_CONTENT_COPY
#define ICON_MDI_LAN_CONNECT
#define ICON_MDI_LAN_DISCONNECT
std::vector< size_t > parent_
std::vector< math::color > color