mcpcap 0.4.7__tar.gz → 0.5.2__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 (59) hide show
  1. {mcpcap-0.4.7 → mcpcap-0.5.2}/.github/workflows/release.yml +7 -15
  2. {mcpcap-0.4.7 → mcpcap-0.5.2}/.gitignore +6 -1
  3. mcpcap-0.5.2/CONTRIBUTING.md +474 -0
  4. mcpcap-0.5.2/PKG-INFO +371 -0
  5. mcpcap-0.5.2/README.md +303 -0
  6. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/source/api/modules.rst +16 -0
  7. mcpcap-0.5.2/docs/source/developer/contributing.md +317 -0
  8. mcpcap-0.5.2/docs/source/developer/module-creation-tutorial.md +741 -0
  9. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/source/index.rst +17 -10
  10. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/source/user-guide/analysis-guides.md +1 -1
  11. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/source/user-guide/mcp-integration.md +14 -13
  12. mcpcap-0.5.2/docs/source/user-guide/quickstart.md +264 -0
  13. mcpcap-0.5.2/examples/README.md +238 -0
  14. {mcpcap-0.4.7 → mcpcap-0.5.2}/pyproject.toml +21 -1
  15. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap/_version.py +3 -3
  16. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap/cli.py +3 -16
  17. mcpcap-0.5.2/src/mcpcap/core/config.py +29 -0
  18. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap/core/server.py +11 -12
  19. mcpcap-0.5.2/src/mcpcap/modules/base.py +133 -0
  20. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap/modules/dhcp.py +6 -117
  21. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap/modules/dns.py +6 -116
  22. mcpcap-0.5.2/src/mcpcap/modules/icmp.py +327 -0
  23. mcpcap-0.5.2/src/mcpcap.egg-info/PKG-INFO +371 -0
  24. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap.egg-info/SOURCES.txt +6 -1
  25. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap.egg-info/requires.txt +3 -0
  26. {mcpcap-0.4.7 → mcpcap-0.5.2}/tests/test_cli.py +14 -20
  27. {mcpcap-0.4.7 → mcpcap-0.5.2}/tests/test_dhcp.py +33 -84
  28. mcpcap-0.5.2/tests/test_dns.py +60 -0
  29. mcpcap-0.5.2/tests/test_modules/test_icmp.py +75 -0
  30. mcpcap-0.4.7/PKG-INFO +0 -345
  31. mcpcap-0.4.7/README.md +0 -280
  32. mcpcap-0.4.7/docs/source/user-guide/quickstart.md +0 -188
  33. mcpcap-0.4.7/examples/README.md +0 -83
  34. mcpcap-0.4.7/src/mcpcap/core/config.py +0 -230
  35. mcpcap-0.4.7/src/mcpcap/modules/base.py +0 -36
  36. mcpcap-0.4.7/src/mcpcap.egg-info/PKG-INFO +0 -345
  37. mcpcap-0.4.7/tests/test_dns.py +0 -111
  38. {mcpcap-0.4.7 → mcpcap-0.5.2}/.github/FUNDING.yml +0 -0
  39. {mcpcap-0.4.7 → mcpcap-0.5.2}/.github/workflows/test.yml +0 -0
  40. {mcpcap-0.4.7 → mcpcap-0.5.2}/.readthedocs.yaml +0 -0
  41. {mcpcap-0.4.7 → mcpcap-0.5.2}/LICENSE +0 -0
  42. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/Makefile +0 -0
  43. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/source/_static/.gitkeep +0 -0
  44. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/source/api/cli.rst +0 -0
  45. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/source/api/core.rst +0 -0
  46. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/source/conf.py +0 -0
  47. {mcpcap-0.4.7 → mcpcap-0.5.2}/docs/source/user-guide/installation.md +0 -0
  48. {mcpcap-0.4.7 → mcpcap-0.5.2}/examples/dhcp.pcap +0 -0
  49. {mcpcap-0.4.7 → mcpcap-0.5.2}/examples/dns.pcap +0 -0
  50. {mcpcap-0.4.7 → mcpcap-0.5.2}/readme-assets/mcpcap-logo.png +0 -0
  51. {mcpcap-0.4.7 → mcpcap-0.5.2}/server.json +0 -0
  52. {mcpcap-0.4.7 → mcpcap-0.5.2}/setup.cfg +0 -0
  53. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap/__init__.py +0 -0
  54. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap/core/__init__.py +0 -0
  55. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap/modules/__init__.py +0 -0
  56. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap.egg-info/dependency_links.txt +0 -0
  57. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap.egg-info/entry_points.txt +0 -0
  58. {mcpcap-0.4.7 → mcpcap-0.5.2}/src/mcpcap.egg-info/top_level.txt +0 -0
  59. {mcpcap-0.4.7 → mcpcap-0.5.2}/tests/__init__.py +0 -0
