Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 03:37 UTC
| 1 | import os |
| 2 | |
| 3 | from agents import Agent, HostedMCPTool, Runner |
| 4 | |
| 5 | from composio import Composio |
| 6 | |
| 7 | composio = Composio() |
| 8 | session = composio.create( |
| 9 | # A user with a connected Gmail account (raises KeyError when unset) |
| 10 | user_id=os.environ["COMPOSIO_EXAMPLES_USER_ID"], |
| 11 | # mcp=True surfaces session.mcp on the returned type |
| 12 | mcp=True, |
| 13 | ) |
| 14 | |
| 15 | print(session.mcp) |
| 16 | |
| 17 | composio_mcp = HostedMCPTool( |
| 18 | tool_config={ |
| 19 | "type": "mcp", |
| 20 | "server_label": "tool_router", |
| 21 | "server_url": session.mcp.url, |
| 22 | "require_approval": "never", |
| 23 | "headers": session.mcp.headers, # type: ignore[typeddict-item] # headers is typed Dict[str, Optional[str]]; the SDK always populates it with str values |
| 24 | } |
| 25 | ) |
| 26 | |
| 27 | agent = Agent( |
| 28 | name="My Agent", |
| 29 | instructions="You are a helpful assistant that can use the tools provided to you.", |
| 30 | tools=[composio_mcp], |
| 31 | ) |
| 32 | |
| 33 | result = Runner.run_sync( |
| 34 | starting_agent=agent, |
| 35 | input="Find my last email and summarize it.", |
| 36 | ) |
| 37 | |
| 38 | print(result.final_output) |