diff --git a/.github/workflows/publish-mcp-registry.yml b/.github/workflows/publish-mcp-registry.yml new file mode 100644 index 0000000..c84472e --- /dev/null +++ b/.github/workflows/publish-mcp-registry.yml @@ -0,0 +1,109 @@ +name: publish-mcp-registry + +# Publishes server.json to the official MCP Registry under the +# app.structkit/mcp domain namespace. +# Gated to published GitHub Releases only — never runs on pull requests. +# GitHub OIDC cannot authenticate a domain namespace; this workflow uses +# DNS login with secrets.MCP_PRIVATE_KEY (Ed25519 hex). If the secret is +# unset, login and publish are skipped so the release is not failed. +# Never commit the private key. +on: + release: + types: + - published + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v7 + + - name: Check server.json version matches package and release tag + run: | + set -euo pipefail + + PACKAGE_VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") + SERVER_VERSION=$(python3 -c "import json; print(json.load(open('server.json'))['version'])") + PACKAGE_ENTRY_VERSION=$(python3 -c "import json; print(json.load(open('server.json'))['packages'][0]['version'])") + RELEASE_VERSION="${GITHUB_REF_NAME#v}" + + echo "Package version: $PACKAGE_VERSION" + echo "server.json version: $SERVER_VERSION" + echo "packages[0].version: $PACKAGE_ENTRY_VERSION" + echo "Release version: $RELEASE_VERSION" + + if [ "$PACKAGE_VERSION" != "$RELEASE_VERSION" ] || \ + [ "$SERVER_VERSION" != "$RELEASE_VERSION" ] || \ + [ "$PACKAGE_ENTRY_VERSION" != "$RELEASE_VERSION" ]; then + echo "Error: pyproject.toml, server.json, and the release tag must share the same version" + exit 1 + fi + + - name: Install mcp-publisher + run: | + set -euo pipefail + curl -fsSL "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" \ + | tar xz mcp-publisher + + - name: Validate server.json + run: ./mcp-publisher validate server.json + + - name: Check whether MCP_PRIVATE_KEY is configured + id: mcp-auth + env: + MCP_PRIVATE_KEY: ${{ secrets.MCP_PRIVATE_KEY }} + run: | + if [ -z "${MCP_PRIVATE_KEY}" ]; then + echo "MCP_PRIVATE_KEY is not set; skipping MCP Registry login and publish" + echo "skip=true" >> "$GITHUB_OUTPUT" + else + echo "skip=false" >> "$GITHUB_OUTPUT" + fi + + - name: Wait for the PyPI release and mcp-name marker + if: steps.mcp-auth.outputs.skip != 'true' + run: | + set -euo pipefail + + VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") + + for i in $(seq 1 30); do + if curl -fsSL "https://pypi.org/pypi/structkit/${VERSION}/json" >/dev/null; then + echo "PyPI ${VERSION} is live" + break + fi + echo "waiting for PyPI ${VERSION} (${i}/30)" + sleep 10 + if [ "$i" -eq 30 ]; then + echo "PyPI ${VERSION} did not appear within 5 minutes" + exit 1 + fi + done + + curl -fsSL "https://pypi.org/pypi/structkit/${VERSION}/json" \ + | python3 -c " + import json + import sys + + data = json.load(sys.stdin) + description = data['info'].get('description') or '' + marker = 'mcp-name: app.structkit/mcp' + present = marker in description + print('marker present:', present) + if not present: + sys.exit('PyPI long description is missing the mcp-name ownership marker') + " + + - name: Authenticate to MCP Registry + if: steps.mcp-auth.outputs.skip != 'true' + env: + MCP_PRIVATE_KEY: ${{ secrets.MCP_PRIVATE_KEY }} + run: ./mcp-publisher login dns --domain structkit.app --private-key "${MCP_PRIVATE_KEY}" + + - name: Publish server to MCP Registry + if: steps.mcp-auth.outputs.skip != 'true' + run: ./mcp-publisher publish diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index e954769..e9e28f6 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -27,12 +27,13 @@ jobs: run: | set -euo pipefail - # Ensure the version in pyproject.toml matches the release tag being - # published. For manual runs, fall back to the latest published - # release tag. - # Read version from pyproject.toml + # Ensure the version in pyproject.toml and server.json matches the + # release tag being published. For manual runs, fall back to the + # latest published release tag. PACKAGE_VERSION=$(python -c "import tomllib; f = open('pyproject.toml', 'rb'); data = tomllib.load(f); f.close(); print(data['project']['version'])") + SERVER_VERSION=$(python -c "import json; print(json.load(open('server.json'))['version'])") echo "Package version: $PACKAGE_VERSION" + echo "server.json version: $SERVER_VERSION" if [ "${GITHUB_EVENT_NAME}" = "release" ]; then RELEASE_TAG="${GITHUB_REF_NAME}" @@ -55,6 +56,11 @@ jobs: exit 1 fi + if [ "$SERVER_VERSION" != "$RELEASE_VERSION" ]; then + echo "Error: server.json version ($SERVER_VERSION) does not match release version ($RELEASE_VERSION)" + exit 1 + fi + - name: Install build dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml index 27a7603..3c20826 100644 --- a/.github/workflows/release-drafter.yaml +++ b/.github/workflows/release-drafter.yaml @@ -24,8 +24,8 @@ jobs: prerelease: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Update pyproject version from release draft - id: pyproject-version + - name: Update package versions from release draft + id: package-version env: RESOLVED_VERSION: ${{ steps.release-drafter.outputs.resolved_version }} run: | @@ -36,13 +36,15 @@ jobs: fi python - <<'PY' + import json import os import re from pathlib import Path version = os.environ["RESOLVED_VERSION"].removeprefix("v") - path = Path("pyproject.toml") - text = path.read_text() + + pyproject = Path("pyproject.toml") + text = pyproject.read_text() updated, count = re.subn( r'(?m)^(version\s*=\s*")[^"]+(")$', rf'\g<1>{version}\2', @@ -51,27 +53,36 @@ jobs: ) if count == 0: raise SystemExit("pyproject.toml version field was not found") - path.write_text(updated) + pyproject.write_text(updated) + + server_json = Path("server.json") + data = json.loads(server_json.read_text()) + data["version"] = version + packages = data.get("packages") or [] + if not packages: + raise SystemExit("server.json packages entry was not found") + packages[0]["version"] = version + server_json.write_text(json.dumps(data, indent=2) + "\n") PY - if git diff --quiet -- pyproject.toml; then - echo "pyproject.toml already matches ${RESOLVED_VERSION}" + if git diff --quiet -- pyproject.toml server.json; then + echo "package versions already match ${RESOLVED_VERSION}" echo "changed=false" >> "$GITHUB_OUTPUT" else - echo "pyproject.toml will be bumped to ${RESOLVED_VERSION}" + echo "package versions will be bumped to ${RESOLVED_VERSION}" echo "changed=true" >> "$GITHUB_OUTPUT" fi - - name: Open pyproject version bump PR - if: steps.pyproject-version.outputs.changed == 'true' + - name: Open package version bump PR + if: steps.package-version.outputs.changed == 'true' uses: peter-evans/create-pull-request@v8.1.1 with: branch: chore/bump-pyproject-version delete-branch: true - commit-message: "chore: bump pyproject version to ${{ steps.release-drafter.outputs.resolved_version }}" - title: "Bump pyproject version to ${{ steps.release-drafter.outputs.resolved_version }}" + commit-message: "chore: bump package version to ${{ steps.release-drafter.outputs.resolved_version }}" + title: "Bump package version to ${{ steps.release-drafter.outputs.resolved_version }}" body: | Release Drafter resolved the next release as `${{ steps.release-drafter.outputs.resolved_version }}`. - This PR updates `pyproject.toml` before the draft release is published so the PyPI publish workflow can build a package whose version matches the release tag. + This PR updates `pyproject.toml` and `server.json` before the draft release is published so the PyPI and MCP Registry publish workflows can ship a package whose version matches the release tag. labels: release diff --git a/.github/workflows/test-script.yaml b/.github/workflows/test-script.yaml index a048e0e..c750d21 100644 --- a/.github/workflows/test-script.yaml +++ b/.github/workflows/test-script.yaml @@ -33,6 +33,21 @@ jobs: /tmp/structkit-smoke/bin/pip install dist/*.whl /tmp/structkit-smoke/bin/structkit --help /tmp/structkit-smoke/bin/structkit generate --help + python - <<'PY' + from pathlib import Path + import zipfile + + wheels = list(Path("dist").glob("*.whl")) + if len(wheels) != 1: + raise SystemExit(f"expected one wheel, found {wheels!r}") + with zipfile.ZipFile(wheels[0]) as wheel: + metadata_name = next(name for name in wheel.namelist() if name.endswith(".dist-info/METADATA")) + metadata = wheel.read(metadata_name).decode("utf-8") + marker = "mcp-name: app.structkit/mcp" + if marker not in metadata: + raise SystemExit("wheel METADATA is missing the MCP Registry ownership marker") + print(f"MCP ownership marker present in {metadata_name}") + PY build: diff --git a/.gitignore b/.gitignore index 5e41b32..5cbea44 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ example_project/ build/* dist/ +# MCP Registry domain-auth private key (never commit) +key.pem + # MkDocs generated documentation site/docs/ diff --git a/README.md b/README.md index 157a972..00847b7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # StructKit + + YAML scaffolding your AI assistant can actually run. Define a repo once (files, CI, Terraform, app layout). Generate it from the CLI, from CI, or through an assistant over MCP. When the org template on GitHub changes, the next generate picks it up. No golden repo. No separate Cookiecutter tree. diff --git a/docs/mcp-integration.md b/docs/mcp-integration.md index 186ebd1..a750261 100644 --- a/docs/mcp-integration.md +++ b/docs/mcp-integration.md @@ -7,6 +7,61 @@ tags: The structkit tool now supports MCP (Model Context Protocol) integration, providing a programmable interface to interact with structure definitions. This enables automation and integration with other tools, particularly AI-assisted development workflows. +## Official MCP Registry + +The official MCP Registry name for StructKit is `app.structkit/mcp` (reverse-DNS of [structkit.app](https://structkit.app/)). The listing is defined in `server.json` at the repository root. Registry clients should launch the stdio server with: + +```bash +uvx structkit mcp --server +``` + +Keep `server.json` `version` (and `packages[0].version`) in sync with the package version in `pyproject.toml`. The Release Drafter version-bump PR updates both files before a GitHub Release. + +Domain namespaces authenticate with DNS or HTTP proof of `structkit.app`. GitHub OIDC (`mcp-publisher login github` / `github-oidc`) only covers `io.github.*` names and will not publish `app.structkit/mcp`. + +### Manual publish (maintainer) + +Do not publish from a pull request. Do not commit the Ed25519 private key (`key.pem` is gitignored). Ownership verification only succeeds after a PyPI release whose long description includes the hidden README marker ``. + +1. Install [`mcp-publisher`](https://github.com/modelcontextprotocol/registry/blob/main/docs/reference/cli/commands.md). +2. Generate an Ed25519 keypair and the DNS TXT proof (from [registry authentication](https://modelcontextprotocol.io/registry/authentication)): + +```bash +MY_DOMAIN="structkit.app" +openssl genpkey -algorithm Ed25519 -out key.pem +PUBLIC_KEY="$(openssl pkey -in key.pem -pubout -outform DER | tail -c 32 | base64)" +echo "${MY_DOMAIN}. IN TXT \"v=MCPv1; k=ed25519; p=${PUBLIC_KEY}\"" +``` + +3. Add that TXT record on **structkit.app** at the DNS host where the domain is registered (the website is hosted on Lovable; Lovable is not the DNS registrar). Host and value: + +```text +Host/name: structkit.app (or `@`) +Type: TXT +Value: v=MCPv1; k=ed25519; p= +``` + +Wait until the record is visible, for example `dig TXT structkit.app +short`. + +HTTP alternative (same keypair): write `v=MCPv1; k=ed25519; p=${PUBLIC_KEY}` to a file and serve it at `https://structkit.app/.well-known/mcp-registry-auth`, then login with `mcp-publisher login http --domain structkit.app --private-key ...` instead of `login dns`. + +4. Extract the private key **hex** (this is what `mcp-publisher` and the GitHub secret expect, not the PEM file) and store it as the repository secret `MCP_PRIVATE_KEY`. Do not commit it. + +```bash +PRIVATE_KEY="$(openssl pkey -in key.pem -noout -text | grep -A3 "priv:" | tail -n +2 | tr -d ' :\n')" +# Store "${PRIVATE_KEY}" as GitHub Actions secret MCP_PRIVATE_KEY +``` + +5. Cut a GitHub Release so `structkit` is uploaded to PyPI with the README marker. Confirm the marker in that version's PyPI JSON `info.description`. +6. From the repository root: + +```bash +mcp-publisher login dns --domain structkit.app --private-key "${PRIVATE_KEY}" +mcp-publisher publish +``` + +Published GitHub Releases also run `.github/workflows/publish-mcp-registry.yml`. That workflow authenticates with `mcp-publisher login dns --domain structkit.app --private-key …` using `secrets.MCP_PRIVATE_KEY`. If the secret is unset, login and publish are skipped and the release still succeeds. It is gated to `release: published` and does not run on pull requests. + ## Available MCP Tools ### 1. list_structures diff --git a/server.json b/server.json new file mode 100644 index 0000000..54d2b14 --- /dev/null +++ b/server.json @@ -0,0 +1,35 @@ +{ + "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", + "name": "app.structkit/mcp", + "title": "StructKit", + "description": "YAML scaffolding your AI assistant can actually run.", + "version": "3.3.1", + "websiteUrl": "https://structkit.app/", + "repository": { + "url": "https://github.com/httpdss/structkit", + "source": "github", + "id": "827469347" + }, + "packages": [ + { + "registryType": "pypi", + "registryBaseUrl": "https://pypi.org", + "identifier": "structkit", + "version": "3.3.1", + "runtimeHint": "uvx", + "packageArguments": [ + { + "type": "positional", + "value": "mcp" + }, + { + "type": "positional", + "value": "--server" + } + ], + "transport": { + "type": "stdio" + } + } + ] +} diff --git a/tests/test_mcp_registry.py b/tests/test_mcp_registry.py new file mode 100644 index 0000000..7a259a0 --- /dev/null +++ b/tests/test_mcp_registry.py @@ -0,0 +1,57 @@ +"""Checks that keep the official MCP Registry listing metadata consistent.""" +import json +import re +import unittest +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[1] +SERVER_JSON = ROOT / "server.json" +PYPROJECT = ROOT / "pyproject.toml" +README = ROOT / "README.md" +SERVER_NAME = "app.structkit/mcp" +OWNERSHIP_MARKER = f"mcp-name: {SERVER_NAME}" + + +class TestMCPRegistryMetadata(unittest.TestCase): + def setUp(self): + self.server = json.loads(SERVER_JSON.read_text()) + pyproject_text = PYPROJECT.read_text() + match = re.search(r'(?m)^version\s*=\s*"([^"]+)"', pyproject_text) + if match is None: + self.fail("pyproject.toml version field was not found") + self.package_version = match.group(1) + self.readme = README.read_text() + + def test_server_json_identity(self): + self.assertEqual(self.server["name"], SERVER_NAME) + self.assertEqual(self.server["title"], "StructKit") + self.assertGreaterEqual(len(self.server["description"]), 1) + self.assertLessEqual(len(self.server["description"]), 100) + self.assertEqual(self.server["repository"]["url"], "https://github.com/httpdss/structkit") + self.assertEqual(self.server["repository"]["source"], "github") + self.assertEqual(self.server["repository"]["id"], "827469347") + + def test_versions_match_pyproject(self): + self.assertEqual(self.server["version"], self.package_version) + self.assertEqual(self.server["packages"][0]["version"], self.package_version) + + def test_pypi_package_launches_mcp_server(self): + package = self.server["packages"][0] + self.assertEqual(package["registryType"], "pypi") + self.assertEqual(package["identifier"], "structkit") + self.assertEqual(package["runtimeHint"], "uvx") + self.assertEqual(package["transport"]["type"], "stdio") + arguments = [ + (item.get("type"), item.get("value")) + for item in package["packageArguments"] + ] + self.assertEqual(arguments, [("positional", "mcp"), ("positional", "--server")]) + + def test_readme_ownership_marker_is_hidden(self): + self.assertIn(f"", self.readme) + self.assertIn(OWNERSHIP_MARKER, self.readme) + + +if __name__ == "__main__": + unittest.main()