Skip to content

feat(python): python packages #39

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

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ concurrency:
env:
GO_VERSION: 1.23
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
UV_PUBLISH_TOKEN: ${{ secrets.UV_PUBLISH_TOKEN }}

permissions:
contents: write
Expand Down Expand Up @@ -41,3 +42,13 @@ jobs:
- name: Publish npm
run:
make npm-publish
python:
name: Release Python
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
- name: Publish Python
run:
make python-publish
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ kubernetes-mcp-server-linux-arm64
!npm/kubernetes-mcp-server-linux-arm64
kubernetes-mcp-server-windows-amd64.exe
kubernetes-mcp-server-windows-arm64.exe

python/.venv/
python/build/
python/dist/
python/kubernetes_mcp_server.egg-info/
!python/kubernetes-mcp-server
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ npm-publish: npm-copy-binaries ## Publish the npm packages
jq '.optionalDependencies |= with_entries(.value = "$(NPM_VERSION)")' ./npm/kubernetes-mcp-server/package.json > tmp.json && mv tmp.json ./npm/kubernetes-mcp-server/package.json; \
cd npm/kubernetes-mcp-server && npm publish

.PHONY: python-publish
python-publish: ## Publish the python packages
cd ./python && \
sed -i "s/version = \".*\"/version = \"$(NPM_VERSION)\"/" pyproject.toml && \
uv build && \
uv push



.PHONY: test
test: ## Run the tests
go test -count=1 -v ./...
Expand Down
1 change: 1 addition & 0 deletions python/README.md
7 changes: 7 additions & 0 deletions python/kubernetes_mcp_server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Kubernetes MCP Server (Model Context Protocol) with special support for OpenShift.
"""
from .kubernetes_mcp_server import main

__all__ = ['main']

4 changes: 4 additions & 0 deletions python/kubernetes_mcp_server/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .kubernetes_mcp_server import main

if __name__ == "__main__":
main()
91 changes: 91 additions & 0 deletions python/kubernetes_mcp_server/kubernetes_mcp_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import os
import platform
import subprocess
import sys
from pathlib import Path
import shutil
import tempfile
import urllib.request

def get_platform_binary():
"""Determine the correct binary for the current platform."""
system = platform.system().lower()
arch = platform.machine().lower()

# Normalize architecture names
if arch in ["x86_64", "amd64"]:
arch = "amd64"
elif arch in ["arm64", "aarch64"]:
arch = "arm64"
else:
raise RuntimeError(f"Unsupported architecture: {arch}")

if system == "darwin":
return f"kubernetes-mcp-server-darwin-{arch}"
elif system == "linux":
return f"kubernetes-mcp-server-linux-{arch}"
elif system == "windows":
return f"kubernetes-mcp-server-windows-{arch}.exe"
else:
raise RuntimeError(f"Unsupported operating system: {system}")

def download_binary(version="latest", destination=None):
"""Download the correct binary for the current platform."""
binary_name = get_platform_binary()
if destination is None:
destination = Path.home() / ".kubernetes-mcp-server" / "bin"

destination = Path(destination)
destination.mkdir(parents=True, exist_ok=True)
binary_path = destination / binary_name

if binary_path.exists():
return binary_path

base_url = "https://github.com/manusa/kubernetes-mcp-server/releases"
if version == "latest":
release_url = f"{base_url}/latest/download/{binary_name}"
else:
release_url = f"{base_url}/download/{version}/{binary_name}"

# Download the binary
print(f"Downloading {binary_name} from {release_url}")
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
try:
with urllib.request.urlopen(release_url) as response:
shutil.copyfileobj(response, temp_file)
temp_file.close()

# Move to destination and make executable
shutil.move(temp_file.name, binary_path)
binary_path.chmod(binary_path.stat().st_mode | 0o755) # Make executable

return binary_path
except Exception as e:
os.unlink(temp_file.name)
raise RuntimeError(f"Failed to download binary: {e}")

def execute(args=None):
"""Download and execute the kubernetes-mcp-server binary."""
if args is None:
args = []

try:
binary_path = download_binary()
cmd = [str(binary_path)] + args

# Execute the binary with the provided arguments
process = subprocess.run(cmd)
return process.returncode
except Exception as e:
print(f"Error executing kubernetes-mcp-server: {e}", file=sys.stderr)
return 1

if __name__ == "__main__":
sys.exit(execute(sys.argv[1:]))


def main():
"""Main function to execute the kubernetes-mcp-server binary."""
args = sys.argv[1:] if len(sys.argv) > 1 else []
return execute(args)
25 changes: 25 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "kubernetes-mcp-server"
version = "0.0.21-7-g869ebc2"
description = "Kubernetes MCP Server (Model Context Protocol) with special support for OpenShift"
readme = {file="README.md", content-type="text/markdown"}
requires-python = ">=3.6"
license = "Apache-2.0"
authors = [
{ name = "Marc Nuri", email = "[email protected]" }
]
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]

[project.urls]
Homepage = "https://github.com/manusa/kubernetes-mcp-server"
Repository = "https://github.com/manusa/kubernetes-mcp-server"

[project.scripts]
kubernetes-mcp-server = "kubernetes_mcp_server:main"
8 changes: 8 additions & 0 deletions python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading