Skip to content

Commit 6228912

Browse files
docs: Add MCP OAuth authentication documentation
- Add OAuth authentication section to MCP settings page explaining how OAuth works, configuration options (CLI, SDK, config file), and supported OAuth MCP servers (Notion) - Enhance SDK MCP guide with OAuth token storage path and headless workflow note - Document that OAuth tokens are stored in ~/.fastmcp/oauth-mcp-client-cache/ Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 3b8952a commit 6228912

3 files changed

Lines changed: 84 additions & 2 deletions

File tree

openhands/usage/settings/mcp-settings.mdx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,80 @@ Other options include:
192192
- **Custom FastAPI/Express servers**: Build your own HTTP wrapper around stdio MCP servers.
193193
- **Docker-based proxies**: Containerized solutions for better isolation.
194194
- **Cloud-hosted MCP services**: Third-party services that provide MCP endpoints.
195+
196+
## OAuth Authentication
197+
198+
Some MCP servers (like Notion MCP) require OAuth authentication instead of API keys. OpenHands supports OAuth-based MCP servers through the [FastMCP](https://gofastmcp.com/) library.
199+
200+
### How OAuth Works
201+
202+
When you configure an OAuth-enabled MCP server:
203+
204+
1. **First connection**: When the agent first attempts to use tools from an OAuth-protected MCP server, OpenHands initiates the OAuth flow
205+
2. **Browser authentication**: A browser window opens automatically for you to authorize access
206+
3. **Token storage**: After authorization, tokens are securely stored locally in `~/.fastmcp/oauth-mcp-client-cache/`
207+
4. **Automatic refresh**: FastMCP automatically refreshes tokens as needed
208+
209+
### Configuration
210+
211+
<Tabs>
212+
<Tab title="CLI">
213+
Use the `--auth oauth` flag when adding an MCP server:
214+
215+
```bash
216+
openhands mcp add notion --transport http \
217+
--auth oauth \
218+
https://mcp.notion.com/mcp
219+
```
220+
221+
This creates a configuration in `~/.openhands/mcp.json`:
222+
```json
223+
{
224+
"mcpServers": {
225+
"notion": {
226+
"url": "https://mcp.notion.com/mcp",
227+
"transport": "http",
228+
"auth": "oauth"
229+
}
230+
}
231+
}
232+
```
233+
</Tab>
234+
<Tab title="SDK">
235+
Configure OAuth in your `mcp_config`:
236+
237+
```python
238+
mcp_config = {
239+
"mcpServers": {
240+
"Notion": {
241+
"url": "https://mcp.notion.com/mcp",
242+
"auth": "oauth"
243+
}
244+
}
245+
}
246+
agent = Agent(llm=llm, tools=tools, mcp_config=mcp_config)
247+
```
248+
249+
See the [SDK MCP Guide](/sdk/guides/mcp) for complete examples.
250+
</Tab>
251+
<Tab title="Config File">
252+
Add the `auth` field to your server configuration:
253+
254+
```toml
255+
[mcp]
256+
shttp_servers = [
257+
{url = "https://mcp.notion.com/mcp", auth = "oauth"}
258+
]
259+
```
260+
</Tab>
261+
</Tabs>
262+
263+
### Supported OAuth MCP Servers
264+
265+
| Server | URL | Description |
266+
|--------|-----|-------------|
267+
| Notion | `https://mcp.notion.com/mcp` | Access Notion workspaces, pages, and databases |
268+
269+
<Note>
270+
OAuth MCP servers require user interaction for the initial authentication. This means they may not be suitable for fully automated/headless workflows. For automation, consider using API key-based authentication where available.
271+
</Note>

overview/model-context-protocol.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ When OpenHands starts, it:
5555
## Getting Started with MCP
5656

5757
- **For detailed configuration**: See [MCP Settings](/openhands/usage/settings/mcp-settings)
58+
- **For CLI usage**: See [CLI MCP Servers](/openhands/usage/cli/mcp-servers)
5859
- **For SDK integration**: See [SDK MCP Guide](/sdk/guides/mcp)
5960
- **For architecture details**: See [MCP Architecture](/sdk/arch/mcp)

sdk/guides/mcp.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ For MCP servers requiring OAuth authentication:
5959
- Configure OAuth-enabled MCP servers by specifying the URL and auth type
6060
- The SDK automatically handles the OAuth flow when first connecting
6161
- When the agent first attempts to use an OAuth-protected MCP server's tools, the SDK initiates the OAuth flow via [FastMCP](https://gofastmcp.com/servers/auth/authentication)
62-
- User will be prompted to authenticate
63-
- Access tokens are securely stored and automatically refreshed by FastMCP as needed
62+
- User will be prompted to authenticate via browser
63+
- Access tokens are securely stored in `~/.fastmcp/oauth-mcp-client-cache/` and automatically refreshed by FastMCP as needed
6464

6565
```python mcp_config focus={5} icon="python" wrap
6666
mcp_config = {
@@ -73,6 +73,10 @@ mcp_config = {
7373
}
7474
```
7575

76+
<Note>
77+
OAuth MCP servers require user interaction for the initial browser-based authentication. This means they are not suitable for fully automated/headless workflows. If you need headless access, check if the MCP provider offers API key authentication as an alternative.
78+
</Note>
79+
7680
## Ready-to-Run Basic MCP Usage Example
7781

7882
<Note>

0 commit comments

Comments
 (0)