Skip to content

Conversation

Copy link

Copilot AI commented Dec 5, 2025

The --mcp flag only enabled MCP mode, requiring users to modify config.yaml to change the listening port.

Changes

  • Flag type: Changed --mcp to support optional values using custom flag implementation
  • Optional value support: --mcp alone uses config.yaml default port (backward compatible)
  • Formats supported:
    • --mcp uses config.yaml default (e.g., port 8080)
    • --mcp=:8080 specifies custom port (short format, auto-expands to http://localhost:8080)
    • --mcp=http://localhost:8080 specifies full URL
    • --mcp=http://0.0.0.0:8080 specifies custom host with port
  • Implementation: Custom mcpFlag type implementing IsBoolFlag() interface for optional value behavior
  • Field additions: Added MCPServerSet field to track if flag was explicitly set
  • Priority: Command-line parameter overrides config.yaml when specified

Usage

# Use config.yaml default port (NEW - addresses feedback)
./enscan --mcp

# Custom port with short format (requires = syntax)
./enscan --mcp=:9999

# Full URL with custom host (requires = syntax)
./enscan --mcp=http://0.0.0.0:8080

# Omit flag entirely to use normal mode
./enscan -n 小米

The implementation uses strings.HasPrefix for safe string handling, validates addresses through the existing utils.ExtractPortString function, and implements Go's IsBoolFlag() interface to support optional values.

Testing

  • --mcp without value uses config.yaml default port
  • --mcp=:PORT custom port format works correctly
  • --mcp=http://... full URL format works correctly
  • ✅ All comprehensive integration tests pass
  • ✅ Code review feedback addressed
  • ✅ Security scan: 0 vulnerabilities found
Original prompt

This section details on the original issue you should resolve

<issue_title>可以在--mcp地方加个参数指定监听到某个端口吗</issue_title>
<issue_description>可以在--mcp地方加个参数指定监听到某个端口吗</issue_description>

<agent_instructions>mcp参数支持自定义</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 5, 2025 08:17
- Change --mcp from boolean to string flag
- Support formats: :8080, http://localhost:8080
- Falls back to config.yaml if not specified
- Update all IsMCPServer references to MCPServer string check

Co-authored-by: keac <[email protected]>
- Use strings.HasPrefix instead of index check for safety
- Organize imports for better readability

Co-authored-by: keac <[email protected]>
Copilot AI changed the title [WIP] Add parameter to specify port for mcp listener Add custom port/address parameter to --mcp flag Dec 5, 2025
Copilot AI requested a review from keac December 5, 2025 08:22
Copy link
Member

@keac keac left a comment

Choose a reason for hiding this comment

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

未配置端口号情况下指定默认端口

Copilot AI and others added 2 commits December 5, 2025 08:48
- Implement custom mcpFlag type with IsBoolFlag() support
- Allow --mcp (uses config.yaml default) or --mcp=:8080 (custom port)
- Add MCPServerSet field to track if flag was explicitly set
- Update all MCP server checks to use MCPServerSet flag

Co-authored-by: keac <[email protected]>
- Add detailed comment explaining IsBoolFlag behavior
- Update help text with specific usage examples
- Address code review feedback

Co-authored-by: keac <[email protected]>
Copy link
Author

Copilot AI commented Dec 5, 2025

未配置端口号情况下指定默认端口

已实现。现在 --mcp 单独使用时会使用配置文件中的默认端口(如 http://localhost:8080),也可以通过 --mcp=:8080--mcp=http://localhost:9999 指定自定义端口。

实现于提交 60ae37945c2fc9

用法示例:

  • ./enscan --mcp - 使用配置文件默认值
  • ./enscan --mcp=:9999 - 使用自定义端口 9999
  • ./enscan --mcp=http://0.0.0.0:8080 - 使用完整地址

Copilot AI changed the title Add custom port/address parameter to --mcp flag Add custom port/address parameter to --mcp flag with optional value support Dec 5, 2025
Copilot AI requested a review from keac December 5, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

可以在--mcp地方加个参数指定监听到某个端口吗

2 participants