{"id":29795604,"url":"https://github.com/alex-ilgayev/mcpspy","last_synced_at":"2025-07-28T04:33:32.755Z","repository":{"id":305313216,"uuid":"1021571950","full_name":"alex-ilgayev/MCPSpy","owner":"alex-ilgayev","description":"MCP Monitoring with eBPF","archived":false,"fork":false,"pushed_at":"2025-07-26T18:15:20.000Z","size":29834,"stargazers_count":211,"open_issues_count":7,"forks_count":24,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-26T22:56:11.910Z","etag":null,"topics":["ai","ai-security","llm","mcp","monitoring","security"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alex-ilgayev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-17T15:47:17.000Z","updated_at":"2025-07-26T22:32:37.000Z","dependencies_parsed_at":"2025-07-19T15:19:10.910Z","dependency_job_id":"eb5c7b34-870f-4e10-937e-b34fc1618503","html_url":"https://github.com/alex-ilgayev/MCPSpy","commit_stats":null,"previous_names":["alex-ilgayev/mcpspy"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alex-ilgayev/MCPSpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-ilgayev%2FMCPSpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-ilgayev%2FMCPSpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-ilgayev%2FMCPSpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-ilgayev%2FMCPSpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alex-ilgayev","download_url":"https://codeload.github.com/alex-ilgayev/MCPSpy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-ilgayev%2FMCPSpy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267464307,"owners_count":24091492,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai-security","llm","mcp","monitoring","security"],"created_at":"2025-07-28T04:32:54.615Z","updated_at":"2025-07-28T04:33:32.747Z","avatar_url":"https://github.com/alex-ilgayev.png","language":"C","funding_links":[],"categories":["Provenance, Instrumentation \u0026 Observability"],"sub_categories":[],"readme":"# MCPSpy - MCP Monitoring with eBPF 🕵️✨\n\n[![CI](https://github.com/alex-ilgayev/mcpspy/actions/workflows/ci.yml/badge.svg)](https://github.com/alex-ilgayev/mcpspy/actions/workflows/ci.yml)\n[![Go Version](https://img.shields.io/badge/go-1.24+-blue.svg)](https://golang.org)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)\n\n\u003cdiv align=\"center\"\u003e\n\u003cpre\u003e\n███╗   ███╗ ██████╗██████╗ ███████╗██████╗ ██╗   ██╗\n████╗ ████║██╔════╝██╔══██╗██╔════╝██╔══██╗╚██╗ ██╔╝\n██╔████╔██║██║     ██████╔╝███████╗██████╔╝ ╚████╔╝ \n██║╚██╔╝██║██║     ██╔═══╝ ╚════██║██╔═══╝   ╚██╔╝  \n██║ ╚═╝ ██║╚██████╗██║     ███████║██║        ██║   \n╚═╝     ╚═╝ ╚═════╝╚═╝     ╚══════╝╚═╝        ╚═╝   \n\u003c/pre\u003e\n\u003cb\u003eMCPSpy - Real-time monitoring for Model Context Protocol communication using eBPF\u003c/b\u003e\n\u003c/div\u003e\n\n## Overview\n\nMCPSpy is a powerful command-line tool that leverages [eBPF (Extended Berkeley Packet Filter)](https://ebpf.io/) technology to monitor [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) communication at the kernel level. It provides real-time visibility into JSON-RPC 2.0 messages exchanged between MCP clients and servers by hooking into low-level system calls.\n\nThe Model Context Protocol supports three transport protocols for communication:\n\n- **Stdio**: Communication over standard input/output streams\n- **Streamable HTTP**: Direct HTTP request/response communication with server-sent events\n- **SSE (Server-Sent Events)**: HTTP-based streaming communication (_Deprecated_)\n\n**MCPSpy currently supports only Stdio transport monitoring**, with plans to extend support to SSE and HTTP transports in future releases.\n\n![demo](./assets/demo.gif)\n\n## Why MCPSpy?\n\nThe Model Context Protocol is becoming the standard for AI tool integration, but understanding what's happening under the hood can be challenging. MCPSpy addresses this by providing:\n\n- **🔒 Security Analysis**: Monitor what data is being transmitted, detect PII leakage, and audit tool executions\n- **🐛 Debugging**: Troubleshoot MCP integrations by seeing the actual message flow\n- **📊 Performance Monitoring**: Track message patterns and identify bottlenecks\n- **🔍 Compliance**: Ensure MCP communications meet regulatory requirements\n- **🎓 Learning**: Understand how MCP works by observing real communications\n\n## Installation\n\n### Prerequisites\n\n- Linux kernel version 5.10 or later\n- Root privileges (required for eBPF)\n\n### Download Pre-built Binary\n\nDownload the latest release from the [releases page](https://github.com/alex-ilgayev/mcpspy/releases):\n\n```bash\nwget https://github.com/alex-ilgayev/mcpspy/releases/latest/download/mcpspy\nchmod +x mcpspy\nsudo mv mcpspy /usr/local/bin/\n```\n\n### Build from Source\n\n```bash\ngit clone https://github.com/alex-ilgayev/mcpspy.git\ncd mcpspy\n\nsudo apt-get update\nsudo apt-get install -y clang llvm make libbpf-dev\nmake\n```\n\n### Docker\n\n```bash\n# Build Docker image\nmake image\n# Or pull the latest image\ndocker pull ghcr.io/alex-ilgayev/mcpspy:latest\n# Or pull a specific image release\ndocker pull ghcr.io/alex-ilgayev/mcpspy:v0.1.0\n\n# Run the container\ndocker run --rm -it --privileged ghcr.io/alex-ilgayev/mcpspy:latest\n```\n\n## Usage\n\n### Basic Usage\n\n```bash\n# Start monitoring MCP communication\nsudo mcpspy\n\n# Start monitoring with raw message buffers\nsudo mcpspy -b\n\n# Start monitoring and save output to JSONL file\nsudo mcpspy -o output.jsonl\n\n# Stop monitoring with Ctrl+C\n```\n\n### Output Format\n\n#### Console Output\n\n```\n\n12:34:56.789 python[12345] → python[12346] REQ tools/call (get_weather) Execute a tool\n12:34:56.890 python[12346] → python[12345] RESP OK\n\n```\n\n#### JSONL Output\n\n```json\n{\n  \"timestamp\": \"2024-01-15T12:34:56.789Z\",\n  \"transport_type\": \"stdio\",\n  \"stdio_transport\": {\n    \"from_pid\": 12345,\n    \"from_comm\": \"python\",\n    \"to_pid\": 12346,\n    \"to_comm\": \"python\"\n  },\n  \"type\": \"request\",\n  \"method\": \"tools/call\",\n  \"params\": {\n    \"name\": \"get_weather\",\n    \"arguments\": { \"city\": \"New York\" }\n  }\n}\n```\n\n## Architecture\n\nMCPSpy consists of several components:\n\n### 1. eBPF Program (`bpf/`)\n\n- Hooks into `vfs_read` and `vfs_write` kernel functions\n- Filters potential MCP traffic by detecting JSON patterns\n- Sends events to userspace via ring buffer\n- Minimal performance impact with early filtering\n\n### 2. eBPF Loader (`pkg/ebpf/`)\n\n- Manages the lifecycle of eBPF programs and resources\n- Loads pre-compiled eBPF objects into the kernel using cilium/ebpf library\n- Converts raw binary events from kernel space into structured Go data types\n\n### 3. MCP Protocol Parser (`pkg/mcp/`)\n\n- Validates JSON-RPC 2.0 message format\n- Parses MCP-specific methods and parameters\n- Correlates read operations and write operations into a single MCP message (relevant for stdio transport)\n- Currently supports stdio transport (streamable HTTP/SSE planned)\n\n### 4. Output Handlers (`pkg/output/`)\n\n- Console display with colored, formatted output\n- JSONL output for programmatic analysis\n- Real-time statistics tracking\n\n## Development\n\n### Building\n\n```bash\n# Generate eBPF bindings and build\nmake\n\n# Build Docker image\nmake image\n```\n\n### Testing\n\nMCPSpy includes comprehensive end-to-end tests that simulate real MCP communication:\n\n```bash\n# (Optional) Set up test environment\nmake test-e2e-setup\n\n# Run tests (requires root privileges)\nmake test-e2e\n```\n\nThe test suite includes:\n\n- MCP server and client simulators\n- Message validation against expected outputs\n- Multiple message type coverage\n\n## Limitations\n\n- **FS Events Buffer Size**: Limited to 16KB per message. This means MCP messages larger than 16KB will be missed / ignored.\n- **Platform**: Linux only (kernel 5.10+).\n- **Transport**: Currently supports stdio transport only. Support for streamable HTTP and SSE transports is planned.\n\n## Contributing\n\nWe welcome contributions! Feel free to open an issue or a pull request.\n\n## License\n\n- **User-mode code** (Mainly Go): Apache 2.0 (see [LICENSE](LICENSE))\n- **eBPF C programs** (`bpf/*`): GPL-2.0-only (see [LICENSE-BPF](LICENSE-BPF))\n\n---\n\n\u003cdiv align=\"center\"\u003e\nMade with ❤️ by Alex Ilgayev\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex-ilgayev%2Fmcpspy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falex-ilgayev%2Fmcpspy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex-ilgayev%2Fmcpspy/lists"}