You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using an external MCP plugin with the OpenAI Agents SDK (MCPServerStdio in this case), I consistently receive a resource_tracker: There appear to be XX leaked semaphore objects to clean up at shutdown warning message during the program's shutdown. The exact number of leaked objects (e.g., 24) varies.
Steps to reproduce
Use the following code snippet which initializes a custom OpenAI client and then attempts to run an agent configured with an MCPServerStdio plugin.
Code Snippet
importasynciofromagentsimportAgent, Runnerfromagentsimportset_default_openai_client, set_default_openai_api, set_tracing_disabledfromagents.mcpimportMCPServerStdiofromopenaiimportAsyncOpenAI# --- Replace with your actual values ---OPENAI_BASE_URL="YOUR_CUSTOM_BASE_URL"# e.g., "http://localhost:11434/v1" or similarOPENAI_API_KEY="YOUR_API_KEY"# Can be "ollama" or similar if using local endpointMODEL_NAME="YOUR_MODEL_NAME"# e.g., "llama3" or "gpt-4o"# --- End of replacements ---asyncdefmain():
# Create custom OpenAI clientcustom_client=AsyncOpenAI(base_url=OPENAI_BASE_URL, api_key=OPENAI_API_KEY)
# Required configuration for using a custom OpenAI API endpointset_default_openai_api("chat_completions") # Or other API type if neededset_default_openai_client(custom_client)
set_tracing_disabled(True) # Disable tracing if not needed# Get Python executable pathcurrent_dir=os.path.dirname(os.path.abspath(__file__))
python_executable=sys.executablesoc_push_script=os.path.join(current_dir, "plugins", "soc_push_script.py") # Assuming this script exists and works as an MCP plugin# Initialize the MCP server plugin using MCPServerStdio# Make sure soc_push_script.py implements the MCP protocol correctlymcp_soc_push=MCPServerStdio(
name="soc_push_script",
params={
"command": python_executable,
"args": [soc_push_script],
})
# Run the agent with the MCP plugintry:
asyncwithmcp_soc_pushaspush_tool: # Use the plugin as a toolagent=Agent(
name="test",
instructions='test',
model=MODEL_NAME,
mcp_servers=[push_tool], # Add the MCP tool to the agent's servers
)
print("Starting agent run...")
result=awaitRunner.run(starting_agent=agent, input='')
print("Agent run finished.")
print("Final Output:", result.final_output)
finally:
# Explicitly attempt cleanup if necessary, though the warning suggests leakageprint("Attempting cleanup (may not prevent warning)...")
# Specific MCP cleanup methods might be needed depending on implementationpass# Add cleanup logic here if known# Assuming this script is run directlyif__name__=="__main__":
asyncio.run(main())
Note: The soc_push_script.py file is not provided, but it is assumed to be a functional MCP plugin script that interacts via standard I/O.
Console Output
/usr/local/Cellar/python@3.13/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/resource_tracker.py:276: UserWarning: resource_tracker: There appear to be 24 leaked semaphore objects to clean up at shutdown: {'/mp-t9hi4oa_', '/mp-pbo_pje7', '/mp-_1jipfl5', '/mp-04d4uokn', '/mp-jw_gfhjk', '/mp-8122t3qm', '/mp-tjg6llji', '/mp-75j5swhj', '/mp-oprtjvq9', '/mp-_9c_6tt4', '/mp-o6ld1gx6', '/mp-vfh4ncjt', '/mp-6pf__aj0', '/mp-h8x7h4uu', '/mp-_heqxtvk', '/mp-uvzgo0ft', '/mp-gqm7a9dj', '/mp-j09dabgf', '/mp-w30c1pxu', '/mp-4gzlcmxm', '/mp-b5004bcn', '/mp-d1l4chll', '/mp-we2hfv61', '/mp-t1hr16ma'}
warnings.warn(
The text was updated successfully, but these errors were encountered:
Debug information
Describe the bug
When using an external MCP plugin with the OpenAI Agents SDK (
MCPServerStdio
in this case), I consistently receive aresource_tracker: There appear to be XX leaked semaphore objects to clean up at shutdown
warning message during the program's shutdown. The exact number of leaked objects (e.g., 24) varies.Steps to reproduce
Use the following code snippet which initializes a custom OpenAI client and then attempts to run an agent configured with an
MCPServerStdio
plugin.Code Snippet
Note: The
soc_push_script.py
file is not provided, but it is assumed to be a functional MCP plugin script that interacts via standard I/O.Console Output
The text was updated successfully, but these errors were encountered: