mcp-as-code 0.1.2__tar.gz → 0.1.4__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 (44) hide show
  1. mcp_as_code-0.1.4/PKG-INFO +148 -0
  2. mcp_as_code-0.1.4/README.md +135 -0
  3. mcp_as_code-0.1.4/VERSION.txt +1 -0
  4. mcp_as_code-0.1.4/examples/serve-mcp/README.md +41 -0
  5. mcp_as_code-0.1.4/src/maco/_build_info.py +4 -0
  6. mcp_as_code-0.1.2/PKG-INFO +0 -202
  7. mcp_as_code-0.1.2/README.md +0 -189
  8. mcp_as_code-0.1.2/VERSION.txt +0 -1
  9. mcp_as_code-0.1.2/examples/serve-mcp/README.md +0 -91
  10. mcp_as_code-0.1.2/src/maco/_build_info.py +0 -4
  11. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/.gitignore +0 -0
  12. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/LICENSE +0 -0
  13. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/docs/mcp-config.md +0 -0
  14. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/images/sandbox/README.md +0 -0
  15. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/pyproject.toml +0 -0
  16. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/__init__.py +0 -0
  17. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/cli.py +0 -0
  18. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/codegen.py +0 -0
  19. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/config.py +0 -0
  20. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/gateway.py +0 -0
  21. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/mcp_manager.py +0 -0
  22. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/oauth.py +0 -0
  23. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/runner.py +0 -0
  24. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/sandbox/__init__.py +0 -0
  25. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/sandbox/core.py +0 -0
  26. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/sandbox/providers/__init__.py +0 -0
  27. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/sandbox/providers/base.py +0 -0
  28. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/sandbox/providers/docker.py +0 -0
  29. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/sandbox/providers/local.py +0 -0
  30. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/sandbox/providers/matchlock.py +0 -0
  31. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/serve_mcp.py +0 -0
  32. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/bash_description.j2 +0 -0
  33. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/code_execute_description.j2 +0 -0
  34. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/codegen/client.py.j2 +0 -0
  35. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/codegen/model.py.j2 +0 -0
  36. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/codegen/package_init.py.j2 +0 -0
  37. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/codegen/pyproject.toml.j2 +0 -0
  38. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/codegen/root_model.py.j2 +0 -0
  39. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/codegen/server_init.py.j2 +0 -0
  40. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/codegen/tool.py.j2 +0 -0
  41. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/codegen/type_alias.py.j2 +0 -0
  42. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/serve_mcp_instructions.j2 +0 -0
  43. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/templates/server_catalog.j2 +0 -0
  44. {mcp_as_code-0.1.2 → mcp_as_code-0.1.4}/src/maco/version.py +0 -0
