codemap_script_run
Manually execute a script. Primarily for utility scripts, but can run any category with custom context.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
category | stringaudit | build | orient | close | utility | ✅ Required | Script category |
name | string | ✅ Required | Script name (filename without .js extension) |
context | object | ❌ Optional | Optional context overrides to pass to script (merged with base context) |
Usage Examples
MCP Usage (for AI Agents like Claude)
json
{
"name": "codemap_script_run",
"arguments": {
"category": "utility",
"name": "generate-report"
}
}Example Output
JSON Response
json
{
"success": true,
"script": {
"category": "utility",
"name": "generate-report"
},
"result": {
"data": "Report generated successfully",
"files": 245,
"timestamp": "2026-04-08T12:34:56Z"
},
"message": "Script executed: utility/generate-report.js"
}When to Use This Tool
- Execute utility scripts manually
- Test audit scripts before integration
- Run ad-hoc analysis scripts
- Validate script logic
- Debug script issues
Common Patterns
Run and Check Result
Run Multiple Scripts
Pass Custom Context
const result = await codemap.scripts.run('audit', 'validate');
if (!result.passed) {
console.error('Validation failed:', result.message);
process.exit(1);
}Run Multiple Scripts
const scripts = ['check-imports', 'validate-structure'];
for (const name of scripts) {
await codemap.scripts.run('audit', name);
}Pass Custom Context
await codemap.scripts.run('utility', 'report', {
context: { format: 'json', verbose: true }
});Pro Tips
Utility scripts are best - Use utility category for manual execution. Audit/build/orient/close run automatically.
Check result format - Audit scripts return {passed, message}. Other scripts vary.
Pass context for flexibility - Use context parameter to customize script behavior.
Check result format - Audit scripts return {passed, message}. Other scripts vary.
Pass context for flexibility - Use context parameter to customize script behavior.
Best Practices
Verify script exists - Use
Handle errors - Wrap in try-catch for graceful failure
Check result structure - Different script categories return different formats
script_list before runningHandle errors - Wrap in try-catch for graceful failure
Check result structure - Different script categories return different formats
Common Mistakes
❌ Mistake: Running non-existent script
✅ Instead: Check first
---
❌ Mistake: Not handling script errors
✅ Instead: Check result
await codemap.scripts.run('utility', 'nonexistent');✅ Instead: Check first
const scripts = await codemap.scripts.list('utility');
if (scripts.some(s => s.name === 'report')) {
await codemap.scripts.run('utility', 'report');
}---
❌ Mistake: Not handling script errors
const result = await codemap.scripts.run('audit', 'validate');
// Assumes success✅ Instead: Check result
const result = await codemap.scripts.run('audit', 'validate');
if (!result.passed) {
console.error('Failed:', result.message);
process.exit(1);
}