24#include <unordered_map>
63 bool was_read(
const std::string&
session,
const std::string& path)
const;
191 const std::filesystem::path&
root_dir()
const;
249 const std::string& tool)
const;
283 void create_fs_tools(
const std::string&
data_dir);
290 void register_fs_tools();
301 void authorize_outside_root(
const std::filesystem::path& resolved,
303 const std::string& tool)
const;
314 void ask_outside_root_approver(
const std::filesystem::path& resolved,
316 const std::string& tool)
const;
323 void log_outside_root_policy()
const;
325 std::filesystem::path root_dir_;
327 int max_read_bytes_ = 0;
332 mutable std::mutex approver_mutex_;
334 void* approver_data_ =
nullptr;
337 std::unique_ptr<ReadFileTool> read_file_;
338 std::unique_ptr<WriteFileTool> write_file_;
339 std::unique_ptr<EditFileTool> edit_file_;
340 std::unique_ptr<GlobTool> glob_;
341 std::unique_ptr<GrepTool> grep_;
342 std::unique_ptr<ListDirectoryTool> list_dir_;
Tracks file read state for read-before-write enforcement.
bool was_read(const std::string &session, const std::string &path) const
Check whether session has read a file.
void record_read(const std::string &session, const std::string &path, size_t hash)
Record that session read a file.
std::size_t session_count() const
Sessions currently holding recorded reads.
bool release_session(const std::string &session)
Forget every read session recorded (gh#158).
Filesystem MCP server with read-before-write enforcement.
int max_read_bytes() const
Get max read bytes (size gate).
void set_outside_root_approver(OutsideRootApprover fn, void *user_data)
Install the approver consulted under optional (v2.13.0).
const IgnoreMatcher & ignore() const
Get the ignore matcher (#15, v2.1.4).
std::size_t session_count() const override
Sessions whose reads this server currently tracks (gh#158).
bool skip_duplicate_check(const std::string &tool_name) const override
read_file must always execute (updates FileAccessTracker).
bool set_working_dir(const std::string &path) override
Set working directory (changes root_dir).
~FilesystemServer() override
Destructor (default, unique_ptr cleanup).
const FilesystemConfig & config() const
Get the filesystem config.
std::filesystem::path resolve_path(const std::string &requested, PathAccess access, const std::string &tool) const
Resolve a path and apply the outside-root policy (v2.13.0).
FileAccessTracker & tracker()
Get the file access tracker.
bool release_session(const std::string &key) override
Release key's recorded reads (gh#158).
const std::filesystem::path & root_dir() const
Get the root directory.
gitignore-style path matcher (#15, v2.1.4).
Concrete base class for MCP servers (80% logic).
One T per session key, under one leaf mutex (gh#158).
A server that keeps state per session and can release it (gh#158).
Configuration structs with defaults.
Path-relative ignore matching honoring .gitignore + .explorerignore.
Activate model on GPU (WARM → ACTIVE).
OutsideRootVerdict
The host's answer to an OutsideRootRequest (v2.13.0).
@ approved
Serve this one call.
@ rejected
The approver said no.
@ no_approver
No approver is registered — refuse, fail loud.
@ optional
optional: every escape asks the host's path approver
@ request
GenerationParams::grammar (COMMON_GRAMMAR_TYPE_USER)
OutsideRootVerdict(*)(const OutsideRootRequest &request, void *user_data) OutsideRootApprover
Approver the server consults under allow_outside_root: optional.
PathAccess
What a filesystem tool is about to do with a path (v2.13.0).
@ read
read_file, list_directory
@ write
write_file, edit_file
MCPServerBase concrete base class + ServerResponse.
Server state that belongs to a SESSION, not to the server (gh#158).
Filesystem MCP server configuration.
One outside-root access awaiting the host's decision (v2.13.0).
PathAccess access
Read or write.
std::string root
Canonical root the path lies outside.
std::string tool
Fully-qualified tool ("filesystem.write_file")
std::string path
Canonical absolute path the tool resolved.