-
Notifications
You must be signed in to change notification settings - Fork 30
Add OAuth support with client credentials and refresh token grant types #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Noravee
wants to merge
64
commits into
main
Choose a base branch
from
mcp-oauth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
df17bfb
Add oauth support with client credentials and authorization code gran…
Noravee a679cb7
lint
Noravee dab4a8d
fix vulnerability due to a user-provided value
Noravee 716f971
lint
Noravee 30db527
name change for client credentials oauth provider
Noravee 5683e15
Merge branch 'main' into mcp-oauth
Noravee bf310b3
Merge branch 'main' into mcp-oauth
Noravee ba899ba
Merge branch 'main' into mcp-oauth
Noravee 72027fc
Merge branch 'main' into mcp-oauth
Noravee 634df53
Merge branch 'main' into mcp-oauth
Noravee b60aa1a
Add sly_data_token_storage.py and pass required info from sly data in…
Noravee 180a372
Merge branch 'mcp-oauth' of https://github.com/leaf-ai/neuro-san into…
Noravee 5342433
Merge branch 'main' into mcp-oauth
Noravee 88f00ff
Merge branch 'main' into mcp-oauth
Noravee 840da4e
Merge branch 'main' into mcp-oauth
Noravee 22aa322
Merge branch 'main' into mcp-oauth
Noravee b0a8ebf
Merge branch 'main' into mcp-oauth
Noravee e838ee9
Merge branch 'main' into mcp-oauth
Noravee b62b166
- add refresh token auth
Noravee 151a5e2
Merge branch 'mcp-oauth' of https://github.com/leaf-ai/neuro-san into…
Noravee 73ee8a3
lint
Noravee 1dea915
Add more comments
Noravee 5b0df2a
lint
Noravee f1ea1cc
add more comments on OAuth providers
Noravee 3a81656
Merge branch 'main' into mcp-oauth
Noravee c92d53b
lint on readme
Noravee 0f8e87d
fix shell check
Noravee 863d1a6
more comments
Noravee a95958e
Merge branch 'main' into mcp-oauth
Noravee aa7585d
Merge branch 'main' into mcp-oauth
Noravee 4270422
Merge branch 'main' into mcp-oauth
Noravee 907218a
- fix typo for timeout env var in langchain mcp adapter
Noravee 2a0a200
Merge branch 'main' into mcp-oauth
Noravee 70c1372
Merge branch 'main' into mcp-oauth
Noravee abe8371
Merge branch 'main' into mcp-oauth
Noravee 61e9d82
Merge branch 'main' into mcp-oauth
Noravee e859ed2
- prioritize provided token endpoint before discovery
Noravee d8351c6
Merge branch 'mcp-oauth' of https://github.com/leaf-ai/neuro-san into…
Noravee 1a84d4a
- Use the same field for client info in sly data and env var
Noravee d540ba5
lint
Noravee 575d045
update docstring for mcp info restorer
Noravee 16cc357
remove comprehension in langchain_mcp_adapter
Noravee 532d073
lint
Noravee 2dd2382
more comments
Noravee 7667a2b
slightly modify docstring for providers
Noravee 19331c3
Merge branch 'main' into mcp-oauth
Noravee eaef714
fix copilot comments
Noravee bc40332
Add more detailed documentation
Noravee 03efad8
remove token like example
Noravee 785abd5
md lint
Noravee d28d8a5
md lint
Noravee a2070b1
Merge branch 'main' into mcp-oauth
Noravee 4af75b9
add deprecated env var in mcp_info_restorer
Noravee b3f147e
set must_exist to False in McpInfoRestorer
Noravee ef88794
Merge branch 'main' into mcp-oauth
Noravee 372cbf2
Merge branch 'main' into mcp-oauth
Noravee 04b79bc
Merge branch 'main' into mcp-oauth
Noravee bb558d1
Merge branch 'main' into mcp-oauth
Noravee 7be8e1a
Merge branch 'main' into mcp-oauth
Noravee b75506a
Merge branch 'main' into mcp-oauth
Noravee ad1beb9
Merge branch 'main' into mcp-oauth
Noravee 4576c80
Merge branch 'main' into mcp-oauth
Noravee f690c83
Merge branch 'main' into mcp-oauth
Noravee 8269afb
Merge branch 'main' into mcp-oauth
Noravee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,299 @@ | ||
| # MCP Authentication Guide | ||
|
|
||
| Neuro-san supports machine-to-machine authentication for MCP servers that require credentials before granting | ||
| access to tools. This guide explains the available authentication methods and how to configure them. | ||
|
|
||
| <!--TOC--> | ||
|
|
||
| - [Authentication Methods](#authentication-methods) | ||
| - [Configuration Methods](#configuration-methods) | ||
| - [Method 1: Using sly_data](#method-1-using-sly_data) | ||
| - [http_headers](#http_headers) | ||
| - [Authorization](#authorization) | ||
| - [mcp_client_info](#mcp_client_info) | ||
| - [client_id](#client_id) | ||
| - [client_secret](#client_secret) | ||
| - [token_endpoint_auth_method](#token_endpoint_auth_method) | ||
| - [scope](#scope) | ||
| - [mcp_tokens](#mcp_tokens) | ||
| - [access_token](#access_token) | ||
| - [refresh_token](#refresh_token) | ||
| - [Method 2: Using Configuration File](#method-2-using-configuration-file) | ||
| - [http_headers](#http_headers-1) | ||
| - [mcp_client_info](#mcp_client_info-1) | ||
| - [mcp_server_info](#mcp_server_info) | ||
| - [token_endpoint](#token_endpoint) | ||
| - [auth_timeout](#auth_timeout) | ||
| - [tools](#tools) | ||
| - [Configuration Precedence Rules](#configuration-precedence-rules) | ||
|
|
||
| --- | ||
|
|
||
| ## Authentication Methods | ||
|
|
||
| Neuro-san supports three authentication methods, applied in the following priority order: | ||
|
|
||
| 1. **Headers** (highest priority) | ||
| - Typically uses the `Authorization` field with `Bearer <token_value>` | ||
| - Required fields depend on the authentication scheme expected by the MCP server | ||
|
|
||
| 2. **Refresh Token** (fallback if headers unavailable) | ||
| - Exchanges client ID and refresh token for an access token | ||
| - Used when both client credentials and refresh token are available | ||
|
|
||
| 3. **Client Credentials** (lowest priority) | ||
| - Exchanges client ID and/or client secret for an access token | ||
| - Used when only client information is provided | ||
|
|
||
| --- | ||
|
|
||
| ## Configuration Methods | ||
|
|
||
| Authentication data can be provided in two ways: through `sly_data` or via an environment variable configuration file. | ||
|
|
||
| ### Method 1: Using `sly_data` | ||
|
|
||
| Pass authentication credentials directly in the `sly_data` object. You can specify different credentials | ||
| for different MCP URLs. | ||
|
|
||
| **Available Fields:** | ||
| - `http_headers` - HTTP headers for authentication | ||
| - `mcp_client_info` - Client credentials for token exchange | ||
| - `mcp_tokens` - Token information (only available via sly_data) | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| { | ||
| "http_headers": { | ||
| "<MCP_URL_1>": { | ||
| "Authorization": "Bearer <token_value>" | ||
| } | ||
| }, | ||
| "mcp_client_info": { | ||
| "<MCP_URL_2>": { | ||
| "client_id": "<client_id>", | ||
| "client_secret": "<client_secret>", | ||
| "token_endpoint_auth_method": "client_secret_post", | ||
| "scope": "<scope>" | ||
| } | ||
| }, | ||
| "mcp_tokens": { | ||
| "<MCP_URL_3>": { | ||
| "access_token": "<access_token>", | ||
| "refresh_token": "<refresh_token>" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| #### `http_headers` | ||
|
|
||
| HTTP headers to be sent with requests to the MCP server for authentication purposes. | ||
|
|
||
| ##### `Authorization` | ||
|
|
||
| The `Authorization` header field typically contains credentials for authenticating the client with the server. | ||
| The most common format is `Bearer <token_value>` for OAuth 2.0 bearer tokens, | ||
| but other authentication schemes may be used depending on the server's requirements | ||
| (e.g., `Basic`, `Digest`, or custom schemes). | ||
| Consult your MCP server's documentation for the specific authentication scheme required. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "Authorization": "Bearer <token_value>" | ||
| ``` | ||
|
|
||
| #### `mcp_client_info` | ||
|
|
||
| Client credentials used for OAuth 2.0 authentication flows to obtain access tokens. | ||
|
|
||
| ##### `client_id` | ||
|
|
||
| The OAuth 2.0 client identifier issued to the client during the registration process. | ||
| This is a required field that uniquely identifies your application to the authorization server. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "client_id": "my-application-client-id" | ||
| ``` | ||
|
|
||
| ##### `client_secret` | ||
|
|
||
| The OAuth 2.0 client secret issued to the client during registration. | ||
| This confidential credential is used to authenticate the client with the authorization server. | ||
| This field is required unless `token_endpoint_auth_method` is set to `null`. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "client_secret": "super-secret-client-secret-value" | ||
| ``` | ||
|
|
||
| ##### `token_endpoint_auth_method` | ||
|
|
||
| Specifies the authentication method used when exchanging credentials for | ||
| an access token at the token endpoint. This follows the OAuth 2.0 specification. | ||
|
|
||
| **Supported values:** | ||
| - `client_secret_basic` (default): Client credentials are sent via | ||
| HTTP Basic authentication, with the client ID and secret encoded in the `Authorization` header | ||
| - `client_secret_post`: Client credentials are sent in the request body as POST parameters | ||
| - `None`: No authentication (for public clients) | ||
|
|
||
| For more details on OAuth 2.0 client authentication methods, | ||
| see [RFC 6749 Section 2.3](https://datatracker.ietf.org/doc/html/rfc6749#section-2.3). | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "token_endpoint_auth_method": "client_secret_post" | ||
| ``` | ||
|
|
||
| ##### `scope` | ||
|
|
||
| A space-separated list of OAuth 2.0 scopes being requested. | ||
| Scopes define the level of access that the application is requesting. | ||
| The available scopes depend on the MCP server's authorization server configuration. | ||
| If omitted, the server will use its default scopes. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "scope": "read:data write:data admin:settings" | ||
| ``` | ||
|
|
||
| #### `mcp_tokens` | ||
|
|
||
| Token information for authentication. This field is only available when using `sly_data` configuration. | ||
|
|
||
| The system will attempt to authenticate using the provided `access_token`. | ||
| If authentication fails (e.g., due to token expiration), the system will automatically attempt to refresh | ||
| the access token using the `refresh_token` if one is provided. | ||
|
|
||
| **Note:** While standard OAuth 2.0 token responses include additional fields such as `token_type`, `expires_in`, | ||
| and `scope`, these fields are not used by the authentication system and should not be included in the configuration. | ||
|
|
||
| ##### `access_token` | ||
|
|
||
| The OAuth 2.0 access token string used to authenticate requests to the MCP server. This is typically a JWT | ||
| (JSON Web Token) or an opaque token string issued by the authorization server. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "access_token": "<token_value>" | ||
| ``` | ||
|
|
||
| ##### `refresh_token` | ||
|
|
||
| An optional OAuth 2.0 refresh token that can be used to obtain a new access token when the current one expires or | ||
| fails. If provided, the system will automatically use this token to refresh authentication when needed. | ||
| Not all authorization servers issue refresh tokens, particularly for short-lived sessions or public clients. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "refresh_token": "<refresh-token-string-value>" | ||
| ``` | ||
|
|
||
| ### Method 2: Using Configuration File | ||
|
|
||
| Set the `AGENT_MCP_INFO_FILE` environment variable to point to a HOCON configuration file containing MCP authentication | ||
| settings. For detailed information about the structure and all available configuration options, | ||
| see the [MCP Info Configuration Documentation](mcp_info_hocon_reference.md). | ||
|
|
||
| **Important Notes:** | ||
| - `MCP_SERVERS_INFO_FILE` is deprecated and will be removed in version 0.7.0 | ||
| - Server info (e.g., token endpoints) can only be configured via environment variable | ||
| - Server URLs must match those defined in the agent network HOCON file | ||
| - We strongly recommend **not** storing secrets directly in any source file. | ||
| Source files can easily be committed to version control, and checking in secrets is a serious security risk. | ||
| If these configuration files need to be committed, use **HOCON substitution** (e.g., environment variable references) | ||
| instead of hardcoding secret values. | ||
|
|
||
| **Example Configuration:** | ||
|
|
||
| ```hocon | ||
| { | ||
| "mcp_server_url_1": { | ||
| "http_headers": { | ||
| "Authorization": "Bearer <token>" | ||
| }, | ||
| "mcp_client_info": { | ||
| "client_id": "<client_id>", | ||
| "client_secret": "<client_secret>", | ||
| "token_endpoint_auth_method": "client_secret_post", | ||
| "scope": "<scope>" | ||
| }, | ||
| "mcp_server_info": { | ||
| "token_endpoint": "https://example.com/token" | ||
| }, | ||
| "auth_timeout": 300.0, | ||
| "tools": ["tool_1", "tool_2"] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| <!--- pyml disable-next-line no-duplicate-heading --> | ||
| #### `http_headers` | ||
|
|
||
| Same as in Method 1. See the `http_headers` section under Method 1 for detailed field descriptions. | ||
|
|
||
| <!--- pyml disable-next-line no-duplicate-heading --> | ||
| #### `mcp_client_info` | ||
|
|
||
| Same as in Method 1. See the `mcp_client_info` section under Method 1 for detailed field descriptions. | ||
|
|
||
| #### `mcp_server_info` | ||
|
|
||
| Configuration for the MCP server's OAuth 2.0 endpoints and authentication behavior. | ||
|
|
||
| ##### `token_endpoint` | ||
|
|
||
| The URL of the OAuth 2.0 token endpoint where the client exchanges credentials for access tokens. | ||
| If not provided, the system will attempt to discover the endpoint automatically through the server's | ||
| discovery mechanism, or fall back to `{base_url}/token`. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "token_endpoint": "https://auth.example.com/oauth/token" | ||
| ``` | ||
|
|
||
| #### `auth_timeout` | ||
|
|
||
| The maximum time in seconds to wait for authentication operations to complete. | ||
| This includes token exchange requests and any other authentication-related network operations. | ||
| The default value is 300.0 seconds (5 minutes). | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "auth_timeout": 180.0 # 3 minutes | ||
| ``` | ||
|
|
||
| **Alternative:** You can also set the `AGENT_MCP_TIMEOUT_SECONDS` environment variable instead of using this field. | ||
|
|
||
| #### `tools` | ||
|
|
||
| An optional list of tool names to filter. | ||
| When specified, only the listed tools from this MCP server will be made available. | ||
| If omitted, all tools from the server are available. | ||
|
|
||
| **Example:** | ||
|
|
||
| ```hocon | ||
| "tools": ["search_database", "update_record", "delete_record"] | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Configuration Precedence Rules | ||
|
|
||
| When authentication data exists in multiple locations, the following precedence applies: | ||
|
|
||
| 1. **sly_data takes precedence** over configuration file for headers and client info on the same server | ||
| 2. **Configuration file tool filtering** is used only if no tool filtering exists in the agent network HOCON file | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.