Skip to content

Add brew mcp-server: a MCP server for Homebrew.#20041

Merged
MikeMcQuaid merged 1 commit into
masterfrom
mcp_server
Jun 4, 2025
Merged

Add brew mcp-server: a MCP server for Homebrew.#20041
MikeMcQuaid merged 1 commit into
masterfrom
mcp_server

Conversation

@MikeMcQuaid

@MikeMcQuaid MikeMcQuaid commented Jun 3, 2025

Copy link
Copy Markdown
Member

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 clients such as Cursor fail if they don't get a response quickly enough.

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.

@MikeMcQuaid MikeMcQuaid requested a review from Copilot June 3, 2025 10:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new brew mcp-server command that launches a standalone Ruby MCP (Model Context Protocol) server for Homebrew, along with documentation, shell completions, and tests.

  • Introduces the MCP server implementation and its test suite
  • Updates manpages and markdown docs for the new command
  • Adds bash, zsh, and fish completions plus the shell wrapper and command registration in brew.sh

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
manpages/brew.1 Bumped manpage date and added mcp-server entry
docs/Manpage.md Added mcp-server section and --debug flag
completions/zsh/_brew Added _brew_mcp_server function and command list
completions/internal_commands_list.txt Registered mcp-server in internal commands list
completions/fish/brew.fish Added fish completion for mcp-server
completions/bash/brew Added _brew_mcp_server and hook in command case
Library/Homebrew/test/mcp_server_spec.rb New RSpec tests covering MCP server behavior
Library/Homebrew/mcp_server.rb Core MCP server implementation in Ruby
Library/Homebrew/cmd/mcp-server.sh Shell wrapper to invoke the MCP server faster
Library/Homebrew/cmd/mcp-server.rb Homebrew command definition for mcp-server
Library/Homebrew/brew.sh Registered mcp-server in the main brew.sh
Comments suppressed due to low confidence (1)

Library/Homebrew/cmd/mcp-server.sh:13

  • [nitpick] The shell wrapper for mcp-server isn't covered by any integration or unit tests. Adding a test to verify that homebrew-mcp-server is invoked correctly would help prevent regressions in the CLI entry point.
"${HOMEBREW_RUBY_PATH}" "-r${HOMEBREW_LIBRARY}/Homebrew/mcp_server.rb" -e "Homebrew::McpServer.new.run" "$@"

Comment thread Library/Homebrew/mcp_server.rb
@MikeMcQuaid MikeMcQuaid self-assigned this Jun 3, 2025
@MikeMcQuaid MikeMcQuaid force-pushed the mcp_server branch 2 times, most recently from 35041bb to 63a5e15 Compare June 3, 2025 14:18
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.

@Bo98 Bo98 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great

@Rylan12 Rylan12 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

In the future if we want to enable more functionality, I bet we could extract a lot of the tool definitions from the command DSLs

@p-linnane p-linnane left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome!

@MikeMcQuaid

Copy link
Copy Markdown
Member Author

Nice!

In the future if we want to enable more functionality, I bet we could extract a lot of the tool definitions from the command DSLs

@Rylan12 Yeh, I was thinking the same. We'd need to do something like dump it to a JSON and use that, though, because we're so constrained on startup time and because we'd only want to support a subset of commands to not go over the (current) 40 maximum.

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Jun 4, 2025
Merged via the queue into master with commit e825cee Jun 4, 2025
36 checks passed
@MikeMcQuaid MikeMcQuaid deleted the mcp_server branch June 4, 2025 08:07
@Rylan12

Rylan12 commented Jun 4, 2025

Copy link
Copy Markdown
Member

We'd need to do something like dump it to a JSON and use that, though, because we're so constrained on startup time and because we'd only want to support a subset of commands to not go over the (current) 40 maximum.

It would probably be easiest to just work this into the manpage generation since that's doing functionally the same thing, regardless. I think while there's the limit of 40 though, let's just keep it manual. These tools are unlikely to change since only the most basic invocations are really important for now, I think

@agouliel

agouliel commented Jun 9, 2025

Copy link
Copy Markdown

Good job!

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.

6 participants