Skip to content

Commit 2a7d4df

Browse files
committed
feat: MCP support
1 parent 414c08f commit 2a7d4df

File tree

11 files changed

+1200
-213
lines changed

11 files changed

+1200
-213
lines changed

.github/actions/python-package-build/action.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ runs:
5151
echo "dist-path=dist" >> $GITHUB_OUTPUT
5252
echo "Built wheel: $WHEEL_FILE"
5353
54-
- name: Test package as CLI tool
55-
if: inputs.test-package == 'true'
56-
shell: bash
57-
run: |
58-
uv venv --python ${{ inputs.python-version }}
59-
uv pip install "${{ steps.build.outputs.wheel-file }}[cli]"
60-
uv run ${{ inputs.cli-test-command }}
61-
62-
- name: Publish package
63-
if: inputs.publish == 'true'
64-
shell: bash
65-
run: |
66-
uv publish
67-
6854
branding:
6955
icon: "package"
7056
color: "blue"

.github/workflows/build-test-docker.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: Build and Test Docker Image
33
on:
44
pull_request:
55
branches: ["main"]
6-
workflow_dispatch:
6+
push:
7+
branches: ["main"]
78

89
jobs:
910
should-test-docker-build:
@@ -37,7 +38,7 @@ jobs:
3738
needs: [should-test-docker-build]
3839
name: Test Docker build ${{ matrix.arch }}
3940
runs-on: ubuntu-latest
40-
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true')
41+
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true') || (github.ref_name == github.event.repository.default_branch)
4142
permissions:
4243
contents: read
4344
packages: read

.github/workflows/build-test-python.yml

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,59 @@ name: Build and Test Python Package
55
on:
66
pull_request:
77
branches: ["main"]
8-
workflow_dispatch:
8+
push:
9+
branches: ["main"]
10+
11+
env:
12+
PYTHON_VERSION: "3.10"
913

1014
jobs:
11-
test-build-package:
12-
name: Test package build
15+
test-build-package-extras:
16+
name: Test package build ${{ matrix.name}}
1317
runs-on: ubuntu-latest
1418
permissions:
1519
contents: read
20+
strategy:
21+
matrix:
22+
include:
23+
- name: cli
24+
test-args: "twyn --version"
25+
- name: mcp
26+
test-args: 'echo {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}} | uv run python src/twyn/mcp/main.py'
27+
28+
steps:
29+
- name: Check out the repo
30+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1631

32+
- name: Build package
33+
uses: ./.github/actions/python-package-build
34+
id: build
35+
with:
36+
uv-version: "0.8.22"
37+
python-version: "$PYTHON_VERSION"
38+
- name: Test package
39+
run: |
40+
uv venv --python $PYTHON_VERSION
41+
uv pip install "${{ steps.build.outputs.wheel-file }}[${{ matrix.name }}]"
42+
uv run ${{ matrix.test-args }}
43+
44+
test-build-package:
45+
name: Test package build no extras
46+
runs-on: ubuntu-latest
47+
permissions:
48+
contents: read
1749
steps:
1850
- name: Check out the repo
1951
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2052

21-
- name: Test build package
53+
- name: Build package
2254
uses: ./.github/actions/python-package-build
55+
id: build
2356
with:
24-
test-package: "true"
2557
uv-version: "0.8.22"
26-
cli-test-command: "twyn --version"
27-
python-version: "3.10"
58+
python-version: "$PYTHON_VERSION"
59+
- name: Test package
60+
run: |
61+
uv venv --python $PYTHON_VERSION
62+
uv pip install "${{ steps.build.outputs.wheel-file }}"
63+
uv run python -c 'import twyn; twyn.check_dependencies()'

.github/workflows/publish.yml

Lines changed: 5 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,14 @@
1-
# This workflow will publish our package on pypi
2-
31
name: Publish
42

53
on:
64
push:
75
tags:
86
- "v*.*.*"
97

