Skip to main content
Glama

Model Control Plane (MCP) Server

OpenAI, Git, 파일 시스템 및 Prometheus 통합을 갖춘 MCP 서버

이 저장소에는 OpenAI 서비스, Git 저장소 분석, 로컬 파일 시스템 작업 및 Prometheus 통합을 지원하는 MCP(모델 제어 평면) 서버 구현이 포함되어 있습니다.

프로젝트 구조

지엑스피1

요구 사항

  • 파이썬 3.8 이상
  • 패스트API
  • 유비콘
  • 오픈AI SDK
  • 깃파이썬
  • 요청
  • Docker 및 Docker Compose(Prometheus 기능용)

설치

  1. 이 저장소를 복제하세요
  2. 종속성을 설치합니다.
pip install -r requirements.txt

환경 변수

다음 환경 변수를 설정하세요.

Azure OpenAI의 경우:

export AZURE_OPENAI_ENDPOINT="your-azure-endpoint" export AZURE_OPENAI_API_KEY="your-azure-api-key" export AZURE_OPENAI_API_VERSION="2023-05-15" export AZURE_DEPLOYMENT_NAME="your-deployment-name"

표준 OpenAI의 경우:

export OPENAI_API_KEY="your-openai-api-key" # Optional: Specify which models to use export OPENAI_CHAT_MODEL="gpt-4o-mini" # Default if not specified export OPENAI_COMPLETION_MODEL="gpt-3.5-turbo-instruct" # Default if not specified

프로메테우스의 경우:

export PROMETHEUS_URL="http://localhost:9090" # Default if not specified

서버 실행

MCP 서버를 시작합니다.

python scripts/start_mcp_server.py

또는 더 많은 옵션을 원하시면:

python scripts/start_mcp_server.py --host 0.0.0.0 --port 8000 --debug

서버는 http://localhost:8000 에서 사용할 수 있습니다.

통합 테스트 도구

우리는 모든 테스트 기능에 사용자 친화적인 인터페이스를 제공하는 통합 테스트 스크립트를 제공합니다:

./mcp_run

이 대화형 스크립트는 다음을 제공합니다.

  • 파일 시스템 테스트
  • Git 통합 테스트
  • 메모리 분석 도구
  • 프로메테우스 테스트와 메모리 스트레스
  • MCP 서버 관리
  • 환경 설정

개별 테스트

개별 테스트를 직접 실행할 수도 있습니다.

OpenAI 통합을 테스트하세요.

python scripts/test_mcp_client.py

Git 통합을 테스트합니다(Git 저장소 URL을 제공하세요):

python scripts/test_git_integration.py https://github.com/username/repository

Git diff 기능 테스트(요구 사항 호환성 분석):

python scripts/test_git_diff.py https://github.com/username/repository [commit-sha]

파일 시스템 기능을 테스트하세요.

python scripts/test_filesystem.py

MCP와 langflow 통합을 테스트하세요.

python scripts/test_langflow_integration.py [OPTIONAL_REPO_URL]

Prometheus 통합을 테스트하세요.

python scripts/test_prometheus.py [prometheus_url]

고급 Git 분석

AI 추천을 통한 더욱 고급 Git 저장소 분석의 경우:

python scripts/langflow_git_analyzer.py https://github.com/username/repository

저장소에서 특정 패턴을 검색할 수도 있습니다.

python scripts/langflow_git_analyzer.py https://github.com/username/repository --search "def main"

또는 AI 통찰력을 사용하여 마지막 커밋 차이점을 분석합니다.

python scripts/langflow_git_analyzer.py https://github.com/username/repository --diff

메모리 분석 도구

MCP에는 메모리 모니터링 및 분석을 위한 여러 도구가 포함되어 있습니다.

# Basic memory diagnostics with AI analysis python scripts/ai_memory_diagnostics.py # Interactive memory dashboard python scripts/mcp_memory_dashboard.py # Memory alerting system python scripts/mcp_memory_alerting.py

테스트를 위해 메모리 압력을 시뮬레이션할 수도 있습니다.

python scripts/simulate_memory_pressure.py --target 85 --duration 300

프로메테우스 통합

설정

  1. Docker Compose를 사용하여 Prometheus 스택을 시작합니다.
docker compose up -d

