-
Notifications
You must be signed in to change notification settings - Fork 768
Cloud/deployable mcp agent server temporal #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
4a1f378
8676796
dbb651b
3858681
366a629
41c4a8f
9519fab
1f44d95
317d6d5
35189aa
3e3241f
92ea4fa
d7d7160
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,7 @@ To run this example, you'll need to: | |
4. In another terminal, start the MCP server: | ||
|
||
```bash | ||
uv run basic_agent_server.py | ||
uv run main.py | ||
``` | ||
Comment on lines
+144
to
145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainRenamed entrypoint to main.py — looks good; please sweep for stale references. 🏁 Script executed: #!/bin/bash
# Find stale references to the old entrypoint name(s)
rg -nP -S '\bbasic[_-]agent[_-]server(\.py)?\b|BasicAgentServer' -g '!**/node_modules/**' Length of output: 148 🏁 Script executed: #!/bin/bash
set -euo pipefail
PATTERN=$'\bbasic[_-]agent[_-]server(\.py)?\b|basicAgentServer|BasicAgentServer'
echo "Searching repo for stale entrypoint references..."
if command -v rg >/dev/null 2>&1; then
rg -nP --hidden --no-ignore -S --ignore-case --glob '!node_modules/**' "$PATTERN" || true
else
echo "rg not found; falling back to git grep"
git grep -n --ignore-case -e 'basic_agent_server' -e 'basic-agent-server' -e 'basicAgentServer' || true
fi Length of output: 198 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "PWD: $(pwd)"
echo "Top-level listing:"
ls -la || true
echo "Git repo root:"
git rev-parse --show-toplevel || true
echo "Git status (short):"
git status --porcelain --untracked-files=all || true
echo "Count files under repo (first 200 shown):"
find . -type f | wc -l || true
find . -type f -print | sed -n '1,200p' || true
echo "rg --version:"
rg --version || true
echo "Running rg --debug to see why files are skipped..."
PATTERN='\bbasic[_-]agent[_-]server(\.py)?\b|basicAgentServer|BasicAgentServer'
rg --debug -nP --hidden --no-ignore -S --ignore-case --glob '!node_modules/**' "$PATTERN" || true
echo "Fallback: git grep for common variants"
git grep -n --ignore-case -e 'basic_agent_server' -e 'basic-agent-server' -e 'basicAgentServer' || true Length of output: 181560 Stale references to basic_agent_server remain — update to main.py Update these files (docs, examples, templates, and CLI code) to reference main.py (and rename worker script references where appropriate):
🤖 Prompt for AI Agents
|
||
|
||
5. In a fourth terminal, run the client: | ||
|
@@ -215,7 +215,7 @@ npx @modelcontextprotocol/inspector \ | |
uv \ | ||
--directory /path/to/mcp-agent/examples/mcp_agent_server/temporal \ | ||
run \ | ||
basic_agent_server.py | ||
main.py | ||
``` | ||
|
||
This will launch the MCP Inspector UI where you can: | ||
|
@@ -239,7 +239,7 @@ To use this server with Claude Desktop: | |
"--directory", | ||
"/path/to/mcp-agent/examples/mcp_agent_server/temporal", | ||
"run", | ||
"basic_agent_server.py" | ||
"main.py" | ||
] | ||
} | ||
``` | ||
|
@@ -250,7 +250,7 @@ To use this server with Claude Desktop: | |
|
||
## Code Structure | ||
|
||
- `basic_agent_server.py` - Defines the workflows and creates the MCP server | ||
- `main.py` - Defines the workflows and creates the MCP server | ||
- `basic_agent_server_worker.py` - Sets up the Temporal worker to process workflow tasks | ||
- `client.py` - Example client that connects to the server and runs workflows | ||
- `mcp_agent.config.yaml` - Configuration for MCP servers and the Temporal execution engine | ||
|
@@ -271,8 +271,8 @@ class PauseResumeWorkflow(Workflow[str]): | |
print(f"Workflow is pausing, workflow_id: {self.id}, run_id: {self.run_id}") | ||
|
||
# Wait for the resume signal - this will pause the workflow | ||
await app.context.executor.signal_bus.wait_for_signal( | ||
Signal(name="resume", workflow_id=self.id, run_id=self.run_id), | ||
await app.context.executor.wait_for_signal( | ||
signal_name="resume", workflow_id=self.id, run_id=self.run_id, | ||
) | ||
|
||
print("Signal received, workflow is resuming...") | ||
|
@@ -318,10 +318,16 @@ async with gen_client("basic_agent_server", context.server_registry) as server: | |
) | ||
|
||
# The workflow will pause - to resume it, send the resume signal | ||
run_id = pause_result.content[0].text | ||
execution = WorkflowExecution( | ||
**json.loads(pause_result.content[0].text) | ||
) | ||
|
||
run_id = execution.run_id | ||
workflow_id = exection.workflow_id | ||
rholinshead marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
await server.call_tool( | ||
"workflows-resume", | ||
arguments={"workflow_id": "PauseResumeWorkflow", "run_id": run_id} | ||
arguments={"workflow_id": workflow_id, "run_id": run_id} | ||
) | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from pydantic import BaseModel | ||
from mcp.server.fastmcp import FastMCP | ||
from mcp.server.elicitation import elicit_with_validation, AcceptedElicitation | ||
|
||
mcp = FastMCP("Nested Elicitation Server") | ||
|
||
|
||
class Confirmation(BaseModel): | ||
confirm: bool | ||
|
||
|
||
@mcp.tool() | ||
async def confirm_action(action: str) -> str: | ||
"""Ask the user to confirm an action via elicitation.""" | ||
ctx = mcp.get_context() | ||
res = await elicit_with_validation( | ||
ctx.session, | ||
message=f"Do you want to {action}?", | ||
schema=Confirmation, | ||
) | ||
if isinstance(res, AcceptedElicitation) and res.data.confirm: | ||
return f"Action '{action}' confirmed by user" | ||
return f"Action '{action}' declined by user" | ||
|
||
|
||
def main(): | ||
mcp.run() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from mcp.server.fastmcp import FastMCP | ||
from mcp.types import ModelPreferences, ModelHint, SamplingMessage, TextContent | ||
|
||
mcp = FastMCP("Nested Sampling Server") | ||
|
||
|
||
@mcp.tool() | ||
async def get_haiku(topic: str) -> str: | ||
"""Use MCP sampling to generate a haiku about the given topic.""" | ||
result = await mcp.get_context().session.create_message( | ||
messages=[ | ||
SamplingMessage( | ||
role="user", | ||
content=TextContent( | ||
type="text", text=f"Generate a quirky haiku about {topic}." | ||
), | ||
) | ||
], | ||
system_prompt="You are a poet.", | ||
max_tokens=100, | ||
temperature=0.7, | ||
model_preferences=ModelPreferences( | ||
hints=[ModelHint(name="gpt-4o-mini")], | ||
costPriority=0.1, | ||
speedPriority=0.8, | ||
intelligencePriority=0.1, | ||
), | ||
) | ||
|
||
if isinstance(result.content, TextContent): | ||
return result.content.text | ||
return "Haiku generation failed" | ||
|
||
|
||
def main(): | ||
mcp.run() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Uh oh!
There was an error while loading. Please reload this page.