Skip to content

chore: MCP 도입할 때 필요한 npx 패키지 적용#367

Merged
wannabeing merged 2 commits intodevfrom
chore/npx-mcp
Aug 11, 2025
Merged

chore: MCP 도입할 때 필요한 npx 패키지 적용#367
wannabeing merged 2 commits intodevfrom
chore/npx-mcp

Conversation

@wannabeing
Copy link
Copy Markdown
Member

@wannabeing wannabeing commented Aug 11, 2025

🔎 작업 내용

  • Dockerfile 설정 변경
    • Node.js + npm 설치
    • @modelcontextprotocol/server-brave-search 전역 설치
  • application.properties 설정 변경
    • npx 대신 전역 설치된 server-brave-search 직접 호출
    • spring.ai.mcp.client.initialized=false 설정 추가
      • 부팅 시 외부 프로세스 미실행 (요청 시 연결)
      • MCP 서버가 실행 시 지연되면 타임아웃이 발생될 수 있음
        → 앱 기동 실패가 다시 발생될 수 있기 때문에

🛠️ 변경 사항

  • 도커 컨테이너 안에 npx가 없어서 실패
  • Dockerfile에 node/npm 설치 + @modelcontextprotocol/server-brave-search 전역 설치
  • application.properties에서 npx 대신 server-brave-search를 직접 실행
  • applicaiton.properteis에서 MCP 부팅과 연결을 분리
    • MCP 서버 실행이 지연되면 앱 전체에 영향이 갈 수 있기 때문
    • 부팅 시에는 연결하지 않고, 실제로 사용할 때 연결을 시도하게 변경

🧩 트러블 슈팅

2025-08-11 14:48:15.298
    Suppressed: java.lang.Exception: #block terminated with an error
    2025-08-11 14:48:15.298
2025-08-11T05:48:15.294Z ERROR 1 --- [cs25-service] [           main] o.s.boot.SpringApplication               : Application run failed
    2025-08-11 14:47:45.013
Caused by: java.io.IOException: error=2, No such file or directory
    2025-08-11 14:47:45.013
Caused by: java.io.IOException: Cannot run program "npx": error=2, No such file or directory
    2025-08-11 14:47:45.013
2025-08-11T05:47:44.983Z ERROR 1 --- [cs25-service] [oundedElastic-1] reactor.core.publisher.Operators         : Operator called default onErrorDropped

기존 application.properties

image

변경 application.properties

image

추가 Dockerfile

image

🙏 코드 리뷰 전 확인 체크리스트

  • 불필요한 콘솔 로그, 주석 제거
  • 커밋 메시지 컨벤션 준수 (type : )
  • 기능 정상 동작 확인

Summary by CodeRabbit

  • Refactor
    • Brave Search 연동 방식을 더 간소화하고 런타임에 표준화된 실행 도구를 포함시켜 호출 방식을 통일했습니다. 서비스 기동 시간이 단축되고 검색 응답의 일관성이 향상됩니다.
  • Chores
    • 런타임에 Node.js 기반 도구를 포함해 종속성 관리와 재현성을 개선했고 관련 설정을 초기화하는 기본값을 추가해 운영 안정성을 높였습니다.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 11, 2025

Walkthrough

Dockerfile에 Node.js 20.x와 전역 npm 패키지 @modelcontextprotocol/server-brave-search를 설치하고, application.properties에서 Brave STDIO 명령을 npx ...에서 server-brave-search로 변경하며 관련 args를 제거하고 초기화 플래그를 추가했습니다.

Changes

Cohort / File(s) Summary
런타임 이미지 설정 (MCP Brave Search)
cs25-service/Dockerfile
OpenJDK 17 런타임 단계에서 apt 업데이트 후 curl/ca-certificates/gnupg 설치, NodeSource로 Node.js 20.x 설치, nodejs 및 전역 npm 패키지 @modelcontextprotocol/server-brave-search 설치, node/npm 및 바이너리 경로 출력, apt 캐시 정리. JAR 복사 전에 실행.
Brave STDIO 명령 구성 변경
cs25-service/src/main/resources/application.properties
Brave STDIO 실행 명령을 npx @modelcontextprotocol/server-brave-search에서 server-brave-search로 변경; 기존 args (-y, 패키지 식별자) 제거; spring.ai.mcp.client.initialized=false 추가; BRAVE_API_KEY 환경변수 설정 유지.

Sequence Diagram(s)

sequenceDiagram
    participant Service as cs25-service
    participant STDIO as server-brave-search (MCP)
    participant Brave as Brave Search API

    Service->>STDIO: 실행: "server-brave-search" (STDIO 프로세스 시작)
    STDIO->>Brave: BRAVE_API_KEY로 검색 요청 전송
    Brave-->>STDIO: 검색 결과 반환
    STDIO-->>Service: STDIO를 통해 결과 스트림 전달
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • crocusia
  • jong-0126
  • Kimyoonbeom

Poem

나는 깡총 토끼, 도커에 발자국 남기네 🐇
Node가 반짝이고, 서버 브레이브가 춤추네 ✨
npx는 작별, 이제는 바로 실행해요 — server-brave-search!
자바와 함께 STDIO로 바다를 건너요.
깡총—검색 완료, 당근 파티 준비 완료! 🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8a7456 and 10c438a.

📒 Files selected for processing (1)
  • cs25-service/src/main/resources/application.properties (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cs25-service/src/main/resources/application.properties
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/npx-mcp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@wannabeing wannabeing linked an issue Aug 11, 2025 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b508652 and d8a7456.

📒 Files selected for processing (2)
  • cs25-service/Dockerfile (1 hunks)
  • cs25-service/src/main/resources/application.properties (1 hunks)
🔇 Additional comments (2)
cs25-service/src/main/resources/application.properties (1)

71-71: 검증 완료: 브레이브 CLI 전환 잔여 설정 없음

  • npx 호출 검색 결과 없음
  • spring.ai.mcp.client.stdio.connections.brave.args 설정 없음
  • Dockerfile에서 전역 설치(npm install -g @modelcontextprotocol/server-brave-search) 및 which server-brave-search 확인
  • application.properties에서 spring.ai.mcp.client.stdio.connections.brave.command=server-brave-search로 정상 설정

(선택) PATH 이슈 우려 시 절대 경로 지정 적용 가능:

-spring.ai.mcp.client.stdio.connections.brave.command=server-brave-search
+spring.ai.mcp.client.stdio.connections.brave.command=/usr/local/bin/server-brave-search
cs25-service/Dockerfile (1)

23-29: 환경 일관성 검증 요약

  • Dockerfile에서 npm install -g @modelcontextprotocol/server-brave-search
    which server-brave-search 로 글로벌 설치 및 PATH 노출이 확인되었습니다.
    (cs25-service/Dockerfile:27–28)

  • application.properties 에서
    spring.ai.mcp.client.stdio.connections.brave.command=server-brave-search
    spring.ai.mcp.client.stdio.connections.brave.env.BRAVE_API_KEY=${BRAVE_API_KEY}
    로 BRAVE_API_KEY를 환경변수로 참조하도록 설정되어 있습니다.
    (cs25-service/src/main/resources/application.properties:71–72)

  • 배포 매니페스트/시크릿에 실제로 BRAVE_API_KEY 환경변수가 주입되는지는 코드베이스만으로는 확인되지 않습니다.
    해당 부분은 쿠버네티스/도커 컴포즈 등 배포 설정에서 수동 검증이 필요합니다.

Comment on lines +23 to +29
# Node.js + npm 설치 후, MCP 서버 전역 설치
RUN apt-get update && apt-get install -y curl ca-certificates gnupg \
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g @modelcontextprotocol/server-brave-search \
&& node -v && npm -v && which server-brave-search \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

런타임에 Node+MCP CLI 설치는 목적에 부합합니다. 재현성(버전 고정)·이미지 슬림화 개선 제안

  • 버전 고정: 최신으로 깔리는 nodejs/npm/CLI는 재현성을 해칩니다. server-brave-search에 버전 핀 권장(@x.y.z 또는 ARG 사용).
  • 이미지 슬림화: apt에 --no-install-recommends, npm cache clean, 사용 후 gnupg purge로 공격면/용량 축소.
  • 디버그 출력(node -v 등)은 일시적 점검엔 유용하나, 불필요하면 제거 가능.

상단(ENTRYPOINT 이전) 어딘가에 다음 ARG를 추가:

ARG MCP_BRAVE_VERSION=0.1.x

변경 구간에 대한 제안 Diff:

-RUN apt-get update && apt-get install -y curl ca-certificates gnupg \
-  && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
-  && apt-get install -y nodejs \
-  && npm install -g @modelcontextprotocol/server-brave-search \
-  && node -v && npm -v && which server-brave-search \
-  && apt-get clean && rm -rf /var/lib/apt/lists/*
+RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates gnupg \
+  && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
+  && apt-get install -y --no-install-recommends nodejs \
+  && npm install -g @modelcontextprotocol/server-brave-search@${MCP_BRAVE_VERSION} \
+  && npm cache clean --force \
+  && node -v && npm -v && which server-brave-search \
+  && apt-get purge -y gnupg && apt-get autoremove -y --purge \
+  && apt-get clean && rm -rf /var/lib/apt/lists/*

필요 시 디버그 출력(node -v, npm -v, which …)은 빌드 안정화 후 제거 가능.

🤖 Prompt for AI Agents
In cs25-service/Dockerfile around lines 23 to 29, pin the MCP CLI version and
slim the image: add an ARG (e.g. MCP_BRAVE_VERSION) near the top and change the
npm install to use that ARG (install
@modelcontextprotocol/server-brave-search@${MCP_BRAVE_VERSION}); install apt
packages with --no-install-recommends, run npm cache clean --force after npm
install, and remove gnupg via apt-get purge -y gnupg (or rm -rf its data) before
cleaning apt lists; remove or comment out transient debug prints (node -v, npm
-v, which ...) unless needed for debugging.

@wannabeing wannabeing merged commit 3e1257c into dev Aug 11, 2025
2 checks passed
@wannabeing wannabeing deleted the chore/npx-mcp branch August 11, 2025 07:28
wannabeing added a commit that referenced this pull request Aug 11, 2025
* chore: MCP 도입할 때 필요한 npx 패키지 적용 (#367)

* chore: MCP 도입할 때 필요한 npx 패키지 적용

* chore: 부팅 시 외부 프로세스 미실행 (요청 시 연결)

* chore: 런타임베이스이미지를 Ubuntu 계열로 변경하여 apt-get 명령어가 동작할 수 있게 변경 (#369)

---------

Co-authored-by: Ksr-ccb <harang4282@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: baegjonghyeon <baek011226@naver.com>
Co-authored-by: Baek jonghyun <69610809+jong-0126@users.noreply.github.com>
Co-authored-by: crocusia <132359536+crocusia@users.noreply.github.com>
Co-authored-by: Kimyoonbeom <101162650+Kimyoonbeom@users.noreply.github.com>
Co-authored-by: HeeMang-Lee <hemsej018@naver.com>
Co-authored-by: Kimyoonbeom <kimybeom@naver.com>
Co-authored-by: crocusia <rainbowsubin0522@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[08.11]10차 배포 후 백엔드 모든 요청에 502에러 반환

4 participants