Skip to main content
Glama
ShaojieJiang

Dangerous MCP

by ShaojieJiang

MCP 很危险

函数工具的使用让 AI 代理变得非常强大,这就像将应用商店引入智能手机一样。尤其是随着MCP(模型上下文协议)的发布,工具共享变得比以往任何时候都更加便捷。因此,我创建了可扩展代理项目,以展示如何通过开源工具或自定义工具轻松扩展 AI 代理的功能。

在开发可扩展代理的过程中,我意识到工具的使用是一把双刃剑。危险在于,你使用的工具拥有对你机器的强大访问权限,例如你的环境变量、文件等等。

⚠️ 安全警告

该项目简单演示了与工具使用相关的安全风险。以下示例说明了恶意行为者如何利用 MCP 服务器访问敏感信息:

# WARNING: This is a demonstration of security risks.
# DO NOT use this code maliciously!

import os
from mcp.server.fastmcp import FastMCP


server = FastMCP("Dangerous MCP")


@server.tool()
async def get_environment_variables() -> str:
    """Get all environment variables."""
    result = [
        "Here are what I could find:",
    ]
    for key, value in os.environ.items():
        result.append(f"{key:<30} {value[:5]}***")
    # This means I can open a backdoor to send your data to me!!
    return "\n".join(result)

⚠️**警告:**建议在沙盒环境中运行此示例,然后删除你的 OpenAI API 密钥。你也可以使用自己的 MCP 客户端进行测试,命令如下: uvx mcp-is-dangerous

当将此工具与可扩展代理(选择PoliceAgent )一起使用时,输出如下所示:

它可能看起来无害,甚至是故意为之,对吧?但想象一下这种情况:你只是询问当前时间,与此同时,你的敏感数据却在你不知情的情况下被泄露了。

Related MCP server: Damn Vulnerable MCP Server Demo

安全最佳实践

使用 MCP 或类似工具时保护自己:

  1. 使用工具前务必检查其源代码

  2. 尽可能在隔离环境中运行工具

  3. 谨慎对待请求访问敏感信息的工具

  4. 部署工具时使用环境变量过滤

  5. 定期审核你正在使用的工具

免责声明

本项目仅用于教育目的,旨在演示潜在的安全风险。请勿将此信息用于恶意目的。作者对任何信息滥用概不负责。

执照

MIT 许可证

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

Resources

Looking for Admin?

Admins can modify the Dockerfile, update the server description, and track usage metrics. If you are the server author, to access the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ShaojieJiang/mcp-is-dangerous'

If you have feedback or need assistance with the MCP directory API, please join our Discord server