Owns a HTTP MCP server (using the SSE protocol).
More...
#include <MRMcp/MRMcp.h>
|
| using | ToolFunc = std::function<nlohmann::json( const nlohmann::json& args )> |
| | Those functions are allowed to throw, that's how you report errors to the MCP.
|
| using | ToolValidator = std::function<Expected<void>( const std::string& toolId )> |
Owns a HTTP MCP server (using the SSE protocol).
◆ ToolFunc
Those functions are allowed to throw, that's how you report errors to the MCP.
◆ ToolValidator
Optional predicate consulted before every tool dispatch, given the tool's id. Return {} to allow; return unexpected("reason") to block — the reason surfaces to the MCP client as the tool-call error. Evaluated per call, so changes (e.g. user sign-in) take effect immediately.
◆ Server() [1/2]
| MRMCP_API MR::Mcp::Server::Server |
( |
| ) |
|
◆ Server() [2/2]
| MRMCP_API MR::Mcp::Server::Server |
( |
Server && | | ) |
|
◆ ~Server()
| MRMCP_API MR::Mcp::Server::~Server |
( |
| ) |
|
◆ addTool()
| MRMCP_API bool MR::Mcp::Server::addTool |
( |
std::string | id, |
|
|
std::string | name, |
|
|
std::string | desc, |
|
|
Schema::Base | inputSchema, |
|
|
Schema::Base | outputSchema, |
|
|
ToolFunc | func ) |
Registers a new tool.
- Parameters
-
| id | An arbitrary function name, e.g. foo.bar. |
| name | A human/ai-readable name. |
| desc | A human/ai-readable explanation of what the tool does. |
| inputSchema | Describes the arguments. Normally it should be Schema::Object{} with some fields added. |
| outputSchema | Describes the returned JSON. Fails if the tool with this id already exists. Must be called early, before setRunning(true) is called for the first time, otherwise fails. Returns true on success. Asserts when returning false, so you don't have to check the return value. NOTE: Consult docs/testing_mcp.md for how to test your tool. |
◆ dumpToolsAsJson()
| MRMCP_API nlohmann::json MR::Mcp::Server::dumpToolsAsJson |
( |
| ) |
const |
|
nodiscard |
Returns the list of currently-registered tools as a JSON array of MCP tool entries (name, optional title/description, inputSchema, outputSchema). Suitable for splicing into a tools/list response or persisting to a cache file.
◆ getParams()
| MRMCP_API const Params & MR::Mcp::Server::getParams |
( |
| ) |
const |
|
nodiscard |
◆ isRunning()
| MRMCP_API bool MR::Mcp::Server::isRunning |
( |
| ) |
const |
|
nodiscard |
◆ operator=()
◆ saveToolsCache()
| MRMCP_API Expected< void > MR::Mcp::Server::saveToolsCache |
( |
const std::filesystem::path & | path | ) |
const |
Atomically writes { "tools": dumpToolsAsJson() } to path, creating parent directories as needed. Returns an error message on I/O failure.
◆ setParams()
| MRMCP_API void MR::Mcp::Server::setParams |
( |
Params | params | ) |
|
This restarts the server if necessary.
◆ setRunning()
| MRMCP_API bool MR::Mcp::Server::setRunning |
( |
bool | enable | ) |
|
Returns true on success, including if the server is already running and you're trying to start it again. Stopping always returns true.
◆ setToolValidator()
| MRMCP_API void MR::Mcp::Server::setToolValidator |
( |
ToolValidator | validator | ) |
|
◆ shutdown()
| MRMCP_API void MR::Mcp::Server::shutdown |
( |
| ) |
|
Tears down the running asio server (if any) and clears all registered tools. Use before unloading DLLs whose translation units called addTool — their captured std::function deleters dangle once those DLLs are unmapped, so a later ~Server would segfault. Idempotent. Safe to call when nothing was registered.
The documentation for this class was generated from the following file: