mcp-exec / rules
Cursor rule1 starsChanged 6 months agoMITView on GitHub
mcp-exec tools — when and how to use tools() and exec() to keep MCP results out of the context window
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- mcp-exec-dev-workflowSkill
- using-mcp-execSkill
The file
We split this mcp-exec.mdc into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Use exec() instead of calling an MCP tool directly when:
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
alwaysApply: true
description: "mcp-exec tools — when and how to use tools() and exec() to keep MCP results out of the context window"
---
# mcp-exec
You have two MCP tools from the `mcp-exec` server:
- **`tools(query)`** — search connected MCP servers for available tools. Returns trimmed summaries `{ server, name, description, signature }`. Full schemas never enter context. Use `"*"` to list all tools.
- **`exec(code, runtime)`** — run code in a sandboxed environment (Node/Bash/Python). Only the final return value or stdout enters context — all intermediate data stays in the sandbox.
## When to use exec()
Use `exec()` instead of calling an MCP tool directly when:
- The result would be large (record lists, API responses, file contents, search results)
- You want to filter, transform, or summarize before the output enters context
- The workflow touches 2+ tools and intermediate results should stay out of context
- A single tool call returns more data than you need — extract only the relevant fields
The single-tool case matters: one MCP call returning 200 records costs ~8,000 tokens in context; `exec()` can reduce it to a 50-token summary.
## Import syntax (inside exec)
```typescript
import { toolName } from 'mcp/server-name';
```
Server names match keys in `.cursor/mcp.json`. Imports resolve at runtime.
## Quick examples
```typescript
// Discover tools
tools("search emails")
tools("github pull request")
tools("*") // list all
// Single large result — keep out of context
exec({
runtime: "node",
code: `
import { searchEmails } from 'mcp/gmail';
const emails = await searchEmails({ query: 'is:unread' });
return { count: emails.length, subjects: emails.slice(0, 3).map(e => e.subject) };
`
})
// Multi-step workflow
exec({
runtime: "node",
code: `
import { listPRs } from 'mcp/github';
import { searchEmails } from 'mcp/gmail';
const prs = await listPRs({ state: 'open' });
const urgent = await searchEmails({ query: 'subject:urgent' });
return { open_prs: prs.length, urgent_emails: urgent.length };
`
})
```
## Call directly (no exec) when
- The result is small and you need to reason over raw output
- A `PreToolUse`/`PostToolUse` hook must fire for that specific tool call
- Interactive debugging where the user needs to see intermediate state
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

