From 02e0c25847c5b034acf3d6e018a2aa99cabb96ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=B8=D0=BB=20=D0=93=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0=D1=80=D1=8C?= Date: Wed, 27 May 2026 17:13:42 +0300 Subject: [PATCH] Append fastMCP model --- README.md | 6 ++++++ rosdep.yaml | 6 ++++++ src/iiwa_config/config/api_endpoints.yaml | 2 +- src/iiwa_web/iiwa_web/main.py | 15 +++++++++++++-- src/iiwa_web/setup.py | 1 + 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4dab777..40775a2 100644 --- a/README.md +++ b/README.md @@ -291,3 +291,9 @@ docker run -it --rm --network host evilfisru/lwa:jazzy-lwa7-noble # dev - src остаётся для отладки `docker build --build-arg BUILD_TYPE=dev -t my-image .` ``` + +``` +# URL для доступа к MCP LLM +http://localhost:8007/mcp/mcp + +``` \ No newline at end of file diff --git a/rosdep.yaml b/rosdep.yaml index dc5ed4f..9d985f2 100644 --- a/rosdep.yaml +++ b/rosdep.yaml @@ -12,3 +12,9 @@ python3-multipart: ubuntu: pip: packages: [python-multipart] + +python3-fastmcp: + ubuntu: + pip: + packages: [fastmcp] + diff --git a/src/iiwa_config/config/api_endpoints.yaml b/src/iiwa_config/config/api_endpoints.yaml index 80265b0..cfa4948 100644 --- a/src/iiwa_config/config/api_endpoints.yaml +++ b/src/iiwa_config/config/api_endpoints.yaml @@ -30,7 +30,7 @@ endpoints: msg_type: std_srvs/srv/Trigger summary: "Немедленно остановить движение" description: "Вызывает сервис экстренной остановки — движение прерывается немедленно." - tags: [robot] + tags: [motion] response_fields: [success, message] timeout: 5.0 enabled: true diff --git a/src/iiwa_web/iiwa_web/main.py b/src/iiwa_web/iiwa_web/main.py index 758ead2..158dfa3 100644 --- a/src/iiwa_web/iiwa_web/main.py +++ b/src/iiwa_web/iiwa_web/main.py @@ -4,6 +4,7 @@ from contextlib import asynccontextmanager import rclpy import uvicorn from fastapi import FastAPI +from fastmcp import FastMCP from sensor_msgs.msg import JointState from .dynamic_router import build_dynamic_router @@ -22,15 +23,25 @@ def main(): endpoints_path = node.get_parameter('endpoints_path').value or None joint_limits_path = node.get_parameter('joint_limits_path').value or None + _schema_app = FastAPI() + _schema_app.include_router(build_dynamic_router(endpoints_path, joint_limits_path)) + _schema_app.include_router(runner.router) + _schema_app.include_router(trajectory.router) + + mcp = FastMCP.from_fastapi(app=_schema_app) + mcp_http = mcp.http_app(path='/mcp') + @asynccontextmanager async def lifespan(_: FastAPI): - get_bridge().subscribe("/joint_states", JointState) - yield + async with mcp_http.router.lifespan_context(_): + get_bridge().subscribe("/joint_states", JointState) + yield app = FastAPI(lifespan=lifespan) app.include_router(build_dynamic_router(endpoints_path, joint_limits_path)) app.include_router(runner.router) app.include_router(trajectory.router) + app.mount("/mcp", mcp_http) uvicorn.run(app, host=host, port=port) diff --git a/src/iiwa_web/setup.py b/src/iiwa_web/setup.py index 6377dd5..b288152 100644 --- a/src/iiwa_web/setup.py +++ b/src/iiwa_web/setup.py @@ -16,6 +16,7 @@ setup( 'fastapi', 'uvicorn[standard]', 'python-multipart', + 'fastmcp', ], zip_safe=True, maintainer='daniel',