golf-mcp 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.
Potentially problematic release.
This version of golf-mcp might be problematic. Click here for more details.
- golf_mcp-0.1.0/.docs/docs.md +220 -0
- golf_mcp-0.1.0/.docs/fast-mcp.md +4886 -0
- golf_mcp-0.1.0/.docs/fastmcp-example-1.py +30 -0
- golf_mcp-0.1.0/.docs/fastmcp-example-2.py +114 -0
- golf_mcp-0.1.0/.docs/mcp.md +325 -0
- golf_mcp-0.1.0/.docs/oauth-implementation.md +316 -0
- golf_mcp-0.1.0/.docs/oauth.md +305 -0
- golf_mcp-0.1.0/LICENSE +201 -0
- golf_mcp-0.1.0/MANIFEST.in +17 -0
- golf_mcp-0.1.0/PKG-INFO +78 -0
- golf_mcp-0.1.0/README.md +41 -0
- golf_mcp-0.1.0/pyproject.toml +133 -0
- golf_mcp-0.1.0/setup.cfg +4 -0
- golf_mcp-0.1.0/src/golf/__init__.py +1 -0
- golf_mcp-0.1.0/src/golf/auth/__init__.py +109 -0
- golf_mcp-0.1.0/src/golf/auth/helpers.py +56 -0
- golf_mcp-0.1.0/src/golf/auth/oauth.py +798 -0
- golf_mcp-0.1.0/src/golf/auth/provider.py +110 -0
- golf_mcp-0.1.0/src/golf/cli/__init__.py +1 -0
- golf_mcp-0.1.0/src/golf/cli/main.py +223 -0
- golf_mcp-0.1.0/src/golf/commands/__init__.py +3 -0
- golf_mcp-0.1.0/src/golf/commands/build.py +78 -0
- golf_mcp-0.1.0/src/golf/commands/init.py +197 -0
- golf_mcp-0.1.0/src/golf/commands/run.py +68 -0
- golf_mcp-0.1.0/src/golf/core/__init__.py +1 -0
- golf_mcp-0.1.0/src/golf/core/builder.py +1169 -0
- golf_mcp-0.1.0/src/golf/core/builder_auth.py +157 -0
- golf_mcp-0.1.0/src/golf/core/builder_telemetry.py +208 -0
- golf_mcp-0.1.0/src/golf/core/config.py +205 -0
- golf_mcp-0.1.0/src/golf/core/parser.py +509 -0
- golf_mcp-0.1.0/src/golf/core/transformer.py +168 -0
- golf_mcp-0.1.0/src/golf/examples/__init__.py +1 -0
- golf_mcp-0.1.0/src/golf/examples/basic/.env +3 -0
- golf_mcp-0.1.0/src/golf/examples/basic/.env.example +3 -0
- golf_mcp-0.1.0/src/golf/examples/basic/README.md +117 -0
- golf_mcp-0.1.0/src/golf/examples/basic/golf.json +9 -0
- golf_mcp-0.1.0/src/golf/examples/basic/pre_build.py +28 -0
- golf_mcp-0.1.0/src/golf/examples/basic/prompts/welcome.py +30 -0
- golf_mcp-0.1.0/src/golf/examples/basic/resources/current_time.py +41 -0
- golf_mcp-0.1.0/src/golf/examples/basic/resources/info.py +27 -0
- golf_mcp-0.1.0/src/golf/examples/basic/resources/weather/common.py +48 -0
- golf_mcp-0.1.0/src/golf/examples/basic/resources/weather/current.py +32 -0
- golf_mcp-0.1.0/src/golf/examples/basic/resources/weather/forecast.py +32 -0
- golf_mcp-0.1.0/src/golf/examples/basic/tools/github_user.py +67 -0
- golf_mcp-0.1.0/src/golf/examples/basic/tools/hello.py +29 -0
- golf_mcp-0.1.0/src/golf/examples/basic/tools/payments/charge.py +50 -0
- golf_mcp-0.1.0/src/golf/examples/basic/tools/payments/common.py +34 -0
- golf_mcp-0.1.0/src/golf/examples/basic/tools/payments/refund.py +50 -0
- golf_mcp-0.1.0/src/golf_mcp.egg-info/PKG-INFO +78 -0
- golf_mcp-0.1.0/src/golf_mcp.egg-info/SOURCES.txt +52 -0
- golf_mcp-0.1.0/src/golf_mcp.egg-info/dependency_links.txt +1 -0
- golf_mcp-0.1.0/src/golf_mcp.egg-info/entry_points.txt +2 -0
- golf_mcp-0.1.0/src/golf_mcp.egg-info/requires.txt +15 -0
- golf_mcp-0.1.0/src/golf_mcp.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Golf Framework — Technical Specification
|
|
2
|
+
|
|
3
|
+
## 1 Purpose
|
|
4
|
+
|
|
5
|
+
Golf is a **filesystem‑first build engine** that compiles a directory tree of *tools*, *prompts*, and *resources* into a runnable [FastMCP](https://github.com/fastmcp/fastmcp) server application. This document is the authoritative technical spec for implementers and integrators.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 2 Terminology
|
|
10
|
+
|
|
11
|
+
| Term | Definition |
|
|
12
|
+
| ------------------ | ---------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| **Component** | A *tool*, *prompt*, or *resource* file discovered under the project’s category directories. |
|
|
14
|
+
| **ID** | Stable identifier derived from a component’s path. Used as registration name inside FastMCP. |
|
|
15
|
+
| **Project Root** | Directory containing `golf.json` (or `golf.yaml`). |
|
|
16
|
+
| **Build Artifact** | The generated Python package (default `build/app.py`) that instantiates and runs the FastMCP server. |
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 3 On‑Disk Layout
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
<project‐root>/
|
|
24
|
+
│
|
|
25
|
+
├─ golf.json # Mandatory configuration
|
|
26
|
+
│
|
|
27
|
+
├─ tools/ # Category directory: tools
|
|
28
|
+
│ └─ …/*.py # Nested arbitrarily deep
|
|
29
|
+
│
|
|
30
|
+
├─ prompts/ # Category directory: prompts
|
|
31
|
+
│ └─ …/*.py
|
|
32
|
+
│
|
|
33
|
+
└─ resources/ # Category directory: resources
|
|
34
|
+
└─ …/*.py
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
*Each Python file defines exactly **one** component.* Non‑Python files and `__init__.py` are ignored. common.py files hold common implementation for group of tools, things like auth or SDK clients, common variables or data types.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 4 ID Derivation Algorithm
|
|
42
|
+
|
|
43
|
+
Given a component file `C` with absolute path
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
<project‑root>/<category>/<p₁>/…/<pₙ>/<filename>.py
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
let `PathRev = [pₙ, …, p₁]` (reverse order of parent dirs under the category). The **ID** is
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
<filename> + ("-" + "-".join(PathRev) if PathRev else "")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Formal Definition (BNF)
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
<id> ::= <token> [ "-" <token> { "-" <token> } ]
|
|
59
|
+
<token> ::= /[a-z0-9_]+/
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Case is preserved; implementers MUST leave tokens unchanged. Collisions are a build‑time error.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 5 Component Specification
|
|
67
|
+
|
|
68
|
+
### 5.1 Metadata Source
|
|
69
|
+
|
|
70
|
+
1. **Module docstring** — mandatory, first triple‑quoted literal.
|
|
71
|
+
2. **Function docstring** — optional; ignored unless module docstring missing.
|
|
72
|
+
|
|
73
|
+
### 5.2 Function Signature Requirements
|
|
74
|
+
|
|
75
|
+
| Component | Required Object | Rules |
|
|
76
|
+
| --------- | ------------------------------- | ---------------------------------------------------------------------------------------------------- |
|
|
77
|
+
| Tool | One top‑level `def` (any name). | ‑ Positional & keyword params MUST have type hints.<br>‑ Return annotation REQUIRED.<br> |
|
|
78
|
+
| Prompt | One top‑level `def`. | Returns `str` or `fastmcp.PromptMessage`. |
|
|
79
|
+
| Resource | Either `def` or constant. | If constant, MUST be JSON‑serialisable. If `def`, obey same type rules as Tool but **no arguments**. |
|
|
80
|
+
|
|
81
|
+
### 5.3 Automatic Validation
|
|
82
|
+
|
|
83
|
+
The parser SHALL fail the build if:
|
|
84
|
+
|
|
85
|
+
* No module docstring.
|
|
86
|
+
* Multiple top‑level functions.
|
|
87
|
+
* Unsupported parameter/return types (not JSON or pydantic‑serialisable).
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 6 Build Process (Pipeline)
|
|
92
|
+
|
|
93
|
+
| Phase | Responsibility |
|
|
94
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
95
|
+
| **0 Config Load** | Parse `golf.json` → `Config` object with defaults. |
|
|
96
|
+
| **1 Discovery** | Recursively walk `tools/`, `prompts/`, `resources/`; collect `.py` files. |
|
|
97
|
+
| **2 Parsing** | `ast.parse()` each file → build `Component` objects (id, type, path, description, function ref, signature). |
|
|
98
|
+
| **3 Semantic Validation** | Detect ID collisions, type‑hint violations, missing metadata, reserved keyword conflicts. |
|
|
99
|
+
| **4 Code Generation** | Emit `build/app.py`: |
|
|
100
|
+
|
|
101
|
+
1. Imports for every component module.
|
|
102
|
+
2. Instantiates `FastMCP(name=config.name)`.
|
|
103
|
+
3. For each component generates `mcp.tool|prompt|resource(...)(func)`.
|
|
104
|
+
4. Configures runtime host/port via `mcp.run(host=config.host, port=config.port, transport=config.transport)`.
|
|
105
|
+
5. Footer `if __name__ == "__main__": mcp.run()`. |
|
|
106
|
+
\| **5 Code Generation** | Emit `build/app.py`:
|
|
107
|
+
6. Imports for every component module.
|
|
108
|
+
7. Instantiates `FastMCP(name=config.name)`.
|
|
109
|
+
8. For each component generates `mcp.tool|prompt|resource(...)(func)`.
|
|
110
|
+
9. Adds runtime injection wrappers where needed.
|
|
111
|
+
10. Configures runtime host/port via `mcp.run(host=config.host, port=config.port, transport=config.transport)` and applies auth middleware if defined.
|
|
112
|
+
11. Footer `if __name__ == "__main__": mcp.run()`.
|
|
113
|
+
\| **6 Packaging** | Copy auxiliary files (e.g. TLS certs) if declared. |
|
|
114
|
+
\| **7 Completion** | Write artifact map & build log. |
|
|
115
|
+
|
|
116
|
+
Build is **incremental**: SHA‑1 of each file stored; unchanged files skip parsing.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 7 CLI Contract
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
$ golf init [--template <repo‑url>] # scaffold
|
|
124
|
+
$ golf build [--outdir DIR] [--watch] # compile once or watch mode
|
|
125
|
+
$ golf run [--host HOST] [--port P] # build if stale then exec app.py
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Exit codes: `0` success · `1` validation error · `2` runtime failure.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## 8 Configuration File (`golf.json` v 0.2)
|
|
133
|
+
|
|
134
|
+
```jsonc
|
|
135
|
+
{
|
|
136
|
+
"name": "AssistantServer", // FastMCP instance name
|
|
137
|
+
"output_dir": "build", // build artifact folder
|
|
138
|
+
"host": "0.0.0.0", // listening interface
|
|
139
|
+
"port": 8080, // listening port
|
|
140
|
+
"transport": "http" // "http" (streamable HTTP, default) or "sse"
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### JSON‑Schema (abridged)
|
|
145
|
+
|
|
146
|
+
````jsonc
|
|
147
|
+
{
|
|
148
|
+
"$schema": "https://json-schema.org/draft-07/schema#",
|
|
149
|
+
"type": "object",
|
|
150
|
+
"properties": {
|
|
151
|
+
"name": { "type": "string" },
|
|
152
|
+
"output_dir": { "type": "string" },
|
|
153
|
+
"host": { "type": "string" },
|
|
154
|
+
"port": { "type": "integer" },
|
|
155
|
+
"transport": { "enum": ["http", "sse"] }
|
|
156
|
+
},
|
|
157
|
+
"required": ["name"]
|
|
158
|
+
}
|
|
159
|
+
```jsonc
|
|
160
|
+
{
|
|
161
|
+
"$schema": "https://json-schema.org/draft-07/schema#",
|
|
162
|
+
"type": "object",
|
|
163
|
+
"properties": {
|
|
164
|
+
"name": { "type": "string" },
|
|
165
|
+
"output_dir": { "type": "string" },
|
|
166
|
+
"host": { "type": "string" },
|
|
167
|
+
"port": { "type": "integer" }
|
|
168
|
+
},
|
|
169
|
+
"required": ["name"]
|
|
170
|
+
}
|
|
171
|
+
````
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 9 File→Code Translation Example (Tool)
|
|
176
|
+
|
|
177
|
+
**Input file** `tools/payments/refund/submit.py`
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
"""Submit a refund request to Stripe."""
|
|
181
|
+
import stripe
|
|
182
|
+
from resources.clients import stripe_client
|
|
183
|
+
|
|
184
|
+
def run(charge_id: str, amount: int) -> dict:
|
|
185
|
+
refund = stripe_client.Refund.create(charge=charge_id, amount=amount)
|
|
186
|
+
return refund
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Generated snippet in `build/app.py`**
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from tools.payments.refund import submit as _submit
|
|
193
|
+
|
|
194
|
+
mcp.tool(
|
|
195
|
+
name="submit-refund-payments",
|
|
196
|
+
description="Submit a refund request to Stripe."
|
|
197
|
+
)(_submit.run)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 10 Extensibility Hooks
|
|
203
|
+
|
|
204
|
+
* **Pre‑Build Plugins** — `pre_build.py` in project root can register callbacks to mutate `Component` objects.
|
|
205
|
+
* **Transport Providers** — third‑party packages can expose `golf_transport` entry‑point returning `TransportFactory` classes recognised by codegen.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## 11 Compliance & Versioning
|
|
210
|
+
|
|
211
|
+
* Spec version is tracked in `golf.json` under `"spec_version"` (default `0.2`).
|
|
212
|
+
* Build engine MUST refuse to build projects with a higher spec\_version than supported.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## 12 Open Items
|
|
217
|
+
|
|
218
|
+
* Auto‑watch & hot‑reload (`golf run --watch`).
|
|
219
|
+
* Injection metadata (`@inject("gmail_client")`) vs type‑based.
|
|
220
|
+
* Resource URI override strategy.
|