nvim-mcp-server 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/README.md +25 -3
- data/exe/nvim-mcp-server +1 -1
- data/lib/nvim-mcp-server/tools/update_buffer_tool.rb +114 -0
- data/lib/nvim-mcp-server/version.rb +1 -1
- data/lib/nvim_mcp_server.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acdfba1e3fa12dbc46655893c542c90e616e5524ba340dd45dea65d16eda2ede
|
4
|
+
data.tar.gz: ebf73d6c98f0fd5c755020607b3015492a17b4551de04268b91ff7ca5e28859b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d0533967f34381dab20aa02fc59eacae836cb3480ee99ac0ac88801ab720eb5b7d43f7d19ef472599abe9882e876730b796783e7c3a04577c487a0ada38b3a3
|
7
|
+
data.tar.gz: 89fa8935a7965fed00f27b308603b947f4e47ee74844a31d2ed96a4d96b64f3f08c8204c9d39e0f6eebb3fb2b6f692512a5db8afa5c94e0c661c38c782484ef1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,34 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
1
8
|
## [Unreleased]
|
2
9
|
|
10
|
+
## [0.2.0] - 2025-07-08
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- New `update_buffer` tool that allows MCP clients to update buffer content in Neovim
|
15
|
+
- Ability to save updated buffers to disk and reload them automatically
|
16
|
+
- Support for external tools (like AI assistants) to modify files open in Neovim
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- Updated tool registration to include both `GetProjectBuffersTool` and `UpdateBufferTool`
|
21
|
+
|
3
22
|
## [0.1.0] - 2025-05-17
|
4
23
|
|
24
|
+
### Added
|
25
|
+
|
5
26
|
- Initial release
|
27
|
+
- Basic MCP server implementation for Neovim
|
28
|
+
- Support for both STDIO and HTTP modes
|
29
|
+
- `get_project_buffers` tool to query open buffers in Neovim instances
|
30
|
+
- Integration with Claude Desktop
|
31
|
+
- Logging functionality with configurable log levels
|
32
|
+
- XDG Base Directory Specification compliance for configuration files
|
33
|
+
- Support for multiple Neovim instances via Unix sockets
|
34
|
+
- MCP Inspector compatibility for testing and debugging
|
data/README.md
CHANGED
@@ -12,6 +12,7 @@ This Neovim MCP Server implements the MCP specification to give AI models access
|
|
12
12
|
|
13
13
|
- Connect to running Neovim instances
|
14
14
|
- Query buffers across multiple Neovim sessions
|
15
|
+
- Update and save buffers with new content
|
15
16
|
- Follow the Model Context Protocol standard
|
16
17
|
- Seamless integration with LLM clients
|
17
18
|
|
@@ -30,7 +31,6 @@ After installation, the `nvim-mcp-server` executable will be available in your P
|
|
30
31
|
The Neovim MCP Server follows the XDG Base Directory Specification for configuration files:
|
31
32
|
|
32
33
|
- On macOS: `$XDG_CONFIG_HOME/nvim-mcp` or `~/.config/nvim-mcp` if XDG_CONFIG_HOME is not set
|
33
|
-
- On Linux: `$XDG_CONFIG_HOME/nvim-mcp` or `~/.config/nvim-mcp` if XDG_CONFIG_HOME is not set
|
34
34
|
- On Windows: `%APPDATA%\nvim-mcp`
|
35
35
|
|
36
36
|
The server will automatically create these directories and a log file the first time it runs.
|
@@ -77,12 +77,10 @@ The Neovim MCP Server can be used with Claude Desktop by manually configuring th
|
|
77
77
|
|
78
78
|
1. Create the appropriate config directory for your platform:
|
79
79
|
- macOS: `$XDG_CONFIG_HOME/nvim-mcp` or `~/.config/nvim-mcp` if XDG_CONFIG_HOME is not set
|
80
|
-
- Linux: `$XDG_CONFIG_HOME/nvim-mcp` or `~/.config/nvim-mcp` if XDG_CONFIG_HOME is not set
|
81
80
|
- Windows: `%APPDATA%\nvim-mcp`
|
82
81
|
|
83
82
|
2. Find or create the Claude Desktop configuration file:
|
84
83
|
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
85
|
-
- Linux: `~/.config/Claude/claude_desktop_config.json`
|
86
84
|
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
87
85
|
|
88
86
|
3. Add or update the MCP server configuration:
|
@@ -198,6 +196,30 @@ I'd like to know what files I'm currently working on in the "blog" project.
|
|
198
196
|
List all the buffers for the "nvim-mcp-server" project.
|
199
197
|
```
|
200
198
|
|
199
|
+
### 2. `update_buffer`
|
200
|
+
|
201
|
+
**Description:** Updates a buffer with new content provided by the MCP client, saves it to disk, and reloads it. This tool connects to a running Neovim instance, replaces the entire buffer content with the provided content, writes it to disk, and then reloads the buffer. This is useful for applying external changes (like from an AI assistant) to files open in Neovim.
|
202
|
+
|
203
|
+
**Parameters:**
|
204
|
+
|
205
|
+
- `project_name`: (String, required) The name of the project directory. This is used to locate the Neovim socket at /tmp/nvim-{project_name}.sock.
|
206
|
+
- `file_path`: (String, required) The absolute or relative file path of the buffer to update. This should match the path as shown in Neovim's buffer list.
|
207
|
+
- `content`: (String, required) The new content to write to the buffer. This will replace the entire current content of the buffer.
|
208
|
+
|
209
|
+
#### Examples
|
210
|
+
|
211
|
+
```
|
212
|
+
Please update the file "src/main.rb" in my "my-project" Neovim instance with the refactored code.
|
213
|
+
```
|
214
|
+
|
215
|
+
```
|
216
|
+
Replace the content of "/home/user/projects/blog/app/controllers/posts_controller.rb" in the "blog" project with the updated controller code.
|
217
|
+
```
|
218
|
+
|
219
|
+
```
|
220
|
+
Update the README.md file in the "nvim-mcp-server" project with the new documentation.
|
221
|
+
```
|
222
|
+
|
201
223
|
## Testing and Debugging
|
202
224
|
|
203
225
|
The easiest way to test and debug the Neovim MCP Server is by using the MCP Inspector, a developer tool designed specifically for testing and debugging MCP servers.
|
data/exe/nvim-mcp-server
CHANGED
@@ -75,7 +75,7 @@ NvimMcpServer.log(:info, "Starting Neovim MCP Server in #{mode} mode...")
|
|
75
75
|
|
76
76
|
# Create tools configuration for both modes
|
77
77
|
def setup_mcp_tools(server)
|
78
|
-
server.register_tools(NvimMcpServer::GetProjectBuffersTool)
|
78
|
+
server.register_tools(NvimMcpServer::GetProjectBuffersTool, NvimMcpServer::UpdateBufferTool)
|
79
79
|
end
|
80
80
|
|
81
81
|
case mode
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module NvimMcpServer
|
2
|
+
class UpdateBufferTool < BaseTool
|
3
|
+
tool_name "update_buffer"
|
4
|
+
|
5
|
+
description "Updates a buffer with new content provided by the MCP client, saves it to disk, and reloads it. This tool connects to a running Neovim instance, replaces the entire buffer content with the provided content, writes it to disk, and then reloads the buffer. This is useful for applying external changes (like from an AI assistant) to files open in Neovim."
|
6
|
+
|
7
|
+
arguments do
|
8
|
+
required(:project_name).filled(:string).description("The name of the project directory. This is used to locate the Neovim socket at /tmp/nvim-{project_name}.sock.")
|
9
|
+
required(:file_path).filled(:string).description("The absolute or relative file path of the buffer to update. This should match the path as shown in Neovim's buffer list.")
|
10
|
+
required(:content).filled(:string).description("The new content to write to the buffer. This will replace the entire current content of the buffer.")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(project_name:, file_path:, content:)
|
14
|
+
socket_path = "/tmp/nvim-#{project_name}.sock"
|
15
|
+
log(:info, "Updating buffer #{file_path} for project #{project_name} using socket #{socket_path}")
|
16
|
+
|
17
|
+
result = {
|
18
|
+
status: "success",
|
19
|
+
project_name: project_name,
|
20
|
+
socket_path: socket_path,
|
21
|
+
file_path: file_path,
|
22
|
+
updated: false,
|
23
|
+
saved: false,
|
24
|
+
reloaded: false
|
25
|
+
}
|
26
|
+
|
27
|
+
begin
|
28
|
+
# Check if socket exists
|
29
|
+
unless File.exist?(socket_path)
|
30
|
+
result[:status] = "error"
|
31
|
+
result[:message] = "Neovim socket not found: #{socket_path}"
|
32
|
+
return result
|
33
|
+
end
|
34
|
+
|
35
|
+
# Connect to Neovim
|
36
|
+
client = Neovim.attach_unix(socket_path)
|
37
|
+
|
38
|
+
# Get all buffers to find the one with the specified file
|
39
|
+
all_buffers = client.list_bufs
|
40
|
+
target_buffer = nil
|
41
|
+
|
42
|
+
all_buffers.each do |buffer|
|
43
|
+
buffer_name = buffer.name
|
44
|
+
|
45
|
+
# Skip unnamed buffers
|
46
|
+
next if buffer_name.nil? || buffer_name.empty?
|
47
|
+
|
48
|
+
# Check if this buffer matches the file path (exact match or ends with the path)
|
49
|
+
if buffer_name == file_path || buffer_name.end_with?(file_path)
|
50
|
+
target_buffer = buffer
|
51
|
+
result[:actual_path] = buffer_name
|
52
|
+
break
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if target_buffer.nil?
|
57
|
+
result[:status] = "error"
|
58
|
+
result[:message] = "Buffer not found for file: #{file_path}"
|
59
|
+
return result
|
60
|
+
end
|
61
|
+
|
62
|
+
# Store original content info
|
63
|
+
original_line_count = target_buffer.line_count
|
64
|
+
result[:original_line_count] = original_line_count
|
65
|
+
|
66
|
+
# Find a window displaying this buffer or use the current window
|
67
|
+
windows = client.list_wins
|
68
|
+
target_window = windows.find { |win| win.buffer.number == target_buffer.number }
|
69
|
+
|
70
|
+
if target_window
|
71
|
+
# If we found a window with this buffer, switch to it
|
72
|
+
client.set_current_win(target_window)
|
73
|
+
else
|
74
|
+
# Otherwise, load the buffer in the current window
|
75
|
+
client.command("buffer #{target_buffer.number}")
|
76
|
+
end
|
77
|
+
|
78
|
+
# Split content into lines
|
79
|
+
new_lines = content.split("\n")
|
80
|
+
result[:new_line_count] = new_lines.length
|
81
|
+
|
82
|
+
# Replace the entire buffer content
|
83
|
+
# First, delete all existing lines
|
84
|
+
target_buffer.lines = new_lines
|
85
|
+
result[:updated] = true
|
86
|
+
|
87
|
+
# Save the buffer to disk
|
88
|
+
client.command("write")
|
89
|
+
result[:saved] = true
|
90
|
+
log(:info, "Saved updated buffer: #{result[:actual_path]}")
|
91
|
+
|
92
|
+
# Reload the buffer to ensure it's in sync
|
93
|
+
client.command("edit")
|
94
|
+
result[:reloaded] = true
|
95
|
+
|
96
|
+
result[:message] = "Successfully updated, saved, and reloaded buffer"
|
97
|
+
|
98
|
+
# Close the connection
|
99
|
+
client.shutdown
|
100
|
+
rescue => e
|
101
|
+
log(:error, "Error updating buffer in Neovim using socket #{socket_path}: #{e.message}")
|
102
|
+
|
103
|
+
# Handle connection and other errors gracefully
|
104
|
+
result[:status] = "error"
|
105
|
+
result[:message] = e.message
|
106
|
+
result[:updated] = false
|
107
|
+
result[:saved] = false
|
108
|
+
result[:reloaded] = false
|
109
|
+
end
|
110
|
+
|
111
|
+
result
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/nvim_mcp_server.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative "nvim-mcp-server/version"
|
|
5
5
|
require_relative "nvim-mcp-server/config"
|
6
6
|
require_relative "nvim-mcp-server/tools/base_tool"
|
7
7
|
require_relative "nvim-mcp-server/tools/get_project_buffers_tool"
|
8
|
+
require_relative "nvim-mcp-server/tools/update_buffer_tool"
|
8
9
|
|
9
10
|
module NvimMcpServer
|
10
11
|
@levels = {debug: Logger::DEBUG, info: Logger::INFO, error: Logger::ERROR}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nvim-mcp-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Alberto Chávez
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/nvim-mcp-server/config.rb
|
113
113
|
- lib/nvim-mcp-server/tools/base_tool.rb
|
114
114
|
- lib/nvim-mcp-server/tools/get_project_buffers_tool.rb
|
115
|
+
- lib/nvim-mcp-server/tools/update_buffer_tool.rb
|
115
116
|
- lib/nvim-mcp-server/version.rb
|
116
117
|
- lib/nvim_mcp_server.rb
|
117
118
|
- sig/nvim/mcp/server.rbs
|