// McpServer.h: embedded MCP (Model Context Protocol) server for BKEmu.
//
// Runs an HTTP listener bound to 127.0.0.1 on a background thread for the whole
// lifetime of the application. AI clients connect to the already-running
// emulator and call tools (registers, memory, breakpoints, ...). Every tool
// runs its emulator access on the UI thread via mcp::Run (see McpMarshal.h).
//
// This header is intentionally free of httplib / nlohmann-json / <windows.h>
// (PIMPL) so it can be included from MFC sources without winsock include-order
// problems. The implementation file disables the precompiled header so it can
// include <winsock2.h> (via httplib) before <windows.h>.
//
// See mcp/README.md for the overall design.

#pragma once

#include <memory>

class CMcpServer
{
	public:
		CMcpServer();
		~CMcpServer();

		// Starts the listener on 127.0.0.1:port. Returns false if it is already
		// running or the port could not be bound.
		bool            Start(unsigned short port);

		// Stops the listener and releases the port. Safe to call when not running.
		void            Stop();

		bool            IsRunning() const;
		unsigned short  GetPort() const;

	private:
		struct Impl;
		std::unique_ptr<Impl> m_pImpl;
};

// Single application-wide instance.
extern CMcpServer g_McpServer;
