代码

"""
💻 Pipedream LinkedIn MCP

此示例展示了如何使用 Pipedream MCP 服务器(在此场景中为 LinkedIn)和 Agno Agents。

1. 连接您的 Pipedream 和 LinkedIn 账户:https://mcp.pipedream.com/app/linkedin
2. 获取您的 Pipedream MCP 服务器网址:https://mcp.pipedream.com/app/linkedin
3. 将 MCP_SERVER_URL 环境变量设置为您上面获取的 MCP 服务器网址
4. 安装依赖项:pip install agno mcp-sdk
"""

import asyncio
import os

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.mcp import MCPTools
from agno.utils.log import log_exception

mcp_server_url = os.getenv("MCP_SERVER_URL")


async def run_agent(task: str) -> None:
    try:
        async with MCPTools(
            url=mcp_server_url, transport="sse", timeout_seconds=20
        ) as mcp:
            agent = Agent(
                model=OpenAIChat(id="gpt-4o-mini"),
                tools=[mcp],
                markdown=True,
            )
            await agent.aprint_response(
                message=task,
                stream=True,
            )
    except Exception as e:
        log_exception(f"Unexpected error: {e}")


if __name__ == "__main__":
    asyncio.run(
        run_agent("在 LinkedIn 上查看 Pipedream 组织并告诉我相关信息")
    )