Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 67 additions & 4 deletions include/MCP_Endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ class MCP_JSONRPC_Resource : public httpserver::http_resource {
* @brief Create a JSON-RPC 2.0 success response
*
* @param result The result data to include
* @param id The request ID
* @param id The request ID (can be string, number, or null)
* @return JSON string representing the response
*/
std::string create_jsonrpc_response(
const std::string& result,
const std::string& id = "1"
const json& id = nullptr
);

/**
* @brief Create a JSON-RPC 2.0 error response
*
* @param code The error code (JSON-RPC standard or custom)
* @param message The error message
* @param id The request ID
* @param id The request ID (can be string, number, or null)
* @return JSON string representing the error response
*/
std::string create_jsonrpc_error(
int code,
const std::string& message,
const std::string& id = ""
const json& id = nullptr
);

/**
Expand Down Expand Up @@ -112,6 +112,24 @@ class MCP_JSONRPC_Resource : public httpserver::http_resource {
*/
json handle_tools_call(const json& req_json);

/**
* @brief Handle prompts/list method
*
* Returns an empty prompts array since ProxySQL doesn't support prompts.
*
* @return JSON with empty prompts array
*/
json handle_prompts_list();

/**
* @brief Handle resources/list method
*
* Returns an empty resources array since ProxySQL doesn't support resources.
*
* @return JSON with empty resources array
*/
json handle_resources_list();

public:
/**
* @brief Constructor for MCP_JSONRPC_Resource
Expand All @@ -127,6 +145,51 @@ class MCP_JSONRPC_Resource : public httpserver::http_resource {
*/
~MCP_JSONRPC_Resource();

/**
* @brief Handle GET requests
*
* Returns HTTP 405 Method Not Allowed for GET requests.
*
* According to the MCP specification 2025-06-18 (Streamable HTTP transport):
* "The server MUST either return Content-Type: text/event-stream in response to
* this HTTP GET, or else return HTTP 405 Method Not Allowed, indicating that
* the server does not offer an SSE stream at this endpoint."
*
* @param req The HTTP request
* @return HTTP 405 response with Allow: POST header
*/
const std::shared_ptr<httpserver::http_response> render_GET(
const httpserver::http_request& req
) override;

/**
* @brief Handle OPTIONS requests (CORS preflight)
*
* Returns CORS headers for OPTIONS preflight requests.
*
* @param req The HTTP request
* @return HTTP response with CORS headers
*/
const std::shared_ptr<httpserver::http_response> render_OPTIONS(
const httpserver::http_request& req
) override;

/**
* @brief Handle DELETE requests
*
* Returns HTTP 405 Method Not Allowed for DELETE requests.
*
* According to the MCP specification 2025-06-18 (Streamable HTTP transport):
* "The server MAY respond to this request with HTTP 405 Method Not Allowed,
* indicating that the server does not allow clients to terminate sessions."
*
* @param req The HTTP request
* @return HTTP 405 response with Allow header
*/
const std::shared_ptr<httpserver::http_response> render_DELETE(
const httpserver::http_request& req
) override;

/**
* @brief Handle POST requests
*
Expand Down
9 changes: 5 additions & 4 deletions include/MCP_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class MCP_Threads_Handler
*/
struct {
bool mcp_enabled; ///< Enable/disable MCP server
int mcp_port; ///< HTTPS port for MCP server (default: 6071)
int mcp_port; ///< HTTP/HTTPS port for MCP server (default: 6071)
bool mcp_use_ssl; ///< Enable/disable SSL/TLS (default: true)
char* mcp_config_endpoint_auth; ///< Authentication for /mcp/config endpoint
char* mcp_observe_endpoint_auth; ///< Authentication for /mcp/observe endpoint
char* mcp_query_endpoint_auth; ///< Authentication for /mcp/query endpoint
Expand All @@ -68,9 +69,9 @@ class MCP_Threads_Handler
} status_variables;

/**
* @brief Pointer to the HTTPS server instance
* @brief Pointer to the HTTP/HTTPS server instance
*
* This is managed by the MCP_Thread module and provides HTTPS
* This is managed by the MCP_Thread module and provides HTTP/HTTPS
* endpoints for MCP protocol communication.
*/
ProxySQL_MCP_Server* mcp_server;
Expand Down Expand Up @@ -138,7 +139,7 @@ class MCP_Threads_Handler
* @brief Initialize the MCP module
*
* Sets up the module with default configuration values and starts
* the HTTPS server if enabled. Must be called before using any
* the HTTP/HTTPS server if enabled. Must be called before using any
* other methods.
*/
void init();
Expand Down
27 changes: 22 additions & 5 deletions include/ProxySQL_MCP_Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ class MCP_Threads_Handler;
/**
* @brief ProxySQL MCP Server class
*
* This class wraps an HTTPS server using libhttpserver to provide
* MCP (Model Context Protocol) endpoints. It supports multiple
* This class wraps an HTTP/HTTPS server using libhttpserver to provide
* MCP (Model Context Protocol) endpoints. Supports both HTTP and HTTPS
* modes based on mcp_use_ssl configuration. It supports multiple
* MCP server endpoints with their own authentication.
*/
class ProxySQL_MCP_Server {
private:
std::unique_ptr<httpserver::webserver> ws;
int port;
bool use_ssl; // SSL mode the server was started with
pthread_t thread_id;

// Endpoint resources
Expand All @@ -36,7 +38,8 @@ class ProxySQL_MCP_Server {
/**
* @brief Constructor for ProxySQL_MCP_Server
*
* Creates a new HTTPS server instance on the specified port.
* Creates a new HTTP/HTTPS server instance on the specified port.
* Uses HTTPS if mcp_use_ssl is true, otherwise uses HTTP.
*
* @param p The port number to listen on
* @param h Pointer to the MCP_Threads_Handler instance
Expand All @@ -51,18 +54,32 @@ class ProxySQL_MCP_Server {
~ProxySQL_MCP_Server();

/**
* @brief Start the HTTPS server
* @brief Start the HTTP/HTTPS server
*
* Starts the webserver in a dedicated thread.
*/
void start();

/**
* @brief Stop the HTTPS server
* @brief Stop the HTTP/HTTPS server
*
* Stops the webserver and waits for the thread to complete.
*/
void stop();

/**
* @brief Get the port the server is listening on
*
* @return int The port number
*/
int get_port() const { return port; }

/**
* @brief Check if the server is using SSL/TLS
*
* @return true if server is using HTTPS, false if using HTTP
*/
bool is_using_ssl() const { return use_ssl; }
};

#endif /* CLASS_PROXYSQL_MCP_SERVER_H */
Loading