Created
December 3, 2025 11:10
-
-
Save larkintuckerllc/a23342797247db9a41f03bd6d7f749ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| from langchain_anthropic import ChatAnthropic | |
| from langchain.agents import create_agent | |
| from langchain_mcp_adapters.tools import load_mcp_tools | |
| from mcp import ClientSession, StdioServerParameters | |
| from mcp.client.stdio import stdio_client | |
| server_params = StdioServerParameters( | |
| command="uv", | |
| args=[ | |
| "--directory", | |
| "/Users/jtucker/desktop/working/weather", | |
| "run", | |
| "weather.py" | |
| ], | |
| ) | |
| async def main(): | |
| async with stdio_client(server_params) as (read, write): | |
| async with ClientSession(read, write) as session: | |
| await session.initialize() | |
| tools = await load_mcp_tools(session) | |
| llm = ChatAnthropic( | |
| model="claude-sonnet-4-5", | |
| max_tokens=1000 | |
| ) | |
| agent = create_agent( | |
| model=llm, | |
| tools=tools, | |
| system_prompt="You are a helpful assistant" | |
| ) | |
| result = await agent.ainvoke({"messages": [{"role": "user", "content": "what is the weather in sf"}]}) | |
| final_message = result["messages"][-1] | |
| print(final_message.content) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment