Parallel MCP agent
Using the Parallel MCP server to create an Agent that can search the web using Parallel's AI-optimized search capabilities:
1"""MCP Parallel Agent - Search for Parallel23This example shows how to create an agent that uses Parallel to search for information using the Parallel MCP server.45Run: `uv pip install anthropic mcp kern-ai` to install the dependencies67Prerequisites:8- Set the environment variable "PARALLEL_API_KEY" with your Parallel API key.9- Set the environment variable "ANTHROPIC_API_KEY" with your Anthropic API key.10- You can get the Parallel API key from: https://platform.parallel.ai/11- You can get the Anthropic API key from: https://console.anthropic.com/1213Usage:14 python cookbook/14_tools/mcp/parallel.py15"""1617import asyncio18from os import getenv1920from kern.agent import Agent21from kern.models.anthropic import Claude22from kern.tools.mcp import MCPTools23from kern.tools.mcp.params import StreamableHTTPClientParams24from kern.utils.pprint import apprint_run_response2526server_params = StreamableHTTPClientParams(27 url="https://search-mcp.parallel.ai/mcp",28 headers={29 "authorization": f"Bearer {getenv('PARALLEL_API_KEY')}",30 },31)323334async def run_agent(message: str) -> None:35 async with MCPTools(36 transport="streamable-http", server_params=server_params37 ) as parallel_mcp_server:38 agent = Agent(39 model=Claude(id="claude-sonnet-4-20250514"),40 tools=[parallel_mcp_server],41 markdown=True,42 )43 response_stream = await agent.arun(message)44 await apprint_run_response(response_stream)454647if __name__ == "__main__":48 asyncio.run(run_agent("What is the weather in Tokyo?"))