Commit Graph

2 Commits

Author SHA1 Message Date
code4me2 abcb81bb07 cmd: add --tools flag for MCP server integration
Integrate MCP servers with the ollama CLI and add route handlers for
tool-enabled chat completions.

CLI (cmd/cmd.go):
- Add --tools flag to 'ollama run' command
- Supports path argument: --tools /path/to/directory
- Multi-round tool execution loop with result display
- Displays available tools on startup

Routes (server/routes.go, server/routes_tools.go):
- MCP server handling in chat completions
- /api/tools endpoint for tool listing
- Session-based MCP manager lifecycle
- Detailed documentation of MCP integration flow

Parser (harmony/harmonyparser.go):
- Handle embedded <think> segments in tool call responses
- Extract tool calls from thinking model outputs

Relates to #7865
2025-12-28 15:06:47 -08:00
code4me2 fc05536d52 server: add MCP security layer for command validation
Add security infrastructure to validate and restrict MCP server commands
before execution.

MCPValidator (server/mcp_validator.go):
- Command allowlist/blocklist validation
- Argument sanitization (blocks shell metacharacters)
- Environment variable name validation
- Per-server security policy enforcement

MCPSecurityConfig (server/mcp_security_config.go):
- Configurable security rules per server
- Default blocklist: bash, sh, sudo, rm, curl, wget, eval
- Blocked metacharacters: ; | & $( ` > < = etc.
- SECURITY REVIEW markers for critical sections

MCPCommandResolver (server/mcp_command_resolver.go):
- Resolves command paths across different environments
- npx/npm detection and path resolution

MCPCodeAPI (server/mcp_code_api.go):
- Programmatic API for MCP server management

Relates to #7865
2025-12-28 15:06:47 -08:00