Skip to content

Commit 6f02b01

Browse files
committed
Change server names, overhaul tests to use a custom MCPServer which tracks calls
1 parent 3c847b6 commit 6f02b01

File tree

6 files changed

+168
-134
lines changed

6 files changed

+168
-134
lines changed

temporalio/contrib/openai_agents/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# Best Effort mcp, as it is not supported on Python 3.9
1212
try:
1313
from temporalio.contrib.openai_agents._mcp import (
14-
StatefulTemporalMCPServer,
15-
StatelessTemporalMCPServer,
14+
StatefulMCPServer,
15+
StatelessMCPServer,
1616
)
1717
except ImportError:
1818
pass
@@ -33,8 +33,8 @@
3333
"OpenAIAgentsPlugin",
3434
"ModelActivityParameters",
3535
"workflow",
36-
"StatelessTemporalMCPServer",
37-
"StatefulTemporalMCPServer",
36+
"StatelessMCPServer",
37+
"StatefulMCPServer",
3838
"TestModel",
3939
"TestModelProvider",
4040
]

temporalio/contrib/openai_agents/_mcp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
logger = logging.getLogger(__name__)
2525

2626

27-
class _StatelessTemporalMCPServerReference(MCPServer):
27+
class _StatelessMCPServerReference(MCPServer):
2828
def __init__(self, server: str, config: Optional[ActivityConfig] = None):
2929
self._name = server + "-stateless"
3030
self._config = config or ActivityConfig(
@@ -83,7 +83,7 @@ async def get_prompt(
8383
)
8484

8585

86-
class StatelessTemporalMCPServer:
86+
class StatelessMCPServer:
8787
"""A stateless MCP server implementation for Temporal workflows.
8888
8989
This class wraps an MCP server to make it stateless by executing each MCP operation
@@ -180,7 +180,7 @@ async def wrapper(*args, **kwargs):
180180
return wrapper
181181

182182

183-
class _StatefulTemporalMCPServerReference(MCPServer, AbstractAsyncContextManager):
183+
class _StatefulMCPServerReference(MCPServer, AbstractAsyncContextManager):
184184
def __init__(
185185
self,
186186
server: str,
@@ -266,7 +266,7 @@ async def get_prompt(
266266
)
267267

268268

269-
class StatefulTemporalMCPServer:
269+
class StatefulMCPServer:
270270
"""A stateful MCP server implementation for Temporal workflows.
271271
272272
This class wraps an MCP server to maintain a persistent connection throughout
@@ -343,6 +343,7 @@ async def connect() -> None:
343343

344344
await worker.run()
345345
finally:
346+
print("Cleanup")
346347
await self._server.cleanup()
347348
heartbeat_task.cancel()
348349
try:

temporalio/contrib/openai_agents/_openai_runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ async def run(
5757

5858
if starting_agent.mcp_servers:
5959
from temporalio.contrib.openai_agents._mcp import (
60-
_StatefulTemporalMCPServerReference,
61-
_StatelessTemporalMCPServerReference,
60+
_StatefulMCPServerReference,
61+
_StatelessMCPServerReference,
6262
)
6363

6464
for s in starting_agent.mcp_servers:
6565
if not isinstance(
6666
s,
6767
(
68-
_StatelessTemporalMCPServerReference,
69-
_StatefulTemporalMCPServerReference,
68+
_StatelessMCPServerReference,
69+
_StatefulMCPServerReference,
7070
),
7171
):
7272
raise ValueError(

temporalio/contrib/openai_agents/_temporal_openai_agents.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060

6161
if typing.TYPE_CHECKING:
6262
from temporalio.contrib.openai_agents import (
63-
StatefulTemporalMCPServer,
64-
StatelessTemporalMCPServer,
63+
StatefulMCPServer,
64+
StatelessMCPServer,
6565
)
6666

6767

@@ -201,7 +201,7 @@ class OpenAIAgentsPlugin(temporalio.client.Plugin, temporalio.worker.Plugin):
201201
Example:
202202
>>> from temporalio.client import Client
203203
>>> from temporalio.worker import Worker
204-
>>> from temporalio.contrib.openai_agents import OpenAIAgentsPlugin, ModelActivityParameters, StatelessTemporalMCPServer
204+
>>> from temporalio.contrib.openai_agents import OpenAIAgentsPlugin, ModelActivityParameters, StatelessMCPServer
205205
>>> from agents.mcp import MCPServerStdio
206206
>>> from datetime import timedelta
207207
>>>
@@ -212,7 +212,7 @@ class OpenAIAgentsPlugin(temporalio.client.Plugin, temporalio.worker.Plugin):
212212
... )
213213
>>>
214214
>>> # Create MCP servers
215-
>>> filesystem_server = StatelessTemporalMCPServer(MCPServerStdio(
215+
>>> filesystem_server = StatelessMCPServer(MCPServerStdio(
216216
... name="Filesystem Server",
217217
... params={"command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "."]}
218218
... ))
@@ -239,9 +239,7 @@ def __init__(
239239
self,
240240
model_params: Optional[ModelActivityParameters] = None,
241241
model_provider: Optional[ModelProvider] = None,
242-
mcp_servers: Sequence[
243-
Union["StatelessTemporalMCPServer", "StatefulTemporalMCPServer"]
244-
] = (),
242+
mcp_servers: Sequence[Union["StatelessMCPServer", "StatefulMCPServer"]] = (),
245243
) -> None:
246244
"""Initialize the OpenAI agents plugin.
247245

temporalio/contrib/openai_agents/workflow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ def stateless_mcp_server(
258258
superior durability guarantees.
259259
"""
260260
from temporalio.contrib.openai_agents._mcp import (
261-
_StatelessTemporalMCPServerReference,
261+
_StatelessMCPServerReference,
262262
)
263263

264-
return _StatelessTemporalMCPServerReference(name, config)
264+
return _StatelessMCPServerReference(name, config)
265265

266266

267267
def stateful_mcp_server(
@@ -294,10 +294,10 @@ def stateful_mcp_server(
294294
Defaults to 1-hour start-to-close timeout.
295295
"""
296296
from temporalio.contrib.openai_agents._mcp import (
297-
_StatefulTemporalMCPServerReference,
297+
_StatefulMCPServerReference,
298298
)
299299

300-
return _StatefulTemporalMCPServerReference(name, config, server_session_config)
300+
return _StatefulMCPServerReference(name, config, server_session_config)
301301

302302

303303
class ToolSerializationError(TemporalError):

0 commit comments

Comments
 (0)