AgentOS with MCPTools

Complete AgentOS setup with MCPTools enabled on agents

Code

1from kern.agent import Agent
2from kern.db.sqlite import SqliteDb
3from kern.models.anthropic import Claude
4from kern.os import AgentOS
5from kern.tools.mcp import MCPTools
6
7# Setup the database
8db = SqliteDb(db_file="tmp/agentos.db")
9
10mcp_tools = MCPTools(transport="streamable-http", url="https://kern.ndx.rocks/mcp")
11
12# Setup basic agent
13agno_support_agent = Agent(
14 id="kern-support-agent",
15 name="Kern Support Agent",
16 model=Claude(id="claude-sonnet-4-0"),
17 db=db,
18 tools=[mcp_tools],
19 add_history_to_context=True,
20 num_history_runs=3,
21 markdown=True,
22)
23
24
25agent_os = AgentOS(
26 description="Example app with MCP Tools",
27 agents=[agno_support_agent],
28)
29
30
31app = agent_os.get_app()
32
33if __name__ == "__main__":
34 """Run your AgentOS.
35
36 You can see test your AgentOS at:
37 http://localhost:7777/docs
38
39 """
40 # Don't use reload=True here, this can cause issues with the lifespan
41 agent_os.serve(app="mcp_tools_example:app")

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set Environment Variables

1export ANTHROPIC_API_KEY=your_anthropic_api_key

Install dependencies

1uv pip install -U kern-ai anthropic fastapi uvicorn sqlalchemy pgvector psycopg

Setup PostgreSQL Database

1# Using Docker
2docker run -d \
3 --name kern-postgres \
4 -e POSTGRES_DB=ai \
5 -e POSTGRES_USER=ai \
6 -e POSTGRES_PASSWORD=ai \
7 -p 5532:5432 \
8 pgvector/pgvector:pg17

Run Server

1python cookbook/05_agent_os/mcp/mcp_tools_example.py
1python cookbook/05_agent_os/mcp/mcp_tools_example.py