载入中...
搜索中...
未找到
McpToolFamilies.hpp
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
4
5#include <Poco/JSON/Object.h>
6#include <map>
7#include <optional>
8#include <string>
9#include <string_view>
10#include <type_traits>
11#include <utility>
12#include <vector>
13
14namespace eve::dev {
15class McpServer;
16
19
22 std::string (*call)(McpServer&, std::string_view, Poco::JSON::Object::Ptr);
24};
25
28 std::string_view id;
29 std::string_view (*schemas)();
31};
32
41public:
48 explicit McpToolFamilyCatalog(const std::vector<McpToolFamily>& families);
50 [[nodiscard]] std::string_view schemas() const noexcept { return schemas_; }
52 [[nodiscard]] std::optional<McpToolRoute> find(std::string_view name) const;
53
54private:
55 std::string schemas_;
56 std::map<std::string, McpToolRoute, std::less<>> routes_;
57};
58
66[[nodiscard]] EVENGINE_API_FOUNDATION const McpToolFamilyCatalog& compiledMcpToolCatalog();
67
71[[nodiscard]] std::vector<McpToolFamily> compiledMcpToolFamilies();
72
73namespace detail {
75template <auto Handler>
76std::string invokeMcpFamily(McpServer& server, std::string_view name, Poco::JSON::Object::Ptr args) {
77 if constexpr (std::is_invocable_v<decltype(Handler), McpServer&, std::string_view, Poco::JSON::Object::Ptr>) {
78 return Handler(server, name, std::move(args));
79 } else {
80 return Handler(name, std::move(args));
81 }
82}
83} // namespace detail
84
86#define EVE_MCP_TOOL_FAMILY(Id, Schemas, Handler, Payload) \
87 McpToolFamily eveMcpToolFamily_##Id() { \
88 return {#Id, &Schemas, {&detail::invokeMcpFamily<&Handler>, McpToolPayload::Payload}}; \
89 }
90} // namespace eve::dev
std::string name
Definition ECS.cpp:154
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
int detail
Embedded Model Context Protocol (MCP) server for AI-assisted game development.
Definition McpServer.hpp:35
Immutable schema/route catalogue built transactionally from compiled families. @ownership Owns schema...
std::string_view schemas() const noexcept
Borrow immutable comma-separated schemas until this catalogue is destroyed.
McpToolPayload
Wire shape returned by a compiled tool provider.
std::vector< McpToolFamily > compiledMcpToolFamilies()
Generated build input; returns binary-owned descriptors for exactly the compiled providers....
const McpToolFamilyCatalog & compiledMcpToolCatalog()
Build the process-immortal compiled catalogue once, then borrow it until exit. @lifetime Survives sta...
Process-lifetime compiled family descriptor, generated from its provider declaration.
std::string_view(* schemas)()
Owned route value; callbacks belong to the compiled binary, never a reloadable plugin.
std::string(* call)(McpServer &, std::string_view, Poco::JSON::Object::Ptr)