Skip to main content
POST
/
workspace
/
mcp
Add Mcp
curl --request POST \
  --url https://api.example.com/workspace/mcp \
  --header 'Content-Type: application/json' \
  --header 'x-user-id: <x-user-id>' \
  --data '
{
  "name": "<string>",
  "is_stateful": true,
  "mcp_config": {
    "command": "<string>",
    "type": "stdio_mcp",
    "args": [
      "<string>"
    ],
    "env": {},
    "cwd": "<string>",
    "encoding_error_handler": "strict"
  },
  "enable_tools": [
    "<string>"
  ],
  "disable_tools": [
    "<string>"
  ],
  "execution_timeout": 123
}
'
{
  "detail": [
    {
      "loc": [
        "<string>"
      ],
      "msg": "<string>",
      "type": "<string>",
      "input": "<unknown>",
      "ctx": {}
    }
  ]
}

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

x-user-id
string
required

Caller's user ID. Temporary header-based identity; will be replaced by JWT auth.

Query Parameters

agent_id
string
required
session_id
string
required

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()
name
string
required

The MCP name.

is_stateful
boolean
required

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.

mcp_config
StdioMCPConfig · object
required

The STDIO MCP server configuration.

enable_tools
string[] | null
disable_tools
string[] | null
execution_timeout
number | null

Response

Successful Response