@@ -32,13 +32,18 @@ jobs:
32
32
  run: |
33
33
  # Extract version from tag (remove 'v' prefix)
34
34
  TAG_VERSION=${GITHUB_REF#refs/tags/v}
35
- # Get version from setuptools-scm
36
- DETECTED_VERSION=$(python -c "from setuptools_scm import get_version; print(get_version())")
35
+ # Debug git state
36
+ echo "Current commit: $(git rev-parse HEAD)"
37
+ echo "Current tag: $(git describe --tags)"
38
+ echo "All tags: $(git tag --list | tail -3)"
39
+ # Get version from setuptools-scm with debug
40
+ DETECTED_VERSION=$(python -c "import setuptools_scm; print(setuptools_scm.get_version())")
37
41
  echo "Tag version: $TAG_VERSION"
38
42
  echo "Detected version: $DETECTED_VERSION"
39
43
  # Verify they match
40
44
  if [ "$TAG_VERSION" != "$DETECTED_VERSION" ]; then
41
45
  echo "Version mismatch! Tag: $TAG_VERSION, Detected: $DETECTED_VERSION"
46
+ echo "This might be due to setuptools-scm caching or git fetch issues"
42
47
  exit 1
43
48
  fi
44
49
 
@@ -138,19 +143,6 @@ jobs:
138
143
  if: steps.pypi_publish.outcome == 'success'
139
144
  run: ./mcp-publisher login dns --domain mcpcap.ai --private-key "${{ secrets.MCP_PRIVATE_KEY }}"
140
145
 
141
- # -------- (Optional) Validate server.json before publishing ----------------
142
- - name: Validate server.json (optional)
143
- if: steps.pypi_publish.outcome == 'success'
144
- run: |
145
- if [ -f server.json ]; then
146
- # Validate against published schema
147
- curl -s https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json | jq . > schema.json
148
- npm i -g ajv-cli >/dev/null 2>&1 || true
149
- ajv validate -s schema.json -d server.json || (echo "server.json failed schema validation"; exit 1)
150
- else
151
- echo "server.json not found; skipping validation"
152
- fi
153
-
154
146
  # -------- MCP Registry: publish -------------------------------------------
155
147
  - name: Publish to MCP Registry
156
148
  if: steps.pypi_publish.outcome == 'success'
@@ -217,4 +217,9 @@ src/mcpcap/_version.py
217
217
 
218
218
  .DS_Store
219
219
  plan.md
220
- key.pem
220
+ key.pem
221
+
222
+ # Website files (used separately)
223
+ index.html
224
+ script.js
225
+ styles.css
@@ -0,0 +1,474 @@
1
+ # Contributing to mcpcap
2
+
3
+ Thank you for your interest in contributing to mcpcap! This guide will help you get started with development and contributing new features, especially new protocol analysis modules.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Development Setup](#development-setup)
8
+ - [Code Style and Standards](#code-style-and-standards)
9
+ - [Creating New Modules](#creating-new-modules)
10
+ - [Testing Requirements](#testing-requirements)
11
+ - [Documentation](#documentation)
12
+ - [Pull Request Process](#pull-request-process)
13
+ - [Getting Help](#getting-help)
14
+
15
+ ## Development Setup
16
+
17
+ ### Prerequisites
18
+
19
+ - Python 3.10 or higher
20
+ - Git
21
+ - Virtual environment tool (venv, conda, etc.)
22
+
23
+ ### Setup Process
24
+
25
+ 1. **Fork and clone the repository:**
26
+ ```bash
27
+ git clone https://github.com/your-username/mcpcap.git
28
+ cd mcpcap
29
+ ```
30
+
31
+ 2. **Create a virtual environment:**
32
+ ```bash
33
+ python -m venv venv
34
+ source venv/bin/activate # On Windows: venv\Scripts\activate
35
+ ```
36
+
37
+ 3. **Install development dependencies:**
38
+ ```bash
39
+ pip install -e ".[dev]"
40
+ ```
41
+
42
+ 4. **Development tools are already included:**
43
+ ```bash
44
+ # The [dev] dependencies include ruff, mypy, pytest, etc.
45
+ # No additional installation needed
46
+ ```
47
+
48
+ 5. **Verify installation:**
49
+ ```bash
50
+ # Run tests
51
+ pytest
52
+
53
+ # Start the server
54
+ mcpcap
55
+ ```
56
+
57
+ ## Code Style and Standards
58
+
59
+ ### Python Code Style
60
+
61
+ We use several tools to maintain code quality:
62
+
63
+ - **Ruff**: For linting and formatting
64
+ - **Black**: Code formatting (via ruff)
65
+ - **isort**: Import sorting (via ruff)
66
+ - **mypy**: Type checking
67
+
68
+ ### Running Code Quality Checks
69
+
70
+ ```bash
71
+ # Format code
72
+ ruff format
73
+
74
+ # Check linting
75
+ ruff check
76
+
77
+ # Type checking (when mypy is configured)
78
+ mypy src/mcpcap
79
+
80
+ # Run all checks together
81
+ ruff check && ruff format && pytest
82
+ ```
83
+
84
+ ### Code Standards
85
+
86
+ 1. **Type Hints**: All functions should have type hints (we're working to improve existing code)
87
+ 2. **Docstrings**: All public functions and classes must have docstrings
88
+ 3. **Error Handling**: Use explicit exception handling with meaningful messages
89
+ 4. **Logging**: Use proper logging instead of print statements
90
+ 5. **Testing**: All new code must have tests with >95% coverage
91
+
92
+ **Note**: We're currently improving our codebase to fully comply with mypy strict mode. New contributions should follow these standards, and we welcome help fixing existing type issues!
93
+
94
+ ## Creating New Modules
95
+
96
+ ### Module Architecture
97
+
98
+ mcpcap uses a modular architecture where each protocol analyzer inherits from `BaseModule`. Here's how to create a new module:
99
+
100
+ ### 1. Create the Module File
101
+
102
+ Create a new file in `src/mcpcap/modules/` for your protocol (e.g., `http.py`):
103
+
104
+ ```python
105
+ """HTTP analysis module."""
106
+
107
+ from typing import Any
108
+ from fastmcp import FastMCP
109
+ from scapy.all import HTTP, TCP, rdpcap
110
+
111
+ from .base import BaseModule
112
+
113
+
114
+ class HTTPModule(BaseModule):
115
+ """Module for analyzing HTTP packets in PCAP files."""
116
+
117
+ @property
118
+ def protocol_name(self) -> str:
119
+ """Return the name of the protocol this module analyzes."""
120
+ return "HTTP"
121
+
122
+ def analyze_http_packets(self, pcap_file: str) -> dict[str, Any]:
123
+ """
124
+ Analyze HTTP packets from a PCAP file.
125
+
126
+ Args:
127
+ pcap_file: Path to local PCAP file or HTTP URL to remote PCAP file
128
+
129
+ Returns:
130
+ A structured dictionary containing HTTP packet analysis results
131
+ """
132
+ return self.analyze_packets(pcap_file)
133
+
134
+ def _analyze_protocol_file(self, pcap_file: str) -> dict[str, Any]:
135
+ """Perform the actual HTTP packet analysis on a local PCAP file."""
136
+ try:
137
+ packets = rdpcap(pcap_file)
138
+ http_packets = [pkt for pkt in packets if pkt.haslayer(HTTP)]
139
+
140
+ if not http_packets:
141
+ return {
142
+ "file": pcap_file,
143
+ "total_packets": len(packets),
144
+ "http_packets_found": 0,
145
+ "message": "No HTTP packets found in this capture",
146
+ }
147
+
148
+ # Apply max_packets limit if specified
149
+ packets_to_analyze = http_packets
150
+ limited = False
151
+ if self.config.max_packets and len(http_packets) > self.config.max_packets:
152
+ packets_to_analyze = http_packets[:self.config.max_packets]
153
+ limited = True
154
+
155
+ packet_details = []
156
+ for i, pkt in enumerate(packets_to_analyze, 1):
157
+ packet_info = self._analyze_http_packet(pkt, i)
158
+ packet_details.append(packet_info)
159
+
160
+ # Generate statistics
161
+ stats = self._generate_statistics(packet_details)
162
+
163
+ result = {
164
+ "file": pcap_file,
165
+ "total_packets": len(packets),
166
+ "http_packets_found": len(http_packets),
167
+ "http_packets_analyzed": len(packet_details),
168
+ "statistics": stats,
169
+ "packets": packet_details,
170
+ }
171
+
172
+ if limited:
173
+ result["note"] = (
174
+ f"Analysis limited to first {self.config.max_packets} HTTP packets"
175
+ )
176
+
177
+ return result
178
+
179
+ except Exception as e:
180
+ return {
181
+ "error": f"Error reading PCAP file '{pcap_file}': {str(e)}",
182
+ "file": pcap_file,
183
+ }
184
+
185
+ def _analyze_http_packet(self, packet, packet_num: int) -> dict[str, Any]:
186
+ """Analyze a single HTTP packet."""
187
+ # Implement packet analysis logic
188
+ return {
189
+ "packet_number": packet_num,
190
+ "timestamp": packet.time,
191
+ # Add more fields as needed
192
+ }
193
+
194
+ def _generate_statistics(self, packets: list[dict[str, Any]]) -> dict[str, Any]:
195
+ """Generate statistics from analyzed HTTP packets."""
196
+ # Implement statistics generation
197
+ return {
198
+ "total_requests": 0,
199
+ "total_responses": 0,
200
+ # Add more statistics as needed
201
+ }
202
+
203
+ def setup_prompts(self, mcp: FastMCP) -> None:
204
+ """Set up HTTP-specific analysis prompts."""
205
+
206
+ @mcp.prompt
207
+ def http_security_analysis():
208
+ """Prompt for analyzing HTTP traffic from a security perspective"""
209
+ return """You are analyzing HTTP traffic for security issues..."""
210
+ ```
211
+
212
+ ### 2. Register the Module
213
+
214
+ Add your module to `src/mcpcap/core/server.py`:
215
+
216
+ ```python
217
+ from ..modules.http import HTTPModule # Add import
218
+
219
+ # In the __init__ method:
220
+ if "http" in self.config.modules:
221
+ self.modules["http"] = HTTPModule(config)
222
+
223
+ # In the _register_tools method:
224
+ elif module_name == "http":
225
+ self.mcp.tool(module.analyze_http_packets)
226
+ ```
227
+
228
+ ### 3. Update Configuration
229
+
230
+ Add your module to the default modules list in `src/mcpcap/cli.py`:
231
+
232
+ ```python
233
+ parser.add_argument(
234
+ "--modules",
235
+ default="dns,dhcp,http", # Add your module here
236
+ help="Comma-separated list of modules to load (dns,dhcp,http)",
237
+ )
238
+ ```
239
+
240
+ ### 4. Create Tests
241
+
242
+ Create tests in `tests/test_modules/test_http.py`:
243
+
244
+ ```python
245
+ """Tests for HTTP module."""
246
+
247
+ from unittest.mock import Mock, patch
248
+ import pytest
249
+
250
+ from mcpcap.modules.http import HTTPModule
251
+ from mcpcap.core.config import Config
252
+
253
+
254
+ class TestHTTPModule:
255
+ """Test HTTP module functionality."""
256
+
257
+ def setup_method(self):
258
+ """Set up test fixtures."""
259
+ config = Config(modules=["http"], max_packets=None)
260
+ self.http_module = HTTPModule(config)
261
+
262
+ def test_protocol_name(self):
263
+ """Test protocol name property."""
264
+ assert self.http_module.protocol_name == "HTTP"
265
+
266
+ @patch("mcpcap.modules.http.rdpcap")
267
+ def test_analyze_http_packets_no_packets(self, mock_rdpcap):
268
+ """Test analysis with no HTTP packets."""
269
+ # Mock empty packet capture
270
+ mock_rdpcap.return_value = []
271
+
272
+ result = self.http_module.analyze_http_packets("test.pcap")
273
+
274
+ assert result["http_packets_found"] == 0
275
+ assert "No HTTP packets found" in result["message"]
276
+ ```
277
+
278
+ ### 5. Add Documentation
279
+
280
+ Create documentation in `docs/source/user-guide/` and add examples to the tutorial.
281
+
282
+ ## Testing Requirements
283
+
284
+ ### Running Tests
285
+
286
+ ```bash
287
+ # Run all tests
288
+ pytest
289
+
290
+ # Run with coverage
291
+ pytest --cov=src/mcpcap --cov-report=html
292
+
293
+ # Run specific test file
294
+ pytest tests/test_modules/test_http.py
295
+
296
+ # Run with verbose output
297
+ pytest -v
298
+ ```
299
+
300
+ ### Test Coverage Requirements
301
+
302
+ - All new modules must have >95% test coverage
303
+ - All public methods must have tests
304
+ - Error conditions must be tested
305
+ - Edge cases should be covered
306
+
307
+ ### Test Structure
308
+
309
+ - Unit tests for individual functions
310
+ - Integration tests for module workflow
311
+ - Mock external dependencies (scapy, file system, network)
312
+ - Test both success and failure scenarios
313
+
314
+ ## Documentation
315
+
316
+ ### Required Documentation
317
+
318
+ 1. **Module docstrings**: Complete API documentation
319
+ 2. **User guide updates**: Add your module to relevant guides
320
+ 3. **Examples**: Provide working examples with sample data
321
+ 4. **Tutorial updates**: Add your module to the module creation tutorial
322
+
323
+ ### Documentation Style
324
+
325
+ - Use clear, concise language
326
+ - Provide practical examples
327
+ - Include both simple and advanced use cases
328
+ - Follow the existing documentation structure
329
+
330
+ ### Building Documentation Locally
331
+
332
+ ```bash
333
+ # Install docs dependencies
334
+ pip install -e ".[docs]"
335
+
336
+ # Build documentation
337
+ cd docs
338
+ make html
339
+
340
+ # View documentation
341
+ open build/html/index.html
342
+ ```
343
+
344
+ ## Development Workflow
345
+
346
+ We follow **GitHub Flow** for all development:
347
+
348
+ 1. **Create feature branches** from `main` for all changes
349
+ 2. **Use descriptive branch names**: `feature/add-http-module`, `fix/dns-parsing-bug`, `docs/update-contributing`
350
+ 3. **Keep branches focused** - one feature or fix per branch
351
+ 4. **Create pull requests early** for feedback and collaboration
352
+ 5. **Merge to main** only after review and CI passes
353
+ 6. **Delete feature branches** after merging
354
+
355
+ ### Branch Naming Convention
356
+
357
+ ```bash
358
+ feature/description-of-feature # New features
359
+ fix/description-of-bug # Bug fixes
360
+ docs/description-of-change # Documentation updates
361
+ refactor/description-of-change # Code refactoring
362
+ test/description-of-test # Test improvements
363
+ ```
364
+
365
+ ## Pull Request Process
366
+
367
+ ### Before Submitting
368
+
369
+ 1. **Run all checks:**
370
+ ```bash
371
+ # Format and lint your code
372
+ ruff format
373
+ ruff check
374
+
375
+ # Run tests
376
+ pytest
377
+
378
+ # Optional: Check types (may show issues in existing code)
379
+ mypy src/mcpcap --follow-imports=skip
380
+ ```
381
+
382
+ 2. **Update documentation:**
383
+ - Add/update docstrings
384
+ - Update user guides if needed
385
+ - Add examples
386
+
387
+ 3. **Write good commit messages:**
388
+ ```
389
+ Add HTTP analysis module
390
+
391
+ - Implement HTTP packet parsing with request/response analysis
392
+ - Add security-focused analysis prompts
393
+ - Include comprehensive test coverage
394
+ - Update documentation with HTTP examples
395
+ ```
396
+
397
+ ### Pull Request Guidelines
398
+
399
+ 1. **Create a feature branch:**
400
+ ```bash
401
+ git checkout -b feature/add-http-module
402
+ ```
403
+
404
+ 2. **Keep PRs focused:** One feature or fix per PR
405
+
406
+ 3. **Write descriptive PR description:**
407
+ - Explain what the PR does
408
+ - Reference any related issues
409
+ - Include testing notes
410
+ - Add examples of usage
411
+
412
+ 4. **Respond to review feedback:** Address all comments promptly
413
+
414
+ ### PR Template
415
+
416
+ ```markdown
417
+ ## Description
418
+ Brief description of changes.
419
+
420
+ ## Type of Change
421
+ - [ ] Bug fix
422
+ - [ ] New feature (new protocol module)
423
+ - [ ] Documentation update
424
+ - [ ] Performance improvement
425
+ - [ ] Other (please describe)
426
+
427
+ ## Testing
428
+ - [ ] Tests pass locally
429
+ - [ ] Added new tests for new functionality
430
+ - [ ] Coverage remains >95%
431
+
432
+ ## Documentation
433
+ - [ ] Updated relevant documentation
434
+ - [ ] Added examples
435
+ - [ ] Docstrings updated
436
+
437
+ ## Checklist
438
+ - [ ] Code follows style guidelines
439
+ - [ ] Self-review completed
440
+ - [ ] Tests added/updated
441
+ - [ ] Documentation updated
442
+ ```
443
+
444
+ ## Getting Help
445
+
446
+ ### Resources
447
+
448
+ - **Documentation**: https://mcpcap.readthedocs.io
449
+ - **Examples**: Check the `examples/` directory
450
+ - **Existing modules**: Study `dns.py` and `dhcp.py` as references
451
+
452
+ ### Communication
453
+
454
+ - **Issues**: Open GitHub issues for bugs or feature requests
455
+ - **Discussions**: Use GitHub discussions for questions
456
+ - **Security**: Report security issues privately
457
+
458
+ ### Module Development Tips
459
+
460
+ 1. **Start simple:** Begin with basic packet parsing
461
+ 2. **Follow patterns:** Use existing modules as templates
462
+ 3. **Test incrementally:** Write tests as you develop
463
+ 4. **Handle errors gracefully:** Provide meaningful error messages
464
+ 5. **Document as you go:** Write docstrings immediately
465
+
466
+ ## Contributing Guidelines Summary
467
+
468
+ - Fork the repository and create feature branches
469
+ - Follow code style and testing requirements
470
+ - Write comprehensive documentation
471
+ - Submit focused pull requests
472
+ - Respond to review feedback promptly
473
+
474
+ Thank you for contributing to mcpcap! Your contributions help make network analysis more accessible and powerful for everyone.