1414import os
1515from dataclasses import dataclass
1616from enum import Enum
17- from typing import Any
17+ from typing import Any , Callable
1818
19- from mcp import ClientSession , StdioServerParameters
19+ from mcp import ClientSession , StdioServerParameters , types
2020from mcp .client .stdio import stdio_client
2121
2222# ---------------------------------------------------------------------------
@@ -69,7 +69,7 @@ async def authorized_call_tool(
6969 session : ClientSession ,
7070 tool_name : str ,
7171 arguments : dict [str , Any ],
72- policy = default_policy ,
72+ policy : Callable [[ AuthRequest ], AuthResult ] = default_policy ,
7373) -> Any :
7474 """Evaluate the authorization policy before calling a tool.
7575 Only executes the tool if the decision is ALLOW.
@@ -86,7 +86,11 @@ async def authorized_call_tool(
8686 tool_result = await session .call_tool (tool_name , arguments )
8787
8888 # Safely extract text output if present
89- output = tool_result .content [0 ].text if getattr (tool_result , "content" , None ) else str (tool_result )
89+ output = str (tool_result )
90+ if hasattr (tool_result , "content" ) and tool_result .content :
91+ first_content = tool_result .content [0 ]
92+ if isinstance (first_content , types .TextContent ):
93+ output = first_content .text
9094 print (f" Result : { output } " )
9195 return tool_result
9296 except Exception as e :
0 commit comments