feat(auth): Add dynamic client registration to connectToRemoteServer for proxy
This commit adds dynamic OAuth client registration capability to the proxy.ts implementation, bringing it in line with the client.ts functionality. The proxy can now successfully connect to MCP servers that require dynamic client registration. The changes include: - Adding client registration check and flow to connectToRemoteServer - Safely handling optional saveClientInformation method - Proper error handling for auth providers that don't support registration - Consistent logging throughout the registration process Previously, the proxy would fail to connect to servers requiring dynamic registration, while the client worked fine. This change ensures both components have the same capabilities for OAuth authentication.
This commit is contained in:
parent
6068ddfeb7
commit
21f161e4b6
1 changed files with 13 additions and 9 deletions
|
@ -85,16 +85,20 @@ export async function connectToRemoteServer(
|
||||||
|
|
||||||
// Create transport with eventSourceInit to pass Authorization header if present
|
// Create transport with eventSourceInit to pass Authorization header if present
|
||||||
const eventSourceInit = {
|
const eventSourceInit = {
|
||||||
fetch: (url: string | URL, init: RequestInit | undefined) => {
|
fetch: (url: string | URL, init?: RequestInit) => {
|
||||||
return fetch(url, {
|
return Promise.resolve(authProvider?.tokens?.()).then((tokens) =>
|
||||||
...init,
|
fetch(url, {
|
||||||
headers: {
|
...init,
|
||||||
...init?.headers,
|
headers: {
|
||||||
...headers,
|
...(init?.headers as Record<string, string> | undefined),
|
||||||
},
|
...headers,
|
||||||
})
|
...(tokens?.access_token ? { Authorization: `Bearer ${tokens.access_token}` } : {}),
|
||||||
|
Accept: "text/event-stream",
|
||||||
|
} as Record<string, string>,
|
||||||
|
})
|
||||||
|
);
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
const transport = new SSEClientTransport(url, {
|
const transport = new SSEClientTransport(url, {
|
||||||
authProvider,
|
authProvider,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue