Skip to content

Commit dac20e4

Browse files
authored
feat(python): python packages (39)
feat(python): python packages --- Update python/kubernetes_mcp_server/__init__.py
1 parent a276dc2 commit dac20e4

File tree

9 files changed

+162
-0
lines changed

9 files changed

+162
-0
lines changed

.github/workflows/release.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ concurrency:
1313
env:
1414
GO_VERSION: 1.23
1515
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
16+
UV_PUBLISH_TOKEN: ${{ secrets.UV_PUBLISH_TOKEN }}
1617

1718
permissions:
1819
contents: write
@@ -41,3 +42,13 @@ jobs:
4142
- name: Publish npm
4243
run:
4344
make npm-publish
45+
python:
46+
name: Release Python
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
- uses: astral-sh/setup-uv@v5
52+
- name: Publish Python
53+
run:
54+
make python-publish

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ kubernetes-mcp-server-linux-arm64
1919
!npm/kubernetes-mcp-server-linux-arm64
2020
kubernetes-mcp-server-windows-amd64.exe
2121
kubernetes-mcp-server-windows-arm64.exe
22+
23+
python/.venv/
24+
python/build/
25+
python/dist/
26+
python/kubernetes_mcp_server.egg-info/
27+
!python/kubernetes-mcp-server

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ npm-publish: npm-copy-binaries ## Publish the npm packages
7979
jq '.optionalDependencies |= with_entries(.value = "$(NPM_VERSION)")' ./npm/kubernetes-mcp-server/package.json > tmp.json && mv tmp.json ./npm/kubernetes-mcp-server/package.json; \
8080
cd npm/kubernetes-mcp-server && npm publish
8181

82+
.PHONY: python-publish
83+
python-publish: ## Publish the python packages
84+
cd ./python && \
85+
sed -i "s/version = \".*\"/version = \"$(NPM_VERSION)\"/" pyproject.toml && \
86+
uv build && \
87+
uv push
88+
89+
90+
8291
.PHONY: test
8392
test: ## Run the tests
8493
go test -count=1 -v ./...

python/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Kubernetes MCP Server (Model Context Protocol) with special support for OpenShift.
3+
"""
4+
from .kubernetes_mcp_server import main
5+
6+
__all__ = ['main']
7+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .kubernetes_mcp_server import main
2+
3+
if __name__ == "__main__":
4+
main()
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import os
2+
import platform
3+
import subprocess
4+
import sys
5+
from pathlib import Path
6+
import shutil
7+
import tempfile
8+
import urllib.request
9+
10+
def get_platform_binary():
11+
"""Determine the correct binary for the current platform."""
12+
system = platform.system().lower()
13+
arch = platform.machine().lower()
14+
15+
# Normalize architecture names
16+
if arch in ["x86_64", "amd64"]:
17+
arch = "amd64"
18+
elif arch in ["arm64", "aarch64"]:
19+
arch = "arm64"
20+
else:
21+
raise RuntimeError(f"Unsupported architecture: {arch}")
22+
23+
if system == "darwin":
24+
return f"kubernetes-mcp-server-darwin-{arch}"
25+
elif system == "linux":
26+
return f"kubernetes-mcp-server-linux-{arch}"
27+
elif system == "windows":
28+
return f"kubernetes-mcp-server-windows-{arch}.exe"
29+
else:
30+
raise RuntimeError(f"Unsupported operating system: {system}")
31+
32+
def download_binary(version="latest", destination=None):
33+
"""Download the correct binary for the current platform."""
34+
binary_name = get_platform_binary()
35+
if destination is None:
36+
destination = Path.home() / ".kubernetes-mcp-server" / "bin"
37+
38+
destination = Path(destination)
39+
destination.mkdir(parents=True, exist_ok=True)
40+
binary_path = destination / binary_name
41+
42+
if binary_path.exists():
43+
return binary_path
44+
45+
base_url = "https://github.com/manusa/kubernetes-mcp-server/releases"
46+
if version == "latest":
47+
release_url = f"{base_url}/latest/download/{binary_name}"
48+
else:
49+
release_url = f"{base_url}/download/{version}/{binary_name}"
50+
51+
# Download the binary
52+
print(f"Downloading {binary_name} from {release_url}")
53+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
54+
try:
55+
with urllib.request.urlopen(release_url) as response:
56+
shutil.copyfileobj(response, temp_file)
57+
temp_file.close()
58+
59+
# Move to destination and make executable
60+
shutil.move(temp_file.name, binary_path)
61+
binary_path.chmod(binary_path.stat().st_mode | 0o755) # Make executable
62+
63+
return binary_path
64+
except Exception as e:
65+
os.unlink(temp_file.name)
66+
raise RuntimeError(f"Failed to download binary: {e}")
67+
68+
def execute(args=None):
69+
"""Download and execute the kubernetes-mcp-server binary."""
70+
if args is None:
71+
args = []
72+
73+
try:
74+
binary_path = download_binary()
75+
cmd = [str(binary_path)] + args
76+
77+
# Execute the binary with the provided arguments
78+
process = subprocess.run(cmd)
79+
return process.returncode
80+
except Exception as e:
81+
print(f"Error executing kubernetes-mcp-server: {e}", file=sys.stderr)
82+
return 1
83+
84+
if __name__ == "__main__":
85+
sys.exit(execute(sys.argv[1:]))
86+
87+
88+
def main():
89+
"""Main function to execute the kubernetes-mcp-server binary."""
90+
args = sys.argv[1:] if len(sys.argv) > 1 else []
91+
return execute(args)

python/pyproject.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "kubernetes-mcp-server"
7+
version = "0.0.21-7-g869ebc2"
8+
description = "Kubernetes MCP Server (Model Context Protocol) with special support for OpenShift"
9+
readme = {file="README.md", content-type="text/markdown"}
10+
requires-python = ">=3.6"
11+
license = "Apache-2.0"
12+
authors = [
13+
{ name = "Marc Nuri", email = "[email protected]" }
14+
]
15+
classifiers = [
16+
"Programming Language :: Python :: 3",
17+
"Operating System :: OS Independent",
18+
]
19+
20+
[project.urls]
21+
Homepage = "https://github.com/manusa/kubernetes-mcp-server"
22+
Repository = "https://github.com/manusa/kubernetes-mcp-server"
23+
24+
[project.scripts]
25+
kubernetes-mcp-server = "kubernetes_mcp_server:main"

python/uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)