模型上下文协议服务器

为Alcatel AOS交换机提供模型上下文协议服务器,支持通过SSH连接执行基本CLI命令,并实现与LLM的交互。

  • by Foricher
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 Foricher/aos-mcp

使用说明

ALE AOS MCP 服务器

这个项目为阿尔卡特朗讯AOS交换机提供了一个MCP(模型上下文协议)服务器,详情请参阅https://modelcontextprotocol.io/docs/getting-started/intro。 通过SSH连接可以使用基本的交换机CLI命令。 它使得大型语言模型(LLM)能够与阿尔卡特朗讯AOS网络交换机进行交互。 它包含两个子项目:

  • aos_ssh:提供一个REST API,用于在ALE aos交换机上运行ssh cli命令
  • aos_mcp:提供MCP工具的MCP服务器,通过AOS_SSH服务器的REST API使LLM能够执行基本的SSH命令。

Demos(德莫斯)

  • 使用 GitHub Copilot CLI 的演示

https://github.com/user-attachments/assets/828169e4-867f-44cb-8bb6-dd90116090a2(该链接可直接复制使用,无需翻译)

建筑

部署MCP和SSH服务器

aos_ssh 和 aos_mcp 服务器的 Docker 镜像现已可用:

  • docker.io/foricher/ale-aos-ssh:[标签]
  • docker.io/foricher/ale-aos-mcp:[标签]

在……之下 deploy 文件夹,MCP 服务器端可通过 Docker Compose 部署来使用。

ale-aos-ssh 配置

更新 data\aos-ssh-host.json 在文件中填写您的交换机的主机名、用户名和用于SSH连接的密码。

{
  "jump_ssh_hosts": [
    {
      "name": "jump_name",
      "public_host": "public_host_or_ip_address",
      "public_port": 22,
      "private_host": "private_host_or_ip_address",
      "private_port": 22,
      "user": "jump_user",
      "password": "jupmp_password"
    }
  ],
  "hosts": [
    {
      "host": "host_or_ip_address1",
      "user": "user",
      "password": "password",
      "tags": ["sw1"]
    },
    {
      "host": "host_or_ip_address2",
      "user": "user",
      "password": "password",
      "tags": ["sw2"],
      "jump_ssh_name": "jump_name"
    }
  ]
}

更新 data\aos-ssh-conf.yaml 包含允许的AOS命令的文件。

allowed_aos_commands:
  - show .*
  - ping .*
  - traceroute .*

ale-aos-ssh 配置

data\mcp_tools.yaml 该文件描述了大型语言模型(LLM)用于执行AOS命令的工具。

Docker Compose 文件

docker-compose.yaml 文件:

services:
  aos-ssh:
    image: docker.io/foricher/ale-aos-ssh:0.1.2.2
    ports:
      - "8210:8110"
    volumes:
      - ./data/aos-ssh-host.json:/app/data/aos-ssh-host.json
      - ./data/aos-ssh-conf.yaml:/app/data/aos-ssh-conf.yaml
  aos-mcp:
    image: docker.io/foricher/ale-aos-mcp:0.1.2
    ports:
      - "8000:8000"
    environment:
      - ALE_AOS_MCP_SSH_URL=http://aos-ssh:8110
      - ALE_AOS_MCP_TRANSPORT=streamable-http
#      - ALE_AOS_MCP_TRANSPORT=sse
      - ALE_AOS_MCP_TOOLS_FILE=/app/data/mcp_tools.yaml
    volumes:
      - ./data:/app/data
    depends_on:
      - aos-ssh

启动 Docker Compose

 cd deploy
 docker compose up 

默认情况下,mcp服务器是使用可传输的流式HTTP进行部署的

使用mcp inspector进行测试

你可以使用 MCP 检查器工具来测试 aos MCP 服务器,请参阅 https://modelcontextprotocol.io/legacy/tools/inspector

npx @modelcontextprotocol/inspector
  • 使用传输类型:可流式传输的HTTP
  • 输入您的网址:http://mcp-host:8000/mcp
  • 输入代理会话令牌

客户

  • 使用可流式传输的HTTP协议连接到远程MCP服务器。

    两个服务器 ale_aos_mcp 和 ale_aos_ssh 均远程运行。

{
 "mcpServers": {
   "aos": {
     "type": "http",
     "url": "http://<aos-mcp-host>:8000/mcp"
   }
 }
}

  • 使用stdio传输方式连接到本地MCP服务器。

    本地 ale_aos_mcp 服务器通过提供的参数 --aos-ssh-url url 连接到远程 ale_aos_ssh 服务器。

{
   "mcpServers": {
       "aos": {
           "command": "uv run ale_aos_mcp",
           "args": [
               "--aos-ssh-url",
               "http://<aos-ssh-host>:8210"
           ],
           "env": {
           }
       }
   }
}

在 Visual Studio Code 中使用 Github Copilot

在你的工作区下方,里面 .vscode 文件夹,放入文件 mcp.json 如下所示。

  • 使用Streamable HTTP传输
{
 "servers": {
   "aos": {
     "type": "http",
     "url": "http://<aos-mcp-host>:8000/mcp"
   }
 }
}

  • 使用stdio传输方式
{
   "servers": {
       "aos": {
           "command": "uv run ale_aos_mcp",
           "args": [
               "--aos-ssh-url",
               "http://<aos-ssh-host>:8210"
           ],
           "env": {
           }
       }
   }
}

设置聊天 agent 模式

在 Visual Studio Code 中使用光标

在您的工作区下方,内部 .cursor 文件夹,放文件 mcp.json 如下所示。

设置聊天 agent 模式

{
   "mcpServers": {
       "aos": {
           "url": "http://<aos-mcp-host>:8000/mcp"
       }
   }
}

使用Gemini CLI

置于……之下 .gemini 文件夹,文件“settings.json”如下。

{
"mcpServers": {
  "aos": {
    "name": "AOS MCP Server",
    "description": "AOS MCP Server for managing AOS switches",
    "httpUrl": "http://<aos-mcp-host>:8000/mcp",
    "timeout" : 60000
  }
}
}

Zscaler问题

set NODE_EXTRA_CA_CERTS=C:\\Data\\zscaler\\zscaler.pem
set NODE_TLS_REJECT_UNAUTHORIZED=0

设置Gemini API密钥

set GEMINI_KEY_API=<gemini-api-key>

安装 gemini-cli

npm install -g @google/gemini-cli@latest
gemini -m gemini-2.5-flash

或者

npx https://github.com/google-gemini/gemini-cli -m gemini-2.5-flash

使用Claude代码CLI(命令行界面)

如需更多信息,请参阅(https://docs.anthropic.com/en/docs/claude-code/mcp)

如遇Zscaler问题

set NODE_EXTRA_CA_CERTS=C:\\Data\\zscaler\\zscaler.pem
set NODE_TLS_REJECT_UNAUTHORIZED=0

安装Claude代码

npm install -g @anthropic-ai/claude-code

在你的项目之下

cd <project>

将AOS MCP服务器添加到Claude项目中。

claude mcp add --transport http --scope project aos http://<mcp-server-host>:8000/mcp

跑,克劳德。

claude

使用开源命令行工具(仅限Linux)

如需更多信息,请访问(https://opencode.ai)。

如遇Zscaler问题

export NODE_TLS_REJECT_UNAUTHORIZED=0

安装Claude代码

npm i -g opencode-ai

在你的项目下

cd <project>

将opencode.json文件添加到项目中。

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "aos": {
      "type": "remote",
      "url": "http://<mcp-host>:8000/mcp",
      "enabled": true
    }
  }
}

运行开源代码。

opencode