10-
env:
11-
UV_VERSION: "0.8.22"
12-
138
jobs:
14-
build_and_test_package:
15-
name: Build and test package
16-
runs-on: ubuntu-latest
17-
18-
permissions:
19-
contents: read
20-
21-
steps:
22-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23-
24-
- name: Build and test package
25-
id: build-test
26-
uses: ./.github/actions/python-package-build
27-
with:
28-
test-package: "true"
29-
publish: "false"
30-
uv-version: ${{ env.UV_VERSION }}
31-
cli-test-command: "twyn --version"
32-
python-version: "3.10"
33-
34-
- name: Upload package artifacts
35-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
36-
with:
37-
name: python-package-${{ github.sha }}
38-
path: ${{ steps.build-test.outputs.dist-path }}
39-
retention-days: 1
40-
41-
build_and_test_docker:
42-
name: Build and test Docker image (${{ matrix.arch }})
43-
runs-on: ubuntu-latest
44-
permissions:
45-
contents: read
46-
packages: write
47-
strategy:
48-
matrix:
49-
include:
50-
- arch: amd64
51-
platform: linux/amd64
52-
cache-ref: buildcache-amd64
53-
needs-qemu: false
54-
- arch: arm64
55-
platform: linux/arm64
56-
cache-ref: buildcache-arm64
57-
needs-qemu: true
58-
steps:
59-
- name: Check out the repo
60-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
61-
62-
- name: Log in to GitHub Container Registry
63-
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
64-
with:
65-
registry: ghcr.io
66-
username: ${{ github.actor }}
67-
password: ${{ secrets.GITHUB_TOKEN }}
68-
69-
- name: Build Docker image (${{ matrix.arch }})
70-
uses: ./.github/actions/docker-build
71-
with:
72-
push: false
73-
load: true
74-
platforms: ${{ matrix.platform }}
75-
dockerfile: ./Dockerfile
76-
context: .
77-
image-name: elementsinteractive/twyn
78-
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:${{ matrix.cache-ref }}
79-
cache-to: type=registry,ref=ghcr.io/elementsinteractive/twyn:${{ matrix.cache-ref }},mode=max,compression=zstd,force-compression=true,oci-mediatypes=true
80-
setup-qemu: ${{ matrix.needs-qemu }}
81-
82-
- name: Test Docker image (${{ matrix.arch }})
83-
run: |
84-
docker run --platform ${{ matrix.platform }} --rm elementsinteractive/twyn --version
85-
869
publish_to_pypi:
8710
name: Publish to PyPI
8811
runs-on: ubuntu-latest
89-
needs: [build_and_test_package, build_and_test_docker]
9012

9113
permissions:
9214
id-token: write
@@ -95,16 +17,12 @@ jobs:
9517
steps:
9618
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
9719

98-
- name: Download package artifacts
99-
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
100-
with:
101-
name: python-package-${{ github.sha }}
102-
path: dist
103-
104-
- name: Install uv
105-
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
20+
- name: Build package
21+
uses: ./.github/actions/python-package-build
22+
id: build
10623
with:
107-
version: ${{ env.UV_VERSION }}
24+
uv-version: "0.8.22"
25+
python-version: "3.10"
10826

10927
- name: Publish package
11028
run: |
@@ -113,7 +31,6 @@ jobs:
11331
publish_to_dockerhub:
11432
name: Push Docker images to registries
11533
runs-on: ubuntu-latest
116-
needs: [build_and_test_docker, build_and_test_package]
11734
permissions:
11835
contents: read
11936
packages: write

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ cli = [
2828
"click<9.0.0,>=8.1.8",
2929
"rich<15.0.0,>=14.0.0",
3030
]
31+
mcp = [
32+
"fastmcp>=3.0.2",
33+
"nest-asyncio>=1.6.0",
34+
]
3135

3236
[tool.hatch.version]
3337
path = "VERSION"

0 commit comments

Comments
 (0)