> ## 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.

# Add Mcp

> Add an MCP client to the session's workspace.



## OpenAPI

````yaml /versions/2.0.2/en/deploy/openapi.json post /workspace/mcp
openapi: 3.1.0
info:
  title: AgentScope
  version: 2.0.1
servers: []
security: []
paths:
  /workspace/mcp:
    post:
      tags:
        - workspace
      summary: Add Mcp
      description: Add an MCP client to the session's workspace.
      operationId: add_mcp_workspace_mcp_post
      parameters:
        - name: agent_id
          in: query
          required: true
          schema:
            type: string
            title: Agent Id
        - name: session_id
          in: query
          required: true
          schema:
            type: string
            title: Session Id
        - name: x-user-id
          in: header
          required: true
          schema:
            type: string
            description: >-
              Caller's user ID. Temporary header-based identity; will be
              replaced by JWT auth.
            title: X-User-Id
          description: >-
            Caller's user ID. Temporary header-based identity; will be replaced
            by JWT auth.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MCPClient'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    MCPClient:
      properties:
        name:
          type: string
          title: MCP Name
          description: The MCP name.
        is_stateful:
          type: boolean
          title: Stateful
          description: >-
            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:
          oneOf:
            - $ref: '#/components/schemas/StdioMCPConfig'
            - $ref: '#/components/schemas/HttpMCPConfig'
          title: MCP Config
          description: The MCP server configuration.
          discriminator:
            propertyName: type
            mapping:
              http_mcp:
                $ref: '#/components/schemas/HttpMCPConfig'
              stdio_mcp:
                $ref: '#/components/schemas/StdioMCPConfig'
        enable_tools:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Enable Tools
        disable_tools:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Disable Tools
        execution_timeout:
          anyOf:
            - type: number
            - type: 'null'
          title: Execution Timeout
      type: object
      required:
        - name
        - is_stateful
        - mcp_config
      title: MCPClient
      description: >-
        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()
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    StdioMCPConfig:
      properties:
        type:
          type: string
          const: stdio_mcp
          title: Type
          default: stdio_mcp
        command:
          type: string
          title: Command
          description: The command to start the MCP server.
        args:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Args
          description: The command line arguments to pass to the MCP server.
        env:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Environment Variables
          description: The environment variables to pass to the MCP server.
        cwd:
          anyOf:
            - type: string
            - type: string
              format: path
            - type: 'null'
          title: CWD
          description: The working directory to use when spawning the process.
        encoding_error_handler:
          type: string
          enum:
            - strict
            - ignore
            - replace
          title: Encoding Error Handler
          description: The text encoding error handler.
          default: strict
      type: object
      required:
        - command
      title: StdioMCPConfig
      description: The STDIO MCP server configuration.
    HttpMCPConfig:
      properties:
        type:
          type: string
          const: http_mcp
          title: Type
          default: http_mcp
        url:
          type: string
          title: URL
          description: The URL of the MCP server.
        headers:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Headers
          description: The additional headers to include in the HTTP request.
        timeout:
          anyOf:
            - type: number
            - type: 'null'
          title: Timeout
          description: The HTTP request timeout in seconds.
          default: 30
      type: object
      required:
        - url
      title: HttpMCPConfig
      description: The HTTP MCP server configuration.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````