linux-mcp-server 0.1.0.dev0__tar.gz

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.
Files changed (37) hide show
  1. linux_mcp_server-0.1.0.dev0/.gitignore +51 -0
  2. linux_mcp_server-0.1.0.dev0/.python-version +1 -0
  3. linux_mcp_server-0.1.0.dev0/CONTRIBUTING.md +350 -0
  4. linux_mcp_server-0.1.0.dev0/DEBUGGING.md +133 -0
  5. linux_mcp_server-0.1.0.dev0/LICENSE +21 -0
  6. linux_mcp_server-0.1.0.dev0/PKG-INFO +331 -0
  7. linux_mcp_server-0.1.0.dev0/README.md +316 -0
  8. linux_mcp_server-0.1.0.dev0/USAGE.md +350 -0
  9. linux_mcp_server-0.1.0.dev0/claude_desktop_config.example.json +19 -0
  10. linux_mcp_server-0.1.0.dev0/example_config.sh +66 -0
  11. linux_mcp_server-0.1.0.dev0/pyproject.toml +49 -0
  12. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/__init__.py +4 -0
  13. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/__main__.py +30 -0
  14. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/audit.py +285 -0
  15. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/logging_config.py +144 -0
  16. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/server.py +328 -0
  17. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/__init__.py +2 -0
  18. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/logs.py +225 -0
  19. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/network.py +281 -0
  20. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/processes.py +257 -0
  21. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/services.py +147 -0
  22. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/ssh_executor.py +324 -0
  23. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/storage.py +358 -0
  24. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/system_info.py +507 -0
  25. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/utils.py +27 -0
  26. linux_mcp_server-0.1.0.dev0/src/linux_mcp_server/tools/validation.py +58 -0
  27. linux_mcp_server-0.1.0.dev0/tests/__init__.py +2 -0
  28. linux_mcp_server-0.1.0.dev0/tests/test_audit.py +315 -0
  29. linux_mcp_server-0.1.0.dev0/tests/test_logging_config.py +214 -0
  30. linux_mcp_server-0.1.0.dev0/tests/test_processes.py +56 -0
  31. linux_mcp_server-0.1.0.dev0/tests/test_server.py +49 -0
  32. linux_mcp_server-0.1.0.dev0/tests/test_services.py +115 -0
  33. linux_mcp_server-0.1.0.dev0/tests/test_ssh_executor.py +358 -0
  34. linux_mcp_server-0.1.0.dev0/tests/test_storage.py +383 -0
  35. linux_mcp_server-0.1.0.dev0/tests/test_system_info.py +83 -0
  36. linux_mcp_server-0.1.0.dev0/tests/test_validation.py +165 -0
  37. linux_mcp_server-0.1.0.dev0/uv.lock +1001 -0
