Skip to content

Commit 96a680b

Browse files
authored
fix /.pomerium/mcp/connect call when base url has path prefix (#153)
We support specifying MCP server path prefix since pomerium/pomerium#5726, so that the URLs might not be necessarily at `/`. This PR fixes to always use URL base path when appending `/.pomerium/mcp/connect` to it. Fix: https://linear.app/pomerium/issue/ENG-2620/mcp-connect-500-instead-of-sending-to-oauth-screen
1 parent bee646a commit 96a680b

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/components/ServerSelector.test.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,45 @@ describe('ServerSelector', () => {
545545
screen.getByRole('button', { name: /Servers & Tools \(2\/2\)/i }),
546546
).toBeInTheDocument()
547547
})
548+
549+
it('redirects to base URL with connect path when clicking disconnected server', async () => {
550+
// Mock window.location.href assignment
551+
const originalLocation = window.location
552+
delete (window as any).location
553+
window.location = {
554+
href: 'https://current-app.example.com/some/path',
555+
} as any
556+
557+
const servers: Servers = {
558+
'test-server': {
559+
...baseServer,
560+
status: 'disconnected',
561+
connected: false,
562+
url: 'https://db-server.example.com/some/path',
563+
needs_oauth: true,
564+
},
565+
}
566+
567+
await act(() => {
568+
renderWithQueryClient(
569+
<ServerSelector
570+
servers={servers}
571+
onServersChange={mockOnServersChange}
572+
selectedServers={[]}
573+
onServerToggle={mockOnServerToggle}
574+
toolToggles={[]}
575+
/>,
576+
)
577+
})
578+
579+
await userEvent.click(screen.getByText('Test Server'))
580+
581+
// Should redirect to base URL + connect path, not full URL + connect path
582+
expect(window.location.href).toBe(
583+
'https://db-server.example.com/.pomerium/mcp/connect?redirect_url=https%3A%2F%2Fcurrent-app.example.com%2Fsome%2Fpath',
584+
)
585+
586+
// Restore original location
587+
;(window as any).location = originalLocation
588+
})
548589
})

src/components/ServerSelector.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ const ServerSelectionContent = ({
135135
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
136136
if (!server) return
137137
const currentUrl = window.location.href
138-
const connectUrl = `${server.url}${POMERIUM_CONNECT_PATH}?redirect_url=${encodeURIComponent(currentUrl)}`
139-
window.location.href = connectUrl
138+
const connectUrl = new URL(POMERIUM_CONNECT_PATH, server.url)
139+
connectUrl.searchParams.set('redirect_url', currentUrl)
140+
window.location.href = connectUrl.toString()
140141
}
141142

142143
const disconnectMutation = useDisconnectServer(servers, onServersChange)

0 commit comments

Comments
 (0)