이렇게 시작됩니다:

  • Prometheus 서버( http://localhost:9090 에서 접근 가능)
  • 노드 내보내기(호스트 메트릭용)
  • cAdvisor(컨테이너 메트릭용)
  1. 스트레스 테스트를 위해 메모리 스트레스 컨테이너를 시작할 수 있습니다.
docker compose up -d --build memory-stress

또는 컨테이너 테스트 스크립트를 사용하세요.

./scripts/container-memory-test.sh start

Docker 구성 및 재설정 스크립트

이 프로젝트에는 다양한 환경에서 안정적으로 작동할 수 있는 여러 Docker 구성과 재설정 스크립트가 포함되어 있습니다.

Docker 구성
  • 표준 구성 ( docker-compose.yml ): Prometheus와 Langflow에 대한 사용자 정의 Dockerfiles를 사용하여 시스템 전체에서 일관된 권한을 보장합니다.
  • 브리지 네트워크 구성 ( docker-compose.bridge.yml ): 호스트 네트워킹에 문제가 있는 환경에서 브리지 네트워킹을 사용하는 대체 구성입니다.
권한 문제 해결을 위한 사용자 정의 Dockerfile

이 프로젝트는 Prometheus와 Langflow 모두에 대한 사용자 정의 Dockerfiles를 사용하여 일반적인 권한 문제를 해결합니다.

  • Dockerfile.prometheus : nobody 사용자에게 적절한 권한을 부여하여 Prometheus 구성을 설정합니다.
  • Dockerfile.langflow : 파일 소유권을 변경하지 않고 구성 요소 디렉토리를 컨테이너에 복사하여 Langflow가 권한 오류 없이 구성 요소에 액세스할 수 있도록 합니다.

이 접근 방식을 사용하면 서로 다른 컴퓨터와 사용자 구성에서 권한 충돌이 발생할 수 있는 볼륨 마운트가 필요 없게 됩니다.

스크립트 재설정
  • 모든 서비스 재설정 ( reset-all.sh ): 단일 명령으로 모든 컨테이너를 재설정합니다.
    # Basic reset (rebuilds containers with existing volumes) ./reset-all.sh # Full reset (removes volumes and rebuilds containers) ./reset-all.sh --clean
  • 개별 서비스 재설정 :
    # Reset only Prometheus ./reset-prometheus.sh # Reset only Langflow ./reset-langflow.sh

이러한 스크립트는 컨테이너가 올바른 권한과 최신 코드 변경 사항을 사용하여 제대로 구성되었는지 확인합니다.

문제 해결

권한 문제가 발생하는 경우:

  1. 재설정 스크립트를 사용하여 컨테이너를 다시 빌드합니다.
  2. docker compose logs <service_name> 으로 로그를 확인하세요.
  3. Langflow에 추가된 모든 구성 요소가 Dockerfile.langflow에 포함되어 있는지 확인하세요.
크로스 머신 배포

새 컴퓨터에 배포할 때:

  1. 저장소를 복제합니다
  2. 재설정 스크립트를 실행 가능하게 만들기: chmod +x *.sh
  3. 재설정 스크립트를 실행합니다: ./reset-all.sh

사용자 정의 Dockerfile은 다양한 시스템에서 발생할 수 있는 모든 권한 문제를 자동으로 처리합니다.

Prometheus 클라이언트 사용

MCPAIComponent 클래스에는 Prometheus 기능이 포함되어 있습니다.

from langflow import MCPAIComponent # Initialize the client mcp = MCPAIComponent(mcp_server_url="http://localhost:8000") # Instant query (current metric values) result = mcp.prometheus_query("up") # Range query (metrics over time) result = mcp.prometheus_query_range( query="rate(node_cpu_seconds_total{mode='system'}[1m])", start="2023-03-01T00:00:00Z", end="2023-03-01T01:00:00Z", step="15s" ) # Get all labels labels = mcp.prometheus_get_labels() # Get label values values = mcp.prometheus_get_label_values("job") # Get targets targets = mcp.prometheus_get_targets() # Get alerts alerts = mcp.prometheus_get_alerts()

유용한 PromQL 쿼리

  • CPU 사용량: rate(node_cpu_seconds_total{mode!="idle"}[1m])
  • 메모리 사용량: node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes
  • 디스크 사용량: node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}
  • 컨테이너 CPU 사용량: rate(container_cpu_usage_seconds_total[1m])
  • 컨테이너 메모리 사용량: container_memory_usage_bytes

API 엔드포인트

OpenAI 엔드포인트

  • GET /v1/models - 사용 가능한 모든 모델 나열
  • GET /v1/models/{model_id} - 특정 모델에 대한 정보 가져오기
  • POST /v1/models/azure-gpt-4/completion - Azure OpenAI를 사용하여 텍스트 완성 생성
  • POST /v1/models/azure-gpt-4/chat - Azure OpenAI를 사용하여 채팅 응답 생성
  • POST /v1/models/openai-gpt-chat/chat - OpenAI 채팅 모델을 사용하여 채팅 응답 생성
  • POST /v1/models/openai-gpt-completion/completion - OpenAI 완성 모델을 사용하여 텍스트 완성 생성

Git 통합 엔드포인트

  • POST /v1/models/git-analyzer/analyze - Git 저장소 분석
  • POST /v1/models/git-analyzer/search - 패턴과 일치하는 파일을 Git 저장소에서 검색합니다.
  • POST /v1/models/git-analyzer/diff - 저장소의 마지막 커밋의 diff를 가져옵니다.

파일 시스템 엔드포인트

  • POST /v1/models/filesystem/list - 디렉토리 내용 나열
  • POST /v1/models/filesystem/read - 파일 내용 읽기
  • POST /v1/models/filesystem/read-multiple - 여러 파일을 한 번에 읽기
  • POST /v1/models/filesystem/write - 파일에 콘텐츠 쓰기
  • POST /v1/models/filesystem/edit - 여러 개의 대체 항목이 있는 파일 편집
  • POST /v1/models/filesystem/mkdir - 디렉토리 생성
  • POST /v1/models/filesystem/move - 파일 또는 디렉토리 이동
  • POST /v1/models/filesystem/search - 패턴과 일치하는 파일 검색
  • POST /v1/models/filesystem/info - 파일이나 디렉토리에 대한 정보 가져오기

프로메테우스 엔드포인트

  • POST /v1/models/prometheus/query - 즉석 쿼리 실행
  • POST /v1/models/prometheus/query_range - 범위 쿼리 실행
  • POST /v1/models/prometheus/series - 시리즈 데이터 가져오기
  • GET /v1/models/prometheus/labels - 사용 가능한 모든 레이블 가져오기
  • POST /v1/models/prometheus/label_values - 특정 레이블에 대한 값 가져오기
  • GET /v1/models/prometheus/targets - 모든 대상 가져오기
  • GET /v1/models/prometheus/rules - 모든 규칙 가져오기
  • GET /v1/models/prometheus/alerts - 모든 알림 받기

클라이언트 사용

MCP 서버 URL을 제공하여 LangFlow 파이프라인에서 MCPAIComponent 사용할 수 있습니다.

from langflow import MCPAIComponent mcp = MCPAIComponent(mcp_server_url="http://localhost:8000") # List available models models = mcp.list_models() print(models) # Generate chat completion with OpenAI model chat_response = mcp.chat( model_id="openai-gpt-chat", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Tell me a joke about programming."} ], max_tokens=100, temperature=0.7 ) print(chat_response) # Generate text completion with OpenAI model completion_response = mcp.completion( model_id="openai-gpt-completion", prompt="Write a function in Python to calculate the factorial of a number:", max_tokens=150, temperature=0.7 ) print(completion_response) # Analyze a Git repository repo_analysis = mcp.analyze_git_repo("https://github.com/username/repository") print(repo_analysis) # Search a Git repository search_results = mcp.search_git_repo("https://github.com/username/repository", "def main") print(search_results) # Get the diff of the last commit diff_info = mcp.get_git_diff("https://github.com/username/repository") print(diff_info) # List files in the current directory dir_contents = mcp.list_directory() print(dir_contents) # Read a file file_content = mcp.read_file("path/to/file.txt") print(file_content) # Write to a file write_result = mcp.write_file("path/to/new_file.txt", "Hello, world!") print(write_result) # Search for files search_result = mcp.search_files("*.py") print(search_result)

GitCodeAnalyzer 클래스 사용

더욱 체계적인 Git 분석을 위해 GitCodeAnalyzer 클래스를 사용할 수 있습니다.

