Skip to content

Commit 49892d7

Browse files
committed
Disable sessions support by default (use -L to enable this)
1 parent 4cfa83e commit 49892d7

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void r2mcp_help(void) {
4949
" -S [url] enable supervisor control; connect to svc at [url]\n"
5050
" -P [dir] specify custom prompts directory (supports colon-separated paths like r2ai)\n"
5151
" -N do not load any prompts\n"
52+
" -L enable session management tools (list/open/close sessions)\n"
5253
" -v show version\n";
5354
printf ("%s", help_text);
5455
}
@@ -81,10 +82,11 @@ int r2mcp_main(int argc, const char **argv) {
8182
char *prompts_dir = NULL;
8283
bool load_prompts = true;
8384
bool ignore_analysis_level = false;
85+
bool use_sessions = false;
8486
const char *dsl_tests = NULL;
8587
RList *disabled_tools = NULL;
8688
RGetopt opt;
87-
r_getopt_init (&opt, argc, argv, "hmvpd:nc:u:l:s:rite:D:RT:S:P:N");
89+
r_getopt_init (&opt, argc, argv, "hmvpd:nc:u:l:s:rite:D:RT:S:P:NL");
8890
int c;
8991
while ((c = r_getopt_next (&opt)) != -1) {
9092
switch (c) {
@@ -166,6 +168,9 @@ int r2mcp_main(int argc, const char **argv) {
166168
case 'N':
167169
load_prompts = false;
168170
break;
171+
case 'L':
172+
use_sessions = true;
173+
break;
169174
default:
170175
R_LOG_ERROR ("Invalid flag -%c", c);
171176
return 1;
@@ -191,6 +196,7 @@ int r2mcp_main(int argc, const char **argv) {
191196
.readonly_mode = readonly_mode,
192197
.permissive_tools = permissive,
193198
.enable_run_command_tool = enable_run_command_tool,
199+
.use_sessions = use_sessions,
194200
.http_mode = http_mode,
195201
.baseurl = baseurl,
196202
.svc_baseurl = svc_baseurl,

src/r2mcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef struct {
3939
bool minimode;
4040
bool permissive_tools; // allow calling tools not exposed for current mode
4141
bool enable_run_command_tool;
42+
/* When true, enable session management tools (list/open/close sessions) */
43+
bool use_sessions;
4244
/* When true operate in read-only mode: only expose non-mutating tools */
4345
bool readonly_mode;
4446
/* When true, operate in HTTP r2pipe client mode and do NOT use r2 C APIs */

src/tools.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ static inline ToolMode current_mode(const ServerState *ss) {
7474
if (ss->http_mode) {
7575
return TOOL_MODE_HTTP;
7676
}
77+
if (ss->use_sessions) {
78+
return TOOL_MODE_SESSIONS;
79+
}
7780
if (ss->readonly_mode) {
7881
return TOOL_MODE_RO;
7982
}
@@ -212,6 +215,9 @@ void tools_print_table(const ServerState *ss) {
212215
if (t->modes & TOOL_MODE_RO) {
213216
modes_buf[p++] = 'R';
214217
}
218+
if (t->modes & TOOL_MODE_SESSIONS) {
219+
modes_buf[p++] = 'S';
220+
}
215221
if (t->modes & TOOL_MODE_NORMAL) {
216222
modes_buf[p++] = 'N';
217223
}
@@ -792,6 +798,9 @@ static char *tool_run_javascript(ServerState *ss, RJson *tool_args) {
792798
}
793799

794800
static char *tool_list_sessions(ServerState *ss, RJson *tool_args) {
801+
if (!ss->use_sessions) {
802+
return jsonrpc_error_response (-32603, "Start r2mcp with -L to support sessions", NULL, NULL);
803+
}
795804
(void)tool_args;
796805
(void)ss;
797806
// r2agent command doesn't require an open file, run it directly
@@ -810,6 +819,9 @@ static char *tool_list_sessions(ServerState *ss, RJson *tool_args) {
810819
}
811820

812821
static char *tool_open_session(ServerState *ss, RJson *tool_args) {
822+
if (!ss->use_sessions) {
823+
return jsonrpc_error_response (-32603, "Start r2mcp with -L to support sessions", NULL, NULL);
824+
}
813825
const char *url;
814826
if (!validate_required_string_param (tool_args, "url", &url)) {
815827
return jsonrpc_error_missing_param ("url");
@@ -852,6 +864,9 @@ static char *tool_open_session(ServerState *ss, RJson *tool_args) {
852864
}
853865

854866
static char *tool_close_session(ServerState *ss, RJson *tool_args) {
867+
if (!ss->use_sessions) {
868+
return jsonrpc_error_response (-32603, "Start r2mcp with -L to support sessions", NULL, NULL);
869+
}
855870
(void)tool_args;
856871

857872
if (!ss->http_mode) {
@@ -1048,9 +1063,9 @@ ToolSpec tool_specs[] = {
10481063
{ "open_file", "Opens a binary file with radare2 for analysis <think>Call this tool before any other one from r2mcp. Use an absolute file_path</think>", "{\"type\":\"object\",\"properties\":{\"file_path\":{\"type\":\"string\",\"description\":\"Path to the file to open\"}},\"required\":[\"file_path\"]}", TOOL_MODE_NORMAL | TOOL_MODE_MINI, NULL },
10491064
{ "run_javascript", "Executes JavaScript code using radare2's qjs runtime", "{\"type\":\"object\",\"properties\":{\"script\":{\"type\":\"string\",\"description\":\"The JavaScript code to execute\"}},\"required\":[\"script\"]}", TOOL_MODE_NORMAL | TOOL_MODE_MINI | TOOL_MODE_HTTP, tool_run_javascript },
10501065
{ "run_command", "Executes a raw radare2 command directly", "{\"type\":\"object\",\"properties\":{\"command\":{\"type\":\"string\",\"description\":\"The radare2 command to execute\"}},\"required\":[\"command\"]}", TOOL_MODE_NORMAL | TOOL_MODE_MINI | TOOL_MODE_HTTP, tool_run_command },
1051-
{ "list_sessions", "Lists available r2agent sessions in JSON format", "{\"type\":\"object\",\"properties\":{}}", TOOL_MODE_NORMAL | TOOL_MODE_HTTP | TOOL_MODE_RO, tool_list_sessions },
1052-
{ "open_session", "Connects to a remote r2 instance using r2pipe API", "{\"type\":\"object\",\"properties\":{\"url\":{\"type\":\"string\",\"description\":\"URL of the remote r2 instance to connect to\"}},\"required\":[\"url\"]}", TOOL_MODE_NORMAL | TOOL_MODE_HTTP, tool_open_session },
1053-
{ "close_session", "Close the currently open remote session", "{\"type\":\"object\",\"properties\":{}}", TOOL_MODE_NORMAL | TOOL_MODE_HTTP, tool_close_session },
1066+
{ "list_sessions", "Lists available r2agent sessions in JSON format", "{\"type\":\"object\",\"properties\":{}}", TOOL_MODE_NORMAL | TOOL_MODE_HTTP | TOOL_MODE_RO | TOOL_MODE_SESSIONS, tool_list_sessions },
1067+
{ "open_session", "Connects to a remote r2 instance using r2pipe API", "{\"type\":\"object\",\"properties\":{\"url\":{\"type\":\"string\",\"description\":\"URL of the remote r2 instance to connect to\"}},\"required\":[\"url\"]}", TOOL_MODE_NORMAL | TOOL_MODE_HTTP | TOOL_MODE_SESSIONS , tool_open_session },
1068+
{ "close_session", "Close the currently open remote session", "{\"type\":\"object\",\"properties\":{}}", TOOL_MODE_NORMAL | TOOL_MODE_HTTP | TOOL_MODE_SESSIONS, tool_close_session },
10541069
{ "close_file", "Close the currently open file", "{\"type\":\"object\",\"properties\":{}}", TOOL_MODE_NORMAL, tool_close_file },
10551070
{ "list_functions", "Lists all functions discovered during analysis", "{\"type\":\"object\",\"properties\":{\"only_named\":{\"type\":\"boolean\",\"description\":\"If true, only list functions with named symbols (excludes functions with numeric suffixes like sym.func.1000016c8)\"},\"filter\":{\"type\":\"string\",\"description\":\"Regular expression to filter the results\"}}}", TOOL_MODE_NORMAL | TOOL_MODE_MINI | TOOL_MODE_HTTP | TOOL_MODE_RO, tool_list_functions },
10561071
{ "list_functions_tree", "Lists functions and successors (aflmu)", "{\"type\":\"object\",\"properties\":{}}", TOOL_MODE_NORMAL | TOOL_MODE_MINI | TOOL_MODE_HTTP | TOOL_MODE_RO, tool_list_functions_tree },

src/tools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ typedef enum {
88
TOOL_MODE_HTTP = 1 << 1,
99
TOOL_MODE_NORMAL = 1 << 2,
1010
TOOL_MODE_RO = 1 << 3,
11+
TOOL_MODE_SESSIONS = 1 << 4,
1112
} ToolMode;
1213

1314
// Tool handler signature: returns heap-allocated JSON string describing

0 commit comments

Comments
 (0)