harnessapi 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,35 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ build-and-publish:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write # needed to create GitHub releases
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Install uv
18
+ uses: astral-sh/setup-uv@v4
19
+
20
+ - name: Set up Python
21
+ run: uv python install 3.11
22
+
23
+ - name: Build package
24
+ run: uv build
25
+
26
+ - name: Publish to PyPI
27
+ run: uv publish
28
+ env:
29
+ UV_PUBLISH_TOKEN: ${{ secrets.UV_PUBLISH_TOKEN }}
30
+
31
+ - name: Create GitHub Release
32
+ uses: softprops/action-gh-release@v2
33
+ with:
34
+ files: dist/*
35
+ generate_release_notes: true
@@ -0,0 +1,183 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
175
+
176
+ # Cursor
177
+ # Cursor is an AI-powered code editor.`.cursorignore` specifies files/directories to
178
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
179
+ # refer to https://docs.cursor.com/context/ignore-files
180
+ .cursorignore
181
+ .cursorindexingignore
182
+ /.agents
183
+ skills-lock.json
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Edwin Jose
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,284 @@
1
+ Metadata-Version: 2.4
2
+ Name: harnessapi
3
+ Version: 0.1.0
4
+ Summary: Skill-first API framework: every endpoint is also an MCP tool
5
+ License-File: LICENSE
6
+ Keywords: agents,fastapi,llm,mcp,skills,sse,streaming
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Framework :: FastAPI
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
15
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
16
+ Requires-Python: >=3.11
17
+ Requires-Dist: anyio>=4.0.0
18
+ Requires-Dist: fastapi>=0.115.0
19
+ Requires-Dist: fastmcp>=2.0.0
20
+ Requires-Dist: pydantic>=2.0.0
21
+ Requires-Dist: sse-starlette>=2.0.0
22
+ Requires-Dist: uvicorn[standard]>=0.30.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: httpx>=0.27; extra == 'dev'
25
+ Requires-Dist: mypy>=1.10; extra == 'dev'
26
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
27
+ Requires-Dist: pytest>=8.0; extra == 'dev'
28
+ Requires-Dist: ruff>=0.4; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # harnessapi
32
+
33
+ **Skill-first API framework** — define a skill once, get both an HTTP endpoint and an MCP tool automatically.
34
+
35
+ Every skill is a folder. Drop in a `handler.py` and `models.py` and you have:
36
+ - `POST /skills/{name}` — streaming SSE by default, JSON on request
37
+ - An MCP tool at `/mcp` — ready for Claude Desktop, Cursor, or any MCP client
38
+
39
+ ---
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ uv add harnessapi
45
+ ```
46
+
47
+ Or clone and run locally:
48
+
49
+ ```bash
50
+ git clone <repo>
51
+ cd harnessapi
52
+ uv sync
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Quickstart
58
+
59
+ Create your skill folder:
60
+
61
+ ```
62
+ my_project/
63
+ ├── main.py
64
+ └── skills/
65
+ └── greet/
66
+ ├── models.py
67
+ └── handler.py
68
+ ```
69
+
70
+ **`skills/greet/models.py`**
71
+ ```python
72
+ from harnessapi import SkillInput, SkillOutput
73
+
74
+ class Input(SkillInput):
75
+ name: str
76
+
77
+ class Output(SkillOutput):
78
+ message: str
79
+ ```
80
+
81
+ **`skills/greet/handler.py`**
82
+ ```python
83
+ """Say hello to someone."""
84
+ from .models import Input, Output
85
+
86
+ async def handle(input: Input) -> Output:
87
+ return Output(message=f"Hello, {input.name}!")
88
+ ```
89
+
90
+ **`main.py`**
91
+ ```python
92
+ from pathlib import Path
93
+ from harnessapi import HarnessAPI
94
+
95
+ app = HarnessAPI(skills_dir=Path(__file__).parent / "skills")
96
+ ```
97
+
98
+ Run it exactly like a FastAPI app:
99
+
100
+ ```bash
101
+ uvicorn main:app --reload
102
+ ```
103
+
104
+ ---
105
+
106
+ ## Try the factorial example
107
+
108
+ The repo ships with a streaming factorial skill that demonstrates SSE + MCP together.
109
+
110
+ ```bash
111
+ # from the repo root
112
+ uv run uvicorn examples.factorial_app.main:app --reload
113
+ ```
114
+
115
+ ### Call via HTTP — SSE stream (default)
116
+
117
+ ```bash
118
+ curl -X POST http://localhost:8000/skills/factorial \
119
+ -H "Content-Type: application/json" \
120
+ -d '{"n": 5}'
121
+ ```
122
+
123
+ Response (each multiplication step streamed as it's computed):
124
+
125
+ ```
126
+ event: chunk
127
+ data: start: 1
128
+
129
+ event: chunk
130
+ data: 2: 2
131
+
132
+ event: chunk
133
+ data: 3: 6
134
+
135
+ event: chunk
136
+ data: 4: 24
137
+
138
+ event: chunk
139
+ data: 5: 120
140
+
141
+ event: done
142
+ data:
143
+ ```
144
+
145
+ ### Call via HTTP — plain JSON
146
+
147
+ ```bash
148
+ curl -X POST http://localhost:8000/skills/factorial \
149
+ -H "Content-Type: application/json" \
150
+ -H "Accept: application/json" \
151
+ -d '{"n": 5}'
152
+ ```
153
+
154
+ ```json
155
+ {"chunks": ["start: 1", "2: 2", "3: 6", "4: 24", "5: 120"]}
156
+ ```
157
+
158
+ ### Connect an MCP client
159
+
160
+ The MCP server is automatically available at:
161
+
162
+ ```
163
+ http://localhost:8000/mcp
164
+ ```
165
+
166
+ Add it to **Claude Desktop** (`claude_desktop_config.json`):
167
+
168
+ ```json
169
+ {
170
+ "mcpServers": {
171
+ "harnessapi": {
172
+ "url": "http://localhost:8000/mcp"
173
+ }
174
+ }
175
+ }
176
+ ```
177
+
178
+ Or add it to **Cursor** settings under MCP servers.
179
+
180
+ The `factorial` skill is automatically registered as an MCP tool with parameter `input.n: int`.
181
+
182
+ ---
183
+
184
+ ## Skill folder structure
185
+
186
+ ```
187
+ skills/
188
+ └── my_skill/
189
+ ├── handler.py # REQUIRED — async def handle(input: Input) -> Output
190
+ ├── models.py # REQUIRED — class Input(SkillInput), class Output(SkillOutput)
191
+ ├── skill.toml # optional — metadata
192
+ ├── defaults/
193
+ │ └── input.json # optional — default values shown in OpenAPI docs
194
+ └── examples/
195
+ └── 01.json # optional — {input: {...}, output: {...}} example pairs
196
+ ```
197
+
198
+ **`skill.toml`** (all optional):
199
+ ```toml
200
+ [skill]
201
+ description = "What this skill does"
202
+ is_mcp = true # expose as MCP tool (default: true)
203
+ tags = ["math"]
204
+ timeout_secs = 30
205
+ ```
206
+
207
+ ### Streaming vs non-streaming
208
+
209
+ Return a value → non-streaming (single `result` SSE event):
210
+ ```python
211
+ async def handle(input: Input) -> Output:
212
+ return Output(...)
213
+ ```
214
+
215
+ Use `yield` → streaming (multiple `chunk` SSE events):
216
+ ```python
217
+ async def handle(input: Input):
218
+ for item in compute_steps(input):
219
+ yield item
220
+ ```
221
+
222
+ ---
223
+
224
+ ## Decorator API (no folder needed)
225
+
226
+ ```python
227
+ from harnessapi import HarnessAPI, SkillInput, SkillOutput, skill
228
+
229
+ class TranslateInput(SkillInput):
230
+ text: str
231
+ target_lang: str = "es"
232
+
233
+ class TranslateOutput(SkillOutput):
234
+ translated: str
235
+
236
+ @skill(
237
+ name="translate",
238
+ input_model=TranslateInput,
239
+ output_model=TranslateOutput,
240
+ is_mcp=True,
241
+ )
242
+ async def translate_handler(input: TranslateInput) -> TranslateOutput:
243
+ return TranslateOutput(translated=f"[{input.target_lang}] {input.text}")
244
+
245
+ app = HarnessAPI(title="My Skills")
246
+ ```
247
+
248
+ ---
249
+
250
+ ## Runtime edit endpoint (advanced)
251
+
252
+ Enable hot-swapping a skill's handler over HTTP:
253
+
254
+ ```python
255
+ app = HarnessAPI(skills_dir="./skills", enable_edit_endpoints=True)
256
+ ```
257
+
258
+ ```bash
259
+ curl -X POST http://localhost:8000/skills/factorial/edit \
260
+ -H "Content-Type: application/json" \
261
+ -d '{
262
+ "source_code": "async def handle(input):\n yield f\"custom: {input.n}\"",
263
+ "persist": false
264
+ }'
265
+ ```
266
+
267
+ > **Security note**: The edit endpoint executes arbitrary Python. Always protect it with authentication middleware in production. It is disabled by default.
268
+
269
+ ---
270
+
271
+ ## SSE event protocol
272
+
273
+ | Event | When |
274
+ |----------|-------------------------------------------|
275
+ | `chunk` | Each yielded value from a streaming handler |
276
+ | `result` | The final output of a non-streaming handler |
277
+ | `done` | Always the last event |
278
+ | `error` | Handler raised an exception |
279
+
280
+ ---
281
+
282
+ ## OpenAPI docs
283
+
284
+ Interactive docs are available at `http://localhost:8000/docs` — all skills appear as documented POST endpoints with their Pydantic schemas.