from langflow_git_analyzer import GitCodeAnalyzer # Initialize the analyzer analyzer = GitCodeAnalyzer(mcp_server_url="http://localhost:8000") # Analyze a repository analyzer.analyze_repository("https://github.com/username/repository") # Get a summary summary = analyzer.get_repository_summary() print(summary) # Get AI recommendations recommendations = analyzer.get_repository_recommendations() print(recommendations) # Analyze code patterns pattern_analysis = analyzer.analyze_code_pattern("def process") print(pattern_analysis) # Get the last commit diff diff_info = analyzer.get_last_commit_diff() print(diff_info) # Get a formatted summary of the diff diff_summary = analyzer.get_formatted_diff_summary() print(diff_summary) # Get AI analysis of the commit changes diff_analysis = analyzer.analyze_commit_diff() print(diff_analysis)

문제 해결

프로메테우스 문제

  1. Prometheus가 실행 중인지 확인하세요: docker ps | grep prometheus
  2. Prometheus UI에 액세스할 수 있는지 확인하세요: http://localhost:9090
  3. MCP 서버가 실행 중이고 액세스 가능한지 확인하세요.
  4. MCP 서버 로그에서 오류를 확인하세요.
  5. 연결성을 확인하려면 먼저 간단한 쿼리를 시도하세요(예: up 쿼리).

OpenAI 문제

  1. API 키가 올바르게 설정되었는지 확인하세요
  2. 속도 제한 또는 할당량 문제를 확인하세요
  3. API 키에 지원되는 모델을 사용하고 있는지 확인하세요.

Git 문제

  1. Git 저장소 URL에 액세스할 수 있는지 확인하세요.
  2. 개인 저장소를 사용하는 경우 인증 문제가 있는지 확인하세요.
  3. GitPython이 올바르게 설치되었는지 확인하세요
-
security - not tested
A
license - permissive license
-
quality - not tested

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

REST API 엔드포인트를 통해 OpenAI 서비스, Git 저장소 분석 및 로컬 파일 시스템 작업을 위한 통합 인터페이스를 제공하는 서버 구현입니다.

  1. 프로젝트 구조
    1. 요구 사항
      1. 설치
        1. 환경 변수
          1. 서버 실행
            1. 통합 테스트 도구
              1. 개별 테스트
                1. 고급 Git 분석
                  1. 메모리 분석 도구
                    1. 프로메테우스 통합
                      1. 설정
                      2. Docker 구성 및 재설정 스크립트
                      3. Prometheus 클라이언트 사용
                      4. 유용한 PromQL 쿼리
                    2. API 엔드포인트
                      1. OpenAI 엔드포인트
                      2. Git 통합 엔드포인트
                      3. 파일 시스템 엔드포인트
                      4. 프로메테우스 엔드포인트
                    3. 클라이언트 사용
                      1. GitCodeAnalyzer 클래스 사용
                        1. 문제 해결
                          1. 프로메테우스 문제
                          2. OpenAI 문제
                          3. Git 문제

                        Related MCP Servers

                        • -
                          security
                          A
                          license
                          -
                          quality
                          A Model Context Protocol (MCP) server that lets you seamlessly use OpenAI's models right from Claude.
                          Last updated -
                          1
                          24
                          28
                          JavaScript
                          MIT License
                          • Apple
                        • -
                          security
                          A
                          license
                          -
                          quality
                          An MCP server that exposes HTTP methods defined in an OpenAPI specification as tools, enabling interaction with APIs via the Model Context Protocol.
                          Last updated -
                          2
                          Python
                          MIT License
                        • -
                          security
                          A
                          license
                          -
                          quality
                          A modular server that implements the Model Context Protocol standard, providing tools for interacting with GitHub, GitLab, Google Maps, Memory storage, and web automation through a unified gateway.
                          Last updated -
                          932
                          3
                          Python
                          Apache 2.0
                          • Linux
                          • Apple
                        • -
                          security
                          F
                          license
                          -
                          quality
                          A Model Context Protocol server implementation that enables connection between OpenAI APIs and MCP clients for coding assistance with features like CLI interaction, web API integration, and tool-based architecture.
                          Last updated -
                          28
                          Python
                          • Linux
                          • Apple

                        View all related MCP servers

                        MCP directory API

                        We provide all the information about MCP servers via our MCP API.

                        curl -X GET 'https://glama.ai/api/mcp/v1/servers/dvladimirov/MCP'

                        If you have feedback or need assistance with the MCP directory API, please join our Discord server