Skip to content

feat(extensions): adapt CodeCompanion extension for v19 compatibility#279

Open
bahaaza wants to merge 2 commits into
ravitemer:mainfrom
bahaaza:main
Open

feat(extensions): adapt CodeCompanion extension for v19 compatibility#279
bahaaza wants to merge 2 commits into
ravitemer:mainfrom
bahaaza:main

Conversation

@bahaaza

@bahaaza bahaaza commented Mar 2, 2026

Copy link
Copy Markdown

Summary

Migrate the CodeCompanion extension to support CodeCompanion v19's breaking API changes while maintaining the same user-facing behavior.

Motivation

CodeCompanion v19 introduced several breaking changes to its tool, variable, and image APIs. This PR updates all four CodeCompanion extension modules to work with the new API surface.

Changes

Tool Config Structure (tools.lua)

  • callback = { table }callback = function() return { table } end
  • v19's Tools.resolve() requires callback to be a function, not a table.

Tool cmds Handlers (tools.lua, core.lua)

  • Handler signature: (agent, args, _, output_handler)(self, action, opts)
  • Output callback now accessed via opts.output_cb instead of the 4th positional arg.

Tool Output Handlers (core.lua)

  • Success/error signature: (self, agent, cmd, data)(self, data, meta)
  • Chat object accessed via meta.tools.chat instead of the agent parameter.

Variables → Editor Context (variables.lua)

  • config.interactions.chat.variablesconfig.interactions.chat.editor_context
  • Cleanup logic now uses key prefix (mcp:) instead of the custom id field.
  • Removed unused id field from registrations.

Image Handling (variables.lua, slash_commands.lua)

  • require("codecompanion.interactions.chat.helpers").add_image(chat, img)chat:add_image_message(img)
  • All references to the removed helpers module have been eliminated.

Group System Prompts (tools.lua)

  • system_prompt = function(self)system_prompt = function(group_config, ctx)
  • Updated all three system_prompt functions (static group, individual tools, dynamic server groups).

Files Modified

  • lua/mcphub/extensions/codecompanion/tools.lua
  • lua/mcphub/extensions/codecompanion/core.lua
  • lua/mcphub/extensions/codecompanion/variables.lua
  • lua/mcphub/extensions/codecompanion/slash_commands.lua

Testing

  • All 135 existing tests pass (make test)
  • Code formatted with stylua (make format)
  • No CodeCompanion-specific integration tests exist in the repo currently; changes were verified by tracing the v19 source code for each API contract.

Migrate the CodeCompanion extension to support CodeCompanion v19's
breaking API changes while maintaining the same user-facing behavior.

Changes:
- Tool config: callback = { table } → callback = function() return table end
- Tool cmds handler: (agent, args, _, output_handler) → (self, action, opts)
- Tool output handler: (self, agent, cmd, data) → (self, data, meta)
- Variables → Editor Context: config.interactions.chat.variables →
  config.interactions.chat.editor_context
- Image handling: helpers.add_image() → Chat:add_image_message()
- Group system_prompt: function(self) → function(group_config, ctx)

Files modified:
- lua/mcphub/extensions/codecompanion/tools.lua
- lua/mcphub/extensions/codecompanion/core.lua
- lua/mcphub/extensions/codecompanion/variables.lua
- lua/mcphub/extensions/codecompanion/slash_commands.lua
@powerman

powerman commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Works for me, thanks!

@NarongOk

NarongOk commented Mar 5, 2026

Copy link
Copy Markdown

Would like to see this merged!!!

@EvgeniyRRU

Copy link
Copy Markdown

Yes, we're really looking forward to seeing it happen.

@HendrikPetertje

Copy link
Copy Markdown

Can this be merged pretty please @ravitemer?

@zelch

zelch commented Mar 18, 2026

Copy link
Copy Markdown

I can confirm that this seems to work pretty well on my system.

Comment thread lua/mcphub/extensions/codecompanion/variables.lua Outdated
Co-authored-by: Carlos Galan Cladera <cgcladera@gmail.com>
@augustocdias

augustocdias commented Mar 19, 2026

Copy link
Copy Markdown

The maintainer isn't active on github for quite a while already... Perhaps its time to consider a fork to keep the project going :/

@bahaaza

bahaaza commented Mar 19, 2026

Copy link
Copy Markdown
Author

Well, you can use my fork for the meanwhile, I'll be using mcphub for a while, codecompanion has built in support for mcps but its not as mature as mcphub.

@zelch

zelch commented Mar 20, 2026

Copy link
Copy Markdown

@bahaaza I don't suppose you have any interest in forking the mcp-hub server as well?

Locally I updated the @modelcontextprotocol/sdk dependency to something a bit more current, and oauth support works a ton better.

(I'd do it myself, but there's an annoying amount of paperwork involved with my employer, and bumping the dependency is really the only change.)

@LyndonArmitage

LyndonArmitage commented Mar 20, 2026

Copy link
Copy Markdown

The maintainer isn't active on github for quite a while already... Perhaps its time to consider a fork to keep the project going :/

Not a bad idea.

In the meantime, @powerman on an issue highlighted how you can use the lazy-local-patcher.nvim plugin, if you're using Lazy, to apply a patch while waiting for something to be merged.

For me this was as simple as adding the file lua/plugins/lazy-local-patcher.lua to my NeoVim config directory containing:

return {
    "polirritmico/lazy-local-patcher.nvim",
    config = true,
    ft = "lazy", -- for lazy loading
}

And then adding a patch file to patches/mcphub.nvim/ within my NeoVim configuration folder containing a patch for this issue, which you can get via appending .patch to the URL: https://github.com/ravitemer/mcphub.nvim/pull/279.patch

hhank added a commit to hhank/mcphub.nvim that referenced this pull request Mar 21, 2026
@jamietanna

Copy link
Copy Markdown

Alternatively:

# via https://www.jvt.me/posts/2019/01/19/git-ref-github-pull-requests/
# in the directory that you have `mcphub.nvim` checked out
git config remote.origin.fetch '+refs/pull/*:refs/remotes/origin/pull/*'

Then:

return {
  "ravitemer/mcphub.nvim",
  branch = "pull/279/merge"
}

@jingyi-zhao-01

Copy link
Copy Markdown

when can this PR be merged

hallelujah added a commit to hallelujah/dotfiles that referenced this pull request Apr 18, 2026
@HendrikPetertje

Copy link
Copy Markdown

Hate to ask this and huge respect to the developer for investing their time in making this excellent plugin.
It's super quiet in this repo and without the above in mcphub doesn't really work in codecompanion on any recent versions.

@ravitemer do you need help maintaining this plugin?

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.