Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /agno-agi_agno /cookbook /91_tools /mcp_tools.py
| """ | |
| Mcp Tools | |
| ============================= | |
| Demonstrates mcp tools. | |
| """ | |
| import asyncio | |
| import sys | |
| from pathlib import Path | |
| from agno.agent import Agent | |
| from agno.tools.mcp import MCPTools | |
| from mcp import ClientSession, StdioServerParameters | |
| from mcp.client.stdio import stdio_client | |
| # --------------------------------------------------------------------------- | |
| # Create Agent | |
| # --------------------------------------------------------------------------- | |
| async def main(prompt: str) -> None: | |
| # Initialize the MCP server | |
| server_params = StdioServerParameters( | |
| command="npx", | |
| args=[ | |
| "-y", | |
| "@modelcontextprotocol/server-filesystem", | |
| str(Path(__file__).parent.parent), | |
| ], | |
| ) | |
| # Create a client session to connect to the MCP server | |
| async with stdio_client(server_params) as (read, write): | |
| async with ClientSession(read, write) as session: | |
| # Initialize the MCP toolkit | |
| mcp_tools = MCPTools(session=session) | |
| await mcp_tools.initialize() | |
| # Create an agent with the MCP toolkit | |
| agent = Agent(tools=[mcp_tools]) | |
| # Run the agent | |
| await agent.aprint_response(prompt, stream=True) | |
| # --------------------------------------------------------------------------- | |
| # Run Agent | |
| # --------------------------------------------------------------------------- | |
| if __name__ == "__main__": | |
| prompt = ( | |
| sys.argv[1] if len(sys.argv) > 1 else "Read and summarize the file ./LICENSE" | |
| ) | |
| asyncio.run(main(prompt)) | |
Xet Storage Details
- Size:
- 1.58 kB
- Xet hash:
- f61a7b914de3a669e4d60cd1639f936a9d02085c4d7566ed27299471f9fe07ff
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.