-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add MCP Support with LiteLLM #3937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
f52ddb9
to
10ea9ba
Compare
I've been testing this PR, and overall it seems to be working quite well. Great job on this! However, while testing, I encountered an error message:
I'm not entirely sure if this is expected behavior for this specific configuration, or if I might have missed something in the setup? Additionally, I was also wondering about the feasibility of running aider itself within a container, and using containerized mcpServers. |
@imunique-ZJ Thank you for giving this a spin! 😄 I tested your config outside of a docker container. I was able to start and connect to the server. It sounds like you're running the project in a Docker container which might be the problem. When using the MCP SDK's STDIO transport, Aider is responsible for starting and stopping the server processes. This means Aider has to have access to the executables and dependencies needed to start the server (in this case the docker process). So if you're running Aider inside of a Docker container and want to use MCP tools started with Docker you will have to configure some "Docker-in-Docker" solution. I think this might be beyond the scope of this PR though. |
Thanks for the detailed explanation and for testing this out! I also tested outside of a container environment, and I did occasionally encounter the same error. However, it didn't seem to affect the core functionality, and I was still able to get the expected results. So, it's not a blocking issue for me. 👍 Regarding the Docker-in-Docker or Podman-in-Podman approach, since it would be outside the scope of this particular PR, so I won't go into further discussion here. Thanks again. |
f979394
to
44b385c
Compare
44b385c
to
282b349
Compare
I updated the implementation to allow partial (or total) failure when initializing MCP servers. Even if a user's configured MCP servers fail to initialize we should allow the user to continue using Aider but let them know something has gone wrong. Partial FailureTotal FailureMultiple Total Failures |
I apologize if I'm missing something obvious, but have you been able to test this using local LLMs? If so, could you describe your setup please? I tried using Qwen3 30B-A3B (which has good agentic support) with both Llama.cpp (using --jinga in LCPP and stream=false in Aider since streaming isn't supported) and also with Ollama, wasn't having success. I quite possibly have something set up incorrectly. With Llama.cpp, Qwen3-30B-A3B,
Testing with:
It looks like it's attempting to send a tool_call for But Aider tells me For completeness, without the
Using Ollama with
I still see:
But |
fyi @ishaan-jaff & @krrishdholakia i think you might think this is cool. aider is a perfect test bed to put the litellm mcp bridge to work! |
Looks great, let us know if there's any way we can improve the litellm mcp bridge |
@strawberrymelonpanda I ran into the same problem. I looked at the LiteLLM repo and there seems to be an issue tool calling with Ollama models (BerriAI/litellm#7570). I'm not 100% sure this is the exact problem that is happening behind the scenes, but it does look like the tools are being passed to the completion. So it is feeling like this might be related. I was also able to get tool calling working with Ollama with these settings based on this suggestion: env OPENAI_API_BASE=<ollama-base-url>/v1 aider --model openai/<ollama-model> This option does appear to have some limitations though so YMMV. |
@quinlanjager Thanks for the pointers, that indeed got it moving. For anyone following along, I changed my
A few notes:
@ishaan-jaff, since you're in the thread, any ideas what's happening here? Is the Llama.CPP tool-use
It's probably worth trying to find a way to suppress this message.
Everything worked and there's a new commit as expected, but as a user without always-yes flags set, I'd really want the opportunity to review the MCP tool calls before they're executed. MCP is a must-have for Aider so thanks for this! |
Some other thoughts: I'll also mention that I'd love some new / commands specific to MCP if it's at all possible. /tools - Probably the same list a user gets at startup with the --verbose flag set:
/servers - Add or disable MCP servers on the fly once Aider is started? Finally, granular MCP endpoint support at a config level, as some MCP clients have. Mostly just nice-to-haves and food for thought. |
@strawberrymelonpanda Thanks for the feedback. I think you're right that respecting the As for the warning message, this is happening because some models return "None" content with a tool call (rather than a string like "I'll use tools to find this out for you"). It makes sense to skip this warning if there are tool calls. I'll update my PR to include this. I feel additional Aider commands are beyond the scope of this PR (I think these would be good features to include in a follow up though). I want to focus this PR on the fundamental configuration and execution of MCP tools. Anything building on top of this platform, I'd prefer to leave for follow ups as they benefit from their own discussions. Though these are great suggestions. I actually really like granular tool config. |
@strawberrymelonpanda I pushed confirmation support and removed that warning message if there are tool calls. Here's a screenshot with both features. |
The warning is gone and the confirmation is nice, however I wonder if it has somehow decreased performance? I noticed in your screenshot you say "Use your tools." I too had to say "use tools" otherwise it would not, where as it did automatically previously. I tried a sample prompt I used yesterday, "Review changes and make single-task commits." First it just told me it needed access to the files. Then with "use tools" added to the prompt, after asking for git status permission, it stopped with a long thinking that included:
It was on the right track but now seems to hesitate to continue, where as yesterday it scanned the repo, added the file, and made the commit in one go. Ideally, it'd work the same unless I give it a "no" response to a permission request. |
Perhaps the changes in this recent commit have caused the behavior changes. |
@strawberrymelonpanda Good find... I removed final_reminders and the LLM seems to more keen to use tools. I'll look at tweaking that prompt to encourage tool use. |
- Add tool_prompt to CoderPrompts class - Modify fmt_system_prompt to include tool prompt when MCP tools are available - This enables better handling of tool-based interactions when using MCP servers
@quinlanjager Yep, seems improved I think. A quick test still needed a hint to use tools, which is fine, and then it followed up by using multiple tools as needed. I think it used a few in a strange order, but that's probably down to local model performance issues. The core concept seemed correct. For what it's worth just so it doesn't get lost in the feedback, I really appreciate these changes and think Aider can strongly benefit. I would absolutely recommend this be merged in ASAP so more people can test and use it, and I think this approach makes sense to outsource much of the complexity to LiteLLM. @paul-gauthier What are your thoughts on this approach? |
I've tried this PR and it works quite well. Hope this will be merged soon. |
Hey aider admins, can we get a merge on this? |
Patiently waiting for this. In our codebase, we use code generators and keep a local MD files with our docs. Unfortunately, given the size and non-standard nature of our targets, llms often fall short of simple tasks that require new packages because the context needed to get it right is too large. The ability to rag our docs would also be a game changer in enabling junior devs to traverse the codebase with aider better. MCP support will soon become a deal-breaker for using aider, especially given cursor, etc already support it for quite some time. Please don't let open source stay behind! @paul-gauthier |
I think this change causes the error 67595d2#diff-9f52ef5aacb0c6fd78d0deeb48adfca1ba2d6c9ac09183b314536dfa9b085f1eR897 |
Sadly, it already has for me. I've been using Roocode more often, but I'm watching this PR with interest. |
Yes, this merge into the pull request removes the tools=None from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tools=None seems to be mistakenly removed from send_completion function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix this today. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now.
Thx @quinlanjager for this. It makes sense to keep this a bit minimal when aiming for a merge but some behaviors are a bit clunky for daily use. I attempted to improve some aspects in that regard but I'm not a python dev, so aider wrote almost everything. https://github.com/arosov/aider/tree/mcp Keeping this in my fork for now, feel free to PR or issues if necessary. EDIT: Forgot to show TUI change on tool call Just pushed:
|
Overview
Related: #2525
This PR integrates Model Control Protocol (MCP) servers with Aider using LiteLLM's MCP bridge implementation. Server tools are provided to theunderlying model by Coder so all Coders will have access to them.
Configuration follows the standard MCP Server Configuration JSON schema used by Claude and Cursor. All server operations are ran on the main thread with coroutines. Coders will execute requests to multiple servers concurrently.
Configuration
MCP servers can be configured in multiple ways:
Command Line: Directly specify server configurations as a JSON string:
aider --mcp-servers '{"mcpServers":{"git":{"command":"uvx","args":["mcp-server-git"]}}}'
Config File: Use a separate JSON configuration file:
YAML Config: Add to your
.aider.conf.yml
:Implementation Details
The integration leverages LiteLLM's experimental_mcp_client module to load tools from configured servers and provide them to OpenAI compatible models.
The McpServer class is used to manage stdio transport connections via the Python MCP SDK.
The Coder class has been extended to initialize and use MCP tools, process tool calls in streaming responses, and execute tools concurrently across multiple servers. While generating a single reply, at most 25 tool calls can be made.
Limitations
Currently stdio is the only supported server transport. This was a scoping decision. The Python MCP SDK has an SSE server transport so implementation should be possible if desired.
It would be nice if we maintained persistent server connections throughout Aider's runtime. Currently, connections only exist for the duration of each request. I've been using this quite a bit and it is reasonably fast but I admit it is not ideal. Implementing context management at the top level using the
with
statement would provide a more efficient approach to connection handling.