nvim-mcp-server 0.1.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 +7 -0
- data/.rubocop.yml +14 -0
- data/.standard.yml +3 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +240 -0
- data/Rakefile +10 -0
- data/exe/nvim-mcp-server +119 -0
- data/lib/nvim-mcp-server/config.rb +42 -0
- data/lib/nvim-mcp-server/tools/base_tool.rb +7 -0
- data/lib/nvim-mcp-server/tools/get_project_buffers_tool.rb +75 -0
- data/lib/nvim-mcp-server/version.rb +3 -0
- data/lib/nvim_mcp_server.rb +28 -0
- data/sig/nvim/mcp/server.rbs +8 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 37f1c2ca44998304a9abe21e2df12e7723312c0e339e236e1552606823ce9f7c
|
4
|
+
data.tar.gz: 026a645ec357568819a87c76739a32e2efb0cc4d4736488df17d116f6ccc95c2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7852a33dda675213414deb6fa3710490723a9663d2d4741dfd775d01815465828c84d1ccefc9409c33c3246d463e4a43f931ecb5104e0ab4ae5a2169bb89633
|
7
|
+
data.tar.gz: 2dcbe478aa2e51f754f1c842c10bec02c90a140abb722e69caf9245fd578c2a2bace4756562dbb0a390faf2b8d032b4490e8cf3bf0f2dabe72fd0fe7e150fff4
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Omakase Ruby styling for Rails
|
2
|
+
# inherit_gem: { rubocop-rails-omakase: rubocop.yml }
|
3
|
+
|
4
|
+
# Overwrite or add rules to create your own house style
|
5
|
+
#
|
6
|
+
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
|
7
|
+
# Layout/SpaceInsideArrayLiteralBrackets:
|
8
|
+
# Enabled: false
|
9
|
+
|
10
|
+
require:
|
11
|
+
- standard
|
12
|
+
|
13
|
+
inherit_gem:
|
14
|
+
standard: config/base.yml
|
data/.standard.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Mario Alberto Chávez
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,240 @@
|
|
1
|
+
# Neovim MCP Server
|
2
|
+
|
3
|
+
A Ruby implementation of a Model Context Protocol (MCP) server for Neovim. This server allows LLMs (Large Language Models) to interact with Neovim through the Model Context Protocol, providing capabilities to query buffers and perform operations within the editor.
|
4
|
+
|
5
|
+
## What is MCP?
|
6
|
+
|
7
|
+
The Model Context Protocol (MCP) is a standardized way for AI models to interact with their environment. It defines a structured method for models to request and use tools, access resources, and maintain context during interactions.
|
8
|
+
|
9
|
+
This Neovim MCP Server implements the MCP specification to give AI models access to Neovim for buffer analysis, file exploration, and editing assistance.
|
10
|
+
|
11
|
+
## Features
|
12
|
+
|
13
|
+
- Connect to running Neovim instances
|
14
|
+
- Query buffers across multiple Neovim sessions
|
15
|
+
- Follow the Model Context Protocol standard
|
16
|
+
- Seamless integration with LLM clients
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Install the gem:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
gem install nvim-mcp-server
|
24
|
+
```
|
25
|
+
|
26
|
+
After installation, the `nvim-mcp-server` executable will be available in your PATH.
|
27
|
+
|
28
|
+
## Configuration
|
29
|
+
|
30
|
+
The Neovim MCP Server follows the XDG Base Directory Specification for configuration files:
|
31
|
+
|
32
|
+
- 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
|
+
- On Windows: `%APPDATA%\nvim-mcp`
|
35
|
+
|
36
|
+
The server will automatically create these directories and a log file the first time it runs.
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
### Starting the server
|
41
|
+
|
42
|
+
The Neovim MCP Server can run in two modes:
|
43
|
+
|
44
|
+
1. **STDIO mode (default)**: Communicates over standard input/output for direct integration with clients like Claude Desktop.
|
45
|
+
2. **HTTP mode**: Runs as an HTTP server with JSON-RPC and Server-Sent Events (SSE) endpoints.
|
46
|
+
|
47
|
+
```bash
|
48
|
+
# Start in default STDIO mode
|
49
|
+
nvim-mcp-server
|
50
|
+
|
51
|
+
# Start in HTTP mode on the default port (6030)
|
52
|
+
nvim-mcp-server --mode http
|
53
|
+
|
54
|
+
# Start in HTTP mode on a custom port
|
55
|
+
nvim-mcp-server --mode http -p 8080
|
56
|
+
```
|
57
|
+
|
58
|
+
When running in HTTP mode, the server provides two endpoints:
|
59
|
+
|
60
|
+
- JSON-RPC endpoint: `http://localhost:<port>/mcp/messages`
|
61
|
+
- SSE endpoint: `http://localhost:<port>/mcp/sse`
|
62
|
+
|
63
|
+
### Logging Options
|
64
|
+
|
65
|
+
The server logs to a file in your config directory by default. You can customize logging with these options:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
# Set the log level (debug, info, error)
|
69
|
+
nvim-mcp-server --log-level debug
|
70
|
+
```
|
71
|
+
|
72
|
+
## Claude Desktop Integration
|
73
|
+
|
74
|
+
The Neovim MCP Server can be used with Claude Desktop by manually configuring the integration.
|
75
|
+
|
76
|
+
### Direct Configuration
|
77
|
+
|
78
|
+
1. Create the appropriate config directory for your platform:
|
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
|
+
- Windows: `%APPDATA%\nvim-mcp`
|
82
|
+
|
83
|
+
2. Find or create the Claude Desktop configuration file:
|
84
|
+
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
85
|
+
- Linux: `~/.config/Claude/claude_desktop_config.json`
|
86
|
+
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
87
|
+
|
88
|
+
3. Add or update the MCP server configuration:
|
89
|
+
|
90
|
+
```json
|
91
|
+
{
|
92
|
+
"mcpServers": {
|
93
|
+
"nvimMcpServer": {
|
94
|
+
"command": "ruby",
|
95
|
+
"args": ["/full/path/to/nvim-mcp-server/exe/nvim-mcp-server"]
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
```
|
100
|
+
|
101
|
+
4. Restart Claude Desktop to apply the changes.
|
102
|
+
|
103
|
+
### Ruby Version Manager Users
|
104
|
+
|
105
|
+
Claude Desktop launches the MCP server using your system's default Ruby environment, bypassing version manager initialization (e.g., rbenv, RVM). The MCP server needs to use the same Ruby version where it was installed, as MCP server startup failures can occur when using an incompatible Ruby version.
|
106
|
+
|
107
|
+
If you are using a Ruby version manager such as rbenv, you can create a symbolic link to your Ruby shim to ensure the correct version is used:
|
108
|
+
|
109
|
+
```bash
|
110
|
+
sudo ln -s /home/your_user/.rbenv/shims/ruby /usr/local/bin/ruby
|
111
|
+
```
|
112
|
+
|
113
|
+
Replace "/home/your_user/.rbenv/shims/ruby" with your actual path for the Ruby shim.
|
114
|
+
|
115
|
+
### Using an MCP Proxy (Advanced)
|
116
|
+
|
117
|
+
Claude Desktop and many other LLM clients only support STDIO mode communication, but you might want to use the HTTP/SSE capabilities of the server. An MCP proxy can bridge this gap:
|
118
|
+
|
119
|
+
1. Start the Neovim MCP Server in HTTP mode:
|
120
|
+
|
121
|
+
```bash
|
122
|
+
nvim-mcp-server --mode http
|
123
|
+
```
|
124
|
+
|
125
|
+
2. Install and run an MCP proxy. There are several implementations available in different languages. An MCP proxy allows a client that only supports STDIO communication to communicate via HTTP SSE. Here's an example using a JavaScript-based MCP proxy:
|
126
|
+
|
127
|
+
```bash
|
128
|
+
# Install the Node.js based MCP proxy
|
129
|
+
npm install -g mcp-remote
|
130
|
+
|
131
|
+
# Run the proxy, pointing to your running Neovim MCP Server
|
132
|
+
npx mcp-remote http://localhost:6030/mcp/sse
|
133
|
+
```
|
134
|
+
|
135
|
+
3. Configure Claude Desktop (or other LLM client) to use the proxy instead of connecting directly to the server:
|
136
|
+
|
137
|
+
```json
|
138
|
+
{
|
139
|
+
"mcpServers": {
|
140
|
+
"nvimMcpServer": {
|
141
|
+
"command": "npx",
|
142
|
+
"args": ["mcp-remote", "http://localhost:6030/mcp/sse"]
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
```
|
147
|
+
|
148
|
+
This setup allows STDIO-only clients to communicate with the Neovim MCP Server through the proxy, benefiting from the HTTP/SSE capabilities while maintaining client compatibility.
|
149
|
+
|
150
|
+
## Neovim Configuration
|
151
|
+
|
152
|
+
For the MCP server to work properly, your Neovim instances need to be started with a named socket:
|
153
|
+
|
154
|
+
```bash
|
155
|
+
nvim --listen /tmp/nvim-project_name.sock
|
156
|
+
```
|
157
|
+
|
158
|
+
You can automate this by adding the following to your Neovim configuration:
|
159
|
+
|
160
|
+
```lua
|
161
|
+
-- In your init.lua
|
162
|
+
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t')
|
163
|
+
vim.fn.serverstart('/tmp/nvim-' .. project_name .. '.sock')
|
164
|
+
```
|
165
|
+
|
166
|
+
## How the Server Works
|
167
|
+
|
168
|
+
The Neovim MCP Server implements the Model Context Protocol using either:
|
169
|
+
|
170
|
+
- **STDIO mode**: Reads JSON-RPC 2.0 requests from standard input and returns responses to standard output.
|
171
|
+
- **HTTP mode**: Provides HTTP endpoints for JSON-RPC 2.0 requests and Server-Sent Events.
|
172
|
+
|
173
|
+
The server communicates with Neovim instances through Unix sockets located at `/tmp/nvim-{project_name}.sock`. This allows the server to interact with multiple Neovim instances running different projects.
|
174
|
+
|
175
|
+
## Available Tools
|
176
|
+
|
177
|
+
The server provides the following tools for interacting with Neovim:
|
178
|
+
|
179
|
+
### 1. `get_project_buffers`
|
180
|
+
|
181
|
+
**Description:** Retrieves a list of files currently open in Neovim that belong to a specific project. This tool connects to a running Neovim instance using its socket file at /tmp/nvim-{project_name}.sock and queries for all open buffers. It then filters the buffers to include only files that have the project name as part of their path. This is useful for determining what files a user is currently editing in a particular project, identifying areas of active development, or tracking work context across multiple files. The tool handles connection failures gracefully and returns complete absolute file paths.
|
182
|
+
|
183
|
+
**Parameters:**
|
184
|
+
|
185
|
+
- `project_name`: (String, required) The name of the project directory to filter buffers by. This should match a directory name in the file paths of the buffers you want to retrieve. For example, if your project is at '/home/user/projects/my-app', you would use 'my-app' as the project_name. The tool will also use this name to locate the Neovim socket at /tmp/nvim-{project_name}.sock.
|
186
|
+
|
187
|
+
#### Examples
|
188
|
+
|
189
|
+
```
|
190
|
+
Can you show me which files I have open in my "my-project" Neovim instance?
|
191
|
+
```
|
192
|
+
|
193
|
+
```
|
194
|
+
I'd like to know what files I'm currently working on in the "blog" project.
|
195
|
+
```
|
196
|
+
|
197
|
+
```
|
198
|
+
List all the buffers for the "nvim-mcp-server" project.
|
199
|
+
```
|
200
|
+
|
201
|
+
## Testing and Debugging
|
202
|
+
|
203
|
+
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.
|
204
|
+
|
205
|
+
To use MCP Inspector with Neovim MCP Server:
|
206
|
+
|
207
|
+
```bash
|
208
|
+
# Install and run MCP Inspector with your Neovim MCP Server
|
209
|
+
npm -g install @modelcontextprotocol/inspector
|
210
|
+
|
211
|
+
npx @modelcontextprotocol/inspector /path/to/nvim-mcp-server
|
212
|
+
```
|
213
|
+
|
214
|
+
This will:
|
215
|
+
|
216
|
+
1. Start your Neovim MCP Server in HTTP mode
|
217
|
+
2. Launch the MCP Inspector UI in your browser (default port: 6274)
|
218
|
+
|
219
|
+
In the MCP Inspector UI, you can:
|
220
|
+
|
221
|
+
- See all available tools
|
222
|
+
- Execute tool calls interactively
|
223
|
+
- View request and response details
|
224
|
+
- Debug issues in real-time
|
225
|
+
|
226
|
+
## License
|
227
|
+
|
228
|
+
This Neovim MCP server is released under the MIT License, a permissive open-source license that allows for free use, modification, distribution, and private use.
|
229
|
+
|
230
|
+
Copyright (c) 2025 Mario Alberto Chávez Cárdenas
|
231
|
+
|
232
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
233
|
+
|
234
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
235
|
+
|
236
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
237
|
+
|
238
|
+
## Contributing
|
239
|
+
|
240
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/maquina-app/nvim-mcp-server>.
|
data/Rakefile
ADDED
data/exe/nvim-mcp-server
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
if defined?(Bundler) && !defined?(Bundler::ORIGINAL_ENV)
|
4
|
+
require "bundler/setup"
|
5
|
+
Bundler::ORIGINAL_ENV = ENV.to_h
|
6
|
+
end
|
7
|
+
|
8
|
+
require "fast_mcp"
|
9
|
+
require "rack"
|
10
|
+
require "rack/handler/puma"
|
11
|
+
require "puma"
|
12
|
+
require "puma/configuration"
|
13
|
+
require "puma/launcher"
|
14
|
+
require_relative "../lib/nvim_mcp_server"
|
15
|
+
|
16
|
+
if ARGV[0] == "version"
|
17
|
+
puts "Neovim MCP Server version #{NvimMcpServer::VERSION}"
|
18
|
+
exit 0
|
19
|
+
end
|
20
|
+
|
21
|
+
# Help message
|
22
|
+
if ARGV[0] == "--help" || ARGV[0] == "-h"
|
23
|
+
puts "Neovim MCP Server - MCP protocol server"
|
24
|
+
puts ""
|
25
|
+
puts "Start your Neovim with --listen to allow Remote Procedure Calls"
|
26
|
+
puts "Example:"
|
27
|
+
puts " nvim --listen /tmp/nvim-neovim.sock"
|
28
|
+
puts ""
|
29
|
+
puts "Usage: #{File.basename($0)} [options]"
|
30
|
+
puts ""
|
31
|
+
puts "Options:"
|
32
|
+
puts " --log-level LEVEL Log level: debug, info, warn, error (default: info)"
|
33
|
+
puts " --mode MODE Server mode: http or stdio (default: stdio)"
|
34
|
+
puts " -p, --port PORT Port to listen on (default: 6030)"
|
35
|
+
puts " version Display version information"
|
36
|
+
puts " --help, -h Display this help message"
|
37
|
+
puts ""
|
38
|
+
puts "Example:"
|
39
|
+
puts " #{File.basename($0)} --log-level debug -p 6060"
|
40
|
+
puts " #{File.basename($0)} --mode stdio"
|
41
|
+
exit 0
|
42
|
+
end
|
43
|
+
|
44
|
+
# Default values
|
45
|
+
port = 6030
|
46
|
+
mode = "stdio"
|
47
|
+
|
48
|
+
# Parse command-line arguments
|
49
|
+
i = 0
|
50
|
+
while i < ARGV.length
|
51
|
+
case ARGV[i]
|
52
|
+
when "--log-level"
|
53
|
+
log_level = ARGV[i + 1].to_sym
|
54
|
+
i += 2
|
55
|
+
when "-p", "--port"
|
56
|
+
port = ARGV[i + 1].to_i
|
57
|
+
i += 2
|
58
|
+
when "--mode"
|
59
|
+
mode = ARGV[i + 1].downcase
|
60
|
+
unless ["http", "stdio"].include?(mode) # rubocop:disable Performance/CollectionLiteralInLoop
|
61
|
+
puts "Error: Invalid mode '#{mode}'. Must be 'http' or 'stdio'."
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
i += 2
|
65
|
+
else
|
66
|
+
i += 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
NvimMcpServer.config do |config|
|
71
|
+
config.log_level = log_level
|
72
|
+
end
|
73
|
+
|
74
|
+
NvimMcpServer.log(:info, "Starting Neovim MCP Server in #{mode} mode...")
|
75
|
+
|
76
|
+
# Create tools configuration for both modes
|
77
|
+
def setup_mcp_tools(server)
|
78
|
+
server.register_tools(NvimMcpServer::GetProjectBuffersTool)
|
79
|
+
end
|
80
|
+
|
81
|
+
case mode
|
82
|
+
when "http"
|
83
|
+
puts "Starting Rack application with MCP middleware on http://localhost:#{port}"
|
84
|
+
puts "MCP endpoints:"
|
85
|
+
puts " - http://localhost:#{port}/mcp/sse (SSE endpoint)"
|
86
|
+
puts " - http://localhost:#{port}/mcp/messages (JSON-RPC endpoint)"
|
87
|
+
puts ""
|
88
|
+
puts "Version #{NvimMcpServer::VERSION}"
|
89
|
+
puts ""
|
90
|
+
|
91
|
+
rack_app = ->(env) {
|
92
|
+
[200, {"Content-Type" => "text/plain"}, ["Rails MCP Server #{NvimMcpServer::VERSION}"]]
|
93
|
+
}
|
94
|
+
|
95
|
+
mcp_app = FastMcp.rack_middleware(
|
96
|
+
rack_app,
|
97
|
+
name: "nvim-mcp-server", version: NvimMcpServer::VERSION,
|
98
|
+
logger: NvimMcpServer.logger
|
99
|
+
) { |server| setup_mcp_tools(server) }
|
100
|
+
|
101
|
+
app = Rack::Builder.new { run mcp_app }
|
102
|
+
config = Puma::Configuration.new do |user_config|
|
103
|
+
user_config.bind "tcp://localhost:#{port}"
|
104
|
+
user_config.app app
|
105
|
+
end
|
106
|
+
|
107
|
+
launcher = Puma::Launcher.new(config)
|
108
|
+
launcher.run
|
109
|
+
when "stdio"
|
110
|
+
NvimMcpServer.log(:info, "Starting MCP server in STDIO mode...")
|
111
|
+
|
112
|
+
server = FastMcp::Server.new(name: "nvim-mcp-server", version: NvimMcpServer::VERSION)
|
113
|
+
setup_mcp_tools(server)
|
114
|
+
|
115
|
+
server.start
|
116
|
+
end
|
117
|
+
|
118
|
+
NvimMcpServer.log(:info, "Stopping Neovim MCP Server...")
|
119
|
+
exit
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module NvimMcpServer
|
2
|
+
class Config
|
3
|
+
attr_accessor :logger, :log_level
|
4
|
+
|
5
|
+
def self.setup
|
6
|
+
new.tap do |instance|
|
7
|
+
yield(instance) if block_given?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@log_level = Logger::INFO
|
13
|
+
@config_dir = get_config_dir
|
14
|
+
|
15
|
+
configure_logger
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def configure_logger
|
21
|
+
FileUtils.mkdir_p(File.join(@config_dir, "log"))
|
22
|
+
log_file = File.join(@config_dir, "log", "nvim_mcp_server.log")
|
23
|
+
|
24
|
+
@logger = Logger.new(log_file)
|
25
|
+
@logger.level = @log_level
|
26
|
+
|
27
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
28
|
+
"[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}] #{severity}: #{msg}\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_config_dir
|
33
|
+
# Use XDG_CONFIG_HOME if set, otherwise use ~/.config
|
34
|
+
xdg_config_home = ENV["XDG_CONFIG_HOME"]
|
35
|
+
if xdg_config_home && !xdg_config_home.empty?
|
36
|
+
File.join(xdg_config_home, "nvim-mcp")
|
37
|
+
else
|
38
|
+
File.join(Dir.home, ".config", "nvim-mcp")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module NvimMcpServer
|
2
|
+
class GetProjectBuffersTool < BaseTool
|
3
|
+
tool_name "get_project_buffers"
|
4
|
+
|
5
|
+
description "Retrieves a list of files currently open in Neovim that belong to a specific project. This tool connects to a running Neovim instance using its socket file at /tmp/nvim-{project_name}.sock and queries for all open buffers. It then filters the buffers to include only files that have the project name as part of their path. This is useful for determining what files a user is currently editing in a particular project, identifying areas of active development, or tracking work context across multiple files. The tool handles connection failures gracefully and returns complete absolute file paths."
|
6
|
+
|
7
|
+
arguments do
|
8
|
+
required(:project_name).filled(:string).description("The name of the project directory to filter buffers by. This should match a directory name in the file paths of the buffers you want to retrieve. For example, if your project is at '/home/user/projects/my-app', you would use 'my-app' as the project_name. The tool will also use this name to locate the Neovim socket at /tmp/nvim-{project_name}.sock.")
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(project_name:)
|
12
|
+
socket_path = "/tmp/nvim-#{project_name}.sock"
|
13
|
+
log(:info, "Getting buffers for project #{project_name} using socket #{socket_path}")
|
14
|
+
|
15
|
+
result = {
|
16
|
+
status: "success",
|
17
|
+
project_name: project_name,
|
18
|
+
socket_path: socket_path,
|
19
|
+
files: []
|
20
|
+
}
|
21
|
+
|
22
|
+
begin
|
23
|
+
# Check if socket exists
|
24
|
+
unless File.exist?(socket_path)
|
25
|
+
result[:status] = "error"
|
26
|
+
result[:message] = "Neovim socket not found: #{socket_path}"
|
27
|
+
return result
|
28
|
+
end
|
29
|
+
|
30
|
+
# Connect to Neovim
|
31
|
+
client = Neovim.attach_unix(socket_path)
|
32
|
+
|
33
|
+
# Get all buffers
|
34
|
+
all_buffers = client.list_bufs
|
35
|
+
project_files = []
|
36
|
+
|
37
|
+
all_buffers.each do |buffer|
|
38
|
+
# Get buffer name (file path)
|
39
|
+
buffer_name = buffer.name
|
40
|
+
|
41
|
+
# Skip unnamed buffers
|
42
|
+
next if buffer_name.nil? || buffer_name.empty?
|
43
|
+
|
44
|
+
# Split the path into components
|
45
|
+
path_parts = buffer_name.split(File::SEPARATOR)
|
46
|
+
|
47
|
+
# Check if project_name appears in any part of the path
|
48
|
+
if path_parts.include?(project_name)
|
49
|
+
# Add the complete path to the results
|
50
|
+
project_files << buffer_name
|
51
|
+
end
|
52
|
+
rescue => e
|
53
|
+
# Log error but continue processing other buffers
|
54
|
+
log(:error, "Error processing buffer: #{e.message}")
|
55
|
+
next
|
56
|
+
end
|
57
|
+
|
58
|
+
# Sort the files for consistent output
|
59
|
+
result[:files] = project_files.sort
|
60
|
+
|
61
|
+
# Close the connection
|
62
|
+
client.shutdown
|
63
|
+
rescue => e
|
64
|
+
log(:error, "Error connecting to Neovim using socket #{socket_path}: #{e.message}")
|
65
|
+
|
66
|
+
# Handle connection and other errors gracefully
|
67
|
+
result[:status] = "error"
|
68
|
+
result[:message] = e.message
|
69
|
+
result[:files] = []
|
70
|
+
end
|
71
|
+
|
72
|
+
result
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "neovim"
|
3
|
+
require "forwardable"
|
4
|
+
require_relative "nvim-mcp-server/version"
|
5
|
+
require_relative "nvim-mcp-server/config"
|
6
|
+
require_relative "nvim-mcp-server/tools/base_tool"
|
7
|
+
require_relative "nvim-mcp-server/tools/get_project_buffers_tool"
|
8
|
+
|
9
|
+
module NvimMcpServer
|
10
|
+
@levels = {debug: Logger::DEBUG, info: Logger::INFO, error: Logger::ERROR}
|
11
|
+
@config = Config.setup
|
12
|
+
|
13
|
+
class << self
|
14
|
+
extend Forwardable
|
15
|
+
|
16
|
+
attr_reader :config
|
17
|
+
|
18
|
+
def_delegators :@config, :log_level, :log_level=
|
19
|
+
def_delegators :@config, :logger, :logger=
|
20
|
+
|
21
|
+
def log(level, message)
|
22
|
+
log_level = @levels[level] || Logger::INFO
|
23
|
+
|
24
|
+
@config.logger.add(log_level, message)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
class Error < StandardError; end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nvim-mcp-server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mario Alberto Chávez
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: fast-mcp
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 1.1.0
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 1.1.0
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rack
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.1.12
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.1.12
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: puma
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 6.6.0
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 6.6.0
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: logger
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.6.6
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.6.6
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: neovim
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.10.0
|
75
|
+
type: :runtime
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.10.0
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: standard
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
description: A Ruby implementation of the MCP server protocol for Neovim
|
97
|
+
email:
|
98
|
+
- mario.chavez@gmail.com
|
99
|
+
executables:
|
100
|
+
- nvim-mcp-server
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".rubocop.yml"
|
105
|
+
- ".standard.yml"
|
106
|
+
- CHANGELOG.md
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- exe/nvim-mcp-server
|
112
|
+
- lib/nvim-mcp-server/config.rb
|
113
|
+
- lib/nvim-mcp-server/tools/base_tool.rb
|
114
|
+
- lib/nvim-mcp-server/tools/get_project_buffers_tool.rb
|
115
|
+
- lib/nvim-mcp-server/version.rb
|
116
|
+
- lib/nvim_mcp_server.rb
|
117
|
+
- sig/nvim/mcp/server.rbs
|
118
|
+
homepage: https://github.com/maquina-app/nvim-mcp-server
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata:
|
122
|
+
allowed_push_host: https://rubygems.org
|
123
|
+
homepage_uri: https://github.com/maquina-app/nvim-mcp-server
|
124
|
+
source_code_uri: https://github.com/maquina-app/nvim-mcp-server
|
125
|
+
changelog_uri: https://github.com/maquina-app/nvim-mcp-server
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 3.1.0
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubygems_version: 3.6.9
|
141
|
+
specification_version: 4
|
142
|
+
summary: MCP server for Neovim
|
143
|
+
test_files: []
|