mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
Co-authored-by: David McWherter <davidmcw@gmail.com>
This commit is contained in:
@@ -501,6 +501,9 @@ describe('mcp-client', () => {
|
||||
oauth: {
|
||||
scopes: ['scope1'],
|
||||
},
|
||||
headers: {
|
||||
'X-Goog-User-Project': 'myproject',
|
||||
},
|
||||
},
|
||||
false,
|
||||
);
|
||||
@@ -509,6 +512,11 @@ describe('mcp-client', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const authProvider = (transport as any)._authProvider;
|
||||
expect(authProvider).toBeInstanceOf(GoogleCredentialProvider);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const googUserProject = (transport as any)._requestInit?.headers?.[
|
||||
'X-Goog-User-Project'
|
||||
];
|
||||
expect(googUserProject).toBe('myproject');
|
||||
});
|
||||
|
||||
it('should use GoogleCredentialProvider with SSE transport', async () => {
|
||||
|
||||
@@ -394,6 +394,24 @@ async function handleAutomaticOAuth(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create RequestInit for TransportOptions.
|
||||
*
|
||||
* @param mcpServerConfig The MCP server configuration
|
||||
* @param headers Additional headers
|
||||
*/
|
||||
function createTransportRequestInit(
|
||||
mcpServerConfig: MCPServerConfig,
|
||||
headers: Record<string, string>,
|
||||
): RequestInit {
|
||||
return {
|
||||
headers: {
|
||||
...mcpServerConfig.headers,
|
||||
...headers,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a transport with OAuth token for the given server configuration.
|
||||
*
|
||||
@@ -411,12 +429,9 @@ async function createTransportWithOAuth(
|
||||
if (mcpServerConfig.httpUrl) {
|
||||
// Create HTTP transport with OAuth token
|
||||
const oauthTransportOptions: StreamableHTTPClientTransportOptions = {
|
||||
requestInit: {
|
||||
headers: {
|
||||
...mcpServerConfig.headers,
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
},
|
||||
requestInit: createTransportRequestInit(mcpServerConfig, {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
}),
|
||||
};
|
||||
|
||||
return new StreamableHTTPClientTransport(
|
||||
@@ -426,12 +441,9 @@ async function createTransportWithOAuth(
|
||||
} else if (mcpServerConfig.url) {
|
||||
// Create SSE transport with OAuth token in Authorization header
|
||||
return new SSEClientTransport(new URL(mcpServerConfig.url), {
|
||||
requestInit: {
|
||||
headers: {
|
||||
...mcpServerConfig.headers,
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
},
|
||||
requestInit: createTransportRequestInit(mcpServerConfig, {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1170,6 +1182,7 @@ export async function createTransport(
|
||||
const transportOptions:
|
||||
| StreamableHTTPClientTransportOptions
|
||||
| SSEClientTransportOptions = {
|
||||
requestInit: createTransportRequestInit(mcpServerConfig, {}),
|
||||
authProvider: provider,
|
||||
};
|
||||
|
||||
@@ -1197,6 +1210,7 @@ export async function createTransport(
|
||||
const transportOptions:
|
||||
| StreamableHTTPClientTransportOptions
|
||||
| SSEClientTransportOptions = {
|
||||
requestInit: createTransportRequestInit(mcpServerConfig, {}),
|
||||
authProvider: provider,
|
||||
};
|
||||
if (mcpServerConfig.httpUrl) {
|
||||
|
||||
Reference in New Issue
Block a user