Skip to content

feat: support principal propagation on list mcp tools#151

Merged
NicoleMGomes merged 1 commit into
mainfrom
feat/list-tools-user-token
Jun 9, 2026
Merged

feat: support principal propagation on list mcp tools#151
NicoleMGomes merged 1 commit into
mainfrom
feat/list-tools-user-token

Conversation

@NicoleMGomes

@NicoleMGomes NicoleMGomes commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Disclaimer: Do not include SAP-internal or customer-specific information in this PR (e.g. internal system URLs, customer names, tenant IDs, or confidential configurations). This is a public repository.

Description

Adds an optional user_token parameter to AgentGatewayClient.list_mcp_tools(). When provided, the method uses user-scoped authentication (Phase 2 / token exchange) instead of the default system-scoped authentication, enabling principal propagation during tool discovery — consistent with how call_mcp_tool() already works.

  • LoB agents: if user_token is supplied, calls fetch_user_auth() (token exchange via IAS user fragment) instead of fetch_system_auth().
  • Customer agents: if user_token is supplied, calls exchange_user_token() (jwt-bearer grant via mTLS) instead of get_system_token_mtls().

Both flows are backwards-compatible: omitting user_token preserves the existing system-token behaviour.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Dependency update

How to Test

  1. Create an AgentGatewayClient for a LoB agent with a valid tenant_subdomain.
  2. Call await agw_client.list_mcp_tools(user_token="<valid-user-jwt>") and verify tools are returned with user-scoped auth (check token exchange happens instead of client credentials).
  3. Call await agw_client.list_mcp_tools() (no user_token) and verify the existing system-token behaviour is unchanged.
  4. Repeat steps 2–3 for a Customer agent (file-based credentials).
  5. Run the unit tests: uv run pytest tests/agentgateway/unit/test_agw_client.py::TestListMcpTools -v

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Additional Notes

The user_token parameter accepts both a plain str and a Callable[[], str] (consistent with call_mcp_tool and get_user_auth), allowing lazy token resolution at call time.

@NicoleMGomes NicoleMGomes marked this pull request as ready for review June 9, 2026 13:03
@NicoleMGomes NicoleMGomes requested a review from a team as a code owner June 9, 2026 13:03
@NicoleMGomes NicoleMGomes merged commit b8e6698 into main Jun 9, 2026
10 of 11 checks passed
@NicoleMGomes NicoleMGomes deleted the feat/list-tools-user-token branch June 9, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants