mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
dont use external party for ip address
This commit is contained in:
parent
9936f7d346
commit
5b38cedfa4
3 changed files with 41 additions and 9 deletions
|
|
@ -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"],
|
||||
|
|
|
|||
|
|
@ -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<MCPNetworkSettingsProps> = ({ 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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6338,6 +6338,30 @@ export const fetchMCPAccessGroups = async (accessToken: string) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const fetchMCPClientIp = async (accessToken: string): Promise<string | null> => {
|
||||
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<string, any>, // Assuming formValues is an object
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue