mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00

Add a new `brew mcp-server` command for a Model Context Protocol (MCP) server for Homebrew. This integrates with AI/LLM tools like Claude, Claude Code and Cursor. It currently supports the calls needed/used by the MCP Inspector and Cursor (where I've tested it). It provides as `tools` the subcommands output by `brew help` but should be fairly straightforward to add more in future. It is implemented in a slightly strange way (a standalone Ruby command called from a shell command) as MCP servers need a faster startup time than a normal Homebrew Ruby command allows and fail if they don't get it. There are a few Ruby libraries available but, given how relatively simplistic the implementation is, it didn't feel worthwhile to use and vendor them.
24 lines
668 B
Ruby
24 lines
668 B
Ruby
# typed: strong
|
|
# frozen_string_literal: true
|
|
|
|
require "abstract_command"
|
|
require "shell_command"
|
|
|
|
module Homebrew
|
|
module Cmd
|
|
class McpServerCmd < AbstractCommand
|
|
# This is a shell command as MCP servers need a faster startup time
|
|
# than a normal Homebrew Ruby command allows.
|
|
include ShellCommand
|
|
|
|
cmd_args do
|
|
description <<~EOS
|
|
Starts the Homebrew MCP (Model Context Protocol) server.
|
|
EOS
|
|
switch "-d", "--debug", description: "Enable debug logging to stderr."
|
|
switch "--ping", description: "Start the server, act as if receiving a ping and then exit.", hidden: true
|
|
end
|
|
end
|
|
end
|
|
end
|