Pipedream Slack

This example shows how to use the Slack Pipedream MCP server with Kern Agents.

Code

1"""
2 Pipedream Slack MCP
3
4This example shows how to use Pipedream MCP servers (in this case the Slack one) with Kern Agents.
5
61. Connect your Pipedream and Slack accounts: https://mcp.pipedream.com/app/slack
72. Get your Pipedream MCP server url: https://mcp.pipedream.com/app/slack
83. Set the MCP_SERVER_URL environment variable to the MCP server url you got above
94. Install dependencies: uv pip install kern-ai mcp-sdk
10
11"""
12
13import asyncio
14import os
15
16from kern.agent import Agent
17from kern.models.openai import OpenAIResponses
18from kern.tools.mcp import MCPTools
19from kern.utils.log import log_exception
20
21mcp_server_url = os.getenv("MCP_SERVER_URL")
22
23
24async def run_agent(task: str) -> None:
25 try:
26 async with MCPTools(
27 url=mcp_server_url, transport="sse", timeout_seconds=20
28 ) as mcp:
29 agent = Agent(
30 model=OpenAIResponses(id="gpt-5.2"),
31 tools=[mcp],
32 markdown=True,
33 )
34 await agent.aprint_response(
35 message=task,
36 stream=True,
37 )
38 except Exception as e:
39 log_exception(f"Unexpected error: {e}")
40
41
42if __name__ == "__main__":
43 # The agent can read channels, users, messages, etc.
44 asyncio.run(run_agent("Show me the latest message in the channel #general"))
45
46 # Use your real Slack name for this one to work!
47 asyncio.run(
48 run_agent("Send a message to <YOUR_NAME> saying 'Hello, I'm your Kern Agent!'")
49 )