@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-as-code
3
+ Version: 0.1.4
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: jinja2>=3.1
9
+ Requires-Dist: matchlock==0.2.15
10
+ Requires-Dist: mcp>=1.24.0
11
+ Requires-Dist: pydantic>=2.0
12
+ Description-Content-Type: text/markdown
13
+
14
+ # maco
15
+
16
+ **Connect every MCP server you need, keeping your agent's context lean.**
17
+
18
+ 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.
19
+
20
+ 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.
21
+
22
+ ## How it works
23
+
24
+ **Small context footprint:** the agent starts with two tools (`bash` and `code_execute`), not every MCP tool schema upfront.
25
+
26
+ **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.
27
+
28
+ ```bash
29
+ tools
30
+ ├── playwright
31
+ │ ├── browserClick.py
32
+ │ ├── browserClose.py
33
+ │ ├── ... many other tools
34
+ │ └── __init__.py
35
+ └── github
36
+ ├── addIssueComment.py
37
+ └── __init__.py
38
+ ```
39
+
40
+ **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.
41
+
42
+ ```python
43
+ from collections import Counter
44
+ from tools.github import listCommits
45
+
46
+ owner, repo, page, counts = "openclaw", "openclaw", 1, Counter()
47
+
48
+ while True:
49
+ commits = listCommits(owner=owner, repo=repo, perPage=100, page=page)
50
+ for commit in commits:
51
+ login = (commit.get("author") or {}).get("login")
52
+ if login and "bot" not in login.lower():
53
+ counts[login] += 1
54
+ if len(commits) < 100 or page >= 20:
55
+ break
56
+ page += 1
57
+
58
+ total = sum(counts.values())
59
+ for login, count in counts.most_common():
60
+ if count / total < 0.01:
61
+ break
62
+ print(f"@{login}: {count} commits ({count / total:.1%})")
63
+ ```
64
+
65
+ The example above illustrates the MCP code that will be executed to find the top contributors to an open-source repository.
66
+
67
+ ## Installation
68
+
69
+ Install the Python package `mcp-as-code`; it provides the `maco` executable:
70
+
71
+ ```bash
72
+ uv tool install mcp-as-code
73
+ ```
74
+
75
+ Then verify the CLI:
76
+
77
+ ```bash
78
+ maco version
79
+ ```
80
+
81
+ ## Quick start
82
+
83
+ Create a `mcp.json`:
84
+
85
+ ```json
86
+ {
87
+ "mcpServers": {
88
+ "playwright": {
89
+ "command": "npx",
90
+ "args": ["-y", "@playwright/mcp@latest"]
91
+ },
92
+ "github": {
93
+ "url": "https://api.githubcopilot.com/mcp/",
94
+ "headers": { "Authorization": "Bearer ${GITHUB_TOKEN}" }
95
+ }
96
+ }
97
+ }
98
+ ```
99
+
100
+ This config needs `npx` (for Playwright MCP), a GitHub token in `GITHUB_TOKEN`, and Docker if you use the `docker` provider.
101
+
102
+ Start the `maco` MCP server:
103
+
104
+ ```bash
105
+ maco serve-mcp --config mcp.json --provider docker
106
+ ```
107
+
108
+ Use `--provider local` for a faster, non-isolated local feedback loop.
109
+
110
+ By default this serves Streamable HTTP MCP at `http://127.0.0.1:8789/mcp`.
111
+
112
+ Configure an MCP client to connect to that endpoint:
113
+
114
+ <details>
115
+ <summary>Codex</summary>
116
+
117
+ ```bash
118
+ codex mcp add maco --url http://127.0.0.1:8789/mcp
119
+ ```
120
+
121
+ </details>
122
+
123
+ <details>
124
+ <summary>Claude Code</summary>
125
+
126
+ ```bash
127
+ claude mcp add --transport http maco http://127.0.0.1:8789/mcp
128
+ ```
129
+
130
+ </details>
131
+
132
+ See [`examples/serve-mcp`](examples/serve-mcp) for a complete example that wraps multiple upstream MCP servers behind one `maco` endpoint.
133
+
134
+ ## MCP config
135
+
136
+ 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.
137
+
138
+ ## Sandbox providers
139
+
140
+ Choose the execution provider with `--provider`:
141
+
142
+ - `local`: fastest feedback loop; runs commands as local subprocesses.
143
+ - `docker`: runs commands in a long-lived Docker container.
144
+ - `matchlock`: runs commands in a long-lived Matchlock micro-VM.
145
+
146
+ ## License
147
+
148
+ 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 serve-mcp --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).
@@ -0,0 +1 @@
1
+ 0.1.4
@@ -0,0 +1,41 @@
1
+ # `maco serve-mcp` example
2
+
3
+ This example shows how to expose several upstream MCP servers through one compact `maco serve-mcp` 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 serve-mcp`
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 serve-mcp --provider local
29
+ ```
30
+
31
+ This uses `mcp.json`, writes `.maco/gateway.json`, uses `maco-serve-mcp/` as scratch, 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 serve-mcp`. 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
+ ```
@@ -0,0 +1,4 @@
1
+ """Build metadata embedded during release builds."""
2
+
3
+ COMMIT_SHA = "b592f828ae0d4766fbeff34d47d0b10e6f4158e1"
4
+ RELEASE_DATE = "2026-06-16"
@@ -1,202 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: mcp-as-code
3
- Version: 0.1.2
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: jinja2>=3.1
9
- Requires-Dist: matchlock==0.2.15
10
- Requires-Dist: mcp>=1.24.0
11
- Requires-Dist: pydantic>=2.0
12
- Description-Content-Type: text/markdown
13
-
14
- # maco
15
-
16
- `maco` (mcp-as-code) lets an MCP client interact with many upstream MCP tools through a small code-execution interface.
17
-
18
- It follows Anthropic's [code-execution-with-MCP pattern](https://www.anthropic.com/engineering/code-execution-with-mcp): keep the large MCP surface area behind a gateway, then let agents write short Python programs for loops, filtering, joins, retries, and structured output. Instead of loading hundreds of tool schemas into the context window, the client gets a compact interface for shell discovery and Python execution.
19
-
20
- ## At a glance
21
-
22
- - Point `maco` at a Claude-style `mcp.json` containing one or many MCP servers.
23
- - Run `maco serve-mcp` to expose one Streamable HTTP MCP endpoint.
24
- - Connect your MCP client to that endpoint; it sees only `bash` and `code_execute`.
25
- - Agents thrive on discovery with `rg` and `fd`, so maco gives them `bash` access to navigate the tool interface as a real filesystem.
26
- - Use `code_execute` to call upstream MCP tools from Python with `from tools.<server> import <tool>`.
27
-
28
- ## Why it helps
29
-
30
- - **Small context footprint:** the client starts with two tools, not every upstream schema.
31
- - **Programmatic leverage:** use Python for paging, filtering, joining, caching, retries, and local intermediate files.
32
- - **Progressive discovery:** inspect only the generated wrappers relevant to the task.
33
- - **Flexible isolation:** run code locally for fast iteration or inside Docker/Matchlock for stronger isolation.
34
- - **Works with existing MCP servers:** stdio, Streamable HTTP, and SSE server configs are supported.
35
-
36
- ## How it works
37
-
38
- ```text
39
- MCP client
40
- │ sees only bash + code_execute
41
-
42
- maco serve-mcp ── sandbox ──▶ Python code imports generated tools
43
-
44
-
45
- managed maco gateway
46
-
47
-
48
- upstream MCP servers from mcp.json
49
- ```
50
-
51
- `maco serve-mcp` starts a managed gateway for the upstream MCP servers, prepares a generated Python SDK for the sandbox, and serves a compact MCP endpoint for downstream clients.
52
-
53
- ## Installation
54
-
55
- Install the Python package `mcp-as-code`; it provides the `maco` executable:
56
-
57
- ```bash
58
- uv tool install mcp-as-code
59
- ```
60
-
61
- Then verify the CLI:
62
-
63
- ```bash
64
- maco version
65
- ```
66
-
67
- ## Quick start
68
-
69
- Create a Claude-style `mcp.json`:
70
-
71
- ```json
72
- {
73
- "mcpServers": {
74
- "filesystem": {
75
- "command": "npx",
76
- "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
77
- }
78
- }
79
- }
80
- ```
81
-
82
- Start the `maco` MCP server:
83
-
84
- ```bash
85
- maco serve-mcp --config mcp.json --provider docker
86
- ```
87
-
88
- Use `--provider local` for a faster, non-isolated local feedback loop.
89
-
90
- By default this serves Streamable HTTP MCP at `http://127.0.0.1:8789/mcp`.
91
-
92
- Configure an MCP client to connect to that endpoint:
93
-
94
- <details>
95
- <summary>Codex</summary>
96
-
97
- ```bash
98
- codex mcp add maco --url http://127.0.0.1:8789/mcp
99
- ```
100
-
101
- </details>
102
-
103
- <details>
104
- <summary>Claude Code</summary>
105
-
106
- ```bash
107
- claude mcp add --transport http maco http://127.0.0.1:8789/mcp
108
- ```
109
-
110
- </details>
111
-
112
- From the client, the agent uses the MCP `bash` tool for code navigation inside the sandbox:
113
-
114
- ```bash
115
- rg --files /workspace/macosdk/tools
116
- sed -n '1,160p' /workspace/macosdk/tools/filesystem/__init__.py
117
- ```
118
-
119
- Then use `code_execute` to call tools in a context-efficient manner, using loops and conditions instead of traditional linear tool-call chaining:
120
-
121
- ```python
122
- from tools.filesystem import listDirectory
123
-
124
- for path in ["/tmp", "/var/tmp"]:
125
- listing = listDirectory(path=path)
126
- entries = listing if isinstance(listing, list) else getattr(listing, "entries", [])
127
-
128
- if not entries:
129
- print(f"{path}: empty")
130
- else:
131
- print(f"{path}: {len(entries)} entries")
132
- ```
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
- If you are using the source checkout directly, the script wrapper is equivalent:
137
-
138
- ```bash
139
- ./scripts/maco-serve-mcp --config mcp.json --provider docker
140
- ```
141
-
142
- ## MCP config
143
-
144
- `maco` expects Claude-style JSON with a top-level `mcpServers` object. Supported upstream transports are `stdio`, `http`/`streamable_http`, and `sse`.
145
-
146
- Minimal stdio example:
147
-
148
- ```json
149
- {
150
- "mcpServers": {
151
- "filesystem": {
152
- "command": "npx",
153
- "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
154
- }
155
- }
156
- }
157
- ```
158
-
159
- Minimal Streamable HTTP example:
160
-
161
- ```json
162
- {
163
- "mcpServers": {
164
- "remote": {
165
- "type": "http",
166
- "url": "http://127.0.0.1:8000/mcp",
167
- "headers": {"Authorization": "Bearer ${TOKEN}"}
168
- }
169
- }
170
- }
171
- ```
172
-
173
- For remote HTTP/SSE servers without a static `Authorization` header, maco can perform OAuth from the upstream server's HTTP `401 Bearer` challenge. 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.
174
-
175
- ## Sandbox providers
176
-
177
- Choose the execution provider with `--provider`:
178
-
179
- - `local` — fastest feedback loop; runs commands as local subprocesses.
180
- - `docker` — runs commands in a long-lived Docker container.
181
- - `matchlock` — runs commands in a long-lived Matchlock micro-VM.
182
-
183
- The default Docker/Matchlock image is `ghcr.io/jingkaihe/maco:<VERSION>-alpine`, where `<VERSION>` comes from [`VERSION.txt`](VERSION.txt). It includes `maco`, Python 3.12, `uv`, `pydantic`, `rg`, and `fd`.
184
-
185
- ## Development
186
-
187
- ```bash
188
- make check
189
- make build
190
- make image
191
- ```
192
-
193
- ## Safety notes
194
-
195
- - `maco serve-mcp` exposes code execution to whatever can reach its HTTP MCP endpoint; bind and firewall it accordingly.
196
- - The managed gateway uses a bearer token by default. Do not commit `.maco/gateway.json`.
197
- - Sandbox providers change the isolation boundary, not the authority of the upstream MCP servers. Treat generated tool calls like direct MCP tool calls.
198
- - Inspect unfamiliar generated wrappers before running code that calls them.
199
-
200
- ## License
201
-
202
- Apache License 2.0. See [`LICENSE`](LICENSE).
@@ -1,189 +0,0 @@
1
- # maco
2
-
3
- `maco` (mcp-as-code) lets an MCP client interact with many upstream MCP tools through a small code-execution interface.
4
-
5
- It follows Anthropic's [code-execution-with-MCP pattern](https://www.anthropic.com/engineering/code-execution-with-mcp): keep the large MCP surface area behind a gateway, then let agents write short Python programs for loops, filtering, joins, retries, and structured output. Instead of loading hundreds of tool schemas into the context window, the client gets a compact interface for shell discovery and Python execution.
6
-
7
- ## At a glance
8
-
9
- - Point `maco` at a Claude-style `mcp.json` containing one or many MCP servers.
10
- - Run `maco serve-mcp` to expose one Streamable HTTP MCP endpoint.
11
- - Connect your MCP client to that endpoint; it sees only `bash` and `code_execute`.
12
- - Agents thrive on discovery with `rg` and `fd`, so maco gives them `bash` access to navigate the tool interface as a real filesystem.
13
- - Use `code_execute` to call upstream MCP tools from Python with `from tools.<server> import <tool>`.
14
-
15
- ## Why it helps
16
-
17
- - **Small context footprint:** the client starts with two tools, not every upstream schema.
18
- - **Programmatic leverage:** use Python for paging, filtering, joining, caching, retries, and local intermediate files.
19
- - **Progressive discovery:** inspect only the generated wrappers relevant to the task.
20
- - **Flexible isolation:** run code locally for fast iteration or inside Docker/Matchlock for stronger isolation.
21
- - **Works with existing MCP servers:** stdio, Streamable HTTP, and SSE server configs are supported.
22
-
23
- ## How it works
24
-
25
- ```text
26
- MCP client
27
- │ sees only bash + code_execute
28
-
29
- maco serve-mcp ── sandbox ──▶ Python code imports generated tools
30
-
31
-
32
- managed maco gateway
33
-
34
-
35
- upstream MCP servers from mcp.json
36
- ```
37
-
38
- `maco serve-mcp` starts a managed gateway for the upstream MCP servers, prepares a generated Python SDK for the sandbox, and serves a compact MCP endpoint for downstream clients.
39
-
40
- ## Installation
41
-
42
- Install the Python package `mcp-as-code`; it provides the `maco` executable:
43
-
44
- ```bash
45
- uv tool install mcp-as-code
46
- ```
47
-
48
- Then verify the CLI:
49
-
50
- ```bash
51
- maco version
52
- ```
53
-
54
- ## Quick start
55
-
56
- Create a Claude-style `mcp.json`:
57
-
58
- ```json
59
- {
60
- "mcpServers": {
61
- "filesystem": {
62
- "command": "npx",
63
- "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
64
- }
65
- }
66
- }
67
- ```
68
-
69
- Start the `maco` MCP server:
70
-
71
- ```bash
72
- maco serve-mcp --config mcp.json --provider docker
73
- ```
74
-
75
- Use `--provider local` for a faster, non-isolated local feedback loop.
76
-
77
- By default this serves Streamable HTTP MCP at `http://127.0.0.1:8789/mcp`.
78
-
79
- Configure an MCP client to connect to that endpoint:
80
-
81
- <details>
82
- <summary>Codex</summary>
83
-
84
- ```bash
85
- codex mcp add maco --url http://127.0.0.1:8789/mcp
86
- ```
87
-
88
- </details>
89
-
90
- <details>
91
- <summary>Claude Code</summary>
92
-
93
- ```bash
94
- claude mcp add --transport http maco http://127.0.0.1:8789/mcp
95
- ```
96
-
97
- </details>
98
-
99
- From the client, the agent uses the MCP `bash` tool for code navigation inside the sandbox:
100
-
101
- ```bash
102
- rg --files /workspace/macosdk/tools
103
- sed -n '1,160p' /workspace/macosdk/tools/filesystem/__init__.py
104
- ```
105
-
106
- Then use `code_execute` to call tools in a context-efficient manner, using loops and conditions instead of traditional linear tool-call chaining:
107
-
108
- ```python
109
- from tools.filesystem import listDirectory
110
-
111
- for path in ["/tmp", "/var/tmp"]:
112
- listing = listDirectory(path=path)
113
- entries = listing if isinstance(listing, list) else getattr(listing, "entries", [])
114
-
115
- if not entries:
116
- print(f"{path}: empty")
117
- else:
118
- print(f"{path}: {len(entries)} entries")
119
- ```
120
-
121
- See [`examples/serve-mcp`](examples/serve-mcp) for a complete example that wraps multiple upstream MCP servers behind one `maco` endpoint.
122
-
123
- If you are using the source checkout directly, the script wrapper is equivalent:
124
-
125
- ```bash
126
- ./scripts/maco-serve-mcp --config mcp.json --provider docker
127
- ```
128
-
129
- ## MCP config
130
-
131
- `maco` expects Claude-style JSON with a top-level `mcpServers` object. Supported upstream transports are `stdio`, `http`/`streamable_http`, and `sse`.
132
-
133
- Minimal stdio example:
134
-
135
- ```json
136
- {
137
- "mcpServers": {
138
- "filesystem": {
139
- "command": "npx",
140
- "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
141
- }
142
- }
143
- }
144
- ```
145
-
146
- Minimal Streamable HTTP example:
147
-
148
- ```json
149
- {
150
- "mcpServers": {
151
- "remote": {
152
- "type": "http",
153
- "url": "http://127.0.0.1:8000/mcp",
154
- "headers": {"Authorization": "Bearer ${TOKEN}"}
155
- }
156
- }
157
- }
158
- ```
159
-
160
- For remote HTTP/SSE servers without a static `Authorization` header, maco can perform OAuth from the upstream server's HTTP `401 Bearer` challenge. 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.
161
-
162
- ## Sandbox providers
163
-
164
- Choose the execution provider with `--provider`:
165
-
166
- - `local` — fastest feedback loop; runs commands as local subprocesses.
167
- - `docker` — runs commands in a long-lived Docker container.
168
- - `matchlock` — runs commands in a long-lived Matchlock micro-VM.
169
-
170
- The default Docker/Matchlock image is `ghcr.io/jingkaihe/maco:<VERSION>-alpine`, where `<VERSION>` comes from [`VERSION.txt`](VERSION.txt). It includes `maco`, Python 3.12, `uv`, `pydantic`, `rg`, and `fd`.
171
-
172
- ## Development
173
-
174
- ```bash
175
- make check
176
- make build
177
- make image
178
- ```
179
-
180
- ## Safety notes
181
-
182
- - `maco serve-mcp` exposes code execution to whatever can reach its HTTP MCP endpoint; bind and firewall it accordingly.
183
- - The managed gateway uses a bearer token by default. Do not commit `.maco/gateway.json`.
184
- - Sandbox providers change the isolation boundary, not the authority of the upstream MCP servers. Treat generated tool calls like direct MCP tool calls.
185
- - Inspect unfamiliar generated wrappers before running code that calls them.
186
-
187
- ## License
188
-
189
- Apache License 2.0. See [`LICENSE`](LICENSE).
@@ -1 +0,0 @@
1
- 0.1.2
@@ -1,91 +0,0 @@
1
- # `maco serve-mcp` example
2
-
3
- This example shows how to expose several upstream MCP servers through one compact `maco serve-mcp` 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), launched with the official `ghcr.io/github/github-mcp-server` Docker image
7
-
8
- `maco serve-mcp` generates Python wrappers for those upstream tools, starts a managed local gateway that owns the upstream MCP sessions, then starts a Streamable HTTP MCP server with two tools:
9
-
10
- - `bash` — inspect generated wrappers or run shell probes in the sandbox
11
- - `code_execute` — run Python code that imports generated wrappers
12
-
13
- ```text
14
- MCP client ──HTTP──▶ maco serve-mcp ──sandbox──▶ generated Python wrappers
15
-
16
-
17
- maco gateway
18
-
19
-
20
- Playwright MCP + GitHub MCP
21
- ```
22
-
23
- ## Files
24
-
25
- - `mcp.json` — upstream MCP servers that `maco serve-mcp` connects to.
26
- - `mcp-client.json` — example downstream MCP client config that connects to `maco serve-mcp`.
27
-
28
- ## Prerequisites
29
-
30
- - `uv`
31
- - `node`/`npx`, for Playwright MCP
32
- - Docker, for GitHub MCP and the Docker sandbox provider
33
- - Optional: Matchlock, for the Matchlock sandbox provider
34
- - A GitHub personal access token in `GITHUB_PERSONAL_ACCESS_TOKEN`
35
-
36
- If you are already authenticated with the GitHub CLI, export a token directly:
37
-
38
- ```bash
39
- export GITHUB_TOKEN=$(gh auth token)
40
- ```
41
-
42
- ## 1. Start `maco serve-mcp`
43
-
44
- The short path is to run from this example directory so the defaults line up with the local files:
45
-
46
- ```bash
47
- cd examples/serve-mcp
48
- uv run maco serve-mcp --provider local
49
- ```
50
-
51
- This uses `mcp.json`, writes `.maco/gateway.json`, uses `maco-serve-mcp/` as scratch, 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.
52
-
53
- Inside the MCP client, use the `bash` tool to inspect the generated sandbox SDK progressively:
54
-
55
- ```bash
56
- rg --files /workspace/macosdk/tools
57
- sed -n '1,160p' /workspace/macosdk/tools/playwright/__init__.py
58
- sed -n '1,160p' /workspace/macosdk/tools/github/__init__.py
59
- ```
60
-
61
- To use a different sandbox provider, swap the provider name:
62
-
63
- ```bash
64
- uv run maco serve-mcp --provider docker
65
- uv run maco serve-mcp --provider matchlock
66
- ```
67
-
68
- If you prefer to manage the maco gateway separately, run `uv run maco serve` yourself and pass `--gateway-file .maco/gateway.json` to `maco serve-mcp`.
69
-
70
- ## 2. Connect an MCP client
71
-
72
- Configure your MCP client with `examples/serve-mcp/mcp-client.json`:
73
-
74
- ```json
75
- {
76
- "mcpServers": {
77
- "maco": {
78
- "type": "http",
79
- "url": "http://127.0.0.1:8789/mcp"
80
- }
81
- }
82
- }
83
- ```
84
-
85
- The client will see only two tools, `bash` and `code_execute`, but those tools can use all generated wrappers for Playwright and GitHub. Code executed in the sandbox imports generated tools with `from tools.<server> import <tool>`.
86
-
87
- ## Notes
88
-
89
- - Prefer calling `code_execute` with only the `code` argument. If `filename` is omitted, maco writes the script to a deterministic `<hash>.py` file in scratch.
90
- - The Docker and Matchlock providers use the default sandbox image `ghcr.io/jingkaihe/maco:<VERSION>-alpine`, where `<VERSION>` comes from the repository `VERSION.txt`. It includes Python 3.12, `uv`, `pydantic`, `rg`, and `fd`.
91
- - `.maco/` and `maco-serve-mcp/` are local runtime files and should not be committed.
@@ -1,4 +0,0 @@
1
- """Build metadata embedded during release builds."""
2
-
3
- COMMIT_SHA = "e680ca8b394a20cf951bc0645e452696710ed7de"
4
- RELEASE_DATE = "2026-06-15"
File without changes
File without changes
File without changes
File without changes