Skip to content

Conversation

@namar0x0309
Copy link
Collaborator

@namar0x0309 namar0x0309 commented Dec 16, 2025

Description

This PR adds configuration-based auto-approval for tools and improves non-interactive mode behavior. Users can now specify which MCP server tools and nanocoder tools should automatically run without requiring confirmation, streamlining trusted workflows while maintaining security.

Key Features:

Per-tool auto-approval via alwaysAllow configuration for both MCP servers and nanocoder tools
Non-interactive mode early-exit when tools requiring approval are encountered
Graceful error handling with clear messaging when approval would be required

Implementation Details

• Added alwaysAllow field to MCP server configuration schema (array of tool names)
• Added alwaysAllow field to nanocoderTools configuration (array of nanocoder tool names)
• Modified tool approval logic in conversation loop to check alwaysAllow lists before requiring confirmation
• Implemented non-interactive mode detection via --run flag
• Added early-exit behavior in non-interactive mode when non-approved tools are encountered
• Updated configuration validation to ensure alwaysAllow is an array of strings
• Configuration examples added to agents.config.example.json

Security Considerations

• Opt-in by design: No tools are auto-approved by default
• Users must explicitly list tool names in alwaysAllow arrays
• High-risk operations can be excluded from auto-approval lists
• Existing approval mechanisms remain unchanged for non-configured tools
• Clear documentation on security implications in MCP configuration guide
• Bash tool respects alwaysAllow configuration but users can choose to exclude it

Breaking Changes

• None - this is an additive feature that maintains backward compatibility
• All new configuration fields (alwaysAllow) are optional
• Existing configurations continue to work without modifications

Testing

• Added unit tests for alwaysAllow configuration validation
• Tests verify array validation (must be array of strings)
• Tests cover non-interactive mode early-exit scenarios
• Verified backward compatibility with existing configurations
• Manual testing with filesystem and GitHub MCP servers
• Tested both approved and non-approved tool scenarios

Documentation Updates

• Updated mcp-configuration.md with alwaysAllow field documentation
• Added configuration examples for common use cases
• Updated agents.config.example.json with example alwaysAllow configurations for MCP servers
• Added nanocoderTools.alwaysAllow example configuration
• Configuration validation updated to handle new optional fields

This feature significantly improves the developer experience for trusted and automated workflows (CI/CD, local development with trusted tools) while maintaining nanocoder's security-first approach.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

@spinualexandru
Copy link
Collaborator

just saw it's a draft, sowwee :D

@namar0x0309
Copy link
Collaborator Author

just saw it's a draft, sowwee :D

still helpful! Thank You

@Avtrkrb Avtrkrb added enhancement New feature or request Feature labels Dec 21, 2025
@namar0x0309
Copy link
Collaborator Author

I reimplement/rebased given the many changes since I last started this draft pr.

@will-lamerton
Copy link
Member

I reimplement/rebased given the many changes since I last started this draft pr.

Looks great! I have some time Boxing Day morning tomorrow to sort out outstanding pull requests so will take a look then 😄

Merry Christmas 🎄🎄

@namar0x0309 namar0x0309 marked this pull request as ready for review December 27, 2025 22:55
Copilot AI review requested due to automatic review settings December 27, 2025 22:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds configuration-based auto-approval for MCP server tools and nanocoder tools, along with improved non-interactive mode behavior. Users can configure which tools should automatically execute without requiring user confirmation through alwaysAllow configuration arrays.

Key changes:

  • Added alwaysAllow configuration field to MCP server configurations and nanocoderTools configuration
  • Modified tool approval logic in nanocoder tools (write_file, string_replace, execute_bash) and MCP client to check alwaysAllow lists
  • Introduced non-interactive mode early-exit behavior when non-approved tools are encountered (though implementation has critical bugs)

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
source/wizard/validation.ts Added validation for MCP server alwaysAllow field to ensure it's an array of strings
source/wizard/validation.spec.ts Added tests for alwaysAllow validation (non-array and non-string items)
source/wizard/validation-array.spec.ts Added test data with alwaysAllow examples
source/wizard/templates/mcp-templates.ts Added alwaysAllow field to MCP server config interface
source/types/mcp.ts Added alwaysAllow field with documentation to MCPServer type
source/types/config.ts Added alwaysAllow and nanocoderTools.alwaysAllow fields to AppConfig
source/tools/write-file.tsx Modified needsApproval to check nanocoder tools config
source/tools/string-replace.tsx Modified needsApproval to check nanocoder tools config
source/tools/execute-bash.tsx Modified needsApproval from boolean to function that checks config
source/mcp/mcp-client.ts Added isToolAutoApproved method and integrated it into tool approval logic
source/mcp/mcp-client.spec.ts Added tests for auto-approval behavior
source/hooks/chat-handler/conversation/conversation-loop.tsx Added non-interactive mode allow-list logic (contains critical bugs)
source/config/nanocoder-tools-config.ts New helper function to check if nanocoder tools are auto-approved
source/config/index.ts Added loading of alwaysAllow and nanocoderTools configuration fields
source/commands/mcp.tsx Added display of auto-approved tools in MCP command output
docs/mcp-configuration.md Added documentation for alwaysAllow field
agents.config.example.json Added example configurations with alwaysAllow fields

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@will-lamerton
Copy link
Member

Hey @namar0x0309 - we have done an awful lot of work on the main branch, I think we're ready to proceed with plans we spoke about before the big winter clean up including this :D

… tools

Add support for configuring automatic approval of specific MCP tools through the `alwaysAllow` property in server configurations. This allows certain trusted tools to execute without requiring user confirmation prompts.

- Update configuration schema to include `alwaysAllow` arrays
- Modify MCP client to respect auto-approval settings
- Add documentation for the new configuration option
- Include UI indication of auto-approved tools
- Add test coverage for approval behavior
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

]
],
"nanocoderTools": {
"alwaysAllow": ["execute_bash"]
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using execute_bash in the alwaysAllow configuration is a high-risk security practice. While this is just an example file, consider:

  1. Using a less risky tool as the example (like write_file or string_replace)
  2. Adding a comment warning about the security implications of auto-allowing bash execution
  3. Documenting that users should carefully consider which tools to auto-approve

This would better demonstrate secure configuration practices and prevent users from blindly copying a potentially dangerous setting.

Suggested change
"alwaysAllow": ["execute_bash"]
"_comment": "Example configuration: auto-approving powerful tools (especially shell execution like `execute_bash`) can be dangerous. Carefully review which tools, if any, you add to alwaysAllow in your real configuration.",
"alwaysAllow": ["write_file"]

Copilot uses AI. Check for mistakes.
Comment on lines +65 to 81
if (server.alwaysAllow && !Array.isArray(server.alwaysAllow)) {
errors.push(
`MCP server "${name}" has invalid alwaysAllow (must be an array of strings)`,
);
}

if (Array.isArray(server.alwaysAllow)) {
const invalidItems = server.alwaysAllow.filter(
item => typeof item !== 'string',
);
if (invalidItems.length > 0) {
errors.push(
`MCP server "${name}" has non-string entries in alwaysAllow`,
);
}
}
}
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation only checks alwaysAllow for MCP servers but does not validate the top-level alwaysAllow or nanocoderTools.alwaysAllow configurations. Consider adding validation to ensure:

  1. Both fields are arrays of strings (if present)
  2. The tool names in these arrays correspond to actual available tools
  3. Users receive helpful error messages if they configure non-existent tool names

This would improve the user experience and catch configuration errors early.

Copilot uses AI. Check for mistakes.
Comment on lines 74 to 82
needsApproval: () => {
// Check if this tool is configured to always be allowed
if (isNanocoderToolAlwaysAllowed('write_file')) {
return false;
}

const mode = getCurrentMode();
return mode !== 'auto-accept'; // true in normal/plan, false in auto-accept
},
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes add isNanocoderToolAlwaysAllowed checks to bypass approval, but there are no tests verifying this new functionality. Consider adding tests to source/tools/needs-approval.spec.ts or a dedicated test file that verify:

  1. Tools in nanocoderTools.alwaysAllow skip approval even in normal mode
  2. Tools not in the list still require approval as expected
  3. Invalid configuration (non-array, non-strings) is handled gracefully

This would ensure the security-critical auto-approval feature works correctly across different scenarios.

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +62
],
"nanocoderTools": {
"alwaysAllow": ["execute_bash"]
}
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new top-level alwaysAllow field lacks documentation. This configuration is used specifically for non-interactive mode (--run flag) tool execution and serves a different purpose than nanocoderTools.alwaysAllow. Consider:

  1. Adding a comment in the example configuration explaining what this field does
  2. Creating or updating documentation to explain when to use top-level alwaysAllow vs nanocoderTools.alwaysAllow
  3. Clarifying that this is specifically for non-interactive mode tool approval

Without clear documentation, users may be confused about:

  • Why there are two similar alwaysAllow configurations
  • When to use each one
  • How they interact with each other

Copilot uses AI. Check for mistakes.
Copy link
Member

@will-lamerton will-lamerton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @namar0x0309 - looking great from my point of view! Couple points:

  • Are you able to address the co-pilot review points and ensure all test files related to changes are updated?
  • Are you able to document functionality for users in the README?

This is a great addition :D

@namar0x0309
Copy link
Collaborator Author

Hey @namar0x0309 - looking great from my point of view! Couple points:

* Are you able to address the co-pilot review points and ensure all test files related to changes are updated?

* Are you able to document functionality for users in the README?

This is a great addition :D

Thanks! Tackling this today!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants