Files
archived-Reclass/src/mcp/mcp_bridge.h
IChooseYou 483f87cfbd feat: type hints green [bracketed] notation, workspace cleanup, unique naming
- Type inference hints now show value-first with bracketed type in comment
  green: "0x7ff718570000 [ptr64]", "6, 16 [int32_t×2]"
- Raise hint threshold to strong-only (score >= 75%)
- Remove Bool inference, widen Int16 range to ±16384
- Workspace: remove dead WorkspaceProxy, fix null deref, debounce search,
  cache icons, add pinning support
- Unique naming: UnnamedClass0/UnnamedEnum1 with global counter
- Footer buttons: +10h +100h +1000h replacing +1024
- MCP: project lifecycle API, snapshot provider fix
2026-03-09 10:39:22 -06:00

78 lines
2.7 KiB
C++

#pragma once
#include "mainwindow.h"
#include <QObject>
#include <QLocalServer>
#include <QLocalSocket>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QByteArray>
#include <QTimer>
namespace rcx {
class McpBridge : public QObject {
Q_OBJECT
public:
explicit McpBridge(MainWindow* mainWindow, QObject* parent = nullptr);
~McpBridge() override;
void start();
void stop();
bool isRunning() const { return m_server != nullptr; }
bool slowMode() const { return m_slowMode; }
void setSlowMode(bool v) { m_slowMode = v; }
// Call from controller refresh / data change to notify MCP clients
void notifyTreeChanged();
void notifyDataChanged();
private:
MainWindow* m_mainWindow;
QLocalServer* m_server = nullptr;
QLocalSocket* m_client = nullptr; // single client for v1
QByteArray m_readBuffer;
bool m_initialized = false;
bool m_slowMode = false;
QTimer* m_notifyTimer = nullptr;
// JSON-RPC plumbing
void onNewConnection();
void onReadyRead();
void onDisconnected();
void processLine(const QByteArray& line);
void sendJson(const QJsonObject& obj);
QJsonObject okReply(const QJsonValue& id, const QJsonObject& result);
QJsonObject errReply(const QJsonValue& id, int code, const QString& msg);
void sendNotification(const QString& method, const QJsonObject& params = {});
// MCP method handlers
QJsonObject handleInitialize(const QJsonValue& id, const QJsonObject& params);
QJsonObject handleToolsList(const QJsonValue& id);
QJsonObject handleToolsCall(const QJsonValue& id, const QJsonObject& params);
// Tool implementations
QJsonObject toolProjectState(const QJsonObject& args);
QJsonObject toolTreeApply(const QJsonObject& args);
QJsonObject toolSourceSwitch(const QJsonObject& args);
QJsonObject toolHexRead(const QJsonObject& args);
QJsonObject toolHexWrite(const QJsonObject& args);
QJsonObject toolStatusSet(const QJsonObject& args);
QJsonObject toolUiAction(const QJsonObject& args);
QJsonObject toolTreeSearch(const QJsonObject& args);
QJsonObject toolNodeHistory(const QJsonObject& args);
QJsonObject toolProcessInfo(const QJsonObject& args);
// Helpers
QJsonObject makeTextResult(const QString& text, bool isError = false);
QString resolvePlaceholder(const QString& ref,
const QHash<QString, uint64_t>& placeholderMap,
bool* ok = nullptr);
// Smart tab resolution: tabIndex arg → activeTab → first tab → auto-create
MainWindow::TabState* resolveTab(const QJsonObject& args, int* resolvedIndex = nullptr);
};
} // namespace rcx