Skip to content

Commit d102fba

Browse files
Add Makefile for MCP project (apache#184)
1 parent b8d20e1 commit d102fba

7 files changed

Lines changed: 135 additions & 12 deletions

File tree

.github/workflows/mcp-server.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
- name: Sync dependencies
8484
working-directory: mcp-server
8585
run: |
86-
uv sync --extra test --extra dev
86+
uv sync --all-extras
8787
8888
- name: Lint
8989
working-directory: mcp-server

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,25 @@ console-lint-fix: ## Fix linting issues in the console project
100100
.PHONY: console-version
101101
console-version: ## Display version for console project
102102
@$(MAKE) -C console version
103+
104+
##@ MCP
105+
106+
.PHONY: mcp-build
107+
mcp-build: ## Build the distribution files (sdist and wheel) for MCP project
108+
@$(MAKE) -C mcp-server build
109+
110+
.PHONY: mcp-cleanup
111+
mcp-cleanup: ## Cleanup virtual environment and build artifacts for MCP project
112+
@$(MAKE) -C mcp-server cleanup
113+
114+
.PHONY: mcp-lint
115+
mcp-lint: ## Lint the MCP project
116+
@$(MAKE) -C mcp-server lint
117+
118+
.PHONY: mcp-run
119+
mcp-run: ## Start MCP server (stdin/stdout transport)
120+
@$(MAKE) -C mcp-server run
121+
122+
.PHONY: mcp-test
123+
mcp-test: ## Run unit tests for MCP project
124+
@$(MAKE) -C mcp-server test

mcp-server/Makefile

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# Configures the shell for recipes to use bash, enabling bash commands and ensuring
19+
# that recipes exit on any command failure (including within pipes).
20+
SHELL = /usr/bin/env bash -o pipefail
21+
.SHELLFLAGS = -ec
22+
23+
## Variables
24+
PYTHON ?= python3
25+
VENV_DIR := .venv
26+
ACTIVATE = source $(VENV_DIR)/bin/activate
27+
28+
## Version information
29+
GIT_COMMIT := $(shell git rev-parse HEAD)
30+
UV_VERSION := $(shell cat pyproject.toml | grep -A1 tool.uv | grep -v tool.uv | grep required-version | sed 's/required-version *= *"\([^"]*\)".*/\1/')
31+
32+
##@ General
33+
34+
.PHONY: help
35+
help: ## Display this help
36+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9\.-]+:.*?##/ { printf " \033[36m%-40s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
37+
38+
.PHONY: version
39+
version: ## Display version information
40+
@echo "Git commit: ${GIT_COMMIT}"
41+
@echo "UV version: ${UV_VERSION}"
42+
43+
##@ MCP Server
44+
45+
# Target to create the virtual environment directory
46+
$(VENV_DIR):
47+
@echo "Setting up Python virtual environment at $(VENV_DIR)..."
48+
@$(PYTHON) -m venv $(VENV_DIR)
49+
@echo "Virtual environment created."
50+
51+
.PHONY: install-dependencies
52+
install-dependencies: $(VENV_DIR)
53+
@echo "Installing UV and project dependencies into $(VENV_DIR) for MCP project..."
54+
@$(VENV_DIR)/bin/pip install --upgrade pip
55+
@if [ ! -f "$(VENV_DIR)/bin/uv" ]; then \
56+
$(VENV_DIR)/bin/pip install --upgrade "uv$(UV_VERSION)"; \
57+
fi
58+
@$(ACTIVATE) && uv lock && uv sync --active --all-extras
59+
@echo "uv and dependencies installed for MCP project."
60+
61+
.PHONY: setup-env
62+
setup-env: $(VENV_DIR) install-dependencies
63+
64+
.PHONY: build
65+
build: setup-env ## Build the distribution files (sdist and wheel) for MCP project
66+
@echo "--- Building distribution for MCP project ---"
67+
@$(ACTIVATE) && uv build
68+
@echo "--- Distribution build complete for MCP project ---"
69+
70+
.PHONY: cleanup
71+
cleanup: ## Cleanup virtual environment and build artifacts for MCP project
72+
@echo "--- Cleaning up virtual environment and build artifacts for MCP project ---"
73+
@rm -rf "$(VENV_DIR)" build/ dist/ .pytest_cache/ apache_polaris_mcp.egg-info/
74+
@find . -type d -name "__pycache__" -exec rm -rf {} +
75+
@echo "--- Cleanup complete for MCP project ---"
76+
77+
.PHONY: lint
78+
lint: setup-env ## Lint the MCP project
79+
@echo "--- Running linting checks for MCP project ---"
80+
@$(ACTIVATE) && uv run pre-commit run --all-files
81+
@echo "--- Linting checks complete for MCP project ---"
82+
83+
.PHONY: run
84+
run: setup-env ## Start MCP server (stdin/stdout transport)
85+
@echo "--- Starting MCP server ---"
86+
@$(ACTIVATE) && uv run polaris-mcp
87+
@echo "--- MCP server finished ---"
88+
89+
.PHONY: test
90+
test: setup-env ## Run unit tests for MCP project
91+
@echo "--- Running unit tests for MCP project ---"
92+
@$(ACTIVATE) && uv run pytest tests/
93+
@echo "--- Unit tests complete for MCP project---"

mcp-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The implementation is built on top of [FastMCP](https://gofastmcp.com) for strea
3131
Run the following commands from the `mcp-server` directory:
3232
- `uv sync` - install runtime dependencies
3333
- `uv run polaris-mcp` - start the MCP server (stdin/stdout transport)
34-
- `uv sync --extra test --extra dev` - install runtime, test and dev dependencies
34+
- `uv sync --all-extras` - install runtime and dev dependencies
3535
- `uv run pytest` - run the test suite
3636
- `uv run pre-commit run --all-files` - lint all files
3737
- `uv build && uv publish --index testpypi --token [Pypi-API-token]` - Publish a nightly to test.pypi.org

mcp-server/pyproject.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ dependencies = [
3535
"python-dotenv>=1.2.1",
3636
]
3737

38-
[project.optional-dependencies]
39-
test = [
40-
"pytest>=8.2",
41-
]
38+
[dependency-groups]
4239
dev = [
40+
"pytest>=8.2",
4341
"pre-commit>=3.7",
4442
]
4543

@@ -54,6 +52,12 @@ repository = "https://github.com/apache/polaris-tools/"
5452
requires = ["hatchling"]
5553
build-backend = "hatchling.build"
5654

55+
[tool.uv]
56+
required-version = ">=0.9.0" # keep this as the first item for version parsing
57+
default-groups = [
58+
"dev"
59+
]
60+
5761
[tool.hatch.build.targets.sdist]
5862
include = ["polaris_mcp"]
5963

mcp-server/tests/test_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
def test_main_loads_default_config_file() -> None:
3030
with (
31+
mock.patch("sys.argv", [""]),
3132
mock.patch("polaris_mcp.server.find_dotenv") as mock_find_dotenv,
3233
mock.patch("polaris_mcp.server.load_dotenv") as mock_load_dotenv,
3334
mock.patch("polaris_mcp.server.create_server") as mock_create_server,
@@ -48,6 +49,7 @@ def test_main_loads_default_config_file() -> None:
4849

4950
def test_main_loads_custom_config_file() -> None:
5051
with (
52+
mock.patch("sys.argv", [""]),
5153
mock.patch("polaris_mcp.server.find_dotenv") as mock_find_dotenv,
5254
mock.patch("polaris_mcp.server.load_dotenv") as mock_load_dotenv,
5355
mock.patch("polaris_mcp.server.create_server") as mock_create_server,
@@ -75,6 +77,7 @@ def test_config_loading_precedence(tmp_path: Path) -> None:
7577
)
7678

7779
with (
80+
mock.patch("sys.argv", [""]),
7881
mock.patch("polaris_mcp.server.create_server"),
7982
mock.patch.dict(
8083
os.environ,

mcp-server/uv.lock

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

0 commit comments

Comments
 (0)