diff --git a/Makefile b/Makefile index 180f72d..cb20eec 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,11 @@ endif STAMP := .venv/.installed +HOST ?= 0.0.0.0 +PORT ?= 8000 + .DEFAULT_GOAL := help -.PHONY: help up setup install check-env migrate run test check-lk clean +.PHONY: help up setup install check-env migrate run run-http test check-lk clean help: @$(SYS_PYTHON) -X utf8 -c "import re, sys; [print(' make {:<10} {}'.format(*m.groups())) for m in re.finditer(r'^([a-z-]+):.*?## (.*)', open(sys.argv[1], encoding='utf-8').read(), re.M)]" $(firstword $(MAKEFILE_LIST)) @@ -45,6 +48,9 @@ run: check-env ## запустить MCP-сервер (stdio) @echo mospolytech-mcp is running on stdio, Ctrl+C to stop 1>&2 @$(PY) -m mospolytech_mcp.server +run-http: check-env ## сервер по HTTP, http://HOST:PORT/mcp + $(PY) -m mospolytech_mcp.server --http --host $(HOST) --port $(PORT) + test: install ## офлайн-тесты $(PY) -m pytest -q diff --git a/README.md b/README.md index ed29ab1..f7f6c80 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,23 @@ MPU_LOGIN и MPU_PASSWORD в свой `.env`, дальше `scripts/check_lk_api (например, Claude Desktop/Code). Пока один инструмент, `list_groups` (ФОД-001) — список групп с кэшем в БД на 15 минут. +### HTTP-режим + +Если сервер крутится в VM или на другой машине, stdio не подходит — +есть HTTP-режим (streamable HTTP, эндпоинт `/mcp`): + +```bash +make run-http # 0.0.0.0:8000 +make run-http PORT=9000 # HOST и PORT можно переопределить +``` + +Без make: `python -m mospolytech_mcp.server --http --host 0.0.0.0 --port 8000`. + +В Postman: New → MCP, транспорт HTTP, URL `http://<адрес VM>:8000/mcp`, +Connect — в списке инструментов появится `list_groups`, его можно вызвать +прямо оттуда. Авторизации на сервере нет, так что наружу (`0.0.0.0`) +открывать только на тестовой машине. + ## Структура репозитория ``` diff --git a/src/mospolytech_mcp/server.py b/src/mospolytech_mcp/server.py index eccce53..5c8585f 100644 --- a/src/mospolytech_mcp/server.py +++ b/src/mospolytech_mcp/server.py @@ -2,6 +2,7 @@ from __future__ import annotations +import argparse import asyncio import sys from pathlib import Path @@ -32,7 +33,16 @@ async def list_groups() -> list[str]: def main() -> None: - mcp.run(transport="stdio") + parser = argparse.ArgumentParser(prog="mospolytech-mcp") + parser.add_argument("--http", action="store_true", help="HTTP вместо stdio") + parser.add_argument("--host", default="127.0.0.1") + parser.add_argument("--port", type=int, default=8000) + args = parser.parse_args() + + if args.http: + mcp.run(transport="streamable-http", host=args.host, port=args.port) + else: + mcp.run(transport="stdio") if __name__ == "__main__":