Add Mcp
workspace
Add Mcp
Add an MCP client to the session’s workspace.
POST
Add Mcp
Documentation Index
Fetch the complete documentation index at: https://docs.agentscope.io/llms.txt
Use this file to discover all available pages before exploring further.
Headers
Caller's user ID. Temporary header-based identity; will be replaced by JWT auth.
Body
application/json
The unified MCP client in AgentScope.
This class provides a unified interface for MCP connections, handling both stateful (persistent) and stateless (ephemeral) connections.
- Stateful: Requires explicit connect() and close(), maintains session
- Stateless: No connect() needed, creates temporary session per call
Private attributes:
- _client: The underlying MCP client context manager
- _session: The MCP ClientSession (for stateful connections only)
- _stack: AsyncExitStack for managing connection lifecycle
- _is_connected: Connection state flag
- _cached_tools: Cached list of tools
Example:
.. code-block:: python
# Stateful connection (STDIO or HTTP)
client = MCPClient(
name="file_system",
is_stateful=True,
mcp_config=StdioMCPConfig(
command="mcp-server-filesystem"
)
)
await client.connect()
tools = await client.list_tools()
await client.close()
# Stateless connection (HTTP only)
client = MCPClient(
name="weather_search",
is_stateful=False,
mcp_config=HttpMCPConfig(
url="https://api.weather.com/mcp"
)
)
# No connect() needed
tools = await client.list_tools()The MCP name.
Whether this is a stateful connection that requires explicit connect() and close(). STDIO MCP must be stateful. HTTP MCP can be either stateful or stateless.
The STDIO MCP server configuration.
- StdioMCPConfig
- HttpMCPConfig
Response
Successful Response