mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
fix(responses-api): use server_name for MCP URL routing, fix test path
- Use server_name (not alias) as the URL path segment for MCP server_url; alias is a display name that may differ from the registered proxy route. URL-encode the path to handle names with spaces/special characters. - Fix sys.path.insert in tests to use __file__-relative path so tests pass regardless of which directory pytest is invoked from.
This commit is contained in:
parent
622d0f9d88
commit
b37ac05f4e
2 changed files with 8 additions and 4 deletions
|
|
@ -12,7 +12,8 @@ import os
|
|||
import sys
|
||||
import unittest.mock as mock
|
||||
|
||||
sys.path.insert(0, os.path.abspath("../.."))
|
||||
# Use __file__ so the import path is correct regardless of the pytest working directory.
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
|
|
|||
|
|
@ -105,13 +105,16 @@ export async function makeOpenAIResponsesRequest(
|
|||
// Individual servers selected - create one entry per server
|
||||
selectedMCPServers.forEach((serverId) => {
|
||||
const server = mcpServers?.find((s) => s.server_id === serverId);
|
||||
const serverName = server?.alias || server?.server_name || serverId;
|
||||
// Use server_name for URL routing (proxy registers by name, not alias).
|
||||
const routeName = server?.server_name || serverId;
|
||||
// Use alias as the human-readable label when available.
|
||||
const serverLabel = server?.alias || routeName;
|
||||
const allowedTools = mcpServerToolRestrictions?.[serverId] || [];
|
||||
|
||||
tools.push({
|
||||
type: "mcp",
|
||||
server_label: serverName, // unique label per server so tool calls route correctly
|
||||
server_url: `${proxyBaseUrl}/mcp/${serverName}`,
|
||||
server_label: serverLabel, // unique human-readable label per server
|
||||
server_url: `${proxyBaseUrl}/mcp/${encodeURIComponent(routeName)}`,
|
||||
require_approval: "never",
|
||||
...(allowedTools.length > 0 ? { allowed_tools: allowedTools } : {}),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue