Add client example demonstrating pre-execution authorization check#2681
Open
golevishal wants to merge 6 commits into
Open
Add client example demonstrating pre-execution authorization check#2681golevishal wants to merge 6 commits into
golevishal wants to merge 6 commits into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes part of #539
Adds a client example demonstrating a pre-execution authorization callback pattern. Shows how to evaluate tool calls against a policy (allow / approval_required / deny) before execution — a common need when connecting agents to MCP servers at scale.
PR #1436 covers sampling examples. This is a complementary example focused on the tool-execution authorization loop.
Motivation and Context
The original issue requested client examples. Currently, there are no examples demonstrating how to evaluate tool calls against a policy before execution. This pattern is critical for secure agent architecture where some tools are safe to run automatically, but others require human-in-the-loop approval.
How Has This Been Tested?
Ran the example locally using
uv run examples/snippets/clients/client_with_authorization.py. Verified that the client successfully connects to themcpserver_quickstartsubprocess, correctly allows the execution of safe tools (likeadd), and properly blocks/flags destructive tools.Breaking Changes
None. This is purely an additive documentation/example change.
Types of changes
Checklist
Additional context
We ran into the need for this exact pattern while building AgentIAM to manage tool authorizations at scale, and figured a clean, standalone example using dataclasses would be helpful for others trying to implement similar human-in-the-loop policies!