mcp-code-exec

A command for converting an MCP server into a code-based setup where an agent loads only the tools it needs. MCP is a standard way for agents to connect to outside tools and data.

In plain words
What is it for?
Organising MCP tools as importable Python modules and processing data in code before returning results to the agent.
Why use it?
It reduces the amount of tool information and intermediate results placed in the agent’s working context when many tools are connected.

Command for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/vrsen/openswarm/mcp-code-exec
Clone the repo
git clone --depth 1 https://github.com/VRSEN/OpenSwarm

Made for: Cursor.

Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,872 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02872
Opus 5 $0.00000 $0.01436
Sonnet 5 $0.00000 $0.00574
Haiku 4.5 $0.00000 $0.00287

Measured 2d ago against content hash 7f824ab799bd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

mcp-code-exec scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/commands/mcp-code-exec.md · 334 lines

How it starts

The opening of the file, as written. The whole thing — 334 lines — stays where its author put it; the contents beside it link to each section on GitHub.

MCP Code Execution Pattern - Implementation Guide

Your task is to convert an MCP server into the Code Execution Pattern described in Anthropic's blog post. This pattern enables progressive disclosure of tools, reducing token usage by up to 98% compared to loading all tools upfront.

Why This Pattern?

Problem with Traditional MCP:

  • Loading all tools upfront consumes 150,000+ tokens
  • Intermediate tool results flow through model context repeatedly
  • Agents slow down with many connected tools

Solution - Code Execution Pattern:

  • Tools organized as importable Python modules (filesystem-based)
  • Agents load only what they need (progressive disclosure)
  • Data processing happens in code before returning to model
  • Result: 98.7% token reduction (150K → 2K tokens)

Step-by-Step Implementation

Step 0: Create a TO-DO List.

Before starting, check if the user has provided the necessary auth credentials for the MCP servers. If not, ask the user to provide them before starting this task.

After credentials are provided, create a to-do list for yourself with all the steps you need to complete below.

Step 1: Create MCP Server Files

Create a dedicated folder for the MCP server in ./agent_name/mcp_servers/ directory.

Example:

./agent_name/mcp_servers/[server_name]/
├── notion.py           # Server singleton & connection management (with discovery in __main__)
├── salesforce.py
├── github.py
├── youtube.py
└── __init__.py         # Package exports

Step 2: Create the Server Module

The server.py module manages the MCP server connection as a singleton. It is converted into tools using ToolFactory.from_mcp method, available in agency_swarm specifically for this pattern. This method converts the MCP server into a list of tools.

Include tool discovery in the __main__ block to list available tools.

Note: This pattern works with any MCP server type, except HostedMCPTool. The template below shows MCPServerStdio (most common), but you can use:

Read the full file on GitHub · 334 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 334 lines · 0 tokens per session scan A 7f824ab799bd

Subscribe to this mod's changes

mcp-code-exec is a command published in the GitHub repository VRSEN/OpenSwarm (2,856 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,872 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.