mirror of
https://github.com/NohamR/Reclass.git
synced 2026-05-10 19:59:21 +00:00
Provider base address now stays in sync with tree base address when changed via ChangeBase command, fixing reads from arbitrary memory regions like KUSER_SHARED_DATA at 0x7FFE0000. ReadProcessMemory handles partial reads gracefully. Snapshot extent uses tree-based calculation instead of provider size to avoid oversized reads. MCP source.switch gains pid parameter for programmatic process attach. MCP server starts by default with logging and slow mode support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
72 lines
2.4 KiB
C++
72 lines
2.4 KiB
C++
#pragma once
|
|
#include "mainwindow.h"
|
|
#include <QObject>
|
|
#include <QLocalServer>
|
|
#include <QLocalSocket>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
#include <QJsonDocument>
|
|
#include <QByteArray>
|
|
|
|
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;
|
|
|
|
// 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);
|
|
|
|
// Helpers
|
|
QJsonObject makeTextResult(const QString& text, bool isError = false);
|
|
QString resolvePlaceholder(const QString& ref,
|
|
const QHash<QString, uint64_t>& placeholderMap);
|
|
|
|
// Smart tab resolution: tabIndex arg → activeTab → first tab → auto-create
|
|
MainWindow::TabState* resolveTab(const QJsonObject& args);
|
|
};
|
|
|
|
} // namespace rcx
|