mcp-as-code 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.
- mcp_as_code-0.1.0/.gitignore +51 -0
- mcp_as_code-0.1.0/LICENSE +203 -0
- mcp_as_code-0.1.0/PKG-INFO +212 -0
- mcp_as_code-0.1.0/README.md +199 -0
- mcp_as_code-0.1.0/VERSION.txt +1 -0
- mcp_as_code-0.1.0/examples/serve-mcp/README.md +91 -0
- mcp_as_code-0.1.0/images/sandbox/README.md +20 -0
- mcp_as_code-0.1.0/pyproject.toml +43 -0
- mcp_as_code-0.1.0/src/maco/__init__.py +3 -0
- mcp_as_code-0.1.0/src/maco/_build_info.py +4 -0
- mcp_as_code-0.1.0/src/maco/cli.py +258 -0
- mcp_as_code-0.1.0/src/maco/codegen.py +680 -0
- mcp_as_code-0.1.0/src/maco/config.py +177 -0
- mcp_as_code-0.1.0/src/maco/gateway.py +305 -0
- mcp_as_code-0.1.0/src/maco/mcp_manager.py +157 -0
- mcp_as_code-0.1.0/src/maco/runner.py +104 -0
- mcp_as_code-0.1.0/src/maco/sandbox/__init__.py +43 -0
- mcp_as_code-0.1.0/src/maco/sandbox/core.py +216 -0
- mcp_as_code-0.1.0/src/maco/sandbox/providers/__init__.py +7 -0
- mcp_as_code-0.1.0/src/maco/sandbox/providers/base.py +69 -0
- mcp_as_code-0.1.0/src/maco/sandbox/providers/docker.py +228 -0
- mcp_as_code-0.1.0/src/maco/sandbox/providers/local.py +46 -0
- mcp_as_code-0.1.0/src/maco/sandbox/providers/matchlock.py +224 -0
- mcp_as_code-0.1.0/src/maco/serve_mcp.py +527 -0
- mcp_as_code-0.1.0/src/maco/templates/bash_description.j2 +8 -0
- mcp_as_code-0.1.0/src/maco/templates/code_execute_description.j2 +14 -0
- mcp_as_code-0.1.0/src/maco/templates/codegen/client.py.j2 +104 -0
- mcp_as_code-0.1.0/src/maco/templates/codegen/model.py.j2 +6 -0
- mcp_as_code-0.1.0/src/maco/templates/codegen/package_init.py.j2 +2 -0
- mcp_as_code-0.1.0/src/maco/templates/codegen/pyproject.toml.j2 +8 -0
- mcp_as_code-0.1.0/src/maco/templates/codegen/root_model.py.j2 +3 -0
- mcp_as_code-0.1.0/src/maco/templates/codegen/server_init.py.j2 +11 -0
- mcp_as_code-0.1.0/src/maco/templates/codegen/tool.py.j2 +38 -0
- mcp_as_code-0.1.0/src/maco/templates/codegen/type_alias.py.j2 +2 -0
- mcp_as_code-0.1.0/src/maco/templates/serve_mcp_instructions.j2 +17 -0
- mcp_as_code-0.1.0/src/maco/templates/server_catalog.j2 +8 -0
- mcp_as_code-0.1.0/src/maco/version.py +72 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Python bytecode and caches
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
.pytest_cache/
|
|
6
|
+
.ruff_cache/
|
|
7
|
+
.mypy_cache/
|
|
8
|
+
.pyre/
|
|
9
|
+
.tox/
|
|
10
|
+
.nox/
|
|
11
|
+
.coverage
|
|
12
|
+
.coverage.*
|
|
13
|
+
htmlcov/
|
|
14
|
+
coverage.xml
|
|
15
|
+
|
|
16
|
+
# Virtual environments
|
|
17
|
+
.venv/
|
|
18
|
+
venv/
|
|
19
|
+
env/
|
|
20
|
+
ENV/
|
|
21
|
+
|
|
22
|
+
# Build and packaging artifacts
|
|
23
|
+
build/
|
|
24
|
+
dist/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.eggs/
|
|
27
|
+
*.egg
|
|
28
|
+
|
|
29
|
+
# maco generated/runtime workspace
|
|
30
|
+
.maco/
|
|
31
|
+
gateway.json
|
|
32
|
+
|
|
33
|
+
# Local environment and editor files
|
|
34
|
+
.env
|
|
35
|
+
.env.*
|
|
36
|
+
!.env.example
|
|
37
|
+
.DS_Store
|
|
38
|
+
.idea/
|
|
39
|
+
.vscode/
|
|
40
|
+
*.swp
|
|
41
|
+
*.swo
|
|
42
|
+
|
|
43
|
+
# Logs and temporary files
|
|
44
|
+
*.log
|
|
45
|
+
*.tmp
|
|
46
|
+
*.bak
|
|
47
|
+
|
|
48
|
+
# Example runtime artifacts
|
|
49
|
+
examples/**/.maco/
|
|
50
|
+
examples/**/scratch/
|
|
51
|
+
examples/**/maco-serve-mcp/
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Copyright 2026 Jingkai He
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright 2026 Jingkai He
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-as-code
|
|
3
|
+
Version: 0.1.0
|
|
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.
|
|
145
|
+
|
|
146
|
+
For environment variables, put them under `env`. `maco` expands `$VAR` and `${VAR}` using the environment of the `maco` process, then passes the resolved values to the upstream MCP server:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"mcpServers": {
|
|
151
|
+
"github": {
|
|
152
|
+
"command": "docker",
|
|
153
|
+
"args": [
|
|
154
|
+
"run",
|
|
155
|
+
"-i",
|
|
156
|
+
"--rm",
|
|
157
|
+
"-e",
|
|
158
|
+
"GITHUB_PERSONAL_ACCESS_TOKEN",
|
|
159
|
+
"ghcr.io/github/github-mcp-server"
|
|
160
|
+
],
|
|
161
|
+
"env": {
|
|
162
|
+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
HTTP-style servers can use URL and header fields:
|
|
170
|
+
|
|
171
|
+
```json
|
|
172
|
+
{
|
|
173
|
+
"mcpServers": {
|
|
174
|
+
"remote": {
|
|
175
|
+
"type": "http",
|
|
176
|
+
"url": "http://127.0.0.1:8000/mcp",
|
|
177
|
+
"headers": {"Authorization": "Bearer ${TOKEN}"}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Supported transports are `stdio`, `http`/`streamable_http`, and `sse`.
|
|
184
|
+
|
|
185
|
+
## Sandbox providers
|
|
186
|
+
|
|
187
|
+
Choose the execution provider with `--provider`:
|
|
188
|
+
|
|
189
|
+
- `local` — fastest feedback loop; runs commands as local subprocesses.
|
|
190
|
+
- `docker` — runs commands in a long-lived Docker container.
|
|
191
|
+
- `matchlock` — runs commands in a long-lived Matchlock micro-VM.
|
|
192
|
+
|
|
193
|
+
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`.
|
|
194
|
+
|
|
195
|
+
## Development
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
make check
|
|
199
|
+
make build
|
|
200
|
+
make image
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Safety notes
|
|
204
|
+
|
|
205
|
+
- `maco serve-mcp` exposes code execution to whatever can reach its HTTP MCP endpoint; bind and firewall it accordingly.
|
|
206
|
+
- The managed gateway uses a bearer token by default. Do not commit `.maco/gateway.json`.
|
|
207
|
+
- Sandbox providers change the isolation boundary, not the authority of the upstream MCP servers. Treat generated tool calls like direct MCP tool calls.
|
|
208
|
+
- Inspect unfamiliar generated wrappers before running code that calls them.
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
Apache License 2.0. See [`LICENSE`](LICENSE).
|
|
@@ -0,0 +1,199 @@
|
|
|
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.
|
|
132
|
+
|
|
133
|
+
For environment variables, put them under `env`. `maco` expands `$VAR` and `${VAR}` using the environment of the `maco` process, then passes the resolved values to the upstream MCP server:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"mcpServers": {
|
|
138
|
+
"github": {
|
|
139
|
+
"command": "docker",
|
|
140
|
+
"args": [
|
|
141
|
+
"run",
|
|
142
|
+
"-i",
|
|
143
|
+
"--rm",
|
|
144
|
+
"-e",
|
|
145
|
+
"GITHUB_PERSONAL_ACCESS_TOKEN",
|
|
146
|
+
"ghcr.io/github/github-mcp-server"
|
|
147
|
+
],
|
|
148
|
+
"env": {
|
|
149
|
+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
HTTP-style servers can use URL and header fields:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"mcpServers": {
|
|
161
|
+
"remote": {
|
|
162
|
+
"type": "http",
|
|
163
|
+
"url": "http://127.0.0.1:8000/mcp",
|
|
164
|
+
"headers": {"Authorization": "Bearer ${TOKEN}"}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Supported transports are `stdio`, `http`/`streamable_http`, and `sse`.
|
|
171
|
+
|
|
172
|
+
## Sandbox providers
|
|
173
|
+
|
|
174
|
+
Choose the execution provider with `--provider`:
|
|
175
|
+
|
|
176
|
+
- `local` — fastest feedback loop; runs commands as local subprocesses.
|
|
177
|
+
- `docker` — runs commands in a long-lived Docker container.
|
|
178
|
+
- `matchlock` — runs commands in a long-lived Matchlock micro-VM.
|
|
179
|
+
|
|
180
|
+
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`.
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
make check
|
|
186
|
+
make build
|
|
187
|
+
make image
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Safety notes
|
|
191
|
+
|
|
192
|
+
- `maco serve-mcp` exposes code execution to whatever can reach its HTTP MCP endpoint; bind and firewall it accordingly.
|
|
193
|
+
- The managed gateway uses a bearer token by default. Do not commit `.maco/gateway.json`.
|
|
194
|
+
- Sandbox providers change the isolation boundary, not the authority of the upstream MCP servers. Treat generated tool calls like direct MCP tool calls.
|
|
195
|
+
- Inspect unfamiliar generated wrappers before running code that calls them.
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
Apache License 2.0. See [`LICENSE`](LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|