Pipedream Auth
This example shows how to add authorization when integrating Pipedream MCP servers with Kern Agents.
Code
1"""2�� Using Pipedream MCP servers with authentication34This is an example of how to use Pipedream MCP servers with authentication.5This is useful if your app is interfacing with the MCP servers in behalf of your users.671. Get your access token. You can check how in Pipedream's docs: https://pipedream.com/docs/connect/mcp/developers/82. Get the URL of the MCP server. It will look like this: https://remote.mcp.pipedream.net/<External user id>/<MCP app slug>93. Set the environment variables:10 - MCP_SERVER_URL: The URL of the MCP server you previously got11 - MCP_ACCESS_TOKEN: The access token you previously got12 - PIPEDREAM_PROJECT_ID: The project id of the Pipedream project you want to use13 - PIPEDREAM_ENVIRONMENT: The environment of the Pipedream project you want to use143. Install dependencies: uv pip install kern-ai mcp-sdk15"""1617import asyncio18from os import getenv1920from kern.agent import Agent21from kern.models.openai import OpenAIResponses22from kern.tools.mcp import MCPTools, StreamableHTTPClientParams23from kern.utils.log import log_exception2425mcp_server_url = getenv("MCP_SERVER_URL")26mcp_access_token = getenv("MCP_ACCESS_TOKEN")27pipedream_project_id = getenv("PIPEDREAM_PROJECT_ID")28pipedream_environment = getenv("PIPEDREAM_ENVIRONMENT")293031server_params = StreamableHTTPClientParams(32 url=mcp_server_url,33 headers={34 "Authorization": f"Bearer {mcp_access_token}",35 "x-pd-project-id": pipedream_project_id,36 "x-pd-environment": pipedream_environment,37 },38)394041async def run_agent(task: str) -> None:42 try:43 async with MCPTools(44 server_params=server_params, transport="streamable-http", timeout_seconds=2045 ) as mcp:46 agent = Agent(47 model=OpenAIResponses(id="gpt-5.2"),48 tools=[mcp],49 markdown=True,50 )51 await agent.aprint_response(message=task, stream=True)52 except Exception as e:53 log_exception(f"Unexpected error: {e}")545556if __name__ == "__main__":57 # The agent can read channels, users, messages, etc.58 asyncio.run(run_agent("Show me the latest message in the channel #general"))