strawberry/mcp/mcp_server.hpp
trvon 2a4812829f
Use macOS store paths and launchd hints in the CLI, app and MCP
The CLI fallback, the tray app and strawberry-mcp looked for evidence
in /var/lib/strawberry; kSystemStorePath (config.hpp) is
/var/db/strawberry on macOS. User-facing hints quoted systemctl and
journalctl; they come from include/strawberry/service_hints.hpp
(launchctl and /var/log/strawberry.log on macOS), including doctor's
log-rotation note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 04:39:57 -06:00

62 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/config.hpp"
#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 = kSystemStorePath;
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