@@ -0,0 +1,51 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual environments
24
+ .venv/
25
+ venv/
26
+ ENV/
27
+ env/
28
+
29
+ # Testing
30
+ .pytest_cache/
31
+ .coverage
32
+ htmlcov/
33
+ .tox/
34
+
35
+ # IDEs
36
+ .vscode/
37
+ .idea/
38
+ *.swp
39
+ *.swo
40
+ *~
41
+
42
+ # OS
43
+ .DS_Store
44
+ Thumbs.db
45
+
46
+ # uv
47
+ .uv/
48
+
49
+ # Configuration files (user-specific)
50
+ config.sh
51
+
@@ -0,0 +1 @@
1
+ linux-mcp
@@ -0,0 +1,350 @@
1
+ # Contributing to Linux MCP Server
2
+
3
+ Thank you for your interest in contributing! This document provides guidelines for contributing to the Linux MCP Server project.
4
+
5
+ ## Development Setup
6
+
7
+ 1. **Clone the repository:**
8
+ ```bash
9
+ git clone <repository-url>
10
+ cd linux-mcp-server
11
+ ```
12
+
13
+ 2. **Set up development environment:**
14
+ ```bash
15
+ uv venv
16
+ source .venv/bin/activate
17
+ uv pip install -e ".[dev]"
18
+ ```
19
+
20
+ 3. **Verify setup:**
21
+ ```bash
22
+ pytest
23
+ ```
24
+
25
+ ## Development Workflow
26
+
27
+ We follow Test-Driven Development (TDD) principles:
28
+
29
+ ### 1. RED - Write a Failing Test
30
+ ```python
31
+ # tests/test_new_feature.py
32
+ import pytest
33
+ from linux_mcp_server.tools import new_module
34
+
35
+ @pytest.mark.asyncio
36
+ async def test_new_feature():
37
+ result = await new_module.new_function()
38
+ assert "expected" in result
39
+ ```
40
+
41
+ ### 2. GREEN - Implement Minimal Code to Pass
42
+ ```python
43
+ # src/linux_mcp_server/tools/new_module.py
44
+ async def new_function():
45
+ return "expected result"
46
+ ```
47
+
48
+ ### 3. REFACTOR - Improve Code Quality
49
+ - Improve readability
50
+ - Remove duplication
51
+ - Ensure all tests still pass
52
+
53
+ ### 4. Commit
54
+ ```bash
55
+ git add .
56
+ git commit -m "feat: add new feature
57
+
58
+ - Detailed description of what was added
59
+ - Tests included
60
+ - All tests passing"
61
+ ```
62
+
63
+ ## Code Standards
64
+
65
+ ### Style Guidelines
66
+ - Follow PEP 8 for Python code
67
+ - Use type hints for function parameters and return values
68
+ - Use async/await for I/O operations
69
+ - Maximum line length: 100 characters
70
+
71
+ ### Documentation
72
+ - Add docstrings to all public functions
73
+ - Use clear, descriptive variable names
74
+ - Comment complex logic
75
+
76
+ ### Testing
77
+ - Write tests for all new features
78
+ - Maintain test coverage above 80%
79
+ - Use descriptive test names that explain what is being tested
80
+
81
+ ## Adding New Tools
82
+
83
+ When adding a new diagnostic tool:
84
+
85
+ 1. **Create the tool function in appropriate module:**
86
+ ```python
87
+ # src/linux_mcp_server/tools/my_tool.py
88
+ from typing import Optional
89
+ from .ssh_executor import execute_command
90
+
91
+ async def my_diagnostic_function(
92
+ host: Optional[str] = None,
93
+ username: Optional[str] = None
94
+ ) -> str:
95
+ """
96
+ Brief description of what this tool does.
97
+
98
+ Args:
99
+ host: Optional remote host to connect to via SSH
100
+ username: Optional SSH username (required if host is provided)
101
+
102
+ Returns:
103
+ Formatted string with diagnostic information
104
+ """
105
+ try:
106
+ # Implementation using execute_command for local/remote execution
107
+ returncode, stdout, stderr = await execute_command(
108
+ ["your", "command"],
109
+ host=host,
110
+ username=username
111
+ )
112
+
113
+ if returncode != 0:
114
+ return f"Error: {stderr}"
115
+
116
+ return stdout
117
+ except Exception as e:
118
+ return f"Error: {str(e)}"
119
+ ```
120
+
121
+ 2. **Register the tool in server.py using FastMCP decorator:**
122
+ ```python
123
+ # Import your tool module at the top
124
+ from .tools import my_tool
125
+
126
+ # Add decorated function
127
+ @mcp.tool()
128
+ async def my_tool_name(
129
+ param1: str,
130
+ host: Optional[str] = None,
131
+ username: Optional[str] = None
132
+ ) -> str:
133
+ """Description for LLM to understand the tool.
134
+
135
+ Args:
136
+ param1: Description of the parameter
137
+ host: Remote host to connect to via SSH (optional)
138
+ username: SSH username for remote host (required if host is provided)
139
+ """
140
+ return await _execute_tool(
141
+ "my_tool_name",
142
+ my_tool.my_diagnostic_function,
143
+ param1=param1,
144
+ host=host,
145
+ username=username
146
+ )
147
+ ```
148
+
149
+ 3. **Write tests:**
150
+ ```python
151
+ # tests/test_my_tool.py
152
+ import pytest
153
+ from linux_mcp_server.tools import my_tool
154
+
155
+ @pytest.mark.asyncio
156
+ async def test_my_tool():
157
+ result = await my_tool.my_diagnostic_function()
158
+ assert isinstance(result, str)
159
+ assert "expected content" in result.lower()
160
+
161
+ # Test server integration
162
+ @pytest.mark.asyncio
163
+ async def test_server_has_my_tool():
164
+ from linux_mcp_server.server import mcp
165
+ tools = await mcp.list_tools()
166
+ tool_names = [t.name for t in tools]
167
+ assert "my_tool_name" in tool_names
168
+ ```
169
+
170
+ 4. **Update documentation:**
171
+ - Add tool description to README.md
172
+ - Add usage examples to USAGE.md
173
+
174
+ ## Commit Message Format
175
+
176
+ We use [Conventional Commits](https://www.conventionalcommits.org/):
177
+
178
+ ```
179
+ <type>(<scope>): <subject>
180
+
181
+ <body>
182
+
183
+ <footer>
184
+ ```
185
+
186
+ ### Types:
187
+ - `feat`: New feature
188
+ - `fix`: Bug fix
189
+ - `docs`: Documentation only changes
190
+ - `test`: Adding missing tests
191
+ - `refactor`: Code change that neither fixes a bug nor adds a feature
192
+ - `perf`: Performance improvement
193
+ - `chore`: Changes to build process or auxiliary tools
194
+
195
+ ### Examples:
196
+ ```
197
+ feat(tools): add disk smart status tool
198
+
199
+ - Implement smart status checking
200
+ - Add tests for SMART data parsing
201
+ - Update documentation
202
+
203
+ Closes #123
204
+ ```
205
+
206
+ ```
207
+ fix(network): handle missing network interfaces gracefully
208
+
209
+ Previously crashed when network interface disappeared
210
+ during enumeration. Now catches exception and continues.
211
+ ```
212
+
213
+ ## Security Guidelines
214
+
215
+ ### Read-Only Operations
216
+ - All tools MUST be read-only
217
+ - Never implement any function that modifies system state
218
+ - Use subprocess with caution; validate all inputs
219
+
220
+ ### Input Validation
221
+ - Always validate user input
222
+ - Use whitelists for file paths (see `read_log_file`)
223
+ - Sanitize parameters passed to shell commands
224
+
225
+ ### Error Handling
226
+ - Never expose sensitive information in error messages
227
+ - Catch broad exceptions at the function level
228
+ - Return user-friendly error messages
229
+
230
+ ## Testing Guidelines
231
+
232
+ ### Unit Tests
233
+ Test individual functions in isolation:
234
+ ```python
235
+ @pytest.mark.asyncio
236
+ async def test_function_returns_correct_format():
237
+ result = await module.function()
238
+ assert isinstance(result, str)
239
+ assert "expected" in result
240
+ ```
241
+
242
+ ### Integration Tests
243
+ Test that tools work with the MCP server:
244
+ ```python
245
+ @pytest.mark.asyncio
246
+ async def test_server_has_tool():
247
+ from linux_mcp_server.server import mcp
248
+ tools = await mcp.list_tools()
249
+ tool_names = [t.name for t in tools]
250
+ assert "tool_name" in tool_names
251
+
252
+ @pytest.mark.asyncio
253
+ async def test_server_calls_tool():
254
+ from linux_mcp_server.server import mcp
255
+ result = await mcp.call_tool("tool_name", {})
256
+ assert isinstance(result, str)
257
+ ```
258
+
259
+ ### Running Tests
260
+ ```bash
261
+ # Run all tests
262
+ pytest
263
+
264
+ # Run specific test file
265
+ pytest tests/test_services.py
266
+
267
+ # Run with coverage
268
+ pytest --cov=src --cov-report=html
269
+
270
+ # Run with verbose output
271
+ pytest -v
272
+ ```
273
+
274
+ ## Documentation
275
+
276
+ ### Code Documentation
277
+ - Use docstrings for all public functions
278
+ - Include parameter descriptions
279
+ - Document return values
280
+ - Add usage examples for complex functions
281
+
282
+ ### User Documentation
283
+ - Update README.md for new features
284
+ - Add examples to USAGE.md
285
+ - Document configuration options
286
+ - Include troubleshooting tips
287
+
288
+ ## Pull Request Process
289
+
290
+ 1. **Create a feature branch:**
291
+ ```bash
292
+ git checkout -b feature/my-new-feature
293
+ ```
294
+
295
+ 2. **Make changes following TDD:**
296
+ - Write tests first
297
+ - Implement feature
298
+ - Ensure all tests pass
299
+
300
+ 3. **Update documentation:**
301
+ - Update README.md if needed
302
+ - Update USAGE.md with examples
303
+ - Update CONTRIBUTING.md if changing development process
304
+
305
+ 4. **Run all tests:**
306
+ ```bash
307
+ pytest
308
+ ```
309
+
310
+ 5. **Commit with conventional commit messages:**
311
+ ```bash
312
+ git commit -m "feat: add new diagnostic tool"
313
+ ```
314
+
315
+ 6. **Push and create pull request:**
316
+ ```bash
317
+ git push origin feature/my-new-feature
318
+ ```
319
+
320
+ 7. **PR Description should include:**
321
+ - What the change does
322
+ - Why it's needed
323
+ - How to test it
324
+ - Screenshots/examples if applicable
325
+
326
+ ## Code Review Checklist
327
+
328
+ - [ ] Tests added and passing
329
+ - [ ] Code follows style guidelines
330
+ - [ ] Documentation updated
331
+ - [ ] Commit messages follow conventional format
332
+ - [ ] No security vulnerabilities introduced
333
+ - [ ] All operations are read-only
334
+ - [ ] Error handling is appropriate
335
+ - [ ] Input validation is present
336
+
337
+ ## Questions or Issues?
338
+
339
+ - Open an issue on GitHub
340
+ - Check existing issues first
341
+ - Provide detailed information:
342
+ - System information (OS, version)
343
+ - Steps to reproduce
344
+ - Expected vs actual behavior
345
+ - Relevant logs
346
+
347
+ ## License
348
+
349
+ By contributing, you agree that your contributions will be licensed under the MIT License.
350
+
@@ -0,0 +1,133 @@
1
+ # Debug Logging and Diagnostics
2
+
3
+ This document describes how to enable and use logging to debug and monitor the MCP server operations.
4
+
5
+ ## Overview
6
+
7
+ The Linux MCP Server provides comprehensive logging for:
8
+ - Tool invocations with parameters
9
+ - SSH connection events
10
+ - Command execution (local and remote)
11
+ - Tool execution timing
12
+ - Errors and exceptions
13
+
14
+ Logging is centralized in the server layer with tiered verbosity based on log level.
15
+
16
+ ## Enabling Debug Logging
17
+
18
+ Set the `LINUX_MCP_LOG_LEVEL` environment variable to `DEBUG`:
19
+
20
+ ```bash
21
+ export LINUX_MCP_LOG_LEVEL=DEBUG
22
+ ```
23
+
24
+ ## Log Output Locations
25
+
26
+ Logs are written to two formats:
27
+
28
+ 1. **Human-readable**: `~/.local/share/linux-mcp-server/logs/server.log`
29
+ 2. **JSON format**: `~/.local/share/linux-mcp-server/logs/server.json`
30
+
31
+ You can customize the log directory with:
32
+
33
+ ```bash
34
+ export LINUX_MCP_LOG_DIR=/path/to/your/logs
35
+ ```
36
+
37
+ ## Example Log Output
38
+
39
+ ### Human-Readable Format (INFO level)
40
+
41
+ ```
42
+ 2025-10-10 15:30:45.123 | INFO | linux_mcp_server.audit | TOOL_CALL: list_directories_by_size | path=/home/user, top_n=10 | event=TOOL_CALL | tool=list_directories_by_size | execution_mode=local
43
+ 2025-10-10 15:30:45.456 | INFO | linux_mcp_server.audit | TOOL_COMPLETE: list_directories_by_size | event=TOOL_COMPLETE | tool=list_directories_by_size | status=success | duration=0.333s
44
+ ```
45
+
46
+ ### Human-Readable Format (DEBUG level - shows command execution)
47
+
48
+ ```
49
+ 2025-10-10 15:30:45.123 | INFO | linux_mcp_server.audit | TOOL_CALL: list_directories_by_size | path=/home/user, top_n=10 | event=TOOL_CALL | tool=list_directories_by_size | execution_mode=local
50
+ 2025-10-10 15:30:45.234 | DEBUG | linux_mcp_server.tools.ssh_executor | LOCAL_EXEC completed: du -b --max-depth=1 /home/user | exit_code=0 | duration=0.200s
51
+ 2025-10-10 15:30:45.456 | INFO | linux_mcp_server.audit | TOOL_COMPLETE: list_directories_by_size | event=TOOL_COMPLETE | tool=list_directories_by_size | status=success | duration=0.333s
52
+ ```
53
+
54
+ ### JSON Format
55
+
56
+ ```json
57
+ {
58
+ "timestamp": "2025-10-10T15:30:45",
59
+ "level": "INFO",
60
+ "logger": "linux_mcp_server.audit",
61
+ "message": "TOOL_CALL: list_directories_by_size | path=/home/user, top_n=10",
62
+ "event": "TOOL_CALL",
63
+ "tool": "list_directories_by_size",
64
+ "execution_mode": "local"
65
+ }
66
+ ```
67
+
68
+ ## Implementation
69
+
70
+ Logging is centralized in `src/linux_mcp_server/server.py` using the `_execute_tool()` helper:
71
+
72
+ ```python
73
+ async def _execute_tool(tool_name: str, handler, **kwargs):
74
+ """Execute a tool with logging and error handling."""
75
+ log_tool_call(tool_name, kwargs) # Log invocation
76
+
77
+ start_time = time.time()
78
+ try:
79
+ result = await handler(**kwargs)
80
+ duration = time.time() - start_time
81
+ log_tool_complete(tool_name, status="success", duration=duration)
82
+ return result
83
+ except Exception as e:
84
+ duration = time.time() - start_time
85
+ log_tool_complete(tool_name, status="error", duration=duration, error=str(e))
86
+ raise
87
+ ```
88
+
89
+ All tools are registered using FastMCP decorators:
90
+ ```python
91
+ @mcp.tool()
92
+ async def list_directories_by_size(path: str, top_n: int, ...) -> str:
93
+ return await _execute_tool("list_directories_by_size",
94
+ storage.list_directories_by_size,
95
+ path=path, top_n=top_n, ...)
96
+ ```
97
+
98
+ The `audit.py` module provides structured logging functions:
99
+ - `log_tool_call()`: Logs tool invocation with parameters
100
+ - `log_tool_complete()`: Logs completion with timing and status
101
+ - `log_ssh_connect()`: Logs SSH connection events
102
+ - `log_ssh_command()`: Logs remote command execution
103
+
104
+ ## Log Levels
105
+
106
+ ### INFO Level
107
+ - Tool invocations with parameters
108
+ - Tool completion with status and timing
109
+ - SSH connection success/failure
110
+ - Remote command execution
111
+
112
+ ### DEBUG Level
113
+ - Detailed command execution timing
114
+ - SSH connection pool state
115
+ - Local command execution details
116
+ - All INFO level events plus detailed diagnostics
117
+
118
+ ## Benefits
119
+
120
+ 1. **Centralized Logging**: All logging happens in one place (server.py + audit.py)
121
+ 2. **Structured Data**: Both human-readable and JSON formats available
122
+ 3. **Audit Trail**: Complete record of all operations with timing
123
+ 4. **SSH Monitoring**: Track remote connections and command execution
124
+ 5. **Performance Insights**: Execution duration for every tool call
125
+
126
+ ## Use Cases
127
+
128
+ - **Debugging**: Track tool invocations and identify issues
129
+ - **Auditing**: Complete record of all operations
130
+ - **Performance**: Monitor execution times
131
+ - **SSH Troubleshooting**: Debug connection and authentication issues
132
+ - **Development**: Understand tool behavior during testing
133
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Nicolás M.
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 all
13
+ 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 THE
21
+ SOFTWARE.