7#include <nlohmann/json.hpp>
29 [[nodiscard]]
const nlohmann::json&
asJson() const & {
return json; }
30 [[nodiscard]] nlohmann::json&&
asJson() && {
return std::move(
json ); }
58 {
"type",
"boolean" },
69 {
"items", std::move( elemSchema ).asJson() },
81 {
"properties", nlohmann::json::object() },
82 {
"required", nlohmann::json::array() },
89 json.at(
"required").push_back( name );
96 json.at(
"properties" ).push_back( nlohmann::json::object_t::value_type( std::move( name ), std::move( schema ).
asJson() ) );
103 addMember( std::move( name ), std::move( schema ) );
104 return std::move( *
this );
110 return std::move( *
this );
137 using ToolFunc = std::function<nlohmann::json(
const nlohmann::json& args )>;
180 using ToolValidator = std::function<Expected<void>(
const std::string& toolId )>;
187 std::unique_ptr<State> state_;
Owns a HTTP MCP server (using the SSE protocol).
Definition MRMcp.h:117
MRMCP_API bool addTool(std::string id, std::string name, std::string desc, Schema::Base inputSchema, Schema::Base outputSchema, ToolFunc func)
std::function< nlohmann::json(const nlohmann::json &args)> ToolFunc
Those functions are allowed to throw, that's how you report errors to the MCP.
Definition MRMcp.h:137
MRMCP_API void setParams(Params params)
This restarts the server if necessary.
MRMCP_API Server(Server &&)
std::function< Expected< void >(const std::string &toolId)> ToolValidator
Definition MRMcp.h:180
MRMCP_API Expected< void > saveToolsCache(const std::filesystem::path &path) const
MRMCP_API Server & operator=(Server &&)
MRMCP_API const Params & getParams() const
MRMCP_API void shutdown()
MRMCP_API void setToolValidator(ToolValidator validator)
MRMCP_API nlohmann::json dumpToolsAsJson() const
MRMCP_API bool setRunning(bool enable)
MRMCP_API bool isRunning() const
tl::expected< T, E > Expected
Definition MRExpected.h:31
This is used to build json schemas.
Definition MRMcp.h:20
MRMCP_API Server & getDefaultServer()
The global instance of the MCP server.
Array(Base elemSchema)
Definition MRMcp.h:66
A common base class for the different schemas. Functions can accept this by value,...
Definition MRMcp.h:23
nlohmann::json && asJson() &&
Definition MRMcp.h:30
Base(nlohmann::json json)
Definition MRMcp.h:26
const nlohmann::json & asJson() const &
Definition MRMcp.h:29
nlohmann::json json
Definition MRMcp.h:25
Bool()
Definition MRMcp.h:56
Number()
Definition MRMcp.h:36
Object & addMemberOpt(std::string name, Base schema) &
Add optional member. Returns a reference to *this.
Definition MRMcp.h:94
Object && addMember(std::string name, Base schema) &&
Add required member. Returns a reference to *this.
Definition MRMcp.h:101
Object && addMemberOpt(std::string name, Base schema) &&
Add optional member. Returns a reference to *this.
Definition MRMcp.h:107
Object & addMember(std::string name, Base schema) &
Add required member. Returns a reference to *this.
Definition MRMcp.h:87
Object()
Definition MRMcp.h:78
String()
Definition MRMcp.h:46
friend bool operator==(const Params &, const Params &)=default
std::string address
You don't need to change this, unless you want to accept connections from the outside world.
Definition MRMcp.h:121
std::string name
A default string is set in the constructor.
Definition MRMcp.h:123
std::string version
A default string is set in the constructor.
Definition MRMcp.h:124
int port
Definition MRMcp.h:122