-
Notifications
You must be signed in to change notification settings - Fork 365
Enable MCP auth for NAT MCP clients #752
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
Merged
+2,001
−134
Merged
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
282da21
Re-format example config files to make diff more apparent
AnuradhaKaruppiah 7c7442f
Initial changes in NAT to enable Protected MCP Server
AnuradhaKaruppiah 11a9fd3
Minor docs enhancements
AnuradhaKaruppiah 6ae33b6
Add a stub token verifier on the server side
AnuradhaKaruppiah 883c3f8
Add auth config to the MCP client
AnuradhaKaruppiah 47a2a77
Document the client and server auth config options
AnuradhaKaruppiah b694fff
Add notes on how client discovery happens
AnuradhaKaruppiah ef1740e
Minor doc updates
AnuradhaKaruppiah b905bda
Merge remote-tracking branch 'upstream/develop' into ak-mcp-auth
AnuradhaKaruppiah 183dfc4
Update docs with AuthenticationRef
AnuradhaKaruppiah 69b771e
Move MCP auth config to AuthenticationRef
AnuradhaKaruppiah bc5ae77
Merge remote-tracking branch 'upstream/develop' into ak-mcp-auth
AnuradhaKaruppiah 8574a57
Add sample mcp auth config file
AnuradhaKaruppiah e070756
Config fixup
AnuradhaKaruppiah f137c73
Setup MCP session without auth for dynamic tool discovery
AnuradhaKaruppiah 3bac053
Remove auth session from exit stack for now
AnuradhaKaruppiah 4d779f3
Use httpx Auth for intercepting HTTP requests and adding the header
AnuradhaKaruppiah a434bdd
Enable auth for tool calls only
AnuradhaKaruppiah 2e2a1cb
Drop auth session
AnuradhaKaruppiah 5393fef
Remove auth support for SSE
AnuradhaKaruppiah 218eb0a
Move MCP schema to model conversion code to an utils file
AnuradhaKaruppiah 5975595
Update tool the in the mcp auth example
AnuradhaKaruppiah cec64da
Drop unnecessary NAT prefix from the class name
AnuradhaKaruppiah 81e35cd
Refactor mcp-oauth2 files
AnuradhaKaruppiah 323c142
Add MCP server in the Auth provider config
AnuradhaKaruppiah 9c02c0a
Add a new MCP oauth2 provider
AnuradhaKaruppiah e9ffa4d
Minor fixups
AnuradhaKaruppiah d3011ad
Merge remote-tracking branch 'upstream/develop' into ak-mcp-auth
AnuradhaKaruppiah cf66e19
Some more fixes needed here
AnuradhaKaruppiah 1250a6d
Move to using pydantic models defined in mcp auth.py
AnuradhaKaruppiah 6360e8e
Add an option to effective scopes from the auth server
AnuradhaKaruppiah 373e773
Add a lock for discovery, DCR and deletgate building
AnuradhaKaruppiah 65cb9ed
Add unncessary key comp
AnuradhaKaruppiah 2c9553c
Minor fixups
AnuradhaKaruppiah 089f424
Rename auth provider files for consistency
AnuradhaKaruppiah a205310
Misc fixes for problems found during testing
AnuradhaKaruppiah d1500c6
Merge remote-tracking branch 'upstream/develop' into ak-mcp-auth
AnuradhaKaruppiah 6e92f94
Update the MCP auth scratch pad
AnuradhaKaruppiah 10e8789
Add a Dockerfile for launching the example auth server
AnuradhaKaruppiah 79bd88c
Add notes in mcp-auth.md
AnuradhaKaruppiah 89d03cd
Update MCP version to the latest
AnuradhaKaruppiah b9d3384
Update uv lock
AnuradhaKaruppiah c7bf652
Rename math servers to indicate they are protected
AnuradhaKaruppiah 7822952
Update comments to indicate that this is a protected MCP server
AnuradhaKaruppiah 718255e
Drop helper method from the authenticate model
AnuradhaKaruppiah d7a5351
Merge remote-tracking branch 'upstream/develop' into ak-mcp-auth
AnuradhaKaruppiah 4ac39b7
Misc fixups
AnuradhaKaruppiah 5b4eacd
Basic unit tests to catch breakages during auth dev
AnuradhaKaruppiah 739688c
Style fixes
AnuradhaKaruppiah f4b59a0
More style fixes
AnuradhaKaruppiah f3cc020
Fix spelling
AnuradhaKaruppiah 01568e8
Style fixes
AnuradhaKaruppiah 9a68f00
Fix docs build
AnuradhaKaruppiah e4ab888
Pass auth request via provider config
AnuradhaKaruppiah 90a2107
Update unit tests to match the src changes
AnuradhaKaruppiah eea3135
Remove auth request from the oauth2 flow provider
AnuradhaKaruppiah 2a9bd97
Drop unnecessarty cleanup
AnuradhaKaruppiah 7c59f86
Test fixup in response to review comments
AnuradhaKaruppiah 2b071be
Ensure auth_server_url is configured when require_auth is specified
AnuradhaKaruppiah 8b5d908
Add todo comments
AnuradhaKaruppiah daf300c
Don't yield the response on retry
AnuradhaKaruppiah e26c24c
Merge remote-tracking branch 'upstream/develop' into ak-mcp-auth
AnuradhaKaruppiah 711ae67
Add tests to increase code coverage
AnuradhaKaruppiah e075842
Drop some superfluos tests
AnuradhaKaruppiah 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,50 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
# 🧪 Temporary MCP Auth Planning Notes (Experimental) | ||
This is currently a scratch pad for planning MCP auth. It will be rewritten when all the components are ready. | ||
|
||
## Phases of MCP auth implementation | ||
1. [Completed] MCP client with new `mcp_oauth2` auth provider. | ||
2. [Pending] MCP protected server with `TokenVerifier`. | ||
3. [Pending] Changes for end-to-end MCP auth testing. | ||
|
||
## Steps for testing MCP auth | ||
1. Start the MCP server with auth enabled | ||
```bash | ||
nat mcp --config_file examples/MCP/simple_calculator_mcp/configs/config-mcp-server-auth.yml | ||
``` | ||
This starts a protected MCP server on port 9901. This MCP server has a stub token verifier that will always return success without AS introspection. | ||
|
||
2. Start a container with the example auth server from the MCP repo. This will start the auth server on port 9000. | ||
```bash | ||
docker build -t mcp-sample-as -f examples/MCP/simple_calculator_mcp/deploy_example_as/Dockerfile examples/MCP/simple_calculator_mcp/deploy_example_as/ | ||
docker run -p 9000:9000 mcp-sample-as | ||
``` | ||
This starts the auth server on port 9000. | ||
|
||
3. Start NAT UI and enable websocket | ||
|
||
4. Run the workflow with MCP auth enabled client | ||
|
||
```bash | ||
nat serve --config_file examples/MCP/simple_calculator_mcp/configs/config-mcp-auth-dynamic.yml | ||
``` | ||
This starts the workflow with a MCP client that uses the `mcp_oauth2` auth provider. This provider: | ||
- Discovers the auth server endpoints. | ||
- Registers a client with the auth server. | ||
- Performs the OAuth2 authorization code flow using the `OAuth2AuthCodeFlowProvider`. |
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
56 changes: 56 additions & 0 deletions
56
examples/MCP/simple_calculator_mcp/configs/config-mcp-auth-dynamic.yml
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,56 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
functions: | ||
current_datetime_local: | ||
_type: current_datetime | ||
mcp_protected_math: | ||
_type: mcp_client | ||
server: | ||
transport: streamable-http | ||
auth_provider: mcp_oauth2_dynamic | ||
url: "http://localhost:9901/mcp" | ||
tool_filter: | ||
# skip react_agent and datetime tools from the math MCP server | ||
- calculator_multiply | ||
- calculator_inequality | ||
- calculator_divide | ||
- calculator_subtract | ||
|
||
authentication: | ||
mcp_oauth2_dynamic: | ||
_type: mcp_oauth2 | ||
server_url: http://localhost:9901 | ||
redirect_uri: http://localhost:8000/auth/redirect | ||
|
||
llms: | ||
nim_llm: | ||
_type: nim | ||
model_name: meta/llama-3.1-70b-instruct | ||
temperature: 0.0 | ||
max_tokens: 1024 | ||
|
||
workflow: | ||
_type: react_agent | ||
tool_names: | ||
- calculator_multiply | ||
- calculator_inequality | ||
- calculator_divide | ||
- calculator_subtract | ||
- current_datetime_local | ||
llm_name: nim_llm | ||
verbose: true | ||
retry_parsing_errors: true | ||
max_retries: 3 |
69 changes: 69 additions & 0 deletions
69
examples/MCP/simple_calculator_mcp/configs/config-mcp-auth-static.yml
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,69 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
functions: | ||
current_datetime_local: | ||
_type: current_datetime | ||
mcp_protected_math: | ||
_type: mcp_client | ||
server: | ||
AnuradhaKaruppiah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
transport: streamable-http | ||
auth_provider: static_oauth2 | ||
url: "http://localhost:9901/mcp" | ||
tool_filter: | ||
# skip react_agent and datetime tools from the math MCP server | ||
- calculator_multiply | ||
- calculator_inequality | ||
- calculator_divide | ||
- calculator_subtract | ||
|
||
authentication: | ||
static_oauth2: | ||
_type: oauth2_auth_code_flow | ||
redirect_uri: http://localhost:8000/auth/redirect | ||
authorization_url: http://localhost:5001/oauth/authorize | ||
token_url: http://localhost:5001/oauth/token | ||
token_endpoint_auth_method: client_secret_post | ||
client_id: ${MCP_CLIENT_ID} | ||
client_secret: ${MCP_CLIENT_SECRET} | ||
scopes: | ||
- openid | ||
- profile | ||
use_pkce: false | ||
|
||
llms: | ||
nim_llm: | ||
_type: nim | ||
model_name: meta/llama-3.1-70b-instruct | ||
temperature: 0.0 | ||
max_tokens: 1024 | ||
openai_llm: | ||
_type: openai | ||
model_name: gpt-3.5-turbo | ||
max_tokens: 2000 | ||
|
||
workflow: | ||
_type: react_agent | ||
tool_names: | ||
- calculator_multiply | ||
- calculator_inequality | ||
- calculator_divide | ||
- calculator_subtract | ||
- current_datetime_local | ||
llm_name: nim_llm | ||
verbose: true | ||
retry_parsing_errors: true | ||
max_retries: 3 |
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
58 changes: 58 additions & 0 deletions
58
examples/MCP/simple_calculator_mcp/configs/config-mcp-server-auth.yml
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,58 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This is used to start a protected MCP math server with auth enabled. | ||
|
||
general: | ||
front_end: | ||
_type: mcp | ||
require_auth: true | ||
auth_server_url: http://localhost:9000 | ||
required_scopes: ["user"] | ||
|
||
functions: | ||
calculator_multiply: | ||
_type: calculator_multiply | ||
calculator_inequality: | ||
_type: calculator_inequality | ||
calculator_divide: | ||
_type: nat_simple_calculator/calculator_divide | ||
current_datetime: | ||
_type: current_datetime | ||
calculator_subtract: | ||
_type: calculator_subtract | ||
|
||
llms: | ||
nim_llm: | ||
_type: nim | ||
model_name: meta/llama-3.1-70b-instruct | ||
temperature: 0.0 | ||
max_tokens: 1024 | ||
openai_llm: | ||
_type: openai | ||
model_name: gpt-3.5-turbo | ||
max_tokens: 2000 | ||
|
||
workflow: | ||
_type: react_agent | ||
tool_names: | ||
- calculator_multiply | ||
- calculator_inequality | ||
- current_datetime | ||
- calculator_divide | ||
- calculator_subtract | ||
llm_name: nim_llm | ||
verbose: true | ||
parse_agent_response_max_retries: 3 |
47 changes: 47 additions & 0 deletions
47
examples/MCP/simple_calculator_mcp/deploy_example_as/Dockerfile
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,47 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# ---- Base OS ---- | ||
FROM ubuntu:22.04 | ||
|
||
# ---- System deps ---- | ||
RUN apt-get update && apt-get upgrade -y \ | ||
&& apt-get install -y --no-install-recommends \ | ||
python3 python3-pip git ca-certificates \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Make python/pip the default names | ||
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \ | ||
&& update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 | ||
ENV PIP_NO_CACHE_DIR=1 PYTHONUNBUFFERED=1 | ||
|
||
# ---- Install uv (to match your steps) ---- | ||
RUN pip install --no-cache-dir uv | ||
|
||
# ---- Clone the MCP SDK repo ---- | ||
WORKDIR /opt | ||
RUN git clone https://github.com/modelcontextprotocol/python-sdk.git mcp-sdk | ||
WORKDIR /opt/mcp-sdk | ||
RUN git checkout v1.14.0 | ||
|
||
# ---- Install the sample auth server (editable) ---- | ||
WORKDIR /opt/mcp-sdk/examples/servers/simple-auth | ||
RUN uv pip install --system -e . | ||
|
||
# ---- Network ---- | ||
EXPOSE 9000 | ||
|
||
# ---- Run the sample auth server ---- | ||
ENTRYPOINT ["mcp-simple-auth-as", "--port=9000"] |
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
14 changes: 14 additions & 0 deletions
14
packages/nvidia_nat_mcp/src/nat/plugins/mcp/auth/__init__.py
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,14 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
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.