Execute MCP tools through generated Python code interfaces
Project description
maco
Connect every MCP server you need, keeping your agent's context lean.
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.
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.
How it works
Small context footprint: the agent starts with two tools (bash and code_execute), not every MCP tool schema upfront.
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.
tools
├── playwright
│ ├── browserClick.py
│ ├── browserClose.py
│ ├── ... many other tools
│ └── __init__.py
└── github
├── addIssueComment.py
└── __init__.py
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.
from collections import Counter
from tools.github import listCommits
owner, repo, page, counts = "openclaw", "openclaw", 1, Counter()
while True:
commits = listCommits(owner=owner, repo=repo, perPage=100, page=page)
for commit in commits:
login = (commit.get("author") or {}).get("login")
if login and "bot" not in login.lower():
counts[login] += 1
if len(commits) < 100 or page >= 20:
break
page += 1
total = sum(counts.values())
for login, count in counts.most_common():
if count / total < 0.01:
break
print(f"@{login}: {count} commits ({count / total:.1%})")
The example above illustrates the MCP code that will be executed to find the top contributors to an open-source repository.
Installation
Install the Python package mcp-as-code; it provides the maco executable:
uv tool install mcp-as-code
Then verify the CLI:
maco version
Quick start
Create a mcp.json:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["-y", "@playwright/mcp@latest"]
},
"github": {
"url": "https://api.githubcopilot.com/mcp/",
"headers": { "Authorization": "Bearer ${GITHUB_TOKEN}" }
}
}
}
This config needs npx (for Playwright MCP), a GitHub token in GITHUB_TOKEN, and Docker if you use the docker provider.
Start the maco MCP server:
maco up --config mcp.json --provider docker
Use --provider local for a faster, non-isolated local feedback loop.
By default this serves Streamable HTTP MCP at http://127.0.0.1:8789/mcp.
Configure an MCP client to connect to that endpoint:
Codex
codex mcp add maco --url http://127.0.0.1:8789/mcp
Claude Code
claude mcp add --transport http maco http://127.0.0.1:8789/mcp
See examples/serve-mcp for a complete example that wraps multiple upstream MCP servers behind one maco endpoint.
MCP config
See docs/mcp-config.md for the full config reference, including environment expansion, headers, OAuth hints, token caching, and tool filtering.
Sandbox providers
Choose the execution provider with --provider:
local: fastest feedback loop; runs commands as local subprocesses.docker: runs commands in a long-lived Docker container.matchlock: runs commands in a long-lived Matchlock micro-VM.
License
Apache License 2.0. See LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_as_code-0.1.5.tar.gz.
File metadata
- Download URL: mcp_as_code-0.1.5.tar.gz
- Upload date:
- Size: 49.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4ecb2bafa5dad49af37fbd9765c4cdff42491fa309d3ad4ee9c855db0c6d96d
|
|
| MD5 |
c8d61d1d491a5b94f6526e2656429e8d
|
|
| BLAKE2b-256 |
f3964d15bbba5e929abf9f6c4c2139889350c96891d40859a96e0d27debb6507
|
Provenance
The following attestation bundles were made for mcp_as_code-0.1.5.tar.gz:
Publisher:
release.yml on jingkaihe/maco
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_as_code-0.1.5.tar.gz -
Subject digest:
a4ecb2bafa5dad49af37fbd9765c4cdff42491fa309d3ad4ee9c855db0c6d96d - Sigstore transparency entry: 1864336180
- Sigstore integration time:
-
Permalink:
jingkaihe/maco@d750ab4baa50cf5408a296a2c5a10328da4c5533 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/jingkaihe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d750ab4baa50cf5408a296a2c5a10328da4c5533 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mcp_as_code-0.1.5-py3-none-any.whl.
File metadata
- Download URL: mcp_as_code-0.1.5-py3-none-any.whl
- Upload date:
- Size: 59.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9108b574a7cd04a8fe25de187a2bfb6f49aff7866950a3c07771422c6d822e1c
|
|
| MD5 |
377761e7a633c966b178cf843b8bff79
|
|
| BLAKE2b-256 |
235de85445776cc814376de39fdb6aa0819adb8234c445b76ee28e7418598f24
|
Provenance
The following attestation bundles were made for mcp_as_code-0.1.5-py3-none-any.whl:
Publisher:
release.yml on jingkaihe/maco
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_as_code-0.1.5-py3-none-any.whl -
Subject digest:
9108b574a7cd04a8fe25de187a2bfb6f49aff7866950a3c07771422c6d822e1c - Sigstore transparency entry: 1864336512
- Sigstore integration time:
-
Permalink:
jingkaihe/maco@d750ab4baa50cf5408a296a2c5a10328da4c5533 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/jingkaihe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d750ab4baa50cf5408a296a2c5a10328da4c5533 -
Trigger Event:
push
-
Statement type: