-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathworkflow.py
More file actions
34 lines (26 loc) · 986 Bytes
/
Copy pathworkflow.py
File metadata and controls
34 lines (26 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Workflow that uses an MCP server through ``TemporalMCPClient``.
The plugin connects to each registered MCP server at worker startup and
caches the tool manifest. ``TemporalMCPClient`` on the workflow side is a
pure handle that references the server by name and carries the activity
options for each tool call.
"""
# @@@SNIPSTART python-strands-mcp-workflow
from datetime import timedelta
from temporalio import workflow
from temporalio.contrib.strands import TemporalAgent, TemporalMCPClient
@workflow.defn
class MCPWorkflow:
def __init__(self) -> None:
echo = TemporalMCPClient(
server="echo",
start_to_close_timeout=timedelta(seconds=30),
)
self.agent = TemporalAgent(
start_to_close_timeout=timedelta(seconds=60),
tools=[echo],
)
@workflow.run
async def run(self, prompt: str) -> str:
result = await self.agent.invoke_async(prompt)
return str(result)
# @@@SNIPEND