All Products
Search
Document Center

Agent Run:Create an MCP tool

Last Updated:Aug 24, 2026

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

Remote connection

Import an existing MCP Server using a JSON configuration.

You have an existing remote or local MCP Server.

Create from code or a code package

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

  1. Log on to the AgentRun console.

  2. In the left-side navigation pane, choose Models and Tools > Tools and Skills.

  3. On the Tools and Skills page, click Create Tool.

  4. In the Creation Type section, select MCP.

  5. For Creation Method, select Remote Connection.

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

  7. 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"
        }
      }
    }
    Note

    Click 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 npx or uvx.

    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": {}
        }
      }
    }
    Note

    Click Local Example to automatically fill the editor with a sample configuration.

    Important

    Local mode does not support the url field. You must use the command startup method.

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

  9. (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.

    Warning

    Anonymous access can create security risks. We recommend configuring a credential to protect your data. Ensure that your tool service supports unauthenticated access.

  10. (Optional) Configure the Workspace.

  11. 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, not 127.0.0.1.

Procedure

  1. Log on to the AgentRun console.

  2. In the left-side navigation pane, choose Models and Tools > Tools and Skills.

  3. On the Tools and Skills page, click Create Tool.

  4. In the Creation Type section, select MCP.

  5. For Creation Method, select Create Code / Code Package.

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

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

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

  9. 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 /mcp and cannot be changed. The default path for SSE is /sse but can be customized.

    Important

    This method does not support the stdio protocol. If your MCP Server uses the stdio protocol, select Remote connection > Local.

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

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

    Note

    The vCPU-to-memory ratio must be between 1:1 and 1:4.

  12. (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.

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

  14. (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.

    Warning

    Anonymous access can create security risks. We recommend configuring a credential to protect your data. Ensure that your tool service supports unauthenticated access.

  15. (Optional) Configure the Workspace.

  16. (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.

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

  1. Log on to the AgentRun console.

  2. In the left-side navigation pane, choose Models and Tools > Tools and Skills.

  3. On the Tools and Skills page, click Create Tool.

  4. In the Creation Type section, select MCP.

  5. For Creation Method, select API/MCP Packaging.

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

  7. 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 openapi version of 3.0.x or 3.1.x, and include the info.title, info.version, and paths fields. Each operation within paths must also have an operationId.

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

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

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

    Warning

    Anonymous access can create security risks. We recommend configuring a credential to protect your data.

  11. Configure the Workspace.

    The current workspace is automatically selected and is required.

  12. 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, not 127.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.