Lesson
Script: Creating Reusable AI Automation with MCP and Claude Code
Learn how to transform a multi-step, interactive AI workflow into a single, executable bash script using Cursor's "rules," MCP tools, and the command line.
- Access
- Included
- Transcript
- Needs source
Manually running AI agents or multi-step processes in your editor is tedious and repetitive, even with powerful tools. Interactive prompts slow you down when you know exactly what task you want done. This lesson demonstrates how to transform a multi-step, interactive AI workflow into a single, executable bash script.
You'll learn how to leverage Cursor's "rules," MCP (Model Context Protocol) tools, and the command line to create fully automated, locked-down scripts. Go from manually guiding an AI through parsing daily notes and creating structured issue files to running a single, reliable command that does it all for you.
Workflow Demonstrated
- Configure an MCP server to provide custom tools to the AI (e.g., for a note-taking system).
- Create a "Cursor Rule" (a detailed prompt file) that defines the multi-step task.
- Run the rule interactively, approving each tool the AI wants to use.
- Convert the interactive process into a non-interactive script using command-line flags (
-pfor print mode,--allowedToolsfor security). - Use the AI to generate a final, reusable bash script from the complex command.
Key Benefits
- Full Automation: Turn complex, multi-step AI interactions into a single, reusable command.
- Increased Speed: Eliminate the need for interactive approvals and manual steps.
- Security & Reliability: Lock down scripts by explicitly allowing only the necessary tools, preventing unexpected actions.
- Reusability: Encapsulate powerful workflows into simple scripts that you or your team can run.
Prompts
Please create a bash script in my scripts folder for this command cat .cursor/rules/create-issues-from-today.mdc | claude -p --allowedTools "mcp_basic-memory_switch_project,mcp_basic-memory_write_note"
Terminal Commands
# Add a new MCP server named 'basic-memory' that uses the 'bm' command
claude mcp add -t stdio basic-memory -- bm --project "issues" mcp
# Launch the Claude interactive agent
claude
# Inside Claude, view the configured MCP servers
/mcp
# Run a rule file interactively
cat .cursor/rules/create-issues-from-today.mdc | claude
# Run the same rule file non-interactively, pre-approving specific tools
cat .cursor/rules/create-issues-from-today.mdc | claude -p --allowedTools "mcp_basic-memory_switch_project,mcp_basic-memory_write_note"
# Run the final, generated script
./scripts/create-issues-from-today.sh
# Verify the output of the script
cat issues/feature/Add\ chat\ feature\ for\ script\ collaboration.md
Code Snippets
// .claude/settings.local.json
{
"permissions": [
{
"allow": [
"mcp_basic-memory_switch_project",
"mcp_basic-memory_write_note"
],
"deny": []
}
]
}