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 Parallel
2
3This example shows how to create an agent that uses Parallel to search for information using the Parallel MCP server.
4
5Run: `uv pip install anthropic mcp kern-ai` to install the dependencies
6
7Prerequisites:
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/
12
13Usage:
14 python cookbook/14_tools/mcp/parallel.py
15"""
16
17import asyncio
18from os import getenv
19
20from kern.agent import Agent
21from kern.models.anthropic import Claude
22from kern.tools.mcp import MCPTools
23from kern.tools.mcp.params import StreamableHTTPClientParams
24from kern.utils.pprint import apprint_run_response
25
26server_params = StreamableHTTPClientParams(
27 url="https://search-mcp.parallel.ai/mcp",
28 headers={
29 "authorization": f"Bearer {getenv('PARALLEL_API_KEY')}",
30 },
31)
32
33
34async def run_agent(message: str) -> None:
35 async with MCPTools(
36 transport="streamable-http", server_params=server_params
37 ) 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)
45
46
47if __name__ == "__main__":
48 asyncio.run(run_agent("What is the weather in Tokyo?"))