server: add --ui-mcp-proxy-allow-private-urls (#32633)

This commit is contained in:
Xuan-Son Nguyen authored and GitHub committed 2026-11-20 14:10:06 +01:00
1 parent 28de970cc1
commit 36cd3aff40
8 files changed
+32 -23

No files matched your search

+9 -1
View File
@@ -3420,12 +3420,20 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
add_opt(common_arg(
{"--ui-mcp-proxy", "--webui-mcp-proxy"},
{"--no-ui-mcp-proxy", "--no-webui-mcp-proxy"},
"experimental: whether to enable MCP CORS proxy, for Llama Chat to reach public MCP servers without CORS headers; local and private addresses are refused - do not enable in untrusted environments (default: disabled)\n"
"experimental: whether to enable MCP CORS proxy, for Llama Chat to reach public MCP servers without CORS headers; local and private addresses are refused unless --ui-mcp-proxy-allow-private-urls is set - do not enable in untrusted environments (default: disabled)\n"
"note: for security reasons, this will limit --cors-origins to localhost by default",
[](common_params & params, bool value) {
params.ui_mcp_proxy = value;
}
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_UI_MCP_PROXY"));
add_opt(common_arg(
{"--ui-mcp-proxy-allow-private-urls"},
"allow the MCP CORS proxy to reach local or private addresses (e.g. MCP servers on localhost or LAN) - anyone who can reach the proxy can then reach your local network (default: disabled, only public addresses)\n"
"note: only has effect with --ui-mcp-proxy",
[](common_params & params) {
params.ui_mcp_proxy_allow_private_urls = true;
}
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_UI_MCP_PROXY_ALLOW_PRIVATE_URLS"));
add_opt(common_arg(
{"--tools"}, "TOOL1,TOOL2,...",
"experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)\n"
+1
View File
@@ -702,6 +702,7 @@ struct common_params {
// UI configs
bool ui = true;
bool ui_mcp_proxy = false;
bool ui_mcp_proxy_allow_private_urls = false; // allow the MCP CORS proxy to reach local or private addresses
std::string ui_config_json;
// "advanced" endpoints are disabled by default for better security
+3 -2
View File
@@ -202,7 +202,8 @@ For the full list of features, please refer to [server's changelog](https://gith
| `--api-prefix PREFIX` | prefix path the server serves from, without the trailing slash (default: )<br/>(env: LLAMA_ARG_API_PREFIX) |
| `--ui-config, --webui-config JSON` | JSON that provides default UI settings (overrides UI defaults)<br/>(env: LLAMA_ARG_UI_CONFIG) |
| `--ui-config-file, --webui-config-file PATH` | JSON file that provides default UI settings (overrides UI defaults)<br/>(env: LLAMA_ARG_UI_CONFIG_FILE) |
| `--ui-mcp-proxy, --webui-mcp-proxy, --no-ui-mcp-proxy, --no-webui-mcp-proxy` | experimental: whether to enable MCP CORS proxy, for Llama Chat to reach public MCP servers without CORS headers; local and private addresses are refused - do not enable in untrusted environments (default: disabled)<br/>note: for security reasons, this will limit --cors-origins to localhost by default<br/>(env: LLAMA_ARG_UI_MCP_PROXY) |
| `--ui-mcp-proxy, --webui-mcp-proxy, --no-ui-mcp-proxy, --no-webui-mcp-proxy` | experimental: whether to enable MCP CORS proxy, for Llama Chat to reach public MCP servers without CORS headers; local and private addresses are refused unless --ui-mcp-proxy-allow-private-urls is set - do not enable in untrusted environments (default: disabled)<br/>note: for security reasons, this will limit --cors-origins to localhost by default<br/>(env: LLAMA_ARG_UI_MCP_PROXY) |
| `--ui-mcp-proxy-allow-private-urls` | allow the MCP CORS proxy to reach local or private addresses (e.g. MCP servers on localhost or LAN) - anyone who can reach the proxy can then reach your local network (default: disabled, only public addresses)<br/>note: only has effect with --ui-mcp-proxy<br/>(env: LLAMA_ARG_UI_MCP_PROXY_ALLOW_PRIVATE_URLS) |
| `--tools TOOL1,TOOL2,...` | experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)<br/>specify "all" to enable all tools<br/>available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, get_info<br/>note: for security reasons, this will limit --cors-origins to localhost by default<br/>(env: LLAMA_ARG_TOOLS) |
| `--tools-runtime OPTION` | experimental: run tools in a separate runtime environment (default: none, use host environment)<br/>available options:<br/> 'docker:<image>', 'podman:<image>': spin up a new container and reuse it for all invocations, clean up on server exit<br/> 'docker-container:<id>', 'podman-container:<id>': use an existing container by ID, won't stop on server exit<br/> 'ssh:<target>': run tools on a remote POSIX host over SSH, key-based auth and a trusted host key are required<br/><br/>(env: LLAMA_ARG_TOOLS_RUNTIME) |
| `--allow-unauthenticated-tools` | allow server tools, MCP servers or MCP proxy on a non-loopback address without an API key - only for trusted networks (default: disabled)<br/>(env: LLAMA_ARG_ALLOW_UNAUTHENTICATED_TOOLS) |
@@ -393,7 +394,7 @@ Every server is spawned once at startup to list its tools, then stopped, and res
The child process runs with the same privileges as the server, so only declare commands you trust. As with `--tools`, `--cors-origins` then defaults to `localhost`.
Note: `--ui-mcp-proxy` is unrelated, it only lets Llama Chat reach public MCP servers that do not send CORS headers. It refuses local and private addresses (loopback, LAN, link-local); connect to those from Llama Chat directly.
Note: `--ui-mcp-proxy` is unrelated, it only lets Llama Chat reach public MCP servers that do not send CORS headers. By default it refuses local and private addresses (loopback, LAN, link-local); either connect to those from Llama Chat directly (the MCP server must send CORS headers), or add `--ui-mcp-proxy-allow-private-urls`.
Any server written against the [MCP specification](https://modelcontextprotocol.io) works as is, whether it uses an official SDK or not: the transport is one JSON-RPC message per line on stdio, so a script wrapping an existing program is a valid server too.
+7 -10
View File
@@ -20,7 +20,7 @@ static std::string proxy_header_to_lower(std::string header) {
return header;
}
static server_http_res_ptr proxy_request(const server_http_req & req, std::string method) {
static server_http_res_ptr proxy_request(const server_http_req & req, std::string method, bool allow_private_urls) {
std::string target_url = req.get_param("url");
common_http_url parsed_url = common_http_parse_url(target_url);
@@ -70,8 +70,7 @@ static server_http_res_ptr proxy_request(const server_http_req & req, std::strin
req.should_stop,
600, // timeout_read (default to 10 minutes)
600, // timeout_write (default to 10 minutes)
// test-only escape hatch
server_resolve_public_addr(parsed_url.host, !common_get_env("LLAMA_SERVER_DEBUG_PROXY_ALLOW_PRIVATE").empty())
server_resolve_public_addr(parsed_url.host, allow_private_urls)
);
// route redirects back through the proxy, so each hop is checked
@@ -86,10 +85,8 @@ static server_http_res_ptr proxy_request(const server_http_req & req, std::strin
return proxy;
}
static server_http_context::handler_t proxy_handler_post = [](const server_http_req & req) -> server_http_res_ptr {
return proxy_request(req, "POST");
};
static server_http_context::handler_t proxy_handler_get = [](const server_http_req & req) -> server_http_res_ptr {
return proxy_request(req, "GET");
};
static server_http_context::handler_t proxy_make_handler(const std::string & method, bool allow_private_urls) {
return [method, allow_private_urls](const server_http_req & req) -> server_http_res_ptr {
return proxy_request(req, method, allow_private_urls);
};
}
+5 -3
View File
@@ -281,9 +281,11 @@ static bool server_setup_features(
// CORS proxy (EXPERIMENTAL, only used by Llama Chat for MCP)
if (params.ui_mcp_proxy) {
ctx_http.get ("/cors-proxy", ex_wrapper(proxy_handler_get));
ctx_http.post("/cors-proxy", ex_wrapper(proxy_handler_post));
warn_names.push_back("MCP proxy (experimental)");
ctx_http.get ("/cors-proxy", ex_wrapper(proxy_make_handler("GET", params.ui_mcp_proxy_allow_private_urls)));
ctx_http.post("/cors-proxy", ex_wrapper(proxy_make_handler("POST", params.ui_mcp_proxy_allow_private_urls)));
warn_names.push_back(params.ui_mcp_proxy_allow_private_urls
? "MCP proxy (experimental, local and private addresses allowed)"
: "MCP proxy (experimental)");
} else {
ctx_http.get ("/cors-proxy", ex_wrapper(res_403));
ctx_http.post("/cors-proxy", ex_wrapper(res_403));
+3 -3
View File
@@ -35,7 +35,7 @@ def test_mcp_proxy():
def test_mcp_proxy_custom_port():
global server
server.ui_mcp_proxy = True
server.debug_proxy_allow_private = True
server.ui_mcp_proxy_allow_private_urls = True
server.start()
# try getting the server's models API via the proxy
@@ -61,7 +61,7 @@ def test_mcp_proxy_no_content():
try:
global server
server.ui_mcp_proxy = True
server.debug_proxy_allow_private = True
server.ui_mcp_proxy_allow_private_urls = True
server.start()
res = server.make_request("POST", f"/cors-proxy?url=http://127.0.0.1:{target.server_port}/", data={})
@@ -116,7 +116,7 @@ def test_mcp_proxy_redirect_goes_through_proxy():
try:
global server
server.ui_mcp_proxy = True
server.debug_proxy_allow_private = True
server.ui_mcp_proxy_allow_private_urls = True
server.start()
url = server.make_url(f"/cors-proxy?url=http://127.0.0.1:{target.server_port}/start")
+1 -1
View File
@@ -314,7 +314,7 @@ def test_cors_proxy_only_forwards_explicit_proxy_headers():
server = ServerPreset.tinyllama2()
server.api_key = TEST_API_KEY
server.ui_mcp_proxy = True
server.debug_proxy_allow_private = True
server.ui_mcp_proxy_allow_private_urls = True
server.start()
res = server.make_request("GET", f"/cors-proxy?url=http://127.0.0.1:{target.server_port}/capture", headers={
+3 -3
View File
@@ -126,7 +126,7 @@ class ServerProcess:
no_cache_idle_slots: bool = False
log_path: str | None = None
ui_mcp_proxy: bool = False
debug_proxy_allow_private: bool = False # test-only: lets the CORS proxy reach local servers
ui_mcp_proxy_allow_private_urls: bool = False
media_allow_private_urls: bool = False
allow_unauthenticated_tools: bool = False
backend_sampling: bool = False
@@ -155,8 +155,6 @@ class ServerProcess:
**os.environ,
"LLAMA_SERVER_DEBUG_FAKE_TIMING": "1",
}
if self.debug_proxy_allow_private:
env["LLAMA_SERVER_DEBUG_PROXY_ALLOW_PRIVATE"] = "1"
if self.llama_cache is not None:
env["LLAMA_CACHE"] = self.llama_cache
elif "LLAMA_CACHE" not in os.environ:
@@ -313,6 +311,8 @@ class ServerProcess:
server_args.append("--no-cache-idle-slots")
if self.ui_mcp_proxy:
server_args.append("--ui-mcp-proxy")
if self.ui_mcp_proxy_allow_private_urls:
server_args.append("--ui-mcp-proxy-allow-private-urls")
if self.media_allow_private_urls:
server_args.append("--media-allow-private-urls")
if self.allow_unauthenticated_tools: