This project demonstrates a web application that uses content safety checking before passing user prompts to a calculator service via Model Context Protocol (MCP).
1. User Input: The user enters a calculation prompt in the web interface
2. Content Safety Screening (Input): The prompt is analyzed by Azure Content Safety API
3. Safety Decision (Input):
- If the content is safe (severity < 2 in all categories), it proceeds to the calculator
- If the content is flagged as potentially harmful, the process stops and returns a warning
4. Calculator Integration: Safe content is processed by LangChain4j, which communicates with the MCP calculator server
5. Content Safety Screening (Output): The bot's response is analyzed by Azure Content Safety API
6. Safety Decision (Output):
- If the bot response is safe, it's shown to the user
- If the bot response is flagged as potentially harmful, it's replaced with a warning
7. Response: Results (if safe) are displayed to the user along with both safety analyses
This project demonstrates how to use Model Context Protocol (MCP) to call calculator MCP services from LangChain4j. The implementation uses a local MCP server running on port 8080 to provide calculator operations.
Before using the content safety features, you need to create an Azure Content Safety service resource:
1. Sign in to the Azure Portal
2. Click "Create a resource" and search for "Content Safety"
3. Select "Content Safety" and click "Create"
4. Enter a unique name for your resource
5. Select your subscription and resource group (or create a new one)
6. Choose a supported region (check Region availability for details)
7. Select an appropriate pricing tier
8. Click "Create" to deploy the resource
9. Once deployment is complete, click "Go to resource"
10. In the left pane, under "Resource Management", select "Keys and Endpoint"
11. Copy either of the keys and the endpoint URL for use in the next step
Set the GITHUB_TOKEN environment variable for GitHub models authentication:
export GITHUB_TOKEN=<your_github_token>
For content safety features, set:
export CONTENT_SAFETY_ENDPOINT=<your_content_safety_endpoint>
export CONTENT_SAFETY_KEY=<your_content_safety_key>
These environment variables are used by the application to authenticate with the Azure Content Safety service.
If these variables are not set, the application will use placeholder values for demonstration purposes, but the content safety features will not work properly.
Before running the client, you need to start the calculator MCP server in SSE mode on localhost:8080.
This project demonstrates the integration of Model Context Protocol (MCP) with LangChain4j to call calculator services. Key features include:
The project includes comprehensive content safety features to ensure that both user inputs and system responses are free from harmful content:
1. Input Screening: All user prompts are analyzed for harmful content categories such as hate speech, violence, self-harm, and sexual content before processing.
2. Output Screening: Even when using potentially uncensored models, the system checks all generated responses through the same content safety filters before displaying them to the user.
This dual-layer approach ensures that the system remains safe regardless of which AI model is being used, protecting users from both harmful inputs and potentially problematic AI-generated outputs.
The application includes a user-friendly web interface that allows users to interact with the Content Safety Calculator system:
1. Start the application:
```sh
mvn spring-boot:run
```
2. Open your browser and navigate to http://localhost:8087
3. Enter a calculation prompt in the provided text area (e.g., "Calculate the sum of 24.5 and 17.3")
4. Click "Submit" to process your request
5. View the results, which will include:
- Content safety analysis of your prompt
- The calculated result (if prompt was safe)
- Content safety analysis of the bot's response
- Any safety warnings if either the input or output was flagged
The web client automatically handles both content safety verification processes, ensuring all interactions are safe and appropriate regardless of which AI model is being used.
이 프로젝트는 사용자 프롬프트를 계산기 서비스에 전달하기 전에 콘텐츠 안전성 검사를 수행하는 웹 애플리케이션을 Model Context Protocol (MCP)을 통해 구현한 예시입니다.
1. 사용자 입력: 사용자가 웹 인터페이스에 계산 프롬프트를 입력합니다.
2. 콘텐츠 안전성 검사 (입력): 프롬프트는 Azure Content Safety API로 분석됩니다.
3. 안전성 판단 (입력):
- 모든 카테고리에서 심각도(severity)가 2 미만인 경우 안전하다고 판단되어 계산기로 전달됩니다.
- 잠재적으로 유해한 콘텐츠로 표시되면 프로세스가 중단되고 경고가 반환됩니다.
4. 계산기 연동: 안전한 콘텐츠는 LangChain4j를 통해 MCP 계산기 서버와 통신하여 처리됩니다.
5. 콘텐츠 안전성 검사 (출력): 봇의 응답은 Azure Content Safety API로 분석됩니다.
6. 안전성 판단 (출력):
- 봇 응답이 안전하면 사용자에게 표시됩니다.
- 잠재적으로 유해한 응답으로 표시되면 경고 메시지로 대체됩니다.
7. 응답: 결과(안전한 경우)는 사용자에게 두 번의 안전성 분석 결과와 함께 표시됩니다.
이 프로젝트는 LangChain4j에서 Model Context Protocol (MCP)을 사용해 계산기 MCP 서비스를 호출하는 방법을 보여줍니다. 구현은 포트 8080에서 실행되는 로컬 MCP 서버를 통해 계산기 연산을 제공합니다.
콘텐츠 안전성 기능을 사용하기 전에 Azure Content Safety 서비스 리소스를 생성해야 합니다:
1. Azure Portal에 로그인합니다.
2. "리소스 만들기"를 클릭하고 "Content Safety"를 검색합니다.
3. "Content Safety"를 선택하고 "만들기"를 클릭합니다.
4. 리소스에 고유한 이름을 입력합니다.
5. 구독과 리소스 그룹을 선택하거나 새로 만듭니다.
6. 지원되는 지역을 선택합니다 (지역 가용성 참고).
7. 적절한 가격 책정 계층을 선택합니다.
8. "만들기"를 클릭하여 리소스를 배포합니다.
9. 배포가 완료되면 "리소스로 이동"을 클릭합니다.
10. 왼쪽 메뉴에서 "리소스 관리" 아래의 "키 및 엔드포인트"를 선택합니다.
11. 다음 단계에서 사용할 키 중 하나와 엔드포인트 URL을 복사합니다.
GitHub 모델 인증을 위해 GITHUB_TOKEN 환경 변수를 설정하세요:
export GITHUB_TOKEN=<your_github_token>
콘텐츠 안전성 기능을 위해 다음을 설정하세요:
export CONTENT_SAFETY_ENDPOINT=<your_content_safety_endpoint>
export CONTENT_SAFETY_KEY=<your_content_safety_key>
이 환경 변수들은 애플리케이션이 Azure Content Safety 서비스에 인증하는 데 사용됩니다. 설정하지 않으면 데모용 자리 표시자 값이 사용되지만 콘텐츠 안전성 기능은 제대로 작동하지 않습니다.
클라이언트를 실행하기 전에 localhost:8080에서 SSE 모드로 계산기 MCP 서버를 시작해야 합니다.
이 프로젝트는 LangChain4j와 Model Context Protocol (MCP)을 통합하여 계산기 서비스를 호출하는 방법을 보여줍니다. 주요 기능은 다음과 같습니다:
이 프로젝트는 사용자 입력과 시스템 응답 모두에서 유해한 콘텐츠가 없도록 포괄적인 콘텐츠 안전성 기능을 포함합니다:
1. 입력 검사: 모든 사용자 프롬프트는 증오 발언, 폭력, 자해, 성적 콘텐츠 등 유해 콘텐츠 카테고리에 대해 처리 전에 분석됩니다.
2. 출력 검사: 잠재적으로 검열되지 않은 모델을 사용하더라도, 생성된 모든 응답은 사용자에게 표시되기 전에 동일한 콘텐츠 안전성 필터를 거칩니다.
이중 검사 방식을 통해 어떤 AI 모델을 사용하더라도 시스템이 안전하게 유지되며, 사용자와 AI 생성 출력 모두를 유해한 콘텐츠로부터 보호합니다.
애플리케이션은 사용자가 Content Safety Calculator 시스템과 상호작용할 수 있는 직관적인 웹 인터페이스를 제공합니다:
1. 애플리케이션을 시작합니다:
```sh
mvn spring-boot:run
```
2. 브라우저를 열고 http://localhost:8087로 접속합니다.
3. 제공된 텍스트 영역에 계산 프롬프트를 입력합니다 (예: "24.5와 17.3의 합을 계산해 주세요").
4. "Submit" 버튼을 클릭하여 요청을 처리합니다.
5. 결과를 확인합니다. 결과에는 다음이 포함됩니다:
- 프롬프트에 대한 콘텐츠 안전성 분석
- 계산된 결과 (프롬프트가 안전한 경우)
- 봇 응답에 대한 콘텐츠 안전성 분석
- 입력 또는 출력이 플래그된 경우 안전성 경고
웹 클라이언트는 두 단계의 콘텐츠 안전성 검증을 자동으로 처리하여, 어떤 AI 모델을 사용하더라도 모든 상호작용이 안전하고 적절하게 이루어지도록 보장합니다.
면책 조항:
이 문서는 AI 번역 서비스 Co-op Translator를 사용하여 번역되었습니다.
정확성을 위해 최선을 다하고 있으나, 자동 번역에는 오류나 부정확한 부분이 있을 수 있음을 유의해 주시기 바랍니다.
원문은 해당 언어의 원본 문서가 권위 있는 출처로 간주되어야 합니다.
중요한 정보의 경우 전문적인 인간 번역을 권장합니다.
본 번역의 사용으로 인해 발생하는 오해나 잘못된 해석에 대해 당사는 책임을 지지 않습니다.