diff --git a/examples/usecases/mcp_github_to_slack_agent/README.md b/examples/usecases/mcp_github_to_slack_agent/README.md index 5e20869c3..5e8422cf8 100644 --- a/examples/usecases/mcp_github_to_slack_agent/README.md +++ b/examples/usecases/mcp_github_to_slack_agent/README.md @@ -5,7 +5,7 @@ This application creates an MCP Agent that monitors GitHub pull requests and sub ## How It Works 1. The application connects to both GitHub and Slack via their respective MCP servers -2. The agent retrieves the latest pull requests from a specified GitHub repository +2. The agent retrieves the last 10 pull requests from a specified GitHub repository 3. It analyzes each PR and prioritizes them based on importance factors: - PRs marked as high priority or urgent - PRs addressing security vulnerabilities @@ -21,10 +21,9 @@ This application creates an MCP Agent that monitors GitHub pull requests and sub - Python 3.10 or higher - MCP Agent framework -- [GitHub MCP Server](https://github.com/github/github-mcp-server)) +- GitHub Copilot access (for cloud-based GitHub MCP server) - [Slack MCP Server](https://github.com/korotovsky/slack-mcp-server/tree/master) -- Node.js and npm (this is for the Slack server) -- [Docker](https://www.docker.com/) +- Node.js and npm (for the Slack server) - Access to a GitHub repository - Access to a Slack workspace @@ -67,3 +66,137 @@ Run the application with: ``` uv run main.py --owner --repo --channel ``` + +### [Beta] Deploy to the cloud + +#### `a.` Log in to [MCP Agent Cloud](https://docs.mcp-agent.com/cloud/overview) + +```bash +uv run mcp-agent login +``` + +#### `b.` Update your `mcp_agent.secrets.yaml` to mark your developer secrets (keys) + +```yaml +$schema: ../../../schema/mcp-agent.config.schema.json + +mcp: + servers: + slack: + env: + SLACK_MCP_XOXP_TOKEN: !developer_secret SLACK_MCP_XOXP_TOKEN + + github: + headers: + Authorization: !developer_secret GITHUB_PERSONAL_ACCESS_TOKEN_WITH_BEARER_PREFIX + +anthropic: + api_key: !developer_secret ANTHROPIC_API_KEY +``` + +#### `c.` Deploy your agent with a single command + +```bash +uv run mcp-agent deploy my-first-agent +``` + +#### `d.` Connect to your deployed agent as an MCP server through any MCP client + +##### Claude Desktop Integration + +Configure Claude Desktop to access your agent servers by updating your `~/.claude-desktop/config.json`: + +```json +"my-agent-server": { + "command": "/path/to/npx", + "args": [ + "mcp-remote", + "https://[your-agent-server-id].deployments.mcp-agent-cloud.lastmileai.dev/sse", + "--header", + "Authorization: Bearer ${BEARER_TOKEN}" + ], + "env": { + "BEARER_TOKEN": "your-mcp-agent-cloud-api-token" + } +} +``` + +##### MCP Inspector + +Use MCP Inspector to explore and test your agent servers: + +```bash +npx @modelcontextprotocol/inspector +``` + +Make sure to fill out the following settings: + +| Setting | Value | +|---|---| +| *Transport Type* | *SSE* | +| *SSE* | *https://[your-agent-server-id].deployments.mcp-agent-cloud.lastmileai.dev/sse* | +| *Header Name* | *Authorization* | +| *Bearer Token* | *your-mcp-agent-cloud-api-token* | + +> [!TIP] +> In the Configuration, change the request timeout to a longer time period. Since your agents are making LLM calls, it is expected that it should take longer than simple API calls. + + +##### Trigger Agent Run on Cloud + +Once you are connected to the MCP Agent on cloud, you will get a list of tools as follow: +- MCP Agent Cloud Default Tools: + - workflow-list: list the workflow (you don't need this) + - workflow-run-list: list the execution runs of your agent + - workflow-run: create workflow run (you don't need this) + - workflows-get_status: get your agent run's status + - workflows-resume: signal workflow to pause run + - workflows-cancel: signal workflow to cancel run +- Tool's that your agent expose: + - github_to_slack: default of your tool name, input the parameters to trigger a workflow run + + +Once you run the agent, successful trigger will return a workflow_run metadata object, where you can find your run id to query status: +```json +{ + "workflow_id": "github_to_slack-uuid", + "run_id": "uuid", + "execution_id": "uuid" +} +``` + +If this command returns error, you can tail the agent logs to investigate: + +```shell +uv run mcp-agent cloud logger tail "app_id" -f +``` + +When you agent run successfully finishes, you will see Slack message is posted by your agent and you will also be able to see the agent's text response by using `workflows-get_status`, which will return result like: + +```json +{ + "result": { + "id": "run-uuid", + "name": "github_to_slack", + "status": "completed", + "running": false, + "state": { + "status": "completed", + "metadata": {}, + "updated_at": 1757705891.842188, + "error": null + }, + "result": "{'kind': 'workflow_result', 'value': \"I'll help you complete this workflow. Let me start by retrieving the last 10 pull requests from the GitHub repository lastmile-.......", + "completed": true, + "error": null, + "temporal": { + "id": "github_to_slack-uuid", + "workflow_id": "github_to_slack-uuid", + "run_id": "uuid", + "status": "xxxxx", + "error": "xxxxx" + } + } +} +``` + diff --git a/examples/usecases/mcp_github_to_slack_agent/main.py b/examples/usecases/mcp_github_to_slack_agent/main.py index 62be4e66b..a4f0d0bf3 100644 --- a/examples/usecases/mcp_github_to_slack_agent/main.py +++ b/examples/usecases/mcp_github_to_slack_agent/main.py @@ -9,7 +9,7 @@ app = MCPApp(name="github_to_slack") - +@app.async_tool(name="github_to_slack", description="Tool to list GitHub pull requests and provides summaries to Slack") async def github_to_slack(github_owner: str, github_repo: str, slack_channel: str): async with app.run() as agent_app: context = agent_app.context @@ -19,7 +19,7 @@ async def github_to_slack(github_owner: str, github_repo: str, slack_channel: st name="github_to_slack_agent", instruction=f"""You are an agent that monitors GitHub pull requests and provides summaries to Slack. Your tasks are: - 1. Use the GitHub server to retrieve information about the latest pull requests for the repository {github_owner}/{github_repo} + 1. Use the GitHub server to retrieve information about the last 10 pull requests for the repository {github_owner}/{github_repo} 2. Analyze and prioritize the pull requests based on their importance, urgency, and impact 3. Format a concise summary of high-priority items 4. Submit this summary to the Slack server in the channel {slack_channel} @@ -40,7 +40,7 @@ async def github_to_slack(github_owner: str, github_repo: str, slack_channel: st prompt = f"""Complete the following workflow: - 1. Retrieve the latest pull requests from the GitHub repository {github_owner}/{github_repo}. + 1. Retrieve the last 10 pull requests from the GitHub repository {github_owner}/{github_repo}. Use the GitHub server to get this information. Gather details such as PR title, author, creation date, status, and description. @@ -60,14 +60,18 @@ async def github_to_slack(github_owner: str, github_repo: str, slack_channel: st - Include links to the PRs - End with any relevant action items or recommendations - 4. Use the Slack server to post this summary to the channel {slack_channel}. + 4. Use the Slack server to post this summary to the channel {slack_channel}. If you do not have Slack + tool access, just return the final summary. """ # Execute the workflow print("Executing GitHub to Slack workflow...") - await llm.generate_str(prompt) + result = await llm.generate_str(prompt) print("Workflow completed successfully!") + print(result) + + return result finally: # Clean up the agent diff --git a/examples/usecases/mcp_github_to_slack_agent/mcp_agent.config.yaml b/examples/usecases/mcp_github_to_slack_agent/mcp_agent.config.yaml index dc9401666..c2d211db0 100644 --- a/examples/usecases/mcp_github_to_slack_agent/mcp_agent.config.yaml +++ b/examples/usecases/mcp_github_to_slack_agent/mcp_agent.config.yaml @@ -12,16 +12,16 @@ logger: mcp: servers: github: - command: "docker" - args: [ - "run", - "-i", - "--rm", - "-e", - "GITHUB_PERSONAL_ACCESS_TOKEN", - "ghcr.io/github/github-mcp-server" - ] + transport: "streamable_http" + url: "https://api.githubcopilot.com/mcp/x/pull_requests/readonly" + headers: + Content-Type: "application/json" + http_timeout_seconds: 30 + read_timeout_seconds: 60 description: "Access GitHub API operations" + allowed_tools: + - "list_pull_requests" + - "get_pull_request" slack: command: "npx" args: ["-y", @@ -29,6 +29,8 @@ mcp: "--transport", "stdio"] env: - SLACK_MCP_XOXP_TOKEN: "ADD_YOUR_TOKEN_HERE" + SLACK_TEAM_ID: "T0123213213" SLACK_MCP_ADD_MESSAGE_TOOL: "true" - description: "Access Slack API operations"] \ No newline at end of file + description: "Access Slack API operations" + allowed_tools: + - "conversations_add_message" \ No newline at end of file diff --git a/examples/usecases/mcp_github_to_slack_agent/mcp_agent.secrets.yaml.example b/examples/usecases/mcp_github_to_slack_agent/mcp_agent.secrets.yaml.example index 59202e157..2d49aed61 100644 --- a/examples/usecases/mcp_github_to_slack_agent/mcp_agent.secrets.yaml.example +++ b/examples/usecases/mcp_github_to_slack_agent/mcp_agent.secrets.yaml.example @@ -3,19 +3,21 @@ $schema: ../../../schema/mcp-agent.config.schema.json mcp: servers: # Slack configuration - # Create a Slack Bot Token and get your Team ID + # Create a Slack App Oauth Token and get your Team ID # https://api.slack.com/apps slack: env: - SLACK_BOT_TOKEN: "xoxb-your-bot-token" - SLACK_TEAM_ID: "T01234567" + SLACK_MCP_XOXP_TOKEN: "xoxp-oauth-token" +# SLACK_MCP_XOXP_TOKEN: !developer_secret SLACK_MCP_XOXP_TOKEN # GitHub configuration # Create a GitHub Personal Access Token with repo scope # https://github.com/settings/tokens github: - env: - GITHUB_PERSONAL_ACCESS_TOKEN: "github_pat_your-access-token" + headers: + Authorization: "Bearer ghp_xxxxxxxxxxx" +# Authorization: !developer_secret GITHUB_PERSONAL_ACCESS_TOKEN_WITH_BEARER_PREFIX anthropic: - api_key: your-anthropic-api-key \ No newline at end of file + api_key: your-anthropic-api-key +# api_key: !developer_secret ANTHROPIC_API_KEY \ No newline at end of file