- Insecure MCP Demo
Insecure MCP Demo
Content
Insecure MCP Demo
Overview
This project demonstrates a vulnerable MCP server and multiple clients, including a proof-of-concept attack client and also a good client. It is designed for educational purposes to showcase potential security vulnerabilities in MCP server.
Project Structure
vuln-mcp.py: Vulnerable MCP server exposing insecure tools.good-mcp-client.py: Regular good client for normal interactions (insert/query records).attack-mcp-client.py: Automated attack client that demonstrates exploitation of server vulnerabilities.requirements.txt: Python dependencies for the project.
Features & Vulnerabilities
Exposed Server Tools
- insert_record
- Inserts a name/address record into the database.
- Vulnerability: Prone to SQL injection due to direct string interpolation of user input into SQL queries.
- query_records
- Lists all records in the database.
- Vulnerability: Exposes all data without authentication or access control.
- execute_sql
- Executes arbitrary SQL queries provided by the client.
- Vulnerability: Allows any SQL command, including destructive ones (e.g., data exfiltration, schema changes).
- get_env_variable
- Returns the value of any environment variable requested.
- Vulnerability: Leaks sensitive environment variables (e.g., secrets, API keys).
How to Run
1. Install Dependencies
pip install -r requirements.txt
2. Start the Server and Good Client
In one terminal:
python good-mcp-client.py vuln-mcp.py
Follow the prompts to insert/query records interactively.
3. Run the Attack Client
In another terminal:
python attack-mcp-client.py vuln-mcp.py
This will automatically:
- Attempt SQL injection attacks
- Execute arbitrary SQL queries
- Attempt to read several common environment variables
Example Output
- Attack client will show which payloads succeed or fail, and print out database contents and environment variable values if accessible.
Vulnerabilities Demonstrated
- SQL Injection: User input is unsanitized, allowing attackers to manipulate SQL logic and insert arbitrary data.
- Arbitrary Code Execution: The
execute_sqltool allows attackers to run any SQL command, including data theft or destruction. - Sensitive Data Exposure: The
get_env_variabletool allows attackers to read secrets and configuration values. - Lack of Access Control: Anyone can run all tools and access all data without authentication.
Mitigation Strategies
To secure a real-world MCP server, you should:
- Use Parameterized Queries:
- Always use parameter substitution instead of string interpolation for SQL queries to prevent injection.
- Example (secure):
cursor.execute("INSERT INTO records (name, address) VALUES (?, ?)", (name, address))
- Restrict Dangerous Tools:
- Remove or strictly limit tools like
execute_sqlandget_env_variable. - Only expose necessary functionality.
- Remove or strictly limit tools like
- Implement Authentication & Authorization:
- Require users to authenticate and check permissions before allowing access to sensitive tools or data.
- Validate and Sanitize Input:
- Check and sanitize all user inputs, especially those that interact with the database or system.
- Limit Environment Variable Access:
- Only allow access to non-sensitive variables, or remove this tool entirely.
- Audit and Monitor Usage:
- Log all tool invocations and monitor for suspicious or abusive behavior.
- Principle of Least Privilege:
- Run the server with minimal privileges and restrict database and OS access as much as possible.
Disclaimer
This project is for educational and demonstration purposes only. Do not deploy this code in production environments.
For questions or further improvements, please open an issue or contact the project maintainer.
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Playwright McpPlaywright MCP server
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题;
Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Serper MCP ServerA Serper MCP Server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Tavily Mcp
Amap Maps高德地图官方 MCP Server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
DeepChatYour AI Partner on Desktop
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
CursorThe AI Code Editor
ChatWiseThe second fastest AI chatbot™
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
WindsurfThe new purpose-built IDE to harness magic