SLS MCP Server
Simple Log Service (SLS) provides an official Model Context Protocol (MCP) server that connects AI agents to your SLS resources. After you add SLS MCP Server to an agent such as Qoder or Codex, you browse projects and LogStores, query and analyze logs, and diagnose alerts by using natural language.
What you can do with SLS MCP Server
SLS MCP Server provides 11 tools in three categories. The AI agent selects the tool that matches your request, so you do not need to remember console entry points or write query statements by hand.
Resource discovery — Ask which projects and LogStores you own instead of logging on to the console and browsing them one by one.
Log query and analysis — Describe what you want to query in one sentence instead of switching between console pages. These tools cover the common log analysis path: check the index configuration, run a query, and then review the distribution over time.
Alert diagnostics — After an alert is triggered, ask the AI agent to analyze the cause and locate the problem quickly.
For the tools in each category, see the Supported tools section.
How SLS MCP Server works
Model Context Protocol (MCP) is an open standard that lets AI assistants connect to external data sources and tools in a uniform way. When a service provides an MCP server, AI assistants can use its capabilities in a Plug and Play manner.
SLS MCP Server runs on your local machine. After an AI agent connects to it, the server calls SLS OpenAPI on your behalf by using the OAuth credentials that you configured. The following diagram shows the end-to-end path.
AI agent (Qoder, Codex, and so on)
│ MCP protocol (stdio transport)
▼
alibabacloud-sls-mcp-proxy (runs locally)
│ OAuth credentials (from an Alibaba Cloud CLI profile)
▼
Simple Log Service (SLS) OpenAPIConsiderations
Review the following items before you connect SLS MCP Server to an AI agent:
Authentication — SLS MCP Server authenticates to SLS with OAuth credentials that are stored in an Alibaba Cloud CLI profile. You sign in through a browser, so you never create or paste an AccessKey pair.
One-time RAM authorization — Before anyone in the Alibaba Cloud account signs in with OAuth for the first time, a RAM administrator must install the
official-cliapplication and add the RAM users or roles that use Alibaba Cloud CLI to the authorization list. For instructions, see the Grant OAuth access to Alibaba Cloud CLI section.Region-less access — You do not need to specify the region of a project when you access it. SLS MCP Server matches the corresponding region automatically, so a single credential profile gives you cross-region access to all of your projects.
Alert tool behavior — The alert diagnostics tools are read-only and do not change the state of any alert. Masking differs by tool:
sls_list_alertsreturns neither query statements nor notification targets, andsls_get_alertreturns diagnostic queries with sensitive notification configurations masked.
Prerequisites
An Alibaba Cloud account. If you use a Resource Access Management (RAM) user, the RAM user must have access permissions for SLS.
The
uvtool installed on your local machine. SLS MCP Server is started with theuvxcommand, which is provided withuv. For installation instructions, see the uv documentation.
Grant OAuth access to Alibaba Cloud CLI
A RAM administrator performs the following steps once for the Alibaba Cloud account. You do not need to repeat them later. If you are not a RAM administrator, confirm with your administrator that this authorization is complete before you start the quick start.
Install the CLI application: Log on to the RAM console. In the left-side navigation pane, choose OAuth (Preview), and then click the Third-party Application tab. If the
official-cliapplication is not listed, select Official CLI to install it.Assign identities: Open the
official-cliapplication details page and click the Allowed Identities tab. Click Add Users or roles to add the RAM users or roles that need to use Alibaba Cloud CLI to the authorization list.
Quick start
The following steps are performed by the user of the AI agent. They assume that the one-time OAuth authorization described in the previous section is complete.
Step 1: Install Alibaba Cloud CLI
Run the following command to install Alibaba Cloud CLI.
sudo /bin/bash -c "$(curl -fsSL https://aliyuncli.alicdn.com/install.sh)"After the installation is complete, run aliyun version. If the command returns a version number, the installation is successful.
Step 2: Sign in with OAuth and create a credential profile
Run the following command. A browser page opens automatically. Complete the sign-in to finish authentication.
aliyun configure --mode OAuthAfter the sign-in succeeds, Alibaba Cloud CLI stores the OAuth credentials in a profile. The default profile name is default. To manage multiple accounts or multiple environments, use the -p parameter to specify a custom profile name.
aliyun configure --mode OAuth -p sls-test-oauthNote the profile name that you use. You specify it with the --profile parameter in Step 3.
Enter cn-hangzhou when the CLI prompts you for a region. The region that you specify does not limit the projects that SLS MCP Server can access.
Step 3: Add SLS MCP Server to your AI agent
Complete the configuration for the client that you use. You do not need to configure more than one client. SLS MCP Server uses the standard stdio transport, so you can connect it to any AI agent that supports MCP: set the startup command to uvx and the arguments to alibabacloud-sls-mcp-proxy@latest --profile <your profile name>.
The following examples use the default profile. If you created a custom profile with the -p parameter in Step 2, replace default with that profile name.
The uvx alibabacloud-sls-mcp-proxy@latest command downloads and runs the latest version of SLS MCP Server locally. Every command in this step requires uvx, which is provided with uv.
Clients that you configure with a CLI command
Qoder
# Add the MCP Server
qodercli mcp add \
--scope user \
--transport stdio \
alibabacloud-sls \
-- uvx alibabacloud-sls-mcp-proxy@latest --profile default
# List the MCP Servers that you added
qodercli mcp listCodex
# Add the MCP Server
codex mcp add alibabacloud-sls \
-- uvx alibabacloud-sls-mcp-proxy@latest --profile default
# List the MCP Servers that you added
codex mcp listClaude Code
# Add the MCP Server. --scope user applies the configuration to all projects of the current user.
claude mcp add --scope user alibabacloud-sls \
-- uvx alibabacloud-sls-mcp-proxy@latest --profile default
# List the MCP Servers that you added
claude mcp listOpenClaw
# Add the MCP Server
openclaw mcp add alibabacloud-sls \
--command uvx \
--arg alibabacloud-sls-mcp-proxy@latest \
--arg --profile \
--arg default
# List the MCP Servers that you added
openclaw mcp listClients that you configure with a configuration file
Cursor, Cline, Cherry Studio, and other JSON-based clients
For clients that configure MCP servers in a JSON file, add the following content to the MCP configuration file:
{
"mcpServers": {
"alibabacloud-sls": {
"command": "uvx",
"args": [
"alibabacloud-sls-mcp-proxy@latest",
"--profile",
"default"
]
}
}
}Hermes Agent
Hermes Agent manages MCP servers in a configuration file. Edit the ~/.hermes/config.yaml file in your home directory, or create the file if it does not exist, and add the following content:
mcp_servers:
alibabacloud-sls:
command: uvx
args:
- alibabacloud-sls-mcp-proxy@latest
- --profile
- defaultSave the file and restart Hermes Agent, or run /reload-mcp in a session to reload the MCP configuration.
Step 4: Verify the connection
Open your AI agent and enter a natural language request.
List the SLS projects that I can accessIf the AI agent returns your project list, SLS MCP Server is connected. If the project list is not returned, confirm the following items:
The
uvxcommand is available on your local machine.The one-time OAuth authorization covers your RAM user or role.
The
--profilevalue in the client configuration matches the profile name that you created in Step 2.
Usage examples
After you complete the connection, ask questions in natural language directly in your AI agent. The following examples show typical usage.
Example 1: Find resources
List the SLS projects that I can access in the China (Hangzhou) regionThe AI agent calls sls_list_projects and returns the project list. You can then ask a follow-up question:
Which Logstores does the nginx-prod project contain?The AI agent calls sls_list_logstores and lists the corresponding LogStores.
Example 2: Query logs
Query the logs that contain error in the access-log Logstore of the nginx-prod project over the last 1 hourThe AI agent calls sls_query_logs and automatically uses a relative time range such as now-1h to now. To understand the log volume distribution, ask a follow-up question:
Approximately how many logs are there? Show me the distribution over timeThe AI agent calls sls_get_log_histogram and returns the total number of matched logs and their distribution over time.
Example 3: View the log context
A single log often does not provide enough information during troubleshooting. Ask the AI agent to retrieve the log context:
Show me the 20 log lines before and after this error logThe AI agent uses the __pack_id__ and __pack_meta__ values from the previous query result, calls sls_get_context_logs, and returns the full context before and after the target log.
Example 4: Diagnose an alert
Why was my cpu-high alert triggered over the last 24 hours? Run a diagnosis for meThe AI agent calls sls_diagnose_alert, which summarizes the lifecycle, severity, evaluation reason, and query evidence of the alert instance. The summary helps you locate the cause quickly.
Debug with MCP Inspector
To debug the tools and parameters of SLS MCP Server during development, use the official MCP Inspector to open a browser-based debugging interface. This command requires Node.js on your local machine, because Node.js provides the npx command. Replace sls-test-oauth with the name of your credential profile.
npx -y @modelcontextprotocol/inspector@latest -- uvx alibabacloud-sls-mcp-proxy@latest --profile sls-test-oauthSupported tools
Tool | Category | Description |
| Resource discovery | Retrieves the SLS projects that the current caller can access. Supports filter conditions such as region, name, and resource group. |
| Resource discovery | Retrieves the LogStores that store log data in a specified project. This tool excludes metricstores. |
| Resource discovery | Retrieves the metricstores that store metric data in a specified project. |
| Log query and analysis | Retrieves the index configuration of a LogStore. |
| Log query and analysis | Queries Raw Logs or runs an SLS SQL analysis. Supports relative time ranges. |
| Log query and analysis | Queries the total number of matched logs and their distribution over time within a specified time range. |
| Log query and analysis | Retrieves the context before and after a target log. The |
| Alert diagnostics | Lists a security summary of alert rules by page. Query statements and notification targets are not returned. |
| Alert diagnostics | Retrieves the schedule, trigger conditions, and diagnostic queries of a single alert rule. Sensitive notification configurations are masked. |
| Alert diagnostics | Queries the firing and resolved history of an alert rule, together with the query results that the alert engine saved at that time. |
| Alert diagnostics | Summarizes the lifecycle, severity, evaluation reason, and query evidence of recent alert instances. Does not change the alert state. |
Tool parameters
The following tables describe the input parameters of each tool. When you call a tool through an AI agent, you usually do not need to handle these parameters because the AI agent fills them in automatically. Use these tables for advanced usage and debugging.
sls_list_projects
Parameter | Type | Required | Description |
| integer | No | The zero-based pagination offset. Default value: 0. |
| integer | No | The number of projects to return per page. The default value and the maximum value in SLS are both 500. |
| string | No | Filters by SLS region ID, for example, |
| string | No | Filters by project name. This field is a search condition and is not validated against the exact resource naming rules. |
| string | No | Filters by resource group ID. |
| string | No | The free-text search condition for projects. |
sls_list_logstores
Parameter | Type | Required | Description |
| string | Yes | The name of the target SLS project. |
| integer | No | The zero-based pagination offset. Default value: 0. |
| integer | No | The number of LogStores to return per page. The default value and the maximum value in SLS are both 500. |
sls_list_metricstores
Parameter | Type | Required | Description |
| string | Yes | The name of the target SLS project. |
| integer | No | The zero-based pagination offset. Default value: 0. |
| integer | No | The number of metricstores to return per page. The default value and the maximum value in SLS are both 500. |
sls_get_logstore_index
Parameter | Type | Required | Description |
| string | Yes | The name of the target SLS project. |
| string | Yes | The name of the LogStore whose index configuration you want to read. |
sls_query_logs
Parameter | Type | Required | Description |
| string | Yes | The name of the target SLS project. |
| string | Yes | The name of the LogStore that you want to query. |
| string | No | The SLS query statement or analytic statement. Default value: empty. |
| string | No | The SLS topic filter condition. |
| string | Yes | The beginning of the query time range. The specified point in time is included, for example, |
| string | Yes | The end of the query time range. The specified point in time is excluded, for example, |
| integer | No | The maximum number of lines to return for a non-SQL query. The default value and the maximum value in SLS are both 100. |
| integer | No | The zero-based result offset for a non-SQL query. Default value: 0. |
| boolean | No | Specifies whether to return the results of a non-SQL query in reverse chronological order. Default value: |
| boolean | No | Specifies whether to use dedicated SQL compute resources. Default value: |
sls_get_log_histogram
Parameter | Type | Required | Description |
| string | Yes | The name of the target SLS project. |
| string | Yes | The name of the LogStore that you want to query. |
| integer | Yes | The beginning of the query time range, in Unix seconds. The specified point in time is included. |
| integer | Yes | The end of the query time range, in Unix seconds. The specified point in time is excluded. |
| string | No | The SLS topic filter condition. |
| string | No | The SLS query expression. SQL analysis is not supported. |
sls_get_context_logs
Parameter | Type | Required | Description |
| string | Yes | The name of the target SLS project. |
| string | Yes | The name of the LogStore that contains the target log. |
| string | Yes | The |
| string | Yes | The |
| integer | No | The number of log lines to return before the target log. Default value: 10. Maximum value: 100. |
| integer | No | The number of log lines to return after the target log. Default value: 10. Maximum value: 100. |
sls_list_alerts
Parameter | Type | Required | Description |
| string | Yes | The name of the SLS project that contains the target alert rules. |
| string | No | The alert rule name filter condition. |
| string | No | The dashboard resource provider filter condition. |
| integer | No | The zero-based pagination offset. Default value: 0. |
| integer | No | The number of alert rules to return per page. If the value is 0 or the parameter is omitted, the default value of the SLS API is used. |
sls_get_alert
Parameter | Type | Required | Description |
| string | Yes | The name of the SLS project that contains the target alert rule. |
| string | Yes | The exact name of the alert rule that you want to retrieve. |
sls_list_alert_history
Parameter | Type | Required | Description |
| string | Yes | The name of the SLS project that contains the |
| string | No | Filters by the exact name of the alert rule. |
| string | No | Filters by the exact ID of the alert instance. |
| string | No | Filters by the lifecycle state of the alert, for example, |
| string | Yes | The beginning of the history query time range. The specified point in time is included. Supports Unix seconds or a relative time such as |
| string | Yes | The end of the history query time range. The specified point in time is excluded. Supports Unix seconds or a relative time such as |
| integer | No | The maximum number of history events. Default value: 20. Maximum value: 100. |
| integer | No | The zero-based history result offset. Default value: 0. |
sls_diagnose_alert
Parameter | Type | Required | Description |
| string | Yes | The name of the SLS project that contains the alert rule and the |
| string | Yes | The exact name of the alert rule that you want to diagnose. |
| string | No | The ID of the alert instance. If you omit this parameter, the latest matching instance within the diagnosis time range is diagnosed. |
| string | Yes | The beginning of the diagnosis time range. The specified point in time is included. Supports Unix seconds or a relative time such as |
| string | Yes | The end of the diagnosis time range. The specified point in time is excluded. Supports Unix seconds or a relative time such as |
| integer | No | The number of latest history events to return as diagnosis evidence. Default value: 20. Maximum value: 100. |
FAQ
Do I need to configure an AccessKey pair to use SLS MCP Server?
No. SLS MCP Server supports OAuth sign-in: you sign in through a browser to complete authentication, and the credentials are stored in an Alibaba Cloud CLI profile. You never create or paste an AccessKey pair.
Does the RAM administrator authorization need to be repeated?
No. This is a one-time setup. After a RAM administrator installs the official-cli application and assigns RAM users or roles, those users can sign in with OAuth directly without repeating the steps.
How do I manage multiple accounts or multiple environments?
Use the -p parameter to create multiple profiles, for example, aliyun configure --mode OAuth -p sls-test-oauth. Then specify the corresponding profile name with the --profile parameter when you add SLS MCP Server to your client. You can also add a separate MCP server for each profile.
Which region do I enter when I configure credentials?
Enter cn-hangzhou when the CLI prompts you for a region, as described in Step 2. The value does not limit the projects that you can reach, because SLS MCP Server matches the corresponding region automatically when you access a project. To view the resources in only one region, filter by the region_id parameter when you list projects.
What do I do if the uvx command is not found?
The uvx command is provided by the uv tool, which is a prerequisite for SLS MCP Server. Install uv first. For installation instructions, see the uv documentation. After the installation is complete, open a new terminal and try again.