openai.agents_server()
Start Console as a native MCP server for an OpenAI agent.
Usage
openai.agents_server(
*,
command=None,
args=None,
name="MCP Console",
params=None,
client_session_timeout_seconds=None,
**kwargs
)Enter the returned async context and pass the server to Agent(mcp_servers=...). The Agents SDK discovers Console’s tools, runs model tool calls, and returns text and image results to the model. Leaving the context closes the server. You do not need a separate AsyncMCPConsole. Use agents_tool() to share an existing connection.
Parameters
command: Command | None = None-
Console executable. Defaults to the installed
mcp-console. args: Sequence[Command] | None = None-
Server arguments. Defaults to
["serve"]. name: str = "MCP Console"-
Display name for this MCP server.
params: Mapping[str, Any] | None = None-
MCP stdio settings such as
cwdandenv. client_session_timeout_seconds: float | None = None-
MCP request deadline.
Noneleaves requests without a client deadline, including long Console startup. **kwargs: Any-
Other options passed to
MCPServerStdio.
Returns
Any-
An Agents
MCPServerStdioasync context manager.
Examples
Install with pip install 'mcp-console[openai-agents]'. Set OPENAI_API_KEY and set OPENAI_MODEL to your model ID. This example gives the agent access to files in the current directory:
import asyncio
import os
import mcp_console
from agents import Agent, Runner
async def main():
async with mcp_console.openai.agents_server(
params={"cwd": os.getcwd()},
) as server:
agent = Agent(
name="Data analyst",
model=os.environ["OPENAI_MODEL"],
mcp_servers=[server],
)
result = await Runner.run(
agent,
"Use Python in Console to plot monthly sales "
"[12, 15, 18, 20, 25] and describe the trend.",
)
print(result.final_output)
asyncio.run(main())