AgentRun supports three methods for integrating MCP (Model Context Protocol) tools: remote connection, creation from code or a code package, and API/MCP packaging. Choose a method based on whether you have an existing MCP Server, need custom code, or have existing API endpoints.
Creation method overview
After you select the MCP type on the creation page, you can choose one of the following creation methods:
|
Creation method |
Description |
Use cases |
|
Import an existing MCP Server using a JSON configuration. |
You have an existing remote or local MCP Server. |
|
|
Upload a code package to deploy a custom MCP tool. |
You need to customize the tool logic. |
|
|
Package existing APIs or MCP configurations into a tool. |
You have existing API endpoints or configured MCP tools. |
Method 1: Remote connection
Connect an existing MCP Server to AgentRun by importing its JSON configuration. This method supports both remote and local modes.
Procedure
-
Log on to the AgentRun console.
-
In the left-side navigation pane, choose Models and Tools > Tools and Skills.
-
On the Tools and Skills page, click Create Tool.
-
In the Creation Type section, select MCP.
-
For Creation Method, select Remote Connection.
-
Configure the basic information.
Parameter
Required
Description
MCP Name
Yes
The unique name of the MCP tool. The name must be 1 to 100 characters in length, start with a letter or an underscore (_), and can contain only letters, digits, underscores (_), and hyphens (-).
Description
No
A brief description of the tool's function and purpose. Up to 1,000 characters.
-
Depending on the deployment location of your MCP Server, click the Remote or Local tab.
Remote
A remote MCP Server connects to AgentRun using the Server-Sent Events (SSE) or Streamable HTTP protocol.
In the MCP Configuration editor, paste the JSON configuration of your MCP Server. If the format is correct, a 'Valid format' message appears at the top of the editor.
Example of the SSE protocol
{ "mcpServers": { "my-server": { "transportType": "sse", "url": "https://your-mcp-server.example.com/sse" } } }Example of the Streamable HTTP protocol
{ "mcpServers": { "my-server": { "transportType": "streamable-http", "url": "https://your-mcp-server.example.com/mcp" } } }NoteClick SSE Example or StreamableHTTP Example to automatically fill the editor with a configuration template in the corresponding format.
Local
A local MCP Server runs directly using commands such as
npxoruvx.In the MCP Configuration editor, paste the MCP configuration for the stdio protocol.
Example of a local MCP configuration
{ "mcpServers": { "my-server": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-everything", "stdio"], "env": {} } } }NoteClick Local Example to automatically fill the editor with a sample configuration.
ImportantLocal mode does not support the
urlfield. You must use thecommandstartup method. -
MCP Agent.
If you enable the MCP proxy, you can configure hooks for the following event types. For details, see MCP Tool Hook:
-
PRE_LIST_TOOLS
-
PRE_CALL_TOOL
-
POST_LIST_TOOLS
-
POST_CALL_TOOL
-
-
(Optional) Configure the Access Credential.
In the Access Credential section, select an authentication option:
-
Use existing credential: Use an existing access credential for authentication.
-
Anonymous access: Make calls without any authentication information.
WarningAnonymous access can create security risks. We recommend configuring a credential to protect your data. Ensure that your tool service supports unauthenticated access.
-
-
(Optional) Configure the Workspace.
-
Click Create Now.
Method 2: Create from code or a code package
Upload a code package to deploy a custom MCP tool. The tool runs as a Function Compute HTTP function.
Prerequisites
-
You have prepared the code for your MCP Server. The code must support the Streamable HTTP or SSE protocol.
-
The listening address in your code is set to
0.0.0.0, not127.0.0.1.
Procedure
-
Log on to the AgentRun console.
-
In the left-side navigation pane, choose Models and Tools > Tools and Skills.
-
On the Tools and Skills page, click Create Tool.
-
In the Creation Type section, select MCP.
-
For Creation Method, select Create Code / Code Package.
-
Configure the basic information.
Parameter
Required
Description
MCP Name
Yes
The unique name of the MCP tool. The name must be 1 to 100 characters in length, start with a letter or an underscore (_), and can contain only letters, digits, underscores (_), and hyphens (-).
Description
No
A brief description of the tool's function and purpose. Up to 1,000 characters.
-
Select an Execution Environment.
Execution environment
Description
Python 3.13
Suitable for MCP Servers written in Python.
Node.js 22
Suitable for MCP Servers written in Node.js.
Container image
Suitable for MCP Servers that have complex dependencies or require a custom runtime environment.
-
Configure the code source. Drag your code package file to the designated area or upload it. The file must be a ZIP file and not exceed 50 MB.
-
Configure the MCP protocol.
Parameter
Required
Description
Transport protocol
Yes
Select MCP Streamable or SSE. We recommend MCP Streamable.
Access path
—
The access path for MCP Streamable is fixed at
/mcpand cannot be changed. The default path for SSE is/ssebut can be customized.ImportantThis method does not support the stdio protocol. If your MCP Server uses the stdio protocol, select Remote connection > Local.
-
Configure the startup configuration.
Parameter
Required
Description
Startup command
Yes
The command to execute when the tool starts, such as
python3 main.py.Service port
Yes
The port number that the service listens on, from 1 to 65535. The default is
8080. This must match the port your code listens on. -
Configure resources.
Parameter
Description
CPU (cores)
The CPU specification for the tool instance. The default is 0.25 cores.
Memory (GB)
The memory specification for the tool instance. The default is 0.5 GB.
Timeout (seconds)
The maximum execution duration for a single request. The default is 300 seconds.
NoteThe vCPU-to-memory ratio must be between 1:1 and 1:4.
-
(Optional) Configure environment variables.
In the Environment Variables section, add environment variables. These variables are injected at runtime and can store sensitive information such as API keys or database connections.
-
MCP Agent.
If you enable the MCP proxy, you can configure hooks for the following event types. For details, see MCP Tool Hook:
-
PRE_LIST_TOOLS
-
PRE_CALL_TOOL
-
POST_LIST_TOOLS
-
POST_CALL_TOOL
-
-
(Optional) Configure the Access Credential.
In the Access Credential section, select an authentication option:
-
Use existing credential: Use an existing access credential for authentication.
-
Anonymous access: Make calls without any authentication information.
WarningAnonymous access can create security risks. We recommend configuring a credential to protect your data. Ensure that your tool service supports unauthenticated access.
-
-
(Optional) Configure the Workspace.
-
(Optional) Expand Advanced Configuration and configure the following options as needed.
Network Configuration
Parameter
Description
Allow internet access from the default network interface
Allows the tool to access the internet through the default network interface. Enabled by default.
Allow VPC access
Allows the tool to access resources within a specified VPC. You must configure the VPC, vSwitch, and security group.
Storage Configuration
Parameter
Description
OSS mount
Mounts an Object Storage Service (OSS) bucket for the tool.
NAS mount
Mounts a NAS file system for the tool. To enable a NAS mount, you must first configure a VPC in network settings.
Log Configuration
Parameter
Description
Enable logging
When enabled, Log Service collects request logs, error logs, and performance logs from the tool for troubleshooting and monitoring.
Execution Role
Parameter
Description
execution role
An execution role grants Function Compute (fc.aliyuncs.com) permissions to access other Alibaba Cloud services. Attach policies based on the services your tool needs.
-
Click Create Now.
Sample code
The following example shows a minimal MCP tool using the FastMCP framework in MCP Streamable mode:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("My App")
@mcp.tool()
async def hello() -> str:
"""Return string 'Hello World!'"""
return "Hello World!"
if __name__ == "__main__":
mcp.run(transport="streamable-http", host="0.0.0.0", port=8080)
Method 3: API/MCP packaging
API/MCP packaging converts existing API endpoints or configured MCP tools into a unified service gateway. It wraps RESTful APIs as MCP tools and serves them alongside other MCP tools through a single endpoint, simplifying management, access, and permission control for upstream agents or applications.
Procedure
-
Log on to the AgentRun console.
-
In the left-side navigation pane, choose Models and Tools > Tools and Skills.
-
On the Tools and Skills page, click Create Tool.
-
In the Creation Type section, select MCP.
-
For Creation Method, select API/MCP Packaging.
-
Configure the basic information.
Parameter
Required
Description
MCP Name
Yes
The unique name of the MCP tool. The name must be 1 to 100 characters in length, start with a letter or an underscore (_), and can contain only letters, digits, underscores (_), and hyphens (-).
Description
No
A brief description of the tool's function and purpose. Up to 1,000 characters.
-
Select a Packaging Method:
Select existing API endpoints
From the API list, select the APIs you want to package. You can perform the following operations:
-
Filter the list by searching for a tool name, toolset name, or API path.
-
Select all or individual API items.
-
The table shows the HTTP method (color-coded, such as GET, POST, PUT, or DELETE), PATH, description, toolset name, and tool name.
Validation rule: In API packaging mode, you must select at least one API.
Import MCP configurations
Your configured MCP tools appear in a three-column card grid. Each card shows the following:
-
Service name
-
Description
-
Tool name tags
You can select multiple cards. The number of selected cards appears in the upper-right corner, along with a "Clear selection" option.
Validation rule: In MCP packaging mode, you must select at least one MCP configuration.
Paste OpenAPI/Swagger specification
Use the OpenAPI specification editor to import an API specification in one of the following ways:
-
Paste an OpenAPI specification in JSON or YAML format directly into the editor.
-
Click Import via URL and enter the OpenAPI specification URL to automatically retrieve and format it (Supports JSON/YAML formats, up to 2 MB).
-
Click Example to automatically fill the editor with a sample configuration.
-
Click Copy to copy the content to the clipboard.
-
A green check mark with the text 'Valid format' appears if the format is correct. A red error message appears if the validation fails.
Validation rule: The OpenAPI specification must be valid, specify an
openapiversion of 3.0.x or 3.1.x, and include theinfo.title,info.version, andpathsfields. Each operation withinpathsmust also have anoperationId. -
-
Network Configuration.
Allow Internet Access for the Default NIC: Enabled by default.
Allow Access to VPC: Disabled by default. If enabled, you must specify a VPC, one or more vSwitches, and a security group.
-
MCP Agent.
If you enable the MCP proxy, you can configure hooks for the following event types. For details, see MCP Tool Hook:
-
PRE_LIST_TOOLS
-
PRE_CALL_TOOL
-
POST_LIST_TOOLS
-
POST_CALL_TOOL
-
-
Configure the Access Credential.
In the Access Credential section, select an authentication option:
-
Use Existing Credentials: Use an existing access credential for authentication.
-
Anonymous Access: Make calls without any authentication information.
WarningAnonymous access can create security risks. We recommend configuring a credential to protect your data.
-
-
Configure the Workspace.
The current workspace is automatically selected and is required.
-
Click Create Now.
FAQ
How do I choose a creation method?
|
Scenario |
Recommended method |
|
You have an existing remote MCP Server. |
Remote connection > Remote |
|
You have an existing MCP Server that uses the stdio protocol. |
Remote connection > Local |
|
You need to customize the tool logic. |
Create from code or a code package |
|
You have existing API endpoints or configured MCP tools. |
API/MCP packaging |
When should I choose MCP Streamable versus SSE?
-
MCP Streamable: Recommended. This HTTP streaming mode offers good compatibility and uses the fixed access path
/mcp. -
SSE: A Server-Sent Events push mode suitable for MCP Servers that already have an SSE implementation.
What should I do if the tool fails to start?
-
Make sure the listening address in your code is
0.0.0.0, not127.0.0.1. -
Make sure the port that your code listens on matches the service port configured in the console.
-
If you are using a container image, make sure the port exposed in the Dockerfile matches the port configured in the console.