Create a custom MCP

Updated at:

Creates and immediately deploys a custom MCP service. Supports STDIO, HTTP, SSE, and OPENAPI.

Endpoint

POST/api/v1/mcp/servers

The service is deployed immediately after creation. A successful request returns 201 and a Location header. If deployment fails, the request still returns 201, the status is ACTIVATE_FAILED, and the reason is returned in activate_fail_reason.

Request body

server_namestringRequired

MCP name. Cannot be blank

descriptionstringRequired

MCP description. Cannot be blank

mcp_typestringRequired

STDIO, HTTP, SSE, or OPENAPI

mcp_configobjectRequired

Configuration for the selected mcp_type

STDIO

commandstringRequired

npx or uvx

argsarray<string>Required

Non-empty startup arguments. Each item must match [A-Za-z0-9_@./:=,+-]+

envmap<string,string>Optional

Environment variables. Names must match [A-Za-z_][A-Za-z0-9_]*. Values must be strings

fc_deploy_regionstringOptional

Function Compute region. Use a region supported by the console

Function Compute must be authorized for the account before using STDIO.

HTTP / SSE

urlstringRequired

Public HTTP(S) URL. Cannot contain credentials, a # fragment, or backslashes

headersmap<string,string>Optional

Downstream request headers. Names must be valid HTTP headers. Values cannot contain CR/LF

If the URL has no path, HTTP uses /mcp and SSE uses /sse.

OPENAPI

api_hoststringRequired

Public HTTP(S) URL. Cannot contain a query string, fragment, credentials, or backslashes

headersmap<string,string>Optional

Downstream request headers. Names must be valid HTTP headers. Values cannot be blank or contain CR/LF

api_listarray<Api>Required

Non-empty API list

Api

namestringRequired

Tool name. Cannot be blank and must be unique in api_list

descriptionstringRequired

Tool description. Cannot be blank

pathstringRequired

Relative path starting with /. Supports {param} placeholders

methodstringRequired

GET or POST

content_typestringOptional

application/json (default) or application/x-www-form-urlencoded

input_paramsarray<InputParam>Optional

Input parameter definitions. Treated as an empty array when omitted

InputParam

namestringRequired

Parameter name. Cannot be blank and must be unique at the same level

descriptionstringRequired

Parameter description. Cannot be blank

locationstringRequired at top level

Query, Path, Header, or Body. Optional for child properties

typestringRequired

String, Number, Integer, Boolean, Object, Array<String>, Array<Number>, Array<Integer>, Array<Boolean>, or Array<Object>

requiredbooleanOptional

Whether the parameter is required. Default false

propertiesarray<InputParam>Depends on type

Required for Object or Array<Object> and cannot be empty

GET cannot define a top-level Body parameter. Top-level object and array parameters can only be placed in Body. All enumerated values are case-sensitive.

Response fields

Returns a CreateResponse. Unassigned fields are omitted.

mcp_codestring

MCP code

server_namestring

MCP name

server_statusstring

Deployment status

server_status_textstring

Status text

activate_fail_reasonstring

Deployment failure reason. Returned only when deployment fails

Examples

Create an HTTP MCP

Request example

curl -X POST "https://{workspace_id}.cn-beijing.maas.aliyuncs.com/api/v1/mcp/servers" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "server_name": "weather-mcp",
    "description": "Weather query MCP",
    "mcp_type": "HTTP",
    "mcp_config": {
      "url": "https://mcp.example.com/mcp",
      "headers": {
        "Authorization": "Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      }
    }
  }'

Response example

{
  "success": true,
  "error_code": null,
  "error_msg": null,
  "data": {
    "mcp_code": "mcp-a1b2c3d4e5f6g7h8",
    "server_name": "weather-mcp",
    "server_status": "ACTIVATED",
    "server_status_text": "已启用"
  },
  "request_id": "6f1c2a8e-3b0d-4c55-9a0e-2f7d1c9b8a11"
}

Response headers:

Location: /api/v1/mcp/servers/mcp-a1b2c3d4e5f6g7h8
X-Request-Id: 6f1c2a8e-3b0d-4c55-9a0e-2f7d1c9b8a11

Create an STDIO MCP

{
  "server_name": "amap-maps",
  "description": "Amap Maps MCP",
  "mcp_type": "STDIO",
  "mcp_config": {
    "command": "npx",
    "args": ["-y", "@amap/amap-maps-mcp-server"],
    "env": {
      "AMAP_MAPS_API_KEY": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    },
    "fc_deploy_region": "cn-hangzhou"
  }
}

Create an OPENAPI MCP

{
  "server_name": "order-api",
  "description": "Order query API",
  "mcp_type": "OPENAPI",
  "mcp_config": {
    "api_host": "https://api.example.com",
    "headers": {
      "X-Api-Key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    },
    "api_list": [
      {
        "name": "getOrder",
        "description": "Queries an order by order ID",
        "path": "/orders/{orderId}",
        "method": "GET",
        "input_params": [
          {
            "name": "orderId",
            "description": "Order ID",
            "location": "Path",
            "type": "String",
            "required": true
          }
        ]
      }
    ]
  }
}

Error codes

HTTP statuserror_codeDescription
400InvalidParameterThe request body is missing, a field type is invalid, or a value is invalid
403AccessDeniedFunction Compute is not authorized, or the target address is not allowed
500InternalErrorInternal service error

A private target address returns 403. An invalid or unresolvable address returns 400.