feat: Supports request header authentication with connectToMCPServer#1690
feat: Supports request header authentication with connectToMCPServer#1690huuyafwww wants to merge 3 commits intobrowserbase:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 91d5e1c The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant User as User Application
participant Core as Stagehand Core (connectToMCPServer)
participant SDK as MCP SDK Client
participant Transport as StreamableHTTPClientTransport
participant Server as Remote MCP Server (e.g. DeepWiki)
Note over User,Server: NEW: HTTP Transport with Auth Headers
User->>Core: connectToMCPServer(config)
alt config is ConnectToMCPServerOptions
Core->>Core: NEW: Extract requestOptions (headers, etc.)
Core->>Transport: NEW: Instantiate with serverUrl and requestOptions
else config is string/URL
Core->>Transport: Instantiate with serverUrl only
end
Core->>SDK: Create Client with Transport
Core->>SDK: client.connect()
SDK->>Transport: start()
Transport->>Server: NEW: HTTP Request with custom headers
Note right of Transport: Headers include Authorization: Bearer <token>
alt Connection Success
Server-->>Transport: 200 OK / SSE Stream
Transport-->>SDK: Connected
SDK-->>Core: Client Instance
Core-->>User: client
else Connection Failure (Auth Error)
Server-->>Transport: 401 Unauthorized
Transport-->>SDK: Error
SDK-->>Core: MCPConnectionError
Core-->>User: throw MCPConnectionError
end
Greptile SummaryThis PR adds support for HTTP request header authentication to Key Changes:
Issues Found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant connectToMCPServer
participant StreamableHTTPClientTransport
participant MCP Server
User->>connectToMCPServer: Call with serverConfig
alt serverConfig has requestOptions
connectToMCPServer->>connectToMCPServer: Extract requestOptions
connectToMCPServer->>StreamableHTTPClientTransport: new Transport(url, requestOptions)
Note over StreamableHTTPClientTransport: requestOptions includes<br/>headers (e.g., Authorization)
else no requestOptions
connectToMCPServer->>StreamableHTTPClientTransport: new Transport(url)
end
connectToMCPServer->>MCP Server: client.connect(transport)
MCP Server-->>connectToMCPServer: Connection established
connectToMCPServer->>MCP Server: client.ping()
MCP Server-->>connectToMCPServer: Ping response
connectToMCPServer-->>User: Return connected client
Last reviewed commit: 2ee2589 |
Additional Comments (2)
|
|
merged |
why
Hello, thank you for developing the wonderful product Stagehand.
I am currently using Stagehand for my project.
It is very comfortable and convenient.
While developing, I was using connectToMCPServer to establish the client connection for agent integration settings,
and I discovered it does not support authentication via request headers (Authorization header).
In my project, I attempted to use DeepWiki's MCP server, which can connect to private repositories.
However, since it doesn't allow setting the API key via URL parameters like Supabase's MCP does,
I couldn't establish a connection using connectToMCPServer.
https://mcp.devin.ai/
Because the API key must be included in the Authorization request header,
I need to make modifications to handle such MCP servers in a more generic way.
what changed
We have modified connectToMCPServer to accept options for StreamableHTTPClientTransport as arguments.
test plan
pnpm installandpnpm build,pnpm lintsucceedpackages/core/tests/public-api/v3-core.test.tsSummary by cubic
Adds request header authentication to connectToMCPServer by exposing requestOptions to the HTTP transport. This enables connecting to MCP servers that require Authorization headers (e.g., DeepWiki).
Written for commit 91d5e1c. Summary will update on new commits. Review in cubic