mirror of
https://github.com/mcp-use/mcp-use.git
synced 2026-09-14 18:06:01 +08:00
ad42b4bb3e
The searchable: false approach on the API Reference tab was inert on visible tabs. Switch to per-page noindex: true frontmatter, which keeps pages in the sidebar but excludes them from search indexing (search engines, internal docs search, and AI context) so generic queries like "CLI" surface curated guides instead of the generated reference. Applied to all 73 existing reference pages and emitted by the generator on every regeneration. Closes MCP-2398
111 lines
2.8 KiB
Plaintext
111 lines
2.8 KiB
Plaintext
---
|
|
title: "Base"
|
|
description: "Base agent interface for MCP tools API Documentation"
|
|
icon: "code"
|
|
github: "https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/agents/base.py"
|
|
noindex: true
|
|
---
|
|
|
|
import {RandomGradientBackground} from "/snippets/gradient.jsx"
|
|
|
|
<Callout type="info" title="Source Code">
|
|
View the source code for this module on GitHub: <a href='https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/agents/base.py' target='_blank' rel='noopener noreferrer'>https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/agents/base.py</a>
|
|
</Callout>
|
|
|
|
Base agent interface for MCP tools.
|
|
|
|
This module provides a base class for agents that use MCP tools.
|
|
|
|
## BaseAgent
|
|
|
|
<div>
|
|
<RandomGradientBackground className="rounded-lg p-4 w-full h-full rounded-full">
|
|
<div className="text-black">
|
|
<div className="text-black font-bold text-xl mb-2 mt-8"><code className="!text-black">class</code> BaseAgent</div>
|
|
|
|
Base class for agents that use MCP tools.
|
|
|
|
This abstract class defines the interface for agents that use MCP tools.
|
|
Agents are responsible for integrating LLMs with MCP tools.
|
|
|
|
</div>
|
|
</RandomGradientBackground>
|
|
```python
|
|
from mcp_use.agents.base import BaseAgent
|
|
```
|
|
|
|
<Card type="info">
|
|
### `method` __init__
|
|
|
|
Initialize a new agent.
|
|
|
|
|
|
**Parameters**
|
|
><ParamField body="session" type="mcp_use.client.session.MCPSession" required="True" > The MCP session to use for tool calls. </ParamField>
|
|
|
|
**Signature**
|
|
```python wrap
|
|
def __init__(session: mcp_use.client.session.MCPSession):
|
|
```
|
|
|
|
</Card>
|
|
<Card type="info">
|
|
### `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**
|
|
```python wrap
|
|
def initialize():
|
|
```
|
|
|
|
</Card>
|
|
|
|
<Card type="info">
|
|
### `method` run
|
|
|
|
Run the agent with a query.
|
|
|
|
|
|
|
|
**Parameters**
|
|
><ParamField body="query" type="str" required="True" > The query to run. </ParamField>
|
|
><ParamField body="max_steps" type="int" default="10" > The maximum number of steps to run. </ParamField>
|
|
|
|
**Returns**
|
|
><ResponseField name="returns" type="dict[str, Any]" >The final result from the agent.</ResponseField>
|
|
|
|
**Signature**
|
|
```python wrap
|
|
def run(query: str, max_steps: int = 10):
|
|
```
|
|
|
|
</Card>
|
|
|
|
<Card type="info">
|
|
### `method` step
|
|
|
|
Perform a single step of the agent.
|
|
|
|
|
|
|
|
**Parameters**
|
|
><ParamField body="query" type="str" required="True" > The query to run. </ParamField>
|
|
><ParamField body="previous_steps" type="list[dict[str, typing.Any]] | None" default="None" > Optional list of previous steps. </ParamField>
|
|
|
|
**Returns**
|
|
><ResponseField name="returns" type="dict[str, Any]" >The result of the step.</ResponseField>
|
|
|
|
**Signature**
|
|
```python wrap
|
|
def step(query: str, previous_steps: list[dict[str, typing.Any]] | None = None):
|
|
```
|
|
|
|
</Card>
|
|
|
|
</div>
|