5ire项目中Notion MCP集成失败的技术分析与解决方案
问题背景
在5ire项目集成Notion MCP(Marketplace Connector Plugin)时,开发人员遇到了JSON负载无效的错误。该问题出现在通过市场安装Notion MCP或直接使用suekou/mcp-notion-server时,系统返回了关于"type"字段的多个错误提示,表明Gemini API无法处理当前的参数结构。
错误现象分析
系统返回的错误信息明确指出:"Proto field is not repeating, cannot start list",这表明在JSON负载中存在类型定义不当的问题。具体来说,错误发生在以下几个位置:
- tools[0].function_declarations[0].parameters.properties[1]层级下的type字段
- tools[0].function_declarations[10].parameters.properties[1]层级下的type字段
这些错误都指向同一个核心问题:在参数定义中,type字段被错误地定义为数组形式,而Gemini API的协议缓冲区(Proto)定义不允许这种结构。
根本原因
经过技术分析,发现问题出在日期时间相关参数的type定义上。原始代码中采用了类似TypeScript的联合类型定义方式:
{
"end": {
"type": ["string", "null"],
"description": "An ISO 8601 formatted end date or date-time, or null if not a range."
},
"time_zone": {
"type": ["string", "null"]
}
}
这种将type定义为数组(包含"string"和"null")的做法不符合Gemini API的协议缓冲区定义规范。在Protocol Buffers中,字段类型应该是单一的,不能是多个类型的联合。
解决方案
针对这个问题,我们需要修改参数定义方式,有以下几种可行的解决方案:
- 单一类型定义:将type字段改为单一类型
{
"end": {
"type": "string",
"description": "An ISO 8601 formatted end date or date-time."
}
}
- 使用nullable标志:如果API支持,可以使用专门的nullable标志
{
"end": {
"type": "string",
"nullable": true,
"description": "An ISO 8601 formatted end date or date-time, or null."
}
}
- 分拆参数:对于必须支持多种类型的情况,可以分拆为多个参数
{
"end_string": {
"type": "string",
"description": "An ISO 8601 formatted end date or date-time."
},
"end_null": {
"type": "boolean",
"description": "Set to true if the end should be null."
}
}
实施建议
对于5ire项目中的Notion MCP集成,建议采用第一种方案,即简化type定义。因为在实际使用中,null值通常可以用空字符串""来代替,这样既保持了接口的简洁性,又满足了业务需求。
修改后的参数定义应该类似于:
{
"end": {
"type": "string",
"description": "An ISO 8601 formatted end date or date-time. Use empty string for no value."
},
"time_zone": {
"type": "string"
}
}
预防措施
为避免类似问题再次发生,建议:
- 在开发MCP插件时,仔细阅读目标API的协议定义文档
- 建立参数定义的验证机制,在开发阶段就能发现不兼容的结构
- 对于复杂参数结构,先进行小规模测试验证
- 保持对API更新和变更的关注,及时调整实现方式
总结
本次5ire项目中Notion MCP集成失败的问题,揭示了在API集成过程中类型定义规范的重要性。不同系统和平台对数据结构的定义可能有细微但关键的差异,开发人员需要特别注意这些细节。通过规范化的参数定义和充分的测试验证,可以避免大多数类似的集成问题,确保系统间的顺畅交互。
atomcodeClaude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed. Get StartedRust0216
cann-learning-hubCANN 学习中心仓,支持在线互动运行、边学边练,提供教程、示例与优化方案,一站式助力昇腾开发者快速上手。Jupyter Notebook0138
uni-appA cross-platform framework using Vue.jsJavaScript08
GLM-5.2智谱开源 GLM-5.2,这是针对长文本任务的最新旗舰模型。相较于前代产品 GLM-5.1,它在长文本任务处理能力上实现了显著飞跃,并且首次在稳定的 100 万 token 上下文中提供这一能力。Jinja00
SwanLab⚡️SwanLab - an open-source, modern-design AI training tracking and visualization tool. Supports Cloud / Self-hosted use. Integrated with PyTorch / Transformers / LLaMA Factory / veRL/ Swift / Ultralytics / MMEngine / Keras etc.Python00
tiny-universe《大模型白盒子构建指南》:一个全手搓的Tiny-UniverseJupyter Notebook03