-
Notifications
You must be signed in to change notification settings - Fork 71
feat(mcp): implements the mcp client #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kasanatte
wants to merge
1
commit into
karmada-io:main
Choose a base branch
from
kasanatte:feature/mcp-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright 2024 The Karmada Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Stage 1: Builder | ||
# Use the Go version specified in go.mod (1.24) | ||
FROM golang:1.24-alpine AS builder | ||
|
||
# Install make, git and bash | ||
# git is used to clone the repository, make is used to execute build commands, and bash is used to execute the build.sh script | ||
RUN apk add --no-cache make git bash | ||
|
||
# Set the working directory | ||
WORKDIR /src | ||
|
||
# Clone the specified git repository | ||
RUN git clone https://github.com/warjiang/karmada-mcp-server.git . | ||
|
||
# Set the target operating system and architecture for multi-platform builds | ||
# These parameters are provided by the `docker buildx build` command at build time | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
|
||
# Use the Makefile to build the binary, passing in the platform parameters | ||
# This will call the project's own hack/build.sh script | ||
RUN make build GOOS=${TARGETOS} GOARCH=${TARGETARCH} | ||
|
||
# Move the compiled binary to the /src directory for easy copying in the next stage | ||
RUN cp /src/_output/bin/${TARGETOS}/${TARGETARCH}/karmada-mcp-server /src/karmada-mcp-server | ||
|
||
# Stage 2: Final Image | ||
# Use the scratch image as the final base image | ||
FROM scratch | ||
|
||
# Copy the compiled binary from the builder stage to the final image | ||
# The binary has been moved to /src/karmada-mcp-server in the previous stage | ||
COPY --from=builder /src/karmada-mcp-server /karmada-mcp-server | ||
|
||
# Set the executable to be executed when the container starts | ||
ENTRYPOINT ["/karmada-mcp-server"] |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Karmada Assistant | ||
|
||
AI-powered chat functionality for Karmada dashboard with MCP (Model Context Protocol) tool integration. | ||
|
||
## 📋 Overview | ||
|
||
The Karmada Assistant provides intelligent chat capabilities that can interact with Karmada clusters through MCP tools. It supports both legacy chat (without tools) and modern chat (with real-time cluster tool integration), enabling users to manage and query their Karmada multi-cluster environments through natural language. | ||
|
||
## 🚀 Quick Start | ||
|
||
### Prerequisites | ||
|
||
1. **Karmada Cluster**: A running Karmada control plane | ||
2. **MCP Server**: Karmada MCP server binary | ||
3. **OpenAI API Key**: For AI model access | ||
4. **Kubeconfig**: Valid Karmada cluster configuration | ||
|
||
## 💬 Usage Examples | ||
|
||
### Basic Cluster Queries | ||
|
||
**List all clusters:** | ||
``` | ||
User: "Show me all clusters" | ||
Assistant: [Executes list_clusters tool and displays cluster information] | ||
``` | ||
|
||
**Get cluster status:** | ||
``` | ||
User: "What's the status of my member clusters?" | ||
Assistant: [Retrieves and displays cluster health and status information] | ||
``` | ||
|
||
**Check resource distribution:** | ||
``` | ||
User: "How are my workloads distributed across clusters?" | ||
Assistant: [Shows workload distribution and resource allocation] | ||
``` | ||
|
||
## ⚙️ Configuration | ||
|
||
### Command Line Flags | ||
|
||
The MCP and OpenAI integration is now configured via command line flags: | ||
|
||
```bash | ||
# Complete configuration example | ||
./karmada-dashboard-api \ | ||
--enable-mcp=true \ | ||
--mcp-transport-mode=stdio \ | ||
--mcp-server-path=/usr/local/bin/karmada-mcp-server \ | ||
--karmada-kubeconfig=/path/to/karmada.config \ | ||
--karmada-context=karmada-apiserver \ | ||
--openai-api-key=sk-xxxx \ | ||
--openai-model=gpt-4 \ | ||
--openai-endpoint=https://api.openai.com/v1 | ||
|
||
# Minimal MCP configuration with stdio mode | ||
./karmada-dashboard-api \ | ||
--enable-mcp=true \ | ||
--mcp-server-path=/usr/local/bin/karmada-mcp-server \ | ||
--karmada-kubeconfig=/path/to/karmada.config \ | ||
--openai-api-key=sk-xxxx | ||
|
||
# MCP with SSE mode | ||
./karmada-dashboard-api \ | ||
--enable-mcp=true \ | ||
--mcp-transport-mode=sse \ | ||
--mcp-sse-endpoint=http://localhost:1234/mcp/sse \ | ||
--karmada-kubeconfig=/path/to/karmada.config \ | ||
--openai-api-key=sk-xxxx | ||
``` | ||
|
||
#### Configuration Flags: | ||
|
||
**MCP Configuration:** | ||
- `--enable-mcp`: Enable MCP integration (default: false) | ||
- `--mcp-transport-mode`: Transport mode - "stdio" or "sse" (default: "stdio") | ||
- `--mcp-server-path`: Path to MCP server binary (required for stdio mode) | ||
- `--mcp-sse-endpoint`: SSE endpoint URL (required for sse mode) | ||
|
||
**OpenAI Configuration:** | ||
- `--openai-api-key`: OpenAI API key (required for AI functionality) | ||
- `--openai-model`: OpenAI model name (default: "gpt-3.5-turbo") | ||
- `--openai-endpoint`: OpenAI API endpoint (default: "https://api.openai.com/v1") | ||
|
||
**Karmada Configuration:** | ||
- `--karmada-kubeconfig`: Path to Karmada kubeconfig (used by MCP) | ||
- `--karmada-context`: Karmada context name (used by MCP, default: "karmada-apiserver") | ||
|
||
### Migration from Environment Variables | ||
|
||
❌ **Removed**: The following environment variables are no longer supported: | ||
|
||
**MCP Related:** | ||
- `ENABLE_MCP` → Use `--enable-mcp` flag | ||
- `MCP_TRANSPORT_MODE` → Use `--mcp-transport-mode` flag | ||
- `KARMADA_MCP_SERVER_PATH` → Use `--mcp-server-path` flag | ||
- `MCP_SSE_ENDPOINT` → Use `--mcp-sse-endpoint` flag | ||
- `KUBECONFIG` → Use `--karmada-kubeconfig` flag | ||
- `KARMADA_CONTEXT` → Use `--karmada-context` flag | ||
|
||
**OpenAI Related:** | ||
- `OPENAI_API_KEY` → Use `--openai-api-key` flag | ||
- `OPENAI_MODEL` → Use `--openai-model` flag | ||
- `OPENAI_ENDPOINT` → Use `--openai-endpoint` flag | ||
|
||
### MCP Server Setup | ||
|
||
The assistant requires a Karmada MCP server to provide cluster management tools: | ||
> 📢 Note: The MCP server is currently under active development and not yet published via GitHub Releases. | ||
> You'll need to build it from source. | ||
|
||
```bash | ||
# Clone the MCP server repository | ||
git clone https://github.com/warjiang/karmada-mcp-server.git | ||
cd karmada-mcp-server | ||
|
||
# Build the server | ||
go build -o karmada-mcp-server ./cmd/karmada-mcp-server | ||
|
||
# (Optional) Move it to a directory in your PATH | ||
sudo mv karmada-mcp-server /usr/local/bin/ | ||
|
||
# Verify installation | ||
karmada-mcp-server --help | ||
|
||
# Test MCP server (optional) | ||
./karmada-mcp-server stdio \ | ||
--karmada-kubeconfig=/path/to/karmada.config \ | ||
--karmada-context=karmada-apiserver | ||
``` |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better security and build reproducibility, it's recommended to avoid cloning from a personal repository and to pin the dependency to a specific version.
warjiang/karmada-mcp-server
, which is a personal repository. This can be a security and maintenance risk. It would be safer to use a repository under the officialkarmada-io
organization.git clone
command uses the default branch, which means the build can change unexpectedly. Pinning to a specific git tag or commit hash ensures that builds are reproducible.