MCP MongoDB 服务器是一款高性能的数据库服务,它旨在为大型语言模型(LLM)与 MongoDB 搭建高效的上下文接口。该服务器针对小上下文窗口(3k tokens)进行了特别优化,能有效提升数据交互效率。
MCP MongoDB 服务器为大型语言模型与 MongoDB 之间架起了高效沟通的桥梁,通过优化小上下文窗口的处理,能为相关应用提供更高效的数据支持。
以下是使用 MCP 方法查询小说详细信息的示例:
# 假设存在一个客户端对象 client 用于与 MCP MongoDB 服务器交互
# 执行查询操作获取小说详细信息
result = client.query_novel_info(novel_id="your_novel_id")
print(result)
以下是使用 REST API 进行数据更新的示例:
import requests
# 定义服务器地址和更新数据
server_url = "http://your_server_address/api"
update_data = {
"chapter_summary": "New chapter summary"
}
# 发送更新请求
response = requests.put(f"{server_url}/chapters/{chapter_id}", json=update_data, headers={"Authorization": "your_token"})
if response.status_code == 200:
print("Update successful")
else:
print("Update failed")
详细定义了各类数据的结构,包括:
{
"_id": "ObjectId",
"title": "String",
"author": "String",
"summary": "String",
"year": "Number",
"tags": ["String"]
}
{
"_id": "ObjectId",
"novel_id": "ObjectId",
"title": "String",
"chapter_number": "Number",
"summary": "String",
"content": "String",
"word_count": "Number"
}
{
"_id": "ObjectId",
"novel_id": "ObjectId",
"name": "String"
}