From 5b38cedfa417173a717651caef880cf3f3a6d3f5 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Fri, 6 Feb 2026 17:57:11 -0800 Subject: [PATCH] dont use external party for ip address --- .../mcp_management_endpoints.py | 12 ++++++++++ .../mcp_tools/MCPNetworkSettings.tsx | 14 ++++------- .../src/components/networking.tsx | 24 +++++++++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/litellm/proxy/management_endpoints/mcp_management_endpoints.py b/litellm/proxy/management_endpoints/mcp_management_endpoints.py index f5c4fb28ab7..90c2f7fdf62 100644 --- a/litellm/proxy/management_endpoints/mcp_management_endpoints.py +++ b/litellm/proxy/management_endpoints/mcp_management_endpoints.py @@ -422,6 +422,18 @@ if MCP_AVAILABLE: access_groups_list = sorted(list(access_groups)) return {"access_groups": access_groups_list} + @router.get( + "/network/client-ip", + tags=["mcp"], + dependencies=[Depends(user_api_key_auth)], + description="Returns the caller's IP address as seen by the proxy.", + ) + async def get_client_ip(request: Request): + from litellm.proxy.auth.ip_address_utils import IPAddressUtils + + client_ip = IPAddressUtils.get_mcp_client_ip(request) + return {"ip": client_ip} + @router.get( "/registry.json", tags=["mcp"], diff --git a/ui/litellm-dashboard/src/components/mcp_tools/MCPNetworkSettings.tsx b/ui/litellm-dashboard/src/components/mcp_tools/MCPNetworkSettings.tsx index 4067755fceb..46fbbbcf2b0 100644 --- a/ui/litellm-dashboard/src/components/mcp_tools/MCPNetworkSettings.tsx +++ b/ui/litellm-dashboard/src/components/mcp_tools/MCPNetworkSettings.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from "react"; import { Select, Button, Card, Typography, Spin, Tag } from "antd"; import { SaveOutlined, PlusOutlined } from "@ant-design/icons"; -import { getGeneralSettingsCall, updateConfigFieldSetting, deleteConfigFieldSetting } from "../networking"; +import { getGeneralSettingsCall, updateConfigFieldSetting, deleteConfigFieldSetting, fetchMCPClientIp } from "../networking"; const { Text } = Typography; @@ -47,14 +47,10 @@ const MCPNetworkSettings: React.FC = ({ accessToken }) }; const detectCurrentIp = async () => { - try { - const res = await fetch("https://api.ipify.org?format=json"); - const data = await res.json(); - if (data.ip) { - setCurrentIp(data.ip); - } - } catch { - // Silently fail — not critical + if (!accessToken) return; + const ip = await fetchMCPClientIp(accessToken); + if (ip) { + setCurrentIp(ip); } }; diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx index 2c7c6be2c14..0d543952efc 100644 --- a/ui/litellm-dashboard/src/components/networking.tsx +++ b/ui/litellm-dashboard/src/components/networking.tsx @@ -6338,6 +6338,30 @@ export const fetchMCPAccessGroups = async (accessToken: string) => { } }; +export const fetchMCPClientIp = async (accessToken: string): Promise => { + try { + const url = proxyBaseUrl + ? `${proxyBaseUrl}/v1/mcp/network/client-ip` + : `/v1/mcp/network/client-ip`; + + const response = await fetch(url, { + method: HTTP_REQUEST.GET, + headers: { + [globalLitellmHeaderName]: `Bearer ${accessToken}`, + }, + }); + + if (!response.ok) { + return null; + } + + const data = await response.json(); + return data.ip || null; + } catch { + return null; + } +}; + export const createMCPServer = async ( accessToken: string, formValues: Record, // Assuming formValues is an object