-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Description:
When using mcp_tools(config = "...") in ellmer with an MCP server configuration that includes an env block, the connection immediately fails on Windows with the following error:
Error in `process_write_input(self, private, str, sep)`:
! Native call to `processx_connection_write_bytes` failed
Caused by error in `chain_call(c_processx_connection_write_bytes, con, str)`:
! Cannot write connection (system error 232, Идет закрытие канала.
) @processx-connection.c:977 (processx_c_connection_write_bytes)
Type .Last.error to see the more details.
If the same configuration is used without the env key, everything works as expected.
Steps to reproduce:
- Create a minimal R MCP server script, e.g.
create_pf_mcp_server.R. - Add it to the MCP config with env:
{
"mcpServers": {
"netpeak_pfworker": {
"command": "Rscript",
"args": ["-e", "source('C:/Users/User/Documents/mcp_servers/create_pf_mcp_server.R')"],
"env": {
"PFW_TOKEN": "00000000111111111xxxx"
}
}
}
}- Call:
library(ellmer)
library(mcptools)
chat <- ellmer::chat_google_gemini(system_prompt = "Test")
chat$set_tools(mcptools::mcp_tools(config = "C:/path/config.json"))-
Observe the error above.
-
Modify the config to remove
env:
{
"mcpServers": {
"netpeak_pfworker": {
"command": "Rscript",
"args": ["-e", "source('C:/Users/User/Documents/mcp_servers/create_pf_mcp_server.R')"]
}
}
}- Run again — works fine.
Expected behavior:
Passing env should merge environment variables with the current process environment (as is common on other platforms), not completely replace them.
Actual behavior:
On Windows, processx appears to replace the entire environment, which causes the Rscript process to fail almost immediately, breaking the MCP connection.
System info:
other attached packages:
[1] ellmer_0.3.0 mcptools_0.1.0.9000
loaded via a namespace (and not attached):
[1] coro_1.1.0 R6_2.5.1 magrittr_2.0.3 rappdirs_0.3.3 glue_1.8.0
[6] lifecycle_1.0.4 ps_1.8.1 cli_3.6.3 S7_0.2.0 processx_3.8.4
[11] compiler_4.4.2 rstudioapi_0.17.1 tools_4.4.2 httr2_1.2.1 rlang_1.1.4
[16] jsonlite_1.8.9
Windows 10/11
R 4.x
Notes:
This looks like a known processx behavior on Windows where env fully overrides the environment instead of merging it. If this is intentional, mcp_tools() might need to explicitly merge the provided env with the current Sys.getenv() before spawning the process, to ensure required variables like PATH and R_HOME are preserved.