MCPcopy Create free account
hub / github.com/openai/openai-agents-python / lifespan

Function lifespan

examples/mcp/manager_example/app.py:32–52  ·  view source on GitHub ↗
(app: FastAPI)

Source from the content-addressed store, hash-verified

30
31@asynccontextmanager
32async def lifespan(app: FastAPI):
33 server = MCPServerStreamableHttp({"url": MCP_SERVER_URL})
34 inactive_server = MCPServerStreamableHttp({"url": INACTIVE_MCP_SERVER_URL})
35 servers = [server, inactive_server]
36 if USE_MCP_MANAGER:
37 async with MCPServerManager(
38 servers=servers,
39 connect_in_parallel=True,
40 ) as manager:
41 app.state.mcp_manager = manager
42 app.state.mcp_servers = servers
43 yield
44 return
45
46 await server.connect()
47 app.state.mcp_servers = servers
48 app.state.active_servers = [server]
49 try:
50 yield
51 finally:
52 await server.cleanup()
53
54
55app = FastAPI(lifespan=lifespan)

Callers

nothing calls this directly

Calls 4

MCPServerManagerClass · 0.90
connectMethod · 0.45
cleanupMethod · 0.45

Tested by

no test coverage detected