Skip to content

Add the mcp support and a simple agent loop#206

Closed
WuJunkai2004 wants to merge 3 commits intomadox2:mainfrom
WuJunkai2004:main
Closed

Add the mcp support and a simple agent loop#206
WuJunkai2004 wants to merge 3 commits intomadox2:mainfrom
WuJunkai2004:main

Conversation

@WuJunkai2004
Copy link

Add the mcp support and a simple agent loop.

Add 4 tools for running shell, reading, writing and editing.
Add a simple agent loop. and enabled default. This PR is just a demo, so needs future development.
Add a test script with write by Gemini AI.

Inject tools description into system messages and parse tool calls from
assistant responses using ```tool```/```json``` blocks.
Add MCPManager integration for external tools and a built-in tool_map
for bash/read_file/write_file/edit_file.
Execute tools iteratively, append results as user messages, limit loop
iterations, and call MCPManager shutdown.
Add tests covering write/read/edit/bash and safety checks.
@WuJunkai2004
Copy link
Author

Additionally, there are several parts I don't understand

the re module

The re module hasn't been imported. I noticed and add import re

A strange except caught

# in py/chat.py :290
        except Exception as e:
            with self.lock:
                self.lines.append("")
                self.lines.append(f"<<< error getting response: {str(e)}")
                self.lines.append("")
                self.lines.append("```python")
                self.lines.extend(traceback.format_exc().split("\n"))
                self.lines.append("```")
                try:
                    self.lines.append("")
                    self.lines.append(json.loads(e.read().decode())["error"]["message"])
                except:
                    pass

the e.read() must raise a AttributeError in my python env. Is there a read method on Exception in the vim's python runtime?

>>> Exception("hello").read
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
AttributeError: 'Exception' object has no attribute 'read'

@madox2
Copy link
Owner

madox2 commented Mar 6, 2026

the re module

it does not work like in standard python modules, in vim it loads everything in an execution script. so re module has been imported probably in utils and are still in scope. But I thing importing it also in this file would be a better practice and does not harm anything

A strange except caught

Yes, I think it is handling a specific kind of exception, but it is not documented which one. I would defensively does not touch it until it is not known

@madox2
Copy link
Owner

madox2 commented Mar 6, 2026

@WuJunkai2004 like I explained in the original issue, I am really sorry to close this PR and I apreciate all your effort. If you decide to implement it in a custom provider, I will support you with anything missing in this plugin. Thanks!

@madox2 madox2 closed this Mar 6, 2026
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.

2 participants