载入中...
搜索中...
未找到
McpServer.hpp
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
4
5#include <atomic>
6#include <cstdint>
7#include <iostream>
8#include <istream>
9#include <memory>
10#include <mutex>
11#include <ostream>
12#include <string>
13#include <thread>
14#include <vector>
15
16namespace Poco::Net {
17class ServerSocket;
18class StreamSocket;
19}
20
21namespace eve::dev {
22
36public:
37 static McpServer& instance();
38
39 McpServer(const McpServer&) = delete;
40 McpServer& operator=(const McpServer&) = delete;
41
42 enum class Transport { None, Tcp, Stdio };
43
45 int listen(uint16_t port);
53 bool listenStdio(std::istream& in = std::cin, std::ostream& out = std::cout);
54 void stop();
55 bool isListening() const { return listening_.load(); }
56 int port() const { return port_.load(); }
57 bool hasClient() const { return hasClient_.load(); }
58 Transport transport() const { return transport_.load(); }
60 bool stdinClosed() const { return stdinClosed_.load(); }
61
63 void poll();
64
66 void setGameRoot(std::string root);
67 const std::string& gameRoot() const { return gameRoot_; }
68
69private:
70 // Immortal<McpServer> constructs the singleton (devtools/Immortal.hpp).
71 template <typename> friend struct Immortal;
72 McpServer();
73 ~McpServer();
74
75 void acceptNonBlocking();
76 void readAndDispatch();
77 bool sendLine(const std::string& json);
78 void handleMessage(const std::string& json);
79
80 std::atomic<bool> listening_{false};
81 std::atomic<bool> hasClient_{false};
82 std::atomic<int> port_{0};
83 std::atomic<Transport> transport_{Transport::None};
84 std::atomic<bool> stdinClosed_{false};
85 std::mutex ioMu_;
86 std::unique_ptr<Poco::Net::ServerSocket> server_;
87 std::unique_ptr<Poco::Net::StreamSocket> client_;
88 std::istream* stdioIn_ = nullptr;
89 std::ostream* stdioOut_ = nullptr;
90 std::vector<std::string> stdioQueue_;
91 std::thread stdioReader_;
92 bool joinReader_ = false;
93 std::string recvBuf_;
94 std::string gameRoot_;
95 bool initialized_ = false;
96 std::string protocolVersion_ = "2025-06-18";
97};
98
99} // namespace eve::dev
#define EVENGINE_API
宿主(eve / libmain)导出宏;插件从进程导入同一批符号。
Definition Export.h:16
Embedded Model Context Protocol (MCP) server for AI-assisted game development.
Definition McpServer.hpp:35
McpServer(const McpServer &)=delete
bool stdinClosed() const
True once the stdio input reached EOF (host should exit).
Definition McpServer.hpp:60
const std::string & gameRoot() const
Definition McpServer.hpp:67
bool hasClient() const
Definition McpServer.hpp:57
bool isListening() const
Definition McpServer.hpp:55
Transport transport() const
Definition McpServer.hpp:58
McpServer & operator=(const McpServer &)=delete
Process-immortal singleton holder for DevTools objects.
Definition Immortal.hpp:19