184 lines
4.9 KiB
C++
184 lines
4.9 KiB
C++
/**
|
|
* @file mcp_workflow_resource.h
|
|
* @brief Resource implementation for MCP workflows
|
|
*
|
|
* This file defines a resource for managing workflows in the MCP protocol.
|
|
*/
|
|
|
|
#ifndef MCP_WORKFLOW_RESOURCE_H
|
|
#define MCP_WORKFLOW_RESOURCE_H
|
|
|
|
#include "mcp_protocol.h"
|
|
#include "mcp_resource.h"
|
|
#include "mcp_tools.h"
|
|
#include <map>
|
|
#include <mutex>
|
|
|
|
namespace mcp {
|
|
|
|
/**
|
|
* @class workflow_resource
|
|
* @brief Resource for managing workflows
|
|
*
|
|
* The workflow_resource class provides a RESTful interface for creating,
|
|
* executing, and managing workflows.
|
|
*/
|
|
class workflow_resource : public resource {
|
|
public:
|
|
/**
|
|
* @brief Constructor
|
|
* @param name Resource name
|
|
*/
|
|
explicit workflow_resource(const std::string& name = "Workflow Manager");
|
|
|
|
/**
|
|
* @brief Get resource type
|
|
* @return Resource type
|
|
*/
|
|
resource_type type() const override {
|
|
return resource_type::custom;
|
|
}
|
|
|
|
/**
|
|
* @brief Get resource metadata
|
|
* @return Metadata as JSON
|
|
*/
|
|
json metadata() const override;
|
|
|
|
/**
|
|
* @brief Handle request
|
|
* @param req The request
|
|
* @return The response
|
|
*/
|
|
response handle_request(const request& req) override;
|
|
|
|
/**
|
|
* @brief Get resource schema
|
|
* @return The schema as JSON
|
|
*/
|
|
json schema() const override;
|
|
|
|
/**
|
|
* @brief Register a workflow
|
|
* @param workflow The workflow to register
|
|
*/
|
|
void register_workflow(const workflow& workflow);
|
|
|
|
/**
|
|
* @brief Unregister a workflow
|
|
* @param name The name of the workflow
|
|
* @return True if the workflow was found and unregistered
|
|
*/
|
|
bool unregister_workflow(const std::string& name);
|
|
|
|
/**
|
|
* @brief Get a workflow by name
|
|
* @param name The name of the workflow
|
|
* @return Pointer to the workflow, or nullptr if not found
|
|
*/
|
|
const workflow* get_workflow(const std::string& name) const;
|
|
|
|
/**
|
|
* @brief Get all registered workflows
|
|
* @return A vector of all registered workflows
|
|
*/
|
|
std::vector<std::string> get_workflow_names() const;
|
|
|
|
private:
|
|
std::string name_;
|
|
std::map<std::string, workflow> workflows_;
|
|
mutable std::mutex mutex_;
|
|
|
|
// Handler methods for different operations
|
|
response list_workflows(const request& req);
|
|
response get_workflow_details(const request& req, const std::string& workflow_name);
|
|
response create_workflow(const request& req);
|
|
response update_workflow(const request& req, const std::string& workflow_name);
|
|
response delete_workflow(const request& req, const std::string& workflow_name);
|
|
response execute_workflow(const request& req, const std::string& workflow_name);
|
|
};
|
|
|
|
/**
|
|
* @class agent_resource
|
|
* @brief Resource for managing agents
|
|
*
|
|
* The agent_resource class provides a RESTful interface for creating
|
|
* and managing agents that can execute workflows and tools.
|
|
*/
|
|
class agent_resource : public resource {
|
|
public:
|
|
/**
|
|
* @brief Constructor
|
|
* @param name Resource name
|
|
*/
|
|
explicit agent_resource(const std::string& name = "Agent Manager");
|
|
|
|
/**
|
|
* @brief Get resource type
|
|
* @return Resource type
|
|
*/
|
|
resource_type type() const override {
|
|
return resource_type::custom;
|
|
}
|
|
|
|
/**
|
|
* @brief Get resource metadata
|
|
* @return Metadata as JSON
|
|
*/
|
|
json metadata() const override;
|
|
|
|
/**
|
|
* @brief Handle request
|
|
* @param req The request
|
|
* @return The response
|
|
*/
|
|
response handle_request(const request& req) override;
|
|
|
|
/**
|
|
* @brief Get resource schema
|
|
* @return The schema as JSON
|
|
*/
|
|
json schema() const override;
|
|
|
|
/**
|
|
* @brief Register an agent
|
|
* @param agent The agent to register
|
|
*/
|
|
void register_agent(std::shared_ptr<agent> agent);
|
|
|
|
/**
|
|
* @brief Unregister an agent
|
|
* @param name The name of the agent
|
|
* @return True if the agent was found and unregistered
|
|
*/
|
|
bool unregister_agent(const std::string& name);
|
|
|
|
/**
|
|
* @brief Get an agent by name
|
|
* @param name The name of the agent
|
|
* @return Pointer to the agent, or nullptr if not found
|
|
*/
|
|
std::shared_ptr<agent> get_agent(const std::string& name) const;
|
|
|
|
/**
|
|
* @brief Get all registered agents
|
|
* @return A vector of agent names
|
|
*/
|
|
std::vector<std::string> get_agent_names() const;
|
|
|
|
private:
|
|
std::string name_;
|
|
std::map<std::string, std::shared_ptr<agent>> agents_;
|
|
mutable std::mutex mutex_;
|
|
|
|
// Handler methods for different operations
|
|
response list_agents(const request& req);
|
|
response get_agent_details(const request& req, const std::string& agent_name);
|
|
response create_agent(const request& req);
|
|
response delete_agent(const request& req, const std::string& agent_name);
|
|
response process_agent_request(const request& req, const std::string& agent_name);
|
|
};
|
|
|
|
} // namespace mcp
|
|
|
|
#endif // MCP_WORKFLOW_RESOURCE_H
|