Skip to content

Add client example demonstrating pre-execution authorization check#2681

Open
golevishal wants to merge 6 commits into
modelcontextprotocol:mainfrom
golevishal:add-auth-client-example
Open

Add client example demonstrating pre-execution authorization check#2681
golevishal wants to merge 6 commits into
modelcontextprotocol:mainfrom
golevishal:add-auth-client-example

Conversation

@golevishal
Copy link
Copy Markdown

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 the mcpserver_quickstart subprocess, correctly allows the execution of safe tools (like add), and properly blocks/flags destructive tools.

Breaking Changes

None. This is purely an additive documentation/example change.

Types of changes

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

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling (N/A - Example script)
  • I have added or updated documentation as needed

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!

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.

1 participant