Skip to main content

room-stu-fault-mcp

教室故障排查 MCP 服务,面向阿里云百炼 uvx / PyPI 部署。

提供三个工具(业务逻辑在 src/room_stu_fault_mcp/tools/ 中自行填充):

工具 说明 填充位置
query_classroom_logs 阿里云教室日志(SLS SDK) tools/classroom_logs.pyfetch_classroom_logs
get_room_network_info 自有服务器 Mongo 网络信息(HTTP) tools/network_info.pyfetch_room_network_info
get_classroom_tickets 教室工单信息(HTTP) tools/tickets.pyfetch_classroom_tickets

未接好真实接口时,工具会返回模拟数据,便于本地和百炼联调。

本地开发

需要 Python 3.10+(本机默认 python3 若是 3.9,不要用它建 venv)。推荐用 uv:

uv python install 3.12
uv venv --python 3.12
source .venv/bin/activate
uv pip install -e .
cp .env.example .env   # 按需填写

或指定解释器:

/path/to/python3.12 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e .

本地以 stdio 启动:

room-stu-fault-mcp
# 或
python -m room_stu_fault_mcp
# 或
fastmcp run src/room_stu_fault_mcp/server.py:mcp

怎么调用测试

stdio 服务本身不会打印结果,要用 Client 去调工具。

1. FastMCP 内存调用(推荐,最快)

source .venv/bin/activate
python examples/call_tools.py

等价手写:

import asyncio
from fastmcp import Client
from room_stu_fault_mcp.server import mcp

async def main():
    async with Client(mcp) as client:
        print(await client.list_tools())
        print(await client.call_tool("query_classroom_logs", {"serial": "R101"}))
        print(await client.call_tool("get_room_network_info", {
            "company_id": 10097,
            "serial": "1000292304",
            "room_unit_id": 575718,
            "send_userid": "379180147",
            "receive_userid": "1b3e2441-b89d-2ef9-fa97-431d101daa51",
        }))
        print(await client.call_tool("get_classroom_tickets", {
            "companyid": 120554,
            "serial": "1248513074",
            "starttime": 1788364800,
            "endtime": 1788451200,
        }))

asyncio.run(main())

2. 只测业务方法(不经过 MCP)

python -c "from room_stu_fault_mcp.tools.classroom_logs import fetch_classroom_logs; print(fetch_classroom_logs('R101'))"
python -c "from room_stu_fault_mcp.tools.network_info import fetch_room_network_info; print(fetch_room_network_info(10097, '1000292304', 575718, '379180147', '1b3e2441-b89d-2ef9-fa97-431d101daa51'))"
python -c "from room_stu_fault_mcp.tools.tickets import fetch_classroom_tickets; print(fetch_classroom_tickets(120554, '1248513074', 1788364800, 1788451200))"

3. MCP Inspector 可视化调试

fastmcp dev src/room_stu_fault_mcp/server.py:mcp

浏览器打开后,在 Tools 里点三个工具,填 serial=R101 即可。

Cursor / Claude Desktop 本地调试配置:

{
  "mcpServers": {
    "room-stu-fault": {
      "command": "uvx",
      "args": ["--from", ".", "room-stu-fault-mcp"],
      "env": {
        "ALIBABA_CLOUD_ACCESS_KEY_ID": "",
        "ALIBABA_CLOUD_ACCESS_KEY_SECRET": ""
      }
    }
  }
}

发布到 PyPI

包名必须全局唯一。发布前把 pyproject.toml 里的 name / version 改成你的。

pip install build twine
python -m build
python -m twine upload dist/*

或使用 uv:

uv build
uv publish --token pypi-xxxxxxxx

部署到阿里云百炼

  1. 控制台 → MCP 管理创建 MCP 服务使用脚本部署
  2. 安装方式选 uvx
  3. 配置粘贴如下(把包名换成你发布到 PyPI 的名字):
{
  "mcpServers": {
    "room-stu-fault": {
      "type": "stdio",
      "command": "uvx",
      "args": ["room-stu-fault-mcp"],
      "env": {
        "ALIBABA_CLOUD_ACCESS_KEY_ID": "你的 AccessKey ID",
        "ALIBABA_CLOUD_ACCESS_KEY_SECRET": "你的 AccessKey Secret",
        "ALIYUN_SLS_ENDPOINT": "cn-hangzhou.log.aliyuncs.com",
        "ALIYUN_SLS_PROJECT": "你的 SLS Project",
        "ALIYUN_SLS_LOGSTORE": "你的 Logstore",
        "NETWORK_API_URL": "https://your-server.example.com",
        "NETWORK_API_PATH": "/room/{serial}/user/figure",
        "NETWORK_API_TOKEN": "",
        "TICKET_API_URL": "https://your-server.example.com",
        "TICKET_API_PATH": "/api/tickets",
        "TICKET_API_TOKEN": ""
      }
    }
  }
}
  1. 部署成功后,在智能体 / 工作流里勾选该 MCP 即可调用三个工具。

环境变量

变量 用途
ALIBABA_CLOUD_ACCESS_KEY_ID 阿里云 AK
ALIBABA_CLOUD_ACCESS_KEY_SECRET 阿里云 SK
ALIYUN_SLS_ENDPOINT SLS 地域入口
ALIYUN_SLS_PROJECT SLS Project
ALIYUN_SLS_LOGSTORE SLS Logstore
NETWORK_API_URL 网络信息服务地址
NETWORK_API_PATH 网络信息接口路径,可用 {serial} / {room_unit_id} 占位
NETWORK_API_TOKEN 网络信息接口 Token(可选)
TICKET_API_URL 工单服务地址,如 https://testing.talk-cloud.net
TICKET_API_PATH 工单接口路径,如 /ClientAPI/workOrderListByAI
TICKET_API_TOKEN 工单接口 Token(可选)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

room_stu_fault_mcp-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

room_stu_fault_mcp-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file room_stu_fault_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: room_stu_fault_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for room_stu_fault_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ff89ff332f0b0d7c20f04f83d69e87bdc70923f353d1faf78af11e5eba44adc7
MD5 34954fd36d196ab3615bff29fcd23682
BLAKE2b-256 fdd11ffb79fd9609f7f1ef7df3e382cee20c5cae5193d80f50491e8dd0088ab5

See more details on using hashes here.

File details

Details for the file room_stu_fault_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for room_stu_fault_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ab4ae0db3049e3b067f96c01272189fb40a95a2e484e61c4ae10db73960cb20
MD5 d1a8aca29cf2280a9954000aeb7c57be
BLAKE2b-256 5b9a0e4123b486c1e70bcb36009d984f347a297efcad2cac0542f9db8b422789

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page