// __DEPRECATED__ using python server instead, but keep this as reference for C++ implementation
#include "httplib.h"
#include "mcp_server.h"
#include "mcp_tool.h"
mcp::json compliler_explore_handler(const mcp::json& params, const std::string& session_id)
{
std::string code = params["code"];
auto options = params.value<std::string>("options", "") + " /c";
auto payload = mcp::json({{"source", code}, {"options", {{"UserArguments", options}}}}).dump();
httplib::Client client("https://godbolt.org");
auto response = cli.Post("/api/compiler/vcpp_v19_latest_x64/compile", payload, "application/json");
return {{{"type", "text"}, {"text", response->body}}};
}
int main()
{
mcp::server server("localhost", 8080, "CPPCon MCP Server", "1.0.0");
mcp::json capabilities = {
{"tools", mcp::json::object()},
};
server.set_capabilities(capabilities);
mcp::tool compiler_explore_tool
= mcp::tool_builder("get_assembly")
.with_description("Provide the assembly that MSVC would produce for a C++ funtion")
.with_string_param("code", "The C++ code to compile")
.with_string_param("options", "Options to pass to the compiler, like /O2 or /Od", false)
.build();
server.register_tool(compiler_explore_tool, compiler_explore_handler);
server.start(true);
return 0;
}
// run below to start the client
// npx @modelcontextprotocol/inspector