Skip to content

Commit 15f1c11

Browse files
authored
chore: add Python server SDK (#92)
1 parent 438ee1e commit 15f1c11

20 files changed

Lines changed: 3966 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
ts_client_files: ${{ steps.filter.outputs.ts_client_files }}
1818
ts_server_files: ${{ steps.filter.outputs.ts_server_files }}
1919
ruby_sdk_files: ${{ steps.filter.outputs.ruby_sdk_files }}
20+
python_sdk_files: ${{ steps.filter.outputs.python_sdk_files }}
2021
example_files: ${{ steps.filter.outputs.example_files }}
2122
steps:
2223
- uses: actions/checkout@v4
@@ -30,6 +31,8 @@ jobs:
3031
- 'sdks/typescript/server/**'
3132
ruby_sdk_files:
3233
- 'sdks/ruby/**'
34+
python_sdk_files:
35+
- 'sdks/python/**'
3336
example_files:
3437
- 'examples/**'
3538
@@ -99,6 +102,43 @@ jobs:
99102
- name: Run tests
100103
run: pnpm test:ruby
101104

105+
python_sdk_test:
106+
needs: filter_changed_paths
107+
if: needs.filter_changed_paths.outputs.python_sdk_files == 'true'
108+
runs-on: ubuntu-latest
109+
steps:
110+
- uses: actions/checkout@v4
111+
112+
- name: Set up Python
113+
uses: actions/setup-python@v4
114+
with:
115+
python-version: '3.11'
116+
117+
- name: Set up uv
118+
uses: astral-sh/setup-uv@v3
119+
with:
120+
enable-cache: true
121+
122+
- name: Install dependencies
123+
run: uv sync --dev
124+
working-directory: sdks/python/server
125+
126+
- name: Lint with ruff
127+
run: uv run ruff check
128+
working-directory: sdks/python/server
129+
130+
- name: Type check with pyright
131+
run: uv run pyright
132+
working-directory: sdks/python/server
133+
134+
- name: Run tests
135+
run: uv run pytest
136+
working-directory: sdks/python/server
137+
138+
- name: Build package
139+
run: uv build
140+
working-directory: sdks/python/server
141+
102142
release_ts_client:
103143
needs: [js_build_and_test, filter_changed_paths]
104144
if: github.ref == 'refs/heads/main' && needs.filter_changed_paths.outputs.ts_client_files == 'true'
@@ -198,4 +238,50 @@ jobs:
198238
working-directory: sdks/ruby
199239
env:
200240
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
201-
run: npx semantic-release
241+
run: npx semantic-release
242+
243+
release_python_sdk:
244+
name: Release Python SDK
245+
needs: [python_sdk_test, release_ruby_sdk, filter_changed_paths]
246+
if: >
247+
always() &&
248+
github.ref == 'refs/heads/main' &&
249+
needs.filter_changed_paths.outputs.python_sdk_files == 'true' &&
250+
needs.python_sdk_test.result == 'success'
251+
runs-on: ubuntu-latest
252+
environment: release
253+
permissions:
254+
contents: write # to push commits and tags
255+
id-token: write # for trusted publishing to PyPI
256+
issues: write # to comment on issues
257+
pull-requests: write # to comment on pull requests
258+
steps:
259+
- uses: actions/checkout@v4
260+
with: { fetch-depth: 0 }
261+
- name: Setup pnpm
262+
uses: pnpm/action-setup@v2
263+
with: { version: 10 }
264+
- name: Setup Node.js
265+
uses: actions/setup-node@v4
266+
with: { node-version: 22.x, cache: 'pnpm' }
267+
- name: Install dependencies
268+
run: pnpm install --frozen-lockfile
269+
- name: Set up Python
270+
uses: actions/setup-python@v4
271+
with:
272+
python-version: '3.11'
273+
- name: Set up uv
274+
uses: astral-sh/setup-uv@v3
275+
with:
276+
enable-cache: true
277+
- name: Install Python dependencies
278+
run: uv sync --dev
279+
working-directory: sdks/python/server
280+
- name: Build package
281+
run: uv build
282+
working-directory: sdks/python/server
283+
- name: Publish to PyPI
284+
uses: pypa/gh-action-pypi-publish@release/v1
285+
with:
286+
packages-dir: sdks/python/server/dist/
287+
print-hash: true

docs/src/guide/introduction.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ MCP-UI provides SDKs for multiple languages, including:
1414
- **`@mcp-ui/client`**: A Typescript package with UI components for easy rendering of interactive UI. It includes a React component (`<UIResourceRenderer />`) and a standard Web Component (`<ui-resource-renderer>`).
1515
- **`@mcp-ui/server`**: A Typescript package with helper functions (like `createUIResource`) for server-side logic to easily construct `UIResource` objects.
1616
- **`mcp_ui_server`**: A Ruby gem with helper methods (like `create_ui_resource`) for server-side logic in Ruby applications.
17+
- **`mcp-ui-server`**: A Python package with helper methods (like `create_UIResource`) for server-side logic in Python applications.
1718

1819
## The Interactive UI Resource Protocol
1920

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# mcp-ui-server Overview
2+
3+
The `mcp-ui-server` package provides utilities to generate UI resources (`UIResource`) on your MCP server. It allows you to define UI snippets on the server-side, which can then be seamlessly and securely rendered on the client.
4+
5+
For a complete example, see the [`python-server-demo`](https://github.com/idosal/mcp-ui/tree/main/examples/python-server-demo).
6+
7+
## Key Exports
8+
9+
- **`create_ui_resource(options_dict: dict[str, Any]) -> UIResource`**:
10+
The primary function for creating UI snippets. It takes a dictionary of options to define the URI, content (direct HTML or external URL), and encoding method (text or blob).
11+
12+
## Purpose
13+
14+
- **Ease of Use**: Simplifies the creation of valid `UIResource` objects.
15+
- **Validation**: Includes basic validation (e.g., URI prefixes matching content type).
16+
- **Encoding**: Handles Base64 encoding when `encoding: 'blob'` is specified.
17+
- **MCP Integration**: Proper integration with the MCP Python SDK using `EmbeddedResource`.
18+
19+
## Installation
20+
21+
Install the package using pip or your preferred package manager:
22+
23+
```bash
24+
pip install mcp-ui-server
25+
```
26+
27+
Or with uv:
28+
29+
```bash
30+
uv add mcp-ui-server
31+
```
32+
33+
## Building
34+
35+
This package is built using Python's standard build tools and distributed via PyPI. It includes full type annotations and is compatible with Python 3.10+.
36+
37+
To build the package from source:
38+
39+
```bash
40+
uv build
41+
```
42+
43+
See the [Server SDK Usage & Examples](./usage-examples.md) page for practical examples.

0 commit comments

Comments
 (0)