一个基于容器的安全实现,用于执行大型语言模型请求的工具。
Container-MCP 提供了一个沙箱环境,可以安全地执行代码、运行命令、访问文件以及执行网络操作。它实现了 MCP 协议,以暴露这些能力作为工具,这些工具可以被AI系统在安全的方式下发现和调用。
架构采用领域特定管理器模式,并有多层安全措施,确保工具在隔离环境中执行并具有适当的限制,从而保护主机系统免受潜在有害操作的影响。
多层安全
MCP 协议实现
领域特定管理器
BashManager:安全命令执行PythonManager:沙箱内 Python 代码执行FileManager:安全文件操作WebManager:安全网络浏览和抓取KnowledgeBaseManager:结构化文档存储与语义搜索可配置环境
system_run_command在安全沙箱环境中执行 bash 命令。
command (字符串,必需):要执行的 bash 命令working_dir (字符串,可选):工作目录(在沙箱中忽略)stdout (字符串):命令的标准输出stderr (字符串):命令的标准错误exit_code (整数):命令退出码success (布尔值):命令是否成功完成{
"stdout": "file1.txt\nfile2.txt\n",
"stderr": "",
"exit_code": 0,
"success": true
}
system_run_python在安全沙箱环境中执行 Python 代码。
code (字符串,必需):要执行的 Python 代码working_dir (字符串,可选):工作目录(在沙箱中忽略)output (字符串):代码的打印输出error (字符串):代码的错误输出result (任意类型):可选返回值(如果代码设置了 _ 变量)success (布尔值):代码是否成功执行{
"output": "Hello, world!\n",
"error": "",
"result": 42,
"success": true
}
system_env_var获取环境变量值。
var_name (字符串,可选):要检索的具体变量variables (对象):环境变量字典requested_var (字符串):请求变量的值(如果提供了 var_name){
"variables": {
"MCP_PORT": "8000",
"SANDBOX_ROOT": "/app/sandbox"
},
"requested_var": "8000"
}
file_read安全地读取文件内容。
path (字符串,必需):文件路径(相对于沙箱根目录)encoding (字符串,可选):文件编码(默认:"utf-8")content (字符串):文件内容size (整数):文件大小(字节)modified (浮点数):最后修改时间戳success (布尔值):读取是否成功{
"content": "这是文件的内容。",
"size": 31,
"modified": 1673452800.0,
"success": true
}
file_write安全地写入文件内容。
path (字符串,必需):文件路径(相对于沙箱根目录)content (字符串,必需):要写入的内容encoding (字符串,可选):文件编码(默认:"utf-8")success (布尔值):写入是否成功path (字符串):已写入文件的路径{
"success": true,
"path": "data/myfile.txt"
}
file_list安全地列出目录内容。
path (字符串,可选):目录路径(默认:"/")pattern (字符串,可选):过滤文件的通配符模式entries (数组):带有元数据的目录条目列表path (字符串):列出的目录路径success (布尔值):列出是否成功{
"entries": [
{
"name": "file1.txt",
"path": "file1.txt",
"is_directory": false,
"size": 1024,
"modified": 1673452800.0
},
{
"name": "data",
"path": "data",
"is_directory": true,
"size": null,
"modified": 1673452500.0
}
],
"path": "/",
"success": true
}
file_delete安全地删除文件。
path (字符串,必需):要删除的文件路径success (布尔值):删除是否成功path (字符串):已删除文件的路径{
"success": true,
"path": "temp/old_file.txt"
}
file_move安全地移动或重命名文件。
source (字符串,必需):源文件路径destination (字符串,必需):目标文件路径success (布尔值):移动是否成功source (字符串):原始文件路径destination (字符串):新文件路径{
"success": true,
"source": "data/old_name.txt",
"destination": "data/new_name.txt"
}
web_search使用搜索引擎在网络上查找信息。
query (字符串,必需):要搜索的查询results (数组):搜索结果列表query (字符串):原始查询{
"results": [
{
"title": "搜索结果标题",
"url": "https://example.com/page1",
"snippet": "来自搜索结果的文本片段..."
}
],
"query": "示例搜索查询"
}
web_scrape抓取特定 URL 并返回内容。
url (字符串,必需):要抓取的 URLselector (字符串,可选):CSS 选择器以定位特定内容content (字符串):抓取的内容url (字符串):被抓取的 URLtitle (字符串):页面标题success (布尔值):抓取是否成功error (字符串):如果抓取失败,错误消息{
"content": "这是网页的内容...",
"url": "https://example.com/page",
"title": "示例页面",
"success": true,
"error": null
}
web_browse使用 Playwright 交互式浏览网站。
url (字符串,必需):浏览会话的起始 URLcontent (字符串):页面 HTML 内容url (字符串):经过任何重定向后的最终 URLtitle (字符串):页面标题success (布尔值):浏览是否成功error (字符串):如果浏览失败,错误消息{
"content": "<!DOCTYPE html><html>...</html>",
"url": "https://example.com/after_redirect",
"title": "示例页面",
"success": true,
"error": null
}
知识库系统提供结构化文档存储,具备语义搜索功能、RDF 样式的关联关系及元数据管理。文档按照层次命名空间结构组织,并支持偏好(任意 RDF 三元组)和引用(文档之间的链接)。
知识库文档使用结构化的路径格式:namespace/collection[/subcollection]*/name
示例:
projects/docs/api-referenceresearch/papers/machine-learning/transformerspersonal/notes/meeting-2024-01-15kb_create_document在知识库中创建一个新的文档,但没有内容。
path (字符串,必需):文档路径,格式为 "namespace/collection[/subcollection]*/name"metadata (对象,可选):文档元数据(默认:{})kb_write_content 添加内容。{
"namespace": "projects",
"collection": "docs",
"name": "api-reference",
"type": "document",
"subtype": "text",
"created_at": "2024-01-15T10:30:00.000Z",
"updated_at": "2024-01-15T10:30:00.000Z",
"content_type": "text/plain",
"chunked": false,
"fragments": {},
"preferences": [],
"references": [],
"referenced_by": [],
"indices": [],
"metadata": {"author": "John Doe", "version": "1.0"}
}
kb_write_content向知识库中的现有文档写入内容。
path (字符串,必需):文档路径content (字符串,必需):文档内容force (布尔值,可选):是否覆盖现有内容(默认:false)kb_create_document 创建文档。{
"namespace": "projects",
"collection": "docs",
"name": "api-reference",
"type": "document",
"subtype": "text",
"created_at": "2024-01-15T10:30:00.000Z",
"updated_at": "2024-01-15T10:35:00.000Z",
"content_type": "text/plain",
"chunked": false,
"fragments": {},
"preferences": [],
"references": [],
"referenced_by": [],
"indices": [],
"metadata": {"author": "John Doe", "version": "1.0"}
}
kb_read从知识库中读取文档数据。
path (字符串,必需):文档路径include_content (布尔值,可选):是否包含文档内容(默认:true)include_index (布尔值,可选):是否包含文档元数据(默认:true){
"status": "success",
"path": "projects/docs/api-reference",
"content": "这是 API 参考内容...",
"index": {
"namespace": "projects",
"collection": "docs",
"name": "api-reference",
"created_at": "2024-01-15T10:30:00Z",
"metadata": {"author": "John Doe"}
}
}
kb_update_metadata更新知识库中文档的元数据。
path (字符串,必需):文档路径metadata (对象,必需):要更新的元数据{
"namespace": "projects",
"collection": "docs",
"name": "api-reference",
"type": "document",
"subtype": "text",
"created_at": "2024-01-15T10:30:00.000Z",
"updated_at": "2024-01-15T10:40:00.000Z",
"content_type": "text/plain",
"chunked": false,
"fragments": {},
"preferences": [],
"references": [],
"referenced_by": [],
"indices": [],
"metadata": {"author": "John Doe", "version": "1.1", "reviewed": true}
}
kb_manage_triples管理文档的 RDF 三元组(偏好和引用)。
action (字符串,必需):要执行的操作("add" 或 "remove")triple_type (字符串,必需):三元组类型("preference" 或 "reference")path (字符串,必需):源文档路径predicate (字符串,必需):三元组的谓词object (字符串,可选):三元组的对象(对于偏好)或关系名称(对于引用)ref_path (字符串,可选):引用文档路径(仅适用于引用)添加偏好(任意 RDF 三元组):
{
"status": "updated",
"preference_count": 3,
"action": "add",
"triple_type": "preference"
}
添加引用(指向另一个文档的链接):
{
"status": "success",
"message": "引用已添加",
"added": true,
"action": "add",
"triple_type": "reference"
}
移除引用:
{
"status": "updated",
"reference_count": 2,
"action": "remove",
"triple_type": "reference"
}
kb_search使用文本查询和/或图扩展搜索知识库。
query (字符串,可选):用于语义搜索和重新排序的文本查询graph_seed_urns (数组,可选):图扩展的起始 URNgraph_expand_hops (整数,可选):扩展的关系跳数(默认:0)filter_urns (数组,可选):要排除的结果 URNrelation_predicates (数组,可选):图遍历时要遵循的谓词(默认:["references"])top_k (整数,可选):要返回的结果数量(默认:10)include_content (布尔值,可选):是否包含文档内容(默认:false)include_index (布尔值,可选):是否包含文档元数据(默认:false)use_reranker (布尔值,可选):是否使用语义重新排序(默认:true){
"results": [
{
"urn": "kb://projects/docs/api-reference",
"sparse_score": 1.95,
"content": "API 参考内容...",
"index": {
"namespace": "projects",
"collection": "docs",
"name": "api-reference",
"type": "document",
"subtype": "text",
"created_at": "2025-07-02T23:13:17.362283Z",
"updated_at": "2025-07-02T23:18:23.396660Z",
"content_type": "text/plain",
"chunked": false,
"fragments": {},