1- """
2- Example: MCP client with a pre-execution authorization callback.
1+ """Example: MCP client with a pre-execution authorization callback.
32
43This example shows how to build a tool-execution loop that evaluates
54every tool call against an authorization policy before execution.
2019from mcp import ClientSession , StdioServerParameters
2120from mcp .client .stdio import stdio_client
2221
23-
2422# ---------------------------------------------------------------------------
2523# Authorization layer
2624# ---------------------------------------------------------------------------
@@ -45,8 +43,7 @@ class AuthResult:
4543
4644
4745def default_policy (request : AuthRequest ) -> AuthResult :
48- """
49- A simple policy function that decides whether a tool call should
46+ """A simple policy function that decides whether a tool call should
5047 be allowed, denied, or held for approval.
5148
5249 Replace or extend this function with your own logic — for example,
@@ -74,8 +71,7 @@ async def authorized_call_tool(
7471 arguments : dict [str , Any ],
7572 policy = default_policy ,
7673) -> Any :
77- """
78- Evaluate the authorization policy before calling a tool.
74+ """Evaluate the authorization policy before calling a tool.
7975 Only executes the tool if the decision is ALLOW.
8076 """
8177 request = AuthRequest (tool_name = tool_name , arguments = arguments )
0 commit comments