@@ -60,12 +60,14 @@ async def resolve_interruptions(agent: Agent, result: Any) -> Any:
6060async def main ():
6161 current_dir = os .path .dirname (os .path .abspath (__file__ ))
6262 samples_dir = os .path .join (current_dir , "sample_files" )
63+ blocked_path = os .path .join (samples_dir , "test.txt" )
6364
6465 async with MCPServerStdio (
6566 name = "Filesystem Server" ,
6667 params = {
6768 "command" : "npx" ,
6869 "args" : ["-y" , "@modelcontextprotocol/server-filesystem" , samples_dir ],
70+ "cwd" : samples_dir ,
6971 },
7072 require_approval = {"always" : {"tool_names" : ["read_text_file" ]}},
7173 ) as server :
@@ -83,10 +85,16 @@ async def main():
8385 # Build an agent that uses the prefetched tools instead of mcp_servers.
8486 prefetched_agent = Agent (
8587 name = "Prefetched MCP Assistant" ,
86- instructions = "Use the prefetched tools to help with file questions." ,
88+ instructions = (
89+ "Use the prefetched tools to help with file questions. "
90+ "When using path arguments, prefer absolute paths in the allowed directory."
91+ ),
8792 tools = all_tools ,
8893 )
89- message = "List the available files and read one of them."
94+ message = (
95+ f"List files in this allowed directory: { samples_dir } . "
96+ "Then read one of those files."
97+ )
9098 print (f"\n Running: { message } \n " )
9199 result = await Runner .run (prefetched_agent , message )
92100 result = await resolve_interruptions (prefetched_agent , result )
@@ -105,10 +113,17 @@ async def main():
105113
106114 filtered_agent = Agent (
107115 name = "Filtered MCP Assistant" ,
108- instructions = "Use the filtered tools to respond." ,
116+ instructions = (
117+ "Use the filtered tools to respond. "
118+ "If a request requires a missing tool, explain that the capability is not "
119+ "available."
120+ ),
109121 tools = filtered_tools ,
110122 )
111- blocked_message = "Create a file named sample_files/test.txt with the text hello."
123+ blocked_message = (
124+ f'Create a file named "{ blocked_path } " with the text "hello". '
125+ "If the available tools cannot create files, explain that clearly."
126+ )
112127 print (f"\n Running: { blocked_message } \n " )
113128 filtered_result = await Runner .run (filtered_agent , blocked_message )
114129 filtered_result = await resolve_interruptions (filtered_agent , filtered_result )
0 commit comments