mcp-as-code 0.1.2__tar.gz → 0.1.5__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.
Files changed (45) hide show
  1. mcp_as_code-0.1.5/PKG-INFO +150 -0
  2. mcp_as_code-0.1.5/README.md +135 -0
  3. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/docs/mcp-config.md +1 -1
  4. mcp_as_code-0.1.5/examples/serve-mcp/README.md +41 -0
  5. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/images/sandbox/README.md +3 -3
  6. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/pyproject.toml +3 -3
  7. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/__init__.py +1 -1
  8. mcp_as_code-0.1.5/src/maco/cli.py +445 -0
  9. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/gateway.py +14 -5
  10. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/oauth.py +23 -7
  11. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/sandbox/__init__.py +1 -1
  12. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/sandbox/core.py +9 -17
  13. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/serve_mcp.py +94 -92
  14. mcp_as_code-0.1.5/src/maco/service.py +589 -0
  15. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/codegen/client.py.j2 +1 -2
  16. mcp_as_code-0.1.5/src/maco/version.py +22 -0
  17. mcp_as_code-0.1.2/PKG-INFO +0 -202
  18. mcp_as_code-0.1.2/README.md +0 -189
  19. mcp_as_code-0.1.2/VERSION.txt +0 -1
  20. mcp_as_code-0.1.2/examples/serve-mcp/README.md +0 -91
  21. mcp_as_code-0.1.2/src/maco/_build_info.py +0 -4
  22. mcp_as_code-0.1.2/src/maco/cli.py +0 -261
  23. mcp_as_code-0.1.2/src/maco/version.py +0 -72
  24. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/.gitignore +0 -0
  25. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/LICENSE +0 -0
  26. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/codegen.py +0 -0
  27. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/config.py +0 -0
  28. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/mcp_manager.py +0 -0
  29. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/runner.py +0 -0
  30. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/sandbox/providers/__init__.py +0 -0
  31. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/sandbox/providers/base.py +0 -0
  32. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/sandbox/providers/docker.py +0 -0
  33. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/sandbox/providers/local.py +0 -0
  34. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/sandbox/providers/matchlock.py +0 -0
  35. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/bash_description.j2 +0 -0
  36. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/code_execute_description.j2 +0 -0
  37. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/codegen/model.py.j2 +0 -0
  38. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/codegen/package_init.py.j2 +0 -0
  39. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/codegen/pyproject.toml.j2 +0 -0
  40. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/codegen/root_model.py.j2 +0 -0
  41. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/codegen/server_init.py.j2 +0 -0
  42. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/codegen/tool.py.j2 +0 -0
  43. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/codegen/type_alias.py.j2 +0 -0
  44. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/serve_mcp_instructions.j2 +0 -0
  45. {mcp_as_code-0.1.2 → mcp_as_code-0.1.5}/src/maco/templates/server_catalog.j2 +0 -0
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-as-code
3
+ Version: 0.1.5
4
+ Summary: Execute MCP tools through generated Python code interfaces
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: click>=8.1
9
+ Requires-Dist: httpx>=0.28
10
+ Requires-Dist: jinja2>=3.1
11
+ Requires-Dist: matchlock==0.2.15
12
+ Requires-Dist: mcp>=1.24.0
13
+ Requires-Dist: pydantic>=2.0
14
+ Description-Content-Type: text/markdown
15
+
16
+ # maco
17
+
18
+ **Connect every MCP server you need, keeping your agent's context lean.**
19
+
20
+ As the number of MCP servers you connect grows, tool schemas and intermediate tool call results clutter your agent's context. `maco` (mcp-as-code) collapses them all into a single endpoint with a programmatic interface.
21
+
22
+ Instead of loading hundreds if not thousands of tool schemas upfront, `maco` reconstructs every MCP tool as Pydantic models and Python functions in a virtual filesystem and hands your agent just two of its favourite tools: `bash` to navigate, and `code_execute` to run. The agent discovers and composes tools as code, the thing frontier models do best.
23
+
24
+ ## How it works
25
+
26
+ **Small context footprint:** the agent starts with two tools (`bash` and `code_execute`), not every MCP tool schema upfront.
27
+
28
+ **Progressive discovery:** frontier models excel at navigating filesystems. By representing the tool interface as code on a filesystem, the agent can leverage `rg`, `fd` and all the POSIX tools to discover and execute relevant MCP tools.
29
+
30
+ ```bash
31
+ tools
32
+ ├── playwright
33
+ │ ├── browserClick.py
34
+ │ ├── browserClose.py
35
+ │ ├── ... many other tools
36
+ │ └── __init__.py
37
+ └── github
38
+ ├── addIssueComment.py
39
+ └── __init__.py
40
+ ```
41
+
42
+ **Programmatic leverage:** the agent is given a real programming language, Python, allowing it to orchestrate complex control flows with exceptional context-efficiency using loops, conditions, and state management.
43
+
44
+ ```python
45
+ from collections import Counter
46
+ from tools.github import listCommits
47
+
48
+ owner, repo, page, counts = "openclaw", "openclaw", 1, Counter()
49
+
50
+ while True:
51
+ commits = listCommits(owner=owner, repo=repo, perPage=100, page=page)
52
+ for commit in commits:
53
+ login = (commit.get("author") or {}).get("login")
54
+ if login and "bot" not in login.lower():
55
+ counts[login] += 1
56
+ if len(commits) < 100 or page >= 20:
57
+ break
58
+ page += 1
59
+
60
+ total = sum(counts.values())
61
+ for login, count in counts.most_common():
62
+ if count / total < 0.01:
63
+ break
64
+ print(f"@{login}: {count} commits ({count / total:.1%})")
65
+ ```
66
+
67
+ The example above illustrates the MCP code that will be executed to find the top contributors to an open-source repository.
68
+
69
+ ## Installation
70
+
71
+ Install the Python package `mcp-as-code`; it provides the `maco` executable:
72
+
73
+ ```bash
74
+ uv tool install mcp-as-code
75
+ ```
76
+
77
+ Then verify the CLI:
78
+
79
+ ```bash
80
+ maco version
81
+ ```
82
+
83
+ ## Quick start
84
+
85
+ Create a `mcp.json`:
86
+
87
+ ```json
88
+ {
89
+ "mcpServers": {
90
+ "playwright": {
91
+ "command": "npx",
92
+ "args": ["-y", "@playwright/mcp@latest"]
93
+ },
94
+ "github": {
95
+ "url": "https://api.githubcopilot.com/mcp/",
96
+ "headers": { "Authorization": "Bearer ${GITHUB_TOKEN}" }
97
+ }
98
+ }
99
+ }
100
+ ```
101
+
102
+ This config needs `npx` (for Playwright MCP), a GitHub token in `GITHUB_TOKEN`, and Docker if you use the `docker` provider.
103
+
104
+ Start the `maco` MCP server:
105
+
106
+ ```bash
107
+ maco up --config mcp.json --provider docker
108
+ ```
109
+
110
+ Use `--provider local` for a faster, non-isolated local feedback loop.
111
+
112
+ By default this serves Streamable HTTP MCP at `http://127.0.0.1:8789/mcp`.
113
+
114
+ Configure an MCP client to connect to that endpoint:
115
+
116
+ <details>
117
+ <summary>Codex</summary>
118
+
119
+ ```bash
120
+ codex mcp add maco --url http://127.0.0.1:8789/mcp
121
+ ```
122
+
123
+ </details>
124
+
125
+ <details>
126
+ <summary>Claude Code</summary>
127
+
128
+ ```bash
129
+ claude mcp add --transport http maco http://127.0.0.1:8789/mcp
130
+ ```
131
+
132
+ </details>
133
+
134
+ See [`examples/serve-mcp`](examples/serve-mcp) for a complete example that wraps multiple upstream MCP servers behind one `maco` endpoint.
135
+
136
+ ## MCP config
137
+
138
+ See [`docs/mcp-config.md`](docs/mcp-config.md) for the full config reference, including environment expansion, headers, OAuth hints, token caching, and tool filtering.
139
+
140
+ ## Sandbox providers
141
+
142
+ Choose the execution provider with `--provider`:
143
+
144
+ - `local`: fastest feedback loop; runs commands as local subprocesses.
145
+ - `docker`: runs commands in a long-lived Docker container.
146
+ - `matchlock`: runs commands in a long-lived Matchlock micro-VM.
147
+
148
+ ## License
149
+
150
+ Apache License 2.0. See [`LICENSE`](LICENSE).
@@ -0,0 +1,135 @@
1
+ # maco
2
+
3
+ **Connect every MCP server you need, keeping your agent's context lean.**
4
+
5
+ As the number of MCP servers you connect grows, tool schemas and intermediate tool call results clutter your agent's context. `maco` (mcp-as-code) collapses them all into a single endpoint with a programmatic interface.
6
+
7
+ Instead of loading hundreds if not thousands of tool schemas upfront, `maco` reconstructs every MCP tool as Pydantic models and Python functions in a virtual filesystem and hands your agent just two of its favourite tools: `bash` to navigate, and `code_execute` to run. The agent discovers and composes tools as code, the thing frontier models do best.
8
+
9
+ ## How it works
10
+
11
+ **Small context footprint:** the agent starts with two tools (`bash` and `code_execute`), not every MCP tool schema upfront.
12
+
13
+ **Progressive discovery:** frontier models excel at navigating filesystems. By representing the tool interface as code on a filesystem, the agent can leverage `rg`, `fd` and all the POSIX tools to discover and execute relevant MCP tools.
14
+
15
+ ```bash
16
+ tools
17
+ ├── playwright
18
+ │ ├── browserClick.py
19
+ │ ├── browserClose.py
20
+ │ ├── ... many other tools
21
+ │ └── __init__.py
22
+ └── github
23
+ ├── addIssueComment.py
24
+ └── __init__.py
25
+ ```
26
+
27
+ **Programmatic leverage:** the agent is given a real programming language, Python, allowing it to orchestrate complex control flows with exceptional context-efficiency using loops, conditions, and state management.
28
+
29
+ ```python
30
+ from collections import Counter
31
+ from tools.github import listCommits
32
+
33
+ owner, repo, page, counts = "openclaw", "openclaw", 1, Counter()
34
+
35
+ while True:
36
+ commits = listCommits(owner=owner, repo=repo, perPage=100, page=page)
37
+ for commit in commits:
38
+ login = (commit.get("author") or {}).get("login")
39
+ if login and "bot" not in login.lower():
40
+ counts[login] += 1
41
+ if len(commits) < 100 or page >= 20:
42
+ break
43
+ page += 1
44
+
45
+ total = sum(counts.values())
46
+ for login, count in counts.most_common():
47
+ if count / total < 0.01:
48
+ break
49
+ print(f"@{login}: {count} commits ({count / total:.1%})")
50
+ ```
51
+
52
+ The example above illustrates the MCP code that will be executed to find the top contributors to an open-source repository.
53
+
54
+ ## Installation
55
+
56
+ Install the Python package `mcp-as-code`; it provides the `maco` executable:
57
+
58
+ ```bash
59
+ uv tool install mcp-as-code
60
+ ```
61
+
62
+ Then verify the CLI:
63
+
64
+ ```bash
65
+ maco version
66
+ ```
67
+
68
+ ## Quick start
69
+
70
+ Create a `mcp.json`:
71
+
72
+ ```json
73
+ {
74
+ "mcpServers": {
75
+ "playwright": {
76
+ "command": "npx",
77
+ "args": ["-y", "@playwright/mcp@latest"]
78
+ },
79
+ "github": {
80
+ "url": "https://api.githubcopilot.com/mcp/",
81
+ "headers": { "Authorization": "Bearer ${GITHUB_TOKEN}" }
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ This config needs `npx` (for Playwright MCP), a GitHub token in `GITHUB_TOKEN`, and Docker if you use the `docker` provider.
88
+
89
+ Start the `maco` MCP server:
90
+
91
+ ```bash
92
+ maco up --config mcp.json --provider docker
93
+ ```
94
+
95
+ Use `--provider local` for a faster, non-isolated local feedback loop.
96
+
97
+ By default this serves Streamable HTTP MCP at `http://127.0.0.1:8789/mcp`.
98
+
99
+ Configure an MCP client to connect to that endpoint:
100
+
101
+ <details>
102
+ <summary>Codex</summary>
103
+
104
+ ```bash
105
+ codex mcp add maco --url http://127.0.0.1:8789/mcp
106
+ ```
107
+
108
+ </details>
109
+
110
+ <details>
111
+ <summary>Claude Code</summary>
112
+
113
+ ```bash
114
+ claude mcp add --transport http maco http://127.0.0.1:8789/mcp
115
+ ```
116
+
117
+ </details>
118
+
119
+ See [`examples/serve-mcp`](examples/serve-mcp) for a complete example that wraps multiple upstream MCP servers behind one `maco` endpoint.
120
+
121
+ ## MCP config
122
+
123
+ See [`docs/mcp-config.md`](docs/mcp-config.md) for the full config reference, including environment expansion, headers, OAuth hints, token caching, and tool filtering.
124
+
125
+ ## Sandbox providers
126
+
127
+ Choose the execution provider with `--provider`:
128
+
129
+ - `local`: fastest feedback loop; runs commands as local subprocesses.
130
+ - `docker`: runs commands in a long-lived Docker container.
131
+ - `matchlock`: runs commands in a long-lived Matchlock micro-VM.
132
+
133
+ ## License
134
+
135
+ Apache License 2.0. See [`LICENSE`](LICENSE).
@@ -1,6 +1,6 @@
1
1
  # MCP configuration
2
2
 
3
- `maco` reads Claude-style MCP configuration files with a top-level `mcpServers` object. The same config is used by `maco gen`, `maco serve`, and `maco serve-mcp`.
3
+ `maco` reads Claude-style MCP configuration files with a top-level `mcpServers` object. The same config is used by `maco gen` and `maco up`.
4
4
 
5
5
  ```json
6
6
  {
@@ -0,0 +1,41 @@
1
+ # `maco up` example
2
+
3
+ This example shows how to expose several upstream MCP servers through one compact `maco up` endpoint. The upstream servers here are:
4
+
5
+ - [Playwright MCP](https://playwright.dev/mcp/introduction), launched with `npx -y @playwright/mcp@latest`
6
+ - [GitHub MCP server](https://github.com/github/github-mcp-server), using GitHub's hosted Streamable HTTP endpoint at `https://api.githubcopilot.com/mcp/`
7
+
8
+ ## Prerequisites
9
+
10
+ - `uv`
11
+ - `node`/`npx`, for Playwright MCP
12
+ - A GitHub personal access token in `GITHUB_TOKEN`, used by the hosted GitHub MCP server
13
+ - Docker, only if you use the Docker sandbox provider
14
+ - Optional: Matchlock, for the Matchlock sandbox provider
15
+
16
+ If you are already authenticated with the GitHub CLI, export a token directly:
17
+
18
+ ```bash
19
+ export GITHUB_TOKEN=$(gh auth token)
20
+ ```
21
+
22
+ ## 1. Start `maco up`
23
+
24
+ The short path is to run from this example directory so the defaults line up with the local files:
25
+
26
+ ```bash
27
+ cd examples/serve-mcp
28
+ uv run maco up --provider local
29
+ ```
30
+
31
+ This uses `mcp.json`, writes `.maco/gateway.json`, uses `.maco/scratch` as the default scratch directory, starts the gateway, and serves HTTP MCP at `http://127.0.0.1:8789/mcp`. Add `--clean` only when you want to recreate the local generated SDK from scratch.
32
+
33
+ ## 2. Connect an agent to the MCP gateway
34
+
35
+ Configure your MCP client with `mcp-client.json` to connect to `maco up`. For example, in your MCP client's settings, set the MCP server URL to `http://127.0.0.1:8789/mcp`.
36
+
37
+ If you are using codex you may connect to it via:
38
+
39
+ ```bash
40
+ codex mcp add maco --url http://127.0.0.1:8789/mcp
41
+ ```
@@ -1,20 +1,20 @@
1
1
  # maco sandbox image
2
2
 
3
- This directory contains the Docker image used by the Docker and Matchlock `maco serve-mcp` sandbox providers.
3
+ This directory contains the Docker image used by the Docker and Matchlock `maco up` sandbox providers.
4
4
 
5
5
  The image extends the pinned Alpine uv/Python image with the `maco` CLI, `ripgrep` (`rg`), and `fd`. Remote sandbox providers use the CLI to bootstrap `/workspace/macosdk/tools` from the live gateway catalog at sandbox startup.
6
6
 
7
7
  ## Build
8
8
 
9
9
  ```bash
10
- VERSION="$(cat VERSION.txt)"
10
+ VERSION="$(scripts/package-version)"
11
11
  docker build -f images/sandbox/Dockerfile -t "ghcr.io/jingkaihe/maco:${VERSION}-alpine" .
12
12
  ```
13
13
 
14
14
  ## Import into Matchlock
15
15
 
16
16
  ```bash
17
- VERSION="$(cat VERSION.txt)"
17
+ VERSION="$(scripts/package-version)"
18
18
  docker save "ghcr.io/jingkaihe/maco:${VERSION}-alpine" \
19
19
  | matchlock image import "ghcr.io/jingkaihe/maco:${VERSION}-alpine"
20
20
  ```
@@ -6,6 +6,8 @@ readme = "README.md"
6
6
  license = "Apache-2.0"
7
7
  requires-python = ">=3.11"
8
8
  dependencies = [
9
+ "click>=8.1",
10
+ "httpx>=0.28",
9
11
  "jinja2>=3.1",
10
12
  "matchlock==0.2.15",
11
13
  "mcp>=1.24.0",
@@ -27,8 +29,7 @@ dev = [
27
29
  ]
28
30
 
29
31
  [tool.hatch.version]
30
- path = "VERSION.txt"
31
- pattern = "(?P<version>.+)"
32
+ path = "src/maco/__init__.py"
32
33
 
33
34
  [tool.hatch.build.targets.wheel]
34
35
  packages = ["src/maco"]
@@ -39,6 +40,5 @@ include = [
39
40
  "docs",
40
41
  "README.md",
41
42
  "LICENSE",
42
- "VERSION.txt",
43
43
  "pyproject.toml",
44
44
  ]
@@ -1,3 +1,3 @@
1
1
  """maco Python interface generator and MCP code-execution server."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.1.5"