-
Notifications
You must be signed in to change notification settings - Fork 749
Add mcp-agent cloud compatibility to basic slack agent example #494
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
base: main
Are you sure you want to change the base?
Conversation
1. Added @app.tool decorator (line 11) - Makes the function available as a cloud tool 2. Renamed function from example_usage() to fetch_latest_slack_message() (line 12) - More descriptive name 3. Added return type annotation -> str (line 12) - Required for cloud compatibility 4. Added docstring (line 13) - Describes what the tool does 6. Added return statement - Returns formatted result for cloud usage
WalkthroughIntroduces a new public tool Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Runner as Main/Runner
participant Tool as app.tool fetch_latest_slack_message()
participant Slack as Slack API
participant LLM as LLM
Runner->>Tool: invoke fetch_latest_slack_message()
rect rgb(240,245,255)
Tool->>Slack: get latest message from `bot-commits`
Slack-->>Tool: latest_message
Tool->>LLM: "Summarize this commit:" + latest_message
LLM-->>Tool: summary
Tool-->>Runner: return final_result (latest_message + "\n\n" + summary)
end
note right of Runner: Runner prints total execution time
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (8)
examples/usecases/mcp_basic_slack_agent/main.py (8)
11-13
: Fix docstring to match behavior (bot-commits vs general).
Docstring says “general” but the prompt targets “bot-commits.” Align to avoid confusion.Apply this diff:
-async def fetch_latest_slack_message() -> str: - """Get the latest message from general channel and provide a summary.""" +async def fetch_latest_slack_message() -> str: + """Get the latest message from the bot-commits channel and provide a summary."""
27-27
: Guard against duplicate/inconsistent filesystem args.
Repeated runs can append the same cwd; also handle missing server/args defensively.Apply this diff:
-context.config.mcp.servers["filesystem"].args.extend([os.getcwd()]) +fs = context.config.mcp.servers.get("filesystem") +if fs is not None: + args = getattr(fs, "args", None) + if args is None: + fs.args = [os.getcwd()] + elif os.getcwd() not in args: + fs.args.append(os.getcwd()) +else: + logger.info("filesystem server not configured; skipping cwd injection")
31-39
: Avoid reusingresult
for different meanings.
Improves readability and log clarity.Apply this diff:
-logger.info("slack: Connected to server, calling list_tools...") -result = await slack_agent.list_tools() -logger.info("Tools available:", data=result.model_dump()) +logger.info("slack: Connected to server, calling list_tools...") +tools = await slack_agent.list_tools() +logger.info("Tools available:", data=tools.model_dump()) llm = await slack_agent.attach_llm(OpenAIAugmentedLLM) -result = await llm.generate_str( +latest_message = await llm.generate_str( message="What was the latest message in the bot-commits channel?", ) -logger.info(f"Result: {result}") +logger.info(f"Latest message: {latest_message}")
41-45
: Label the second log as Summary.
Minor clarity improvement.-summary = await llm.generate_str( +summary = await llm.generate_str( message="Can you summarize what that commit was about?", ) -logger.info(f"Result: {summary}") +logger.info(f"Summary: {summary}")
46-47
: Return machine-readable output for cloud consumers.
Since the tool must return str, prefer JSON for easier downstream parsing.Apply this diff and add an import:
+import json @@ -final_result = f"Latest message: {result}\n\nSummary: {summary}" -return final_result +final_result = {"latest_message": latest_message, "summary": summary} +return json.dumps(final_result)Add near the top:
-import asyncio +import asyncio +import json
35-37
: Parameterize the Slack channel.
Avoid hard-coding; allow override via env.- message="What was the latest message in the bot-commits channel?", + message=f"What was the latest message in the {os.getenv('SLACK_CHANNEL', 'bot-commits')} channel?",
29-47
: Add minimal error handling to avoid tool crashes.
Return a friendly string on failures so cloud calls don’t 500.-async with slack_agent: +async with slack_agent: logger.info("slack: Connected to server, calling list_tools...") - tools = await slack_agent.list_tools() + try: + tools = await slack_agent.list_tools() ... - final_result = {"latest_message": latest_message, "summary": summary} - return json.dumps(final_result) + final_result = {"latest_message": latest_message, "summary": summary} + return json.dumps(final_result) + except Exception as e: + logger.info("slack: error during fetch/summarize", error=str(e)) + return json.dumps({"error": str(e)})
53-58
: Print the tool’s output when run as a script.
Helps make the example useful outside cloud.-start = time.time() -asyncio.run(fetch_latest_slack_message()) -end = time.time() +start = time.time() +result = asyncio.run(fetch_latest_slack_message()) +end = time.time() t = end - start +print(result) print(f"Total run time: {t:.2f}s")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
examples/usecases/mcp_basic_slack_agent/main.py
(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
examples/usecases/mcp_basic_slack_agent/main.py (2)
src/mcp_agent/app.py (1)
logger
(193-210)src/mcp_agent/logging/logger.py (1)
info
(271-279)
Added cloud details
async def example_usage(): | ||
@app.tool | ||
async def fetch_latest_slack_message() -> str: | ||
"""Get the latest message from general channel and provide a summary.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring references the "general" channel, but the implementation on line 36 is fetching from the "bot-commits" channel. For consistency, please update the docstring to match the actual implementation:
"""Get the latest message from bot-commits channel and provide a summary."""
This will ensure the documentation accurately reflects the code's behavior.
"""Get the latest message from general channel and provide a summary.""" | |
"""Get the latest message from bot-commits channel and provide a summary.""" |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
examples/usecases/mcp_basic_slack_agent/README.md (1)
78-90
: Fix YAML nesting for Slack env (current example won’t matchmcp.servers.slack.env.*
).
env
must be nested underslack
. Otherwise secrets/config resolution will fail at runtime.Apply:
mcp: servers: slack: - env: - SLACK_BOT_TOKEN: "xoxb-your-bot-token" - SLACK_TEAM_ID: "T01234567" + env: + SLACK_BOT_TOKEN: "xoxb-your-bot-token" + SLACK_TEAM_ID: "T01234567"
🧹 Nitpick comments (5)
examples/usecases/mcp_basic_slack_agent/README.md (5)
119-119
: Remove trailing punctuation in headings (MD026).-#### For OpenAI API Key: +#### For OpenAI API Key ... -#### For Slack Bot Token: +#### For Slack Bot TokenAlso applies to: 130-130
120-125
: Add language to fenced code blocks (MD040).-``` +```text Select secret type for 'openai.api_key' -``` +``` -``` +```text Select secret type for 'mcp.servers.slack.env.SLACK_BOT_TOKEN' -``` +```Also applies to: 132-136
149-166
: Avoid embedding bearer tokens in config; source from OS env instead.Omit the
env
block to prevent plaintext tokens in dotfiles. Keep${BEARER_TOKEN}
in args and export it at runtime."args": [ "mcp-remote", "https://[your-agent-server-id].deployments.mcp-agent.com/sse", "--header", "Authorization: Bearer ${BEARER_TOKEN}" ], - "env": { - "BEARER_TOKEN": "your-mcp-agent-cloud-api-token" - }Usage:
- macOS/Linux:
export BEARER_TOKEN=...
- Windows (PowerShell):
$Env:BEARER_TOKEN="..."
69-73
: Add a prominent “do not commit secrets” note and ensure.gitignore
covers it.Prevent accidental leakage of
mcp_agent.secrets.yaml
.Add after the copy command:
- “Do not commit mcp_agent.secrets.yaml; ensure it’s in .gitignore.”
107-115
: Confirm CLI verbs (login
,deploy
) formcp-agent
.If the CLI uses different subcommands/entrypoint, update the README to exact names to prevent setup churn.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
examples/usecases/mcp_basic_slack_agent/README.md
(1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
examples/usecases/mcp_basic_slack_agent/README.md
119-119: Trailing punctuation in heading
Punctuation: ':'
(MD026, no-trailing-punctuation)
120-120: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
130-130: Trailing punctuation in heading
Punctuation: ':'
(MD026, no-trailing-punctuation)
131-131: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🔇 Additional comments (1)
examples/usecases/mcp_basic_slack_agent/README.md (1)
189-192
: Verify channel name matches code default.README says "bot-commits" but examples/usecases/mcp_basic_slack_agent/main.py's docstring says "general" while the LLM prompt references "bot-commits" — confirm the intended Slack channel and make README/code consistent.
Locations: examples/usecases/mcp_basic_slack_agent/README.md (lines 189–192); examples/usecases/mcp_basic_slack_agent/main.py (docstring ~line 13; prompt ~line 36).
Summary by CodeRabbit
New Features
Documentation