feat(serve): stdio 외 직접 Streamable HTTP MCP transport 추가 (+선택적 bearer)#11
Closed
epruseal wants to merge 3 commits into
Closed
feat(serve): stdio 외 직접 Streamable HTTP MCP transport 추가 (+선택적 bearer)#11epruseal wants to merge 3 commits into
epruseal wants to merge 3 commits into
Conversation
Extract MCPServer.handle_request(dict) from _handle_raw so the stdio loop and an HTTP transport can share one JSON-RPC dispatch source. Echo the client's requested protocolVersion in initialize (honours both 2024-11-05 stdio and 2025-03-26 Streamable HTTP handshakes).
…r auth - New opencrab/mcp/http_app.py: shared FastAPI mcp_router (POST /mcp dispatch via MCPServer.handle_request, GET 405, DELETE 200) + lightweight create_app. Optional Bearer auth (HMAC compare); token from --auth-token/--auth-token-file or OPENCRAB_MCP_TOKEN(_FILE). Stateless, single worker. - opencrab serve gains --transport [stdio|http], --host, --port, --auth-token, --auth-token-file. stdio stays the default. No new deps (fastapi/uvicorn are already required). - config: MCP_HTTP_HOST (127.0.0.1) / MCP_HTTP_PORT (8765).
README HTTP-transport section, MCP_HTTP_HOST/PORT in .env.example, serve-http Makefile target.
Owner
Author
|
검토용 PR. upstream PR(AlexAI-MCP#8)로 대체되어 닫습니다. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
동기
opencrab serve는 현재 stdio MCP만 제공합니다. 원격/HTTP로 붙이려면supergateway같은 외부 stdio→HTTP 브리지가 필요했습니다. 이 PR은 serve가 직접 Streamable HTTP(2025-03-26) MCP transport를 제공하게 해서 외부 브리지를 불필요하게 만듭니다. stdio는 기본값으로 그대로 유지됩니다(하위호환).변경
opencrab/mcp/server.py—_handle_raw에서handle_request(dict)를 추출해 stdio·HTTP가 JSON-RPC 디스패치를 단일 출처로 공유.initialize가 클라이언트의protocolVersion을 에코(2024-11-05 stdio / 2025-03-26 HTTP 핸드셰이크 모두 수용).opencrab/mcp/http_app.py(신규) — 공유 FastAPImcp_router(POST/mcp→handle_request위임, GET 405, DELETE 200, notification→202, 배치 지원) + 경량create_app. 선택적 Bearer 인증(HMAC compare): 토큰이--auth-token/--auth-token-file또는OPENCRAB_MCP_TOKEN(_FILE)로 주어질 때만 활성, 미설정 시 무인증.opencrab/cli.py—serve --transport [stdio|http] --host --port --auth-token --auth-token-file. http는uvicorn단일 워커(chroma PersistentClient 단일 프로세스 제약).opencrab/config.py—MCP_HTTP_HOST(127.0.0.1) /MCP_HTTP_PORT(8765). 토큰은 config에 저장 안 함..env.example,Makefile serve-http.stateless 설계: 각 POST가 독립 요청/응답(Mcp-Session-Id·서버 푸시 SSE 없음). 모든 툴이 요청-응답형이라 충분. 새 의존성 0(fastapi/uvicorn 이미 필수).
범위 밖 (의도적)
apps/api/main.py의 멀티테넌트·인증 인지/mcp는 건드리지 않음(별도 표면).검증
python -m build성공, wheel/sdist에http_app.py포함, 클린 venv 설치 OK.pytest→ 131 passed, 3 skipped (handle_request 추출이 stdio 동작 보존).tools/list정상./healthz→200(면제). 파일·OPENCRAB_MCP_TOKENenv 양쪽 확인.