Model Context Protocol (MCP) is an open-source protocol designed to standardize how applications provide context to Large Language Models (LLMs). It serves as an interface for AI applications, allowing models to connect flexibly and securely to various data sources and tools. This topic describes how to create and use MCP services.
Feature description
AI Gateway provides the MCP service management feature to allow smooth migration from REST APIs to MCP services. The feature supports two protocols: SSE and Streamable HTTP. This feature also integrates an authentication mechanism based on consumer identity to provide technical support for enterprise-level API governance.
Create an MCP service
Log on to the AI Gateway console.
In the left-side navigation pane, click Instance. In the top navigation bar, select a region.
On the Instance page, click the ID of the desired instance.
In the left-side navigation tree, click MCP Management. Then, click Create MCP Service.
In the Create MCP Service panel, configure the following parameters, and then click Save And Publish.
Parameter
Description
Example
Name
Configure a custom the name for the MCP service.
demo
Description
Enter a custom description of the MCP service.
Test
MCP Access Point
Domain Name
Specify the domain name that is used to access the MCP service. You can select multiple domain names.
NoteYou cannot create more than one MCP service with the same domain name in the same instance.
www.aliyun.com
Path (SSE)
The system generates a path (SSE) based on the service name.
/mcp-servers/{your-mcp-server-name}/ssePath (Streamable HTTP)
The system generates a path (Streamable HTTP) based on the service name.
/mcp-servers/{your-mcp-server-name}Backend Services
Specify the service to which you want to forward API requests.
test
Consumer Authentication
Specify whether to enable authentication. If this feature is enabled, only authorized consumers can access the MCP service.
Enabled
Add tools to an MCP service
Log on to the AI Gateway console.
In the left-side navigation pane, click Instance. In the top navigation bar, select a region.
On the Instance page, click the ID of the desired instance.
In the left-side navigation tree, select MCP Management. Then, click Details in the card of the desired service, and click Add Tool.
Add tools by using one of the following two methods:
Method 1: Use a Swagger file (recommended)
Import a Swagger file to create or incrementally update MCP tools: Upload an Open API file from your local computer or paste the API definition into the edit box, and then click Generate Now.
Update and confirm the MCP tool list: You can see the generated MCP tool description file and further confirm and modify the information.
(Optional) Enable backend service authentication: You can add authentication and authorization configurations based on your business requirements. The following table describes the authentication configuration:
Parameter
Description
Basic
The username and password are Base64-encoded in the format of username: password and sent in the Authorization field of the HTTP request header.
Bearer
The client first obtains a token, usually a JSON Web Token (JWT), by using the logon interface. Each subsequent request includes this token in the Authorization header. In most cases, the token is for temporary use and has a configurable validity period.
API Key
The server assigns a unique string to the client as an access credential. The client submits the credential in a Header or Query parameter in each request.
Method 2: Use custom YAML code
You can manually create MCP tools by using custom YAML.
Click YAML Example. You can modify the generated YAML example.
(Optional) Enable backend service authentication: You can add authentication and authorization configurations based on your business requirements. The following table describes the authentication configuration:
Parameter
Description
Basic
The username and password are Base64-encoded in the format of username: password and sent in the Authorization field of the HTTP request header.
Bearer
The client first obtains a token, usually a JSON Web Token (JWT), by using the logon interface. Each subsequent request includes this token in the Authorization header. In most cases, the token is for temporary use and has a configurable validity period.
API Key
The server assigns a unique string to the client as an access credential. The client submits the credential in a Header or Query parameter in each request.
Click OK. You can view the tool list and tool description information on the Tools tab.
Consumer authentication
Log on to the AI Gateway console.
In the left-side navigation pane, click Instance. In the top navigation bar, select a region.
On the Instance page, click the ID of the desired instance.
In the left-side navigation tree, select MCP Management. Then, click Details in the card of the desired service, and click the Consumer Authentication tab.
Select the Consumer Authentication tab, click Configuration Information on the right side of Edit, and turn on Enable Status. After configuring the relevant parameters, click Confirm.
ImportantAfter consumer authentication is enabled, a consumer cannot access the API unless the consumer is authorized.
We recommend that you use the API Key authentication method for the best compatibility.
Configuration Item
Description
Enable Status
Turn on or off the consumer authentication switch. By default, this switch is turned off.
Authentication Method
Consumer authentication currently supports two methods: API Key and JWT.
An API key is a simple authentication method. When a client accesses an API, the client must add an API key to the request in a specified way. After receiving the request, the gateway verifies the validity and permissions of the API key.
JSON Web Token (JWT) is used to securely transmit information between a client and a server in the form of JSON objects. The transmitted information can be verified and trusted because the JWT can be signed by using the hash-based message authentication code (HMAC) algorithm or a public/private key pair of the Rivest-Shamir-Adleman (RSA) or Elliptic Curve Digital Signature Algorithm (ECDSA) algorithm. You can use JWTs to authenticate users and perform access control.
In the Consumers section, click Authorize, and select a consumer. If none exist, click Create Consumer from the drop-down list to add one. Then, click Add.
Debug MCP services by using MCP Inspector
We recommend that you start MCP Inspector locally for MCP debugging.
MCP Inspector is a debugging tool provided by the MCP community. It can be used for the entire debugging process of MCP services.
MCP Inspector installation command:
npx @modelcontextprotocol/inspector node build/index.js.Select the transport type: Choose
SSEforTransport Type.Enter the
URLaddress: Obtain it from the right side of the MCP service details page.(Optional) If consumer authentication is configured, click
Authenticationto expand the authorization configuration and fill in the token corresponding to the consumer identity.Header NameisAuthenticationand does not need to be modified. EnterHereIsTokeninBearer Token.Click
Connectto establish a connection. After the connection is successful, you can see theList Toolsbutton in the middle. ClickList Toolsto get all tools of the MCP service.(Optional) To debug a specific tool, click the tool name, fill in the necessary parameters on the right, and click
Run Toolto debug the tool call.