Skip to main content
View the source code for this module on GitHub: https://github.com/mcp-use/mcp-use/blob/main/mcp_use/agents/base.py
Base agent interface for MCP tools. This module provides a base class for agents that use MCP tools.

BaseAgent

from mcp_use.agents.base import BaseAgent

method init

Initialize a new agent.Parameters
session
mcp_use.session.MCPSession
required
The MCP session to use for tool calls.
Signature
def __init__(session: mcp_use.session.MCPSession):

method initialize

Initialize the agent.This method should prepare the agent for use, including initializing the MCP session and setting up any necessary components.Signature
def initialize():

method run

Run the agent with a query.Parameters
query
str
required
The query to run.
max_steps
int
default:"10"
The maximum number of steps to run.
Returns
returns
dict[str, Any]
The final result from the agent.
Signature
def run(query: str, max_steps: int = 10):

method step

Perform a single step of the agent.Parameters
query
str
required
The query to run.
previous_steps
list[dict[str, typing.Any]] | None
default:"None"
Optional list of previous steps.
Returns
returns
dict[str, Any]
The result of the step.
Signature
def step(query: str, previous_steps: list[dict[str, typing.Any]] | None = None):
I