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:
Ishaan Jaffer 2026-03-10 17:54:27 -07:00
parent 622d0f9d88
commit b37ac05f4e
2 changed files with 8 additions and 4 deletions

View file

@ -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

View file

@ -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 } : {}),
});