strawberry/mcp/mcp_server.hpp
trvon 47bb058fdc
Add MCP server for agent access
A stdio JSON-RPC MCP server exposing status, findings, process search
and YARA path scans. Evidence fields are marked as untrusted data;
protection actions stay read-only from MCP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 18:17:04 -06:00

61 lines
1.8 KiB
C++

#ifndef STRAWBERRY_MCP_SERVER_HPP
#define STRAWBERRY_MCP_SERVER_HPP
// Transport-free MCP (Model Context Protocol) server for Strawberry.
// `handle()` takes one JSON-RPC message and returns the reply (if any), so the
// protocol and tools are unit-testable without stdio.
#include "strawberry/evidence_store.hpp"
#include <nlohmann/json.hpp>
#include <optional>
#include <string>
namespace strawberry::mcp {
using json = nlohmann::json;
struct McpOptions {
std::string socket_path;
std::string db_path_override; // empty = path reported by the daemon
std::string default_db_path = "/var/lib/strawberry/database.db";
bool read_only = false; // hide reload/rescan/scan tools
};
class McpServer {
public:
explicit McpServer(McpOptions options);
/// Handle one JSON-RPC message. Returns nullopt for notifications.
std::optional<json> handle(const json& message);
/// Serialize for the wire: invalid UTF-8 from host evidence is replaced,
/// never thrown on.
static std::string dump(const json& value);
private:
json handle_initialize(const json& params);
json tools_list() const;
json call_tool(const std::string& name, const json& arguments);
json tool_status();
json tool_list_findings(const json& args);
json tool_get_finding(const json& args);
json tool_search_processes(const json& args);
json tool_get_process(const json& args);
json tool_scan_paths(const json& args);
json tool_control(const std::string& verb);
json tool_get_policy();
/// Daemon status reply (`data` object) or nullopt with `error` set.
std::optional<json> daemon_status(std::string& error);
void refresh_store();
McpOptions options_;
EvidenceStore store_;
};
} // namespace strawberry::mcp
#endif // STRAWBERRY_MCP_SERVER_HPP