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
}
'
import requests

url = "https://api.example.com/workspace/mcp"

payload = {
"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
}
headers = {
"x-user-id": "<x-user-id>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'x-user-id': '<x-user-id>', 'Content-Type': 'application/json'},
body: JSON.stringify({
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
})
};

fetch('https://api.example.com/workspace/mcp', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/workspace/mcp",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'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
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-user-id: <x-user-id>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.example.com/workspace/mcp"

payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"is_stateful\": true,\n \"mcp_config\": {\n \"command\": \"<string>\",\n \"type\": \"stdio_mcp\",\n \"args\": [\n \"<string>\"\n ],\n \"env\": {},\n \"cwd\": \"<string>\",\n \"encoding_error_handler\": \"strict\"\n },\n \"enable_tools\": [\n \"<string>\"\n ],\n \"disable_tools\": [\n \"<string>\"\n ],\n \"execution_timeout\": 123\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("x-user-id", "<x-user-id>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.example.com/workspace/mcp")
.header("x-user-id", "<x-user-id>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"is_stateful\": true,\n \"mcp_config\": {\n \"command\": \"<string>\",\n \"type\": \"stdio_mcp\",\n \"args\": [\n \"<string>\"\n ],\n \"env\": {},\n \"cwd\": \"<string>\",\n \"encoding_error_handler\": \"strict\"\n },\n \"enable_tools\": [\n \"<string>\"\n ],\n \"disable_tools\": [\n \"<string>\"\n ],\n \"execution_timeout\": 123\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.example.com/workspace/mcp")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-user-id"] = '<x-user-id>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"is_stateful\": true,\n \"mcp_config\": {\n \"command\": \"<string>\",\n \"type\": \"stdio_mcp\",\n \"args\": [\n \"<string>\"\n ],\n \"env\": {},\n \"cwd\": \"<string>\",\n \"encoding_error_handler\": \"strict\"\n },\n \"enable_tools\": [\n \"<string>\"\n ],\n \"disable_tools\": [\n \"<string>\"\n ],\n \"execution_timeout\": 123\n}"

response = http.request(request)
puts response.read_body
{
  "detail": [
    {
      "loc": [
        "<string>"
      ],
      "msg": "<string>",
      "type": "<string>",
      "input": "<unknown>",
      "ctx": {}
    }
  ]
}

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