{
  "canonical_name": "tadata-org/fastapi_mcp",
  "compilation_id": "pack_78c49e06e5bf40b5860eab55ab84c863",
  "created_at": "2026-05-11T17:14:20.635552+00:00",
  "created_by": "project-pack-compiler",
  "feedback": {
    "carrier_selection_notes": [
      "viable_asset_types=mcp_config, recipe, host_instruction, eval, preflight",
      "recommended_asset_types=mcp_config, recipe, host_instruction, eval, preflight"
    ],
    "evidence_delta": {
      "confirmed_claims": [
        "identity_anchor_present",
        "capability_and_host_targets_present",
        "install_path_declared_or_better"
      ],
      "missing_required_fields": [],
      "must_verify_forwarded": [
        "Run or inspect `pip install fastapi-mcp` in an isolated environment.",
        "Confirm the project exposes the claimed capability to at least one target host."
      ],
      "quickstart_execution_scope": "allowlisted_sandbox_smoke",
      "sandbox_command": "pip install fastapi-mcp",
      "sandbox_container_image": "python:3.12-slim",
      "sandbox_execution_backend": "docker",
      "sandbox_planner_decision": "llm_execute_isolated_install",
      "sandbox_validation_id": "sbx_6f9066a0e8974b1f9c5806a71a62aa7f"
    },
    "feedback_event_type": "project_pack_compilation_feedback",
    "learning_candidate_reasons": [],
    "template_gaps": []
  },
  "identity": {
    "canonical_id": "project_d2ac08df8bf30708fdde983e161c77dc",
    "canonical_name": "tadata-org/fastapi_mcp",
    "homepage_url": null,
    "license": "unknown",
    "repo_url": "https://github.com/tadata-org/fastapi_mcp",
    "slug": "fastapi-mcp",
    "source_packet_id": "phit_4bf312ca960544fc9bb7c00aa31281f5",
    "source_validation_id": "dval_246d8351a869475d81589da59486f339"
  },
  "merchandising": {
    "best_for": "需要工具连接与集成能力，并使用 mcp_host的用户",
    "github_forks": 945,
    "github_stars": 11861,
    "one_liner_en": "Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!",
    "one_liner_zh": "Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!",
    "primary_category": {
      "category_id": "tool-integrations",
      "confidence": "high",
      "name_en": "Tool Integrations",
      "name_zh": "工具连接与集成",
      "reason": "matched_keywords:mcp, api, github"
    },
    "target_user": "使用 mcp_host, claude, cursor 等宿主 AI 的用户",
    "title_en": "fastapi_mcp",
    "title_zh": "fastapi_mcp 能力包",
    "visible_tags": [
      {
        "label_en": "MCP Tools",
        "label_zh": "MCP 工具",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "product_domain-mcp-tools",
        "type": "product_domain"
      },
      {
        "label_en": "Knowledge Base Q&A",
        "label_zh": "知识库问答",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "user_job-knowledge-base-q-a",
        "type": "user_job"
      },
      {
        "label_en": "Retrieval Augmentation",
        "label_zh": "检索增强",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "core_capability-retrieval-augmentation",
        "type": "core_capability"
      },
      {
        "label_en": "Verifiable Workflow",
        "label_zh": "可验证工作流",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "workflow_pattern-verifiable-workflow",
        "type": "workflow_pattern"
      },
      {
        "label_en": "Local-first",
        "label_zh": "本地优先",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "selection_signal-local-first",
        "type": "selection_signal"
      }
    ]
  },
  "packet_id": "phit_4bf312ca960544fc9bb7c00aa31281f5",
  "page_model": {
    "artifacts": {
      "artifact_slug": "fastapi-mcp",
      "files": [
        "PROJECT_PACK.json",
        "QUICK_START.md",
        "PROMPT_PREVIEW.md",
        "HUMAN_MANUAL.md",
        "AI_CONTEXT_PACK.md",
        "BOUNDARY_RISK_CARD.md",
        "PITFALL_LOG.md",
        "REPO_INSPECTION.json",
        "REPO_INSPECTION.md",
        "CAPABILITY_CONTRACT.json",
        "EVIDENCE_INDEX.json",
        "CLAIM_GRAPH.json"
      ],
      "required_files": [
        "PROJECT_PACK.json",
        "QUICK_START.md",
        "PROMPT_PREVIEW.md",
        "HUMAN_MANUAL.md",
        "AI_CONTEXT_PACK.md",
        "BOUNDARY_RISK_CARD.md",
        "PITFALL_LOG.md",
        "REPO_INSPECTION.json"
      ]
    },
    "detail": {
      "capability_source": "Project Hit Packet + DownstreamValidationResult",
      "commands": [
        {
          "command": "pip install fastapi-mcp",
          "label": "Python / pip · 官方安装入口",
          "source": "https://github.com/tadata-org/fastapi_mcp#readme",
          "verified": true
        }
      ],
      "display_tags": [
        "MCP 工具",
        "知识库问答",
        "检索增强",
        "可验证工作流",
        "本地优先"
      ],
      "eyebrow": "工具连接与集成",
      "glance": [
        {
          "body": "判断自己是不是目标用户。",
          "label": "最适合谁",
          "value": "需要工具连接与集成能力，并使用 mcp_host的用户"
        },
        {
          "body": "先理解能力边界，再决定是否继续。",
          "label": "核心价值",
          "value": "Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!"
        },
        {
          "body": "未完成验证前保持审慎。",
          "label": "继续前",
          "value": "publish to Doramagic.ai project surfaces"
        }
      ],
      "guardrail_source": "Boundary & Risk Card",
      "guardrails": [
        {
          "body": "Prompt Preview 只展示流程，不证明项目已安装或运行。",
          "label": "Check 1",
          "value": "不要把试用当真实运行"
        },
        {
          "body": "mcp_host, claude, cursor",
          "label": "Check 2",
          "value": "确认宿主兼容"
        },
        {
          "body": "publish to Doramagic.ai project surfaces",
          "label": "Check 3",
          "value": "先隔离验证"
        }
      ],
      "mode": "mcp_config, recipe, host_instruction, eval, preflight",
      "pitfall_log": {
        "items": [
          {
            "body": "GitHub 社区证据显示该项目存在一个配置相关的待验证问题：[BUG] MCP session 404 in multi worker production environment",
            "category": "配置坑",
            "evidence": [
              "community_evidence:github | cevd_f318cbe8fc55407da8cb88f5418cce0d | https://github.com/tadata-org/fastapi_mcp/issues/189 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "high",
            "suggested_check": "来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。",
            "title": "来源证据：[BUG] MCP session 404 in multi worker production environment",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.1.8",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_11a827f3808141e4bd7b0541a8628af0 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.1.8 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v0.1.8",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.2.0",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_a145fff6c53f4e709ef1bb7bc291216c | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.2.0 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v0.2.0",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.3.4",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_6dcb58f1897f46a188514e2714e5896d | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.4 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v0.3.4",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。",
            "category": "配置坑",
            "evidence": [
              "capability.host_targets | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | host_targets=mcp_host, claude, cursor"
            ],
            "severity": "medium",
            "suggested_check": "列出会写入的配置文件、目录和卸载/回滚步骤。",
            "title": "可能修改宿主 AI 配置",
            "user_impact": "安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个配置相关的待验证问题：Suggestion: MCPWatch observability example for fastapi_mcp users",
            "category": "配置坑",
            "evidence": [
              "community_evidence:github | cevd_dfa72f41f3094dd5b2ffe188889f2b4f | https://github.com/tadata-org/fastapi_mcp/issues/303 | 来源类型 github_issue 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。",
            "title": "来源证据：Suggestion: MCPWatch observability example for fastapi_mcp users",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个配置相关的待验证问题：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters",
            "category": "配置坑",
            "evidence": [
              "community_evidence:github | cevd_74e4280da33d49e1a3a8d576c7bb78a6 | https://github.com/tadata-org/fastapi_mcp/issues/304 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。",
            "title": "来源证据：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v0.3.6",
            "category": "配置坑",
            "evidence": [
              "community_evidence:github | cevd_bdc90006d16a437798ff2766d514f3d4 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.6 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v0.3.6",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "README/documentation is current enough for a first validation pass.",
            "category": "能力坑",
            "evidence": [
              "capability.assumptions | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | README/documentation is current enough for a first validation pass."
            ],
            "severity": "medium",
            "suggested_check": "将假设转成下游验证清单。",
            "title": "能力判断依赖假设",
            "user_impact": "假设不成立时，用户拿不到承诺的能力。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：[BUG] Description incorrectly passed as version to MCP Server",
            "category": "维护坑",
            "evidence": [
              "community_evidence:github | cevd_2e599a8b03d649d8a47efb6b4d49f5ca | https://github.com/tadata-org/fastapi_mcp/issues/293 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。",
            "title": "来源证据：[BUG] Description incorrectly passed as version to MCP Server",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.3.0",
            "category": "维护坑",
            "evidence": [
              "community_evidence:github | cevd_bc6b7bd2988b48d48920e4ffb259f147 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.0 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v0.3.0",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.3.3 - Fix OpenAPI Conversion Regression",
            "category": "维护坑",
            "evidence": [
              "community_evidence:github | cevd_79b96b9d35b9444c938c355c081410ac | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.3 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v0.3.3 - Fix OpenAPI Conversion Regression",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.4.0",
            "category": "维护坑",
            "evidence": [
              "community_evidence:github | cevd_4382c9c951e14187b76777ad8561ded9 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.4.0 | 来源类型 github_release 暴露的待验证使用条件。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v0.4.0",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "未记录 last_activity_observed。",
            "category": "维护坑",
            "evidence": [
              "evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | last_activity_observed missing"
            ],
            "severity": "medium",
            "suggested_check": "补 GitHub 最近 commit、release、issue/PR 响应信号。",
            "title": "维护活跃度未知",
            "user_impact": "新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。"
          },
          {
            "body": "no_demo",
            "category": "安全/权限坑",
            "evidence": [
              "downstream_validation.risk_items | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | no_demo; severity=medium"
            ],
            "severity": "medium",
            "suggested_check": "进入安全/权限治理复核队列。",
            "title": "下游验证发现风险项",
            "user_impact": "下游已经要求复核，不能在页面中弱化。"
          },
          {
            "body": "No sandbox install has been executed yet; downstream must verify before user use.",
            "category": "安全/权限坑",
            "evidence": [
              "risks.safety_notes | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | No sandbox install has been executed yet; downstream must verify before user use."
            ],
            "severity": "medium",
            "suggested_check": "转成明确权限清单和安全审查提示。",
            "title": "存在安全注意事项",
            "user_impact": "用户安装前需要知道权限边界和敏感操作。"
          }
        ],
        "source": "ProjectPitfallLog + ProjectHitPacket + validation + community signals",
        "summary": "发现 22 个潜在踩坑项，其中 1 个为 high/blocking；最高优先级：配置坑 - 来源证据：[BUG] MCP session 404 in multi worker production environment。",
        "title": "踩坑日志"
      },
      "snapshot": {
        "contributors": 18,
        "forks": 945,
        "license": "unknown",
        "note": "GitHub API 快照，非实时质量证明；用于开工前背景判断。",
        "stars": 11861,
        "open_issues": 151,
        "pushed_at": "2025-11-24T14:51:54.000Z"
      },
      "source_url": "https://github.com/tadata-org/fastapi_mcp",
      "steps": [
        {
          "body": "不安装项目，先体验能力节奏。",
          "code": "preview",
          "title": "先试 Prompt"
        },
        {
          "body": "理解输入、输出、失败模式和边界。",
          "code": "manual",
          "title": "读说明书"
        },
        {
          "body": "把上下文交给宿主 AI 继续工作。",
          "code": "context",
          "title": "带给 AI"
        },
        {
          "body": "进入主力环境前先完成安装入口与风险边界验证。",
          "code": "verify",
          "title": "沙箱验证"
        }
      ],
      "subtitle": "Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!",
      "title": "fastapi_mcp 能力包",
      "trial_prompt": "# fastapi_mcp - Prompt Preview\n\n> 复制下面这段 Prompt 到你常用的 AI，先试一次，不需要安装。\n> 它的目标是让你直接体验这个项目的服务方式，而不是阅读项目介绍。\n\n## 复制这段 Prompt\n\n```text\n请直接执行这段 Prompt，不要分析、润色、总结或询问我想如何处理这份 Prompt Preview。\n\n你现在扮演 fastapi_mcp 的“安装前体验版”。\n这不是项目介绍、不是评价报告、不是 README 总结。你的任务是让我用最小成本体验它的核心服务。\n\n我的试用任务：我想用它完成一个真实的工具连接与集成任务。\n我常用的宿主 AI：MCP Client / claude / Cursor\n\n【体验目标】\n围绕我的真实任务，现场演示这个项目如何把输入转成 示例引导, 判断线索。重点是让我感受到工作方式，而不是给我项目背景。\n\n【业务流约束】\n- 你必须像一个正在提供服务的项目能力包，而不是像一个讲解员。\n- 每一轮只推进一个步骤；提出问题后必须停下来等我回答。\n- 每一步都必须让我感受到一个具体服务动作：澄清、整理、规划、检查、判断或收尾。\n- 每一步都要说明：当前目标、你需要我提供什么、我回答后你会产出什么。\n- 不要安装、不要运行命令、不要写代码、不要声称测试通过、不要声称已经修改文件。\n- 需要真实安装或宿主加载后才能验证的内容，必须明确说“这一步需要安装后验证”。\n- 如果我说“用示例继续”，你可以用虚构示例推进，但仍然不能声称真实执行。\n\n【可体验服务能力】\n- 安装前能力预览: Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth! 输入：用户任务, 当前 AI 对话上下文；输出：示例引导, 判断线索。\n\n【必须安装后才可验证的能力】\n- 命令行启动或安装流程: 项目文档中存在可执行命令，真实使用需要在本地或宿主环境中运行这些命令。 输入：终端环境, 包管理器, 项目依赖；输出：安装结果, 列表/更新/运行结果。\n\n【核心服务流】\n请严格按这个顺序带我体验。不要一次性输出完整流程：\n1. page-overview：项目概览。围绕“项目概览”模拟一次用户任务，不展示安装或运行结果。\n2. page-quickstart：快速开始。围绕“快速开始”模拟一次用户任务，不展示安装或运行结果。\n3. page-architecture：系统架构。围绕“系统架构”模拟一次用户任务，不展示安装或运行结果。\n4. page-transport：传输层。围绕“传输层”模拟一次用户任务，不展示安装或运行结果。\n5. page-openapi-conversion：OpenAPI 到 MCP 转换。围绕“OpenAPI 到 MCP 转换”模拟一次用户任务，不展示安装或运行结果。\n\n【核心能力体验剧本】\n每一步都必须按“输入 -> 服务动作 -> 中间产物”执行。不要只说流程名：\n1. page-overview\n输入：用户提供的“项目概览”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n2. page-quickstart\n输入：用户提供的“快速开始”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n3. page-architecture\n输入：用户提供的“系统架构”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n4. page-transport\n输入：用户提供的“传输层”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n5. page-openapi-conversion\n输入：用户提供的“OpenAPI 到 MCP 转换”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n【项目服务规则】\n这些规则决定你如何服务用户。不要解释规则本身，而要在每一步执行时遵守：\n- 先确认用户任务、输入材料和成功标准，再模拟项目能力。\n- 每一步都必须形成可检查的小产物，并等待用户确认后再继续。\n- 凡是需要安装、调用工具或访问外部服务的能力，都必须标记为安装后验证。\n\n【每一步的服务约束】\n- Step 1 / page-overview：Step 1 必须围绕“项目概览”形成一个小中间产物，并等待用户确认。\n- Step 2 / page-quickstart：Step 2 必须围绕“快速开始”形成一个小中间产物，并等待用户确认。\n- Step 3 / page-architecture：Step 3 必须围绕“系统架构”形成一个小中间产物，并等待用户确认。\n- Step 4 / page-transport：Step 4 必须围绕“传输层”形成一个小中间产物，并等待用户确认。\n- Step 5 / page-openapi-conversion：Step 5 必须围绕“OpenAPI 到 MCP 转换”形成一个小中间产物，并等待用户确认。\n\n【边界与风险】\n- 不要声称已经安装、运行、调用 API、读写本地文件或完成真实任务。\n- 安装前预览只能展示工作方式，不能证明兼容性、性能或输出质量。\n- 涉及安装、插件加载、工具调用或外部服务的能力必须安装后验证。\n\n【可追溯依据】\n这些路径只用于你内部校验或在我追问“依据是什么”时简要引用。不要在首次回复主动展开：\n- https://github.com/tadata-org/fastapi_mcp\n- https://github.com/tadata-org/fastapi_mcp#readme\n- README.md\n- fastapi_mcp/__init__.py\n- CHANGELOG.md\n- examples/01_basic_usage_example.py\n- examples/shared/apps/items.py\n- docs/getting-started/quickstart.mdx\n- fastapi_mcp/server.py\n- fastapi_mcp/types.py\n- docs/advanced/asgi.mdx\n- fastapi_mcp/transport/http.py\n\n【首次问题规则】\n- 首次三问必须先确认用户目标、成功标准和边界，不要提前进入工具、安装或实现细节。\n- 如果后续需要技术条件、文件路径或运行环境，必须等用户确认目标后再追问。\n\n首次回复必须只输出下面 4 个部分：\n1. 体验开始：用 1 句话说明你将带我体验 fastapi_mcp 的核心服务。\n2. 当前步骤：明确进入 Step 1，并说明这一步要解决什么。\n3. 你会如何服务我：说明你会先改变我完成任务的哪个动作。\n4. 只问我 3 个问题，然后停下等待回答。\n\n首次回复禁止输出：后续完整流程、证据清单、安装命令、项目评价、营销文案、已经安装或运行的说法。\n\nStep 1 / brainstorming 的二轮协议：\n- 我回答首次三问后，你仍然停留在 Step 1 / brainstorming，不要进入 Step 2。\n- 第二次回复必须产出 6 个部分：澄清后的任务定义、成功标准、边界条件、\n  2-3 个可选方案、每个方案的权衡、推荐方案。\n- 第二次回复最后必须问我是否确认推荐方案；只有我明确确认后，才能进入下一步。\n- 第二次回复禁止输出 git worktree、代码计划、测试文件、命令或真实执行结果。\n\n后续对话规则：\n- 我回答后，你先完成当前步骤的中间产物并等待确认；只有我确认后，才能进入下一步。\n- 每一步都要生成一个小的中间产物，例如澄清后的目标、计划草案、测试意图、验证清单或继续/停止判断。\n- 所有演示都写成“我会建议/我会引导/这一步会形成”，不要写成已经真实执行。\n- 不要声称已经测试通过、文件已修改、命令已运行或结果已产生。\n- 如果某个能力必须安装后验证，请直接说“这一步需要安装后验证”。\n- 如果证据不足，请明确说“证据不足”，不要补事实。\n```\n",
      "voices": [
        {
          "body": "来源平台：github。github/github_issue: [BUG] MCP session 404 in multi worker production environment（https://github.com/tadata-org/fastapi_mcp/issues/189）；github/github_issue: clean_schema_for_display() strips anyOf and loses items for Optional[Lis（https://github.com/tadata-org/fastapi_mcp/issues/304）；github/github_issue: Suggestion: MCPWatch observability example for fastapi_mcp users（https://github.com/tadata-org/fastapi_mcp/issues/303）；github/github_issue: [BUG] Description incorrectly passed as version to MCP Server（https://github.com/tadata-org/fastapi_mcp/issues/293）；github/github_release: v0.4.0（https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.4.0）；github/github_release: v0.3.7（https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.7）；github/github_release: v0.3.6（https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.6）；github/github_release: v0.3.4（https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.4）；github/github_release: v0.3.3 - Fix OpenAPI Conversion Regression（https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.3）；github/github_release: v0.3.2（https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.2）；github/github_release: v0.3.1 - Authorization（https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.1）；github/github_release: v0.3.0（https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.0）。这些是项目级外部声音，不作为单独质量证明。",
          "items": [
            {
              "kind": "github_issue",
              "source": "github",
              "title": "[BUG] MCP session 404 in multi worker production environment",
              "url": "https://github.com/tadata-org/fastapi_mcp/issues/189"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "clean_schema_for_display() strips anyOf and loses items for Optional[Lis",
              "url": "https://github.com/tadata-org/fastapi_mcp/issues/304"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "Suggestion: MCPWatch observability example for fastapi_mcp users",
              "url": "https://github.com/tadata-org/fastapi_mcp/issues/303"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "[BUG] Description incorrectly passed as version to MCP Server",
              "url": "https://github.com/tadata-org/fastapi_mcp/issues/293"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.4.0",
              "url": "https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.4.0"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.3.7",
              "url": "https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.7"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.3.6",
              "url": "https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.6"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.3.4",
              "url": "https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.4"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.3.3 - Fix OpenAPI Conversion Regression",
              "url": "https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.3"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.3.2",
              "url": "https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.2"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.3.1 - Authorization",
              "url": "https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.1"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v0.3.0",
              "url": "https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.0"
            }
          ],
          "status": "已收录 12 条来源",
          "title": "社区讨论"
        }
      ]
    },
    "homepage_card": {
      "category": "工具连接与集成",
      "desc": "Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!",
      "effort": "安装已验证",
      "forks": 946,
      "icon": "link",
      "name": "fastapi_mcp 能力包",
      "risk": "可发布",
      "slug": "fastapi-mcp",
      "stars": 11857,
      "tags": [
        "MCP 工具",
        "知识库问答",
        "检索增强",
        "可验证工作流",
        "本地优先"
      ],
      "thumb": "gray",
      "type": "MCP 配置"
    },
    "manual": {
      "markdown": "# https://github.com/tadata-org/fastapi_mcp 项目说明书\n\n生成时间：2026-05-11 16:52:13 UTC\n\n## 目录\n\n- [项目概览](#page-overview)\n- [快速开始](#page-quickstart)\n- [系统架构](#page-architecture)\n- [传输层](#page-transport)\n- [OpenAPI 到 MCP 转换](#page-openapi-conversion)\n- [认证与授权](#page-authentication)\n- [端点过滤与自定义](#page-endpoint-filtering)\n- [部署选项](#page-deployment)\n- [配置与自定义](#page-configuration)\n- [示例集](#page-examples)\n\n<a id='page-overview'></a>\n\n## 项目概览\n\n### 相关页面\n\n相关主题：[系统架构](#page-architecture), [快速开始](#page-quickstart)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n- [fastapi_mcp/__init__.py](https://github.com/tadata-org/fapi_mcp/blob/main/fastapi_mcp/__init__.py)\n- [CHANGELOG.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CHANGELOG.md)\n- [CONTRIBUTING.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n</details>\n\n# 项目概览\n\n## 简介\n\n**FastAPI-MCP** 是一个将 FastAPI 应用程序自动转换为 MCP（Model Context Protocol）服务器的框架。该项目由 [Tadata Inc.](https://github.com/tadata-org) 开发，采用 MIT 开源许可证，为开发者提供了一种无缝集成 AI 助手能力到现有 FastAPI 应用的解决方案。\n\n资料来源：[README.md:1](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n\n## 核心特性\n\nFastAPI-MCP 具有以下设计目标和技术特点：\n\n| 特性 | 描述 |\n|------|------|\n| 内置认证 | 支持使用现有的 FastAPI 依赖项进行身份验证 |\n| FastAPI 原生 | 不仅仅是 OpenAPI 到 MCP 的简单转换器 |\n| 零配置/最小配置 | 只需指向 FastAPI 应用即可运行 |\n| Schema 保持 | 保留请求模型和响应模型的完整类型定义 |\n| 文档保留 | 端点文档与 Swagger 中完全一致 |\n| 灵活部署 | 支持将 MCP 服务器挂载到 FastAPI 应用 |\n\n资料来源：[README.md:24-31](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n\n## 技术架构\n\n### 整体架构\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[FastApiMCP]\n    B --> C[MCP 服务器]\n    C --> D[HTTP 端点 /mcp]\n    B --> E[工具发现]\n    E --> F[OpenAPI Schema 解析]\n    F --> G[MCP Tools]\n    B --> H[请求处理]\n    H --> I[httpx.AsyncClient]\n    I --> A\n```\n\n### 核心模块结构\n\n```\nfastapi_mcp/\n├── __init__.py      # 包入口，导出公共API\n├── server.py        # FastApiMCP 主类实现\n├── types.py         # 类型定义（AuthConfig、OAuthMetadata）\n└── openapi/\n    └── convert.py   # OpenAPI Schema 转换逻辑\n```\n\n资料来源：[fastapi_mcp/__init__.py:1-17](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/__init__.py)\n\n## 核心 API\n\n### 公开导出\n\n`fastapi_mcp/__init__.py` 导出了以下核心组件：\n\n```python\nfrom fastapi_mcp import FastApiMCP, AuthConfig, OAuthMetadata\n```\n\n| 组件 | 用途 |\n|------|------|\n| `FastApiMCP` | 主类，用于创建和管理 MCP 服务器 |\n| `AuthConfig` | 认证配置类 |\n| `OAuthMetadata` | OAuth 2.0 元数据类 |\n\n资料来源：[fastapi_mcp/__init__.py:12-16](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/__init__.py)\n\n### 类型定义\n\n`fastapi_mcp/types.py` 定义了以下关键类型：\n\n#### HTTPRequestInfo\n\n```python\nclass HTTPRequestInfo(BaseType):\n    method: str\n    path: str\n    headers: Dict[str, str]\n    cookies: Dict[str, str]\n    query_params: Dict[str, str]\n    body: Any\n```\n\n#### AuthConfig\n\n认证配置类，支持 OAuth 2.0 授权流程：\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `version` | Literal[\"2025-03-26\"] | MCP 规范版本 |\n| `dependencies` | Optional[Sequence[Depends]] | FastAPI 认证依赖项 |\n| `issuer` | Optional[str] | OAuth 2.0 发行方标识 |\n| `oauth_metadata_url` | Optional[StrHttpUrl] | OAuth 元数据端点 URL |\n| `authorize_url` | Optional[StrHttpUrl] | 授权端点 URL |\n| `token_endpoint` | Optional[StrHttpUrl] | 令牌端点 URL |\n\n资料来源：[fastapi_mcp/types.py:80-120](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n\n## 快速开始\n\n### 环境要求\n\n| 要求 | 版本 |\n|------|------|\n| Python | 3.10+（推荐 3.12） |\n| 包管理器 | uv |\n\n资料来源：[README.md:36-39](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n\n### 基础用法\n\n```python\nfrom examples.shared.apps.items import app  # FastAPI 应用\nfrom fastapi_mcp import FastApiMCP\n\n# 创建 MCP 服务器\nmcp = FastApiMCP(app)\n\n# 挂载到 FastAPI 应用\nmcp.mount_http()\n\nif __name__ == \"__main__\":\n    import uvicorn\n    uvicorn.run(app, host=\"0.0.0.0\", port=8000)\n```\n\n资料来源：[examples/01_basic_usage_example.py:1-14](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/01_basic_usage_example.py)\n\n## 高级功能\n\n### 工具过滤\n\n支持通过操作 ID 和标签过滤暴露的 MCP 工具：\n\n```python\n# 通过操作 ID 过滤（包含模式）\nmcp = FastApiMCP(\n    app,\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 通过操作 ID 过滤（排除模式）\nmcp = FastApiMCP(\n    app,\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n\n# 通过标签过滤\nmcp = FastApiMCP(\n    app,\n    include_tags=[\"items\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:18-37](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n\n### 认证配置\n\nFastAPI-MCP 支持基于 FastAPI 依赖项的认证机制：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:30-40](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n\n## 版本历史\n\n| 版本 | 日期 | 主要变更 |\n|------|------|----------|\n| 0.2.0 | - | 移除 CLI，改用运行时集成；添加 `add_mcp_server` 函数 |\n| 0.1.1 | 2024-07-03 | 修复 PEP 604 联合类型语法兼容性 |\n| 0.1.0 | 2024-03-08 | 初始版本发布 |\n\n资料来源：[CHANGELOG.md:1-30](https://github.com/tadata-org/fastapi_mcp/blob/main/CHANGELOG.md)\n\n## 开发指南\n\n### 环境搭建\n\n```bash\n# 1. 安装 uv\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n\n# 2. 克隆仓库\ngit clone https://github.com/YOUR-USERNAME/fastapi_mcp.git\ncd fastapi_mcp\n\n# 3. 同步依赖\nuv sync\n\n# 4. 安装预提交钩子\nuv run pre-commit install\n```\n\n资料来源：[CONTRIBUTING.md:12-26](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n\n### 代码质量检查\n\n| 工具 | 用途 |\n|------|------|\n| ruff | 代码检查和格式化 |\n| mypy | 类型检查 |\n| pytest | 测试框架 |\n\n```bash\n# 运行所有测试\npytest\n\n# 类型检查\nmypy .\n\n# 代码格式化检查\nruff check .\nruff format .\n```\n\n资料来源：[CONTRIBUTING.md:60-75](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n\n## 许可证\n\nMIT License。Copyright (c) 2025 Tadata Inc.\n\n资料来源：[README.md:42](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n\n---\n\n<a id='page-quickstart'></a>\n\n## 快速开始\n\n### 相关页面\n\n相关主题：[项目概览](#page-overview), [示例集](#page-examples)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [examples/01_basic_usage_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/01_basic_usage_example.py)\n- [examples/02_full_schema_description_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/02_full_schema_description_example.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n- [examples/shared/apps/items.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/shared/apps/items.py)\n- [CONTRIBUTING.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n</details>\n\n# 快速开始\n\n本文档面向希望快速上手 **FastAPI-MCP** 的开发者。FastAPI-MCP 是一个将 FastAPI 应用无缝转换为 MCP（Model Context Protocol）服务器的库，使 FastAPI 应用能够作为 MCP 工具被 AI 模型调用。\n\n## 环境要求\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n| 要求 | 版本 | 说明 |\n|------|------|------|\n| Python | 3.10+（推荐 3.12） | 项目依赖类型注解等特性 |\n| uv | 最新稳定版 | 高性能 Python 包管理器 |\n\n资料来源：[CONTRIBUTING.md:1]()\n\n### 安装 uv\n\n如果尚未安装 uv，请参考 [uv 官方安装指南](https://docs.astral.sh/uv/getting-started/installation/)。\n\n## 项目初始化\n\n### 克隆项目\n\n首先，从 GitHub fork 并克隆仓库：\n\n```bash\ngit clone https://github.com/YOUR-USERNAME/fastapi_mcp.git\ncd fastapi-mcp\n\n# 添加上游远程仓库\ngit remote add upstream https://github.com/tadata-org/fastapi_mcp.git\n```\n\n资料来源：[CONTRIBUTING.md:1]()\n\n### 创建虚拟环境并安装依赖\n\n使用 `uv sync` 自动创建虚拟环境并安装所有依赖：\n\n```bash\nuv sync\n```\n\n资料来源：[CONTRIBUTING.md:1]()\n\n### 安装预提交钩子\n\n项目使用 pre-commit 工具自动运行代码检查：\n\n```bash\nuv run pre-commit install\nuv run pre-commit run\n```\n\n资料来源：[CONTRIBUTING.md:1]()\n\n## 基础使用\n\n### 基本示例\n\n以下示例展示将 FastAPI 应用转换为 MCP 服务器的最简方式：\n\n```python\nfrom examples.shared.apps.items import app  # FastAPI 应用\nfrom examples.shared.setup import setup_logging\nfrom fastapi_mcp import FastApiMCP\n\nsetup_logging()\n\n# 创建 MCP 服务器\nmcp = FastApiMCP(app)\n\n# 挂载 MCP 服务器\nmcp.mount_http()\n\nif __name__ == \"__main__\":\n    import uvicorn\n    uvicorn.run(app, host=\"0.0.0.0\", port=8000)\n```\n\n资料来源：[examples/01_basic_usage_example.py:1]()\n\n### 工作流程\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[创建 FastApiMCP 实例]\n    B --> C[挂载 MCP 端点]\n    C --> D[启动 Uvicorn 服务器]\n    D --> E[访问 MCP 端点]\n```\n\n## 核心配置参数\n\n`FastApiMCP` 类支持多种配置选项：\n\n| 参数 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `name` | `str` | - | MCP 服务器名称 |\n| `description` | `str` | - | 服务器描述 |\n| `describe_full_response_schema` | `bool` | `False` | 是否在工具描述中包含完整响应 JSON Schema |\n| `describe_all_responses` | `bool` | `False` | 是否描述所有可能的响应（包括错误响应） |\n| `include_operations` | `List[str]` | `None` | 要包含的操作 ID 列表 |\n| `exclude_operations` | `List[str]` | `None` | 要排除的操作 ID 列表 |\n| `include_tags` | `List[str]` | `None` | 要包含的标签列表 |\n| `exclude_tags` | `List[str]` | `None` | 要排除的标签列表 |\n| `headers` | `List[str]` | `[\"authorization\"]` | 要转发到工具调用的 HTTP 头列表 |\n\n资料来源：[fastapi_mcp/server.py:1]()\n\n### 完整 Schema 描述\n\n如需在工具描述中包含完整的响应 Schema，使用以下配置：\n\n```python\nmcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    description=\"MCP 服务器示例\",\n    describe_full_response_schema=True,\n    describe_all_responses=True,\n)\n\nmcp.mount_http()\n```\n\n资料来源：[examples/02_full_schema_description_example.py:1]()\n\n## 操作过滤\n\n### 按操作 ID 过滤\n\n可以选择性地暴露特定操作：\n\n```python\n# 仅包含指定操作\ninclude_mcp = FastApiMCP(\n    app,\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 排除指定操作\nexclude_mcp = FastApiMCP(\n    app,\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1]()\n\n### 按标签过滤\n\n也可以按 FastAPI 的标签进行过滤：\n\n```python\n# 仅包含 items 标签的操作\nitems_mcp = FastApiMCP(\n    app,\n    include_tags=[\"items\"],\n)\n\n# 排除 search 标签的操作\nexclude_search_mcp = FastApiMCP(\n    app,\n    exclude_tags=[\"search\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1]()\n\n### 过滤规则说明\n\n| 规则 | 说明 |\n|------|------|\n| `include_operations` 和 `exclude_operations` | 互斥，不能同时使用 |\n| `include_tags` 和 `exclude_tags` | 互斥，不能同时使用 |\n| 操作过滤 + 标签过滤 | 可以组合使用，匹配任一条件的操作都会被包含 |\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1]()\n\n## 认证配置\n\n### 令牌传递认证\n\nFastAPI-MCP 支持通过 HTTP 头传递认证令牌：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\n@app.get(\"/private\")\nasync def private(token=Depends(token_auth_scheme)):\n    return token.credentials\n\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n\nmcp.mount_http()\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:1]()\n\n### AuthConfig 配置选项\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `version` | `Literal[\"2025-03-26\"]` | MCP 规范版本 |\n| `dependencies` | `Sequence[params.Depends]` | FastAPI 认证依赖 |\n\n资料来源：[fastapi_mcp/types.py:1]()\n\n## 示例 FastAPI 应用\n\n以下是一个完整的 CRUD 示例应用结构：\n\n```python\nfrom fastapi import FastAPI, HTTPException, Query\nfrom pydantic import BaseModel\nfrom typing import List, Optional\n\napp = FastAPI()\n\nclass Item(BaseModel):\n    id: int\n    name: str\n    description: Optional[str] = None\n    price: float\n    tags: List[str] = []\n\nitems_db = {}\n\n@app.post(\"/items/\", response_model=Item)\nasync def create_item(item: Item):\n    items_db[item.id] = item\n    return item\n\n@app.get(\"/items/{item_id}\", response_model=Item)\nasync def get_item(item_id: int):\n    if item_id not in items_db:\n        raise HTTPException(status_code=404, detail=\"Item not found\")\n    return items_db[item_id]\n\n@app.get(\"/items/\", response_model=List[Item])\nasync def list_items():\n    return list(items_db.values())\n\n@app.put(\"/items/{item_id}\", response_model=Item)\nasync def update_item(item_id: int, item: Item):\n    if item_id not in items_db:\n        raise HTTPException(status_code=404, detail=\"Item not found\")\n    item.id = item_id\n    items_db[item_id] = item\n    return item\n\n@app.delete(\"/items/{item_id}\")\nasync def delete_item(item_id: int):\n    if item_id not in items_db:\n        raise HTTPException(status_code=404, detail=\"Item not found\")\n    del items_db[item_id]\n    return {\"message\": \"Item deleted successfully\"}\n\n@app.get(\"/items/search/\", response_model=List[Item])\nasync def search_items(\n    q: Optional[str] = Query(None),\n    min_price: Optional[float] = Query(None),\n    max_price: Optional[float] = Query(None),\n    tags: List[str] = Query([]),\n):\n    results = list(items_db.values())\n    # 搜索逻辑...\n    return results\n```\n\n资料来源：[examples/shared/apps/items.py:1]()\n\n## 运行测试\n\n### 代码检查\n\n在提交代码前，运行以下检查确保代码质量：\n\n```bash\n# 类型检查\nmypy .\n\n# 运行测试\npytest\n\n# 代码格式化和检查\nruff check .\nruff format .\n```\n\n资料来源：[CONTRIBUTING.md:1]()\n\n### 使用预提交\n\n如果已安装 pre-commit 钩子，这些检查会在每次提交时自动运行：\n\n```bash\nuv run pre-commit run\n```\n\n## 挂载 MCP 端点\n\n### 自定义挂载路径\n\n可以为 MCP 服务器指定不同的挂载路径：\n\n```python\nmcp.mount_http(mount_path=\"/mcp\")\n```\n\n### 多端点挂载\n\n可以同时挂载多个 MCP 服务器实例：\n\n```python\nmcp1 = FastApiMCP(app, name=\"Server 1\")\nmcp2 = FastApiMCP(app, name=\"Server 2\")\n\nmcp1.mount_http(mount_path=\"/mcp1\")\nmcp2.mount_http(mount_path=\"/mcp2\")\n```\n\n## 下一步\n\n- 参考 [示例代码](../examples/) 了解更高级的用法\n- 查看 [贡献指南](../CONTRIBUTING.md) 参与项目开发\n- 访问 [项目仓库](https://github.com/tadata-org/fastapi_mcp) 获取最新资讯\n\n---\n\n<a id='page-architecture'></a>\n\n## 系统架构\n\n### 相关页面\n\n相关主题：[传输层](#page-transport), [OpenAPI 到 MCP 转换](#page-openapi-conversion)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [fastapi_mcp/__init__.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/__init__.py)\n- [fastapi_mcp/openapi/convert.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/openapi/convert.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n- [examples/shared/apps/items.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/shared/apps/items.py)\n</details>\n\n# 系统架构\n\n## 概述\n\nFastAPI-MCP 是一个将 FastAPI 应用自动转换为 MCP（Model Context Protocol）服务器的框架。其核心架构围绕 `FastApiMCP` 类展开，通过 OpenAPI schema 提取、工具过滤、HTTP 请求转发和认证集成四大核心模块实现功能。\n\n系统采用零配置设计理念，开发者只需将现有的 FastAPI 应用传入 `FastApiMCP`，即可自动生成兼容 MCP 协议的服务端点。框架支持灵活的工具过滤机制、多种认证配置方式以及自定义 HTTP 客户端注入。\n\n## 核心组件\n\n### 组件关系图\n\n```mermaid\ngraph TD\n    A[FastAPI App] --> B[FastApiMCP]\n    B --> C[OpenAPI Schema 解析]\n    C --> D[工具转换引擎]\n    D --> E[MCP 工具列表]\n    E --> F[工具过滤器]\n    F --> G[最终 MCP 工具集]\n    H[HTTP 请求转发器] --> G\n    I[认证配置] --> H\n    J[自定义 HTTP Client] --> H\n```\n\n### 主要类结构\n\n| 组件 | 文件位置 | 职责 |\n|------|----------|------|\n| `FastApiMCP` | `fastapi_mcp/server.py` | 主服务器类，核心逻辑入口 |\n| `AuthConfig` | `fastapi_mcp/types.py` | 认证配置数据模型 |\n| `OAuthMetadata` | `fastapi_mcp/types.py` | OAuth 2.0 元数据 |\n| `HTTPRequestInfo` | `fastapi_mcp/types.py` | HTTP 请求信息封装 |\n\n## 工具发现与过滤机制\n\n### 工具过滤流程\n\n```mermaid\ngraph TD\n    A[OpenAPI Schema] --> B{include_operations?}\n    B -->|有值| C[过滤至指定操作ID]\n    B -->|无值| D{exclude_operations?}\n    D -->|有值| E[排除指定操作ID]\n    D -->|无值| F{include_tags?}\n    F -->|有值| G[过滤至指定标签]\n    F -->|无值| H{exclude_tags?}\n    H -->|有值| I[排除指定标签]\n    H -->|无值| J[返回全部工具]\n    C --> J\n    E --> J\n    G --> J\n    I --> J\n```\n\n### 过滤配置参数\n\n| 参数名 | 类型 | 说明 | 互斥参数 |\n|--------|------|------|----------|\n| `include_operations` | `List[str]` | 仅包含指定的操作 ID | `exclude_operations` |\n| `exclude_operations` | `List[str]` | 排除指定的操作 ID | `include_operations` |\n| `include_tags` | `List[str]` | 仅包含指定标签的端点 | `exclude_tags` |\n| `exclude_tags` | `List[str]` | 排除指定标签的端点 | `include_tags` |\n\n资料来源：[fastapi_mcp/server.py:50-75]()\n\n### 过滤实现逻辑\n\n```python\ndef _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any]) -> List[types.Tool]:\n    if (\n        self._include_operations is None\n        and self._exclude_operations is None\n        and self._include_tags is None\n        and self._exclude_tags is None\n    ):\n        return tools\n    # 构建按标签分组操作ID的映射\n    operations_by_tag: Dict[str, List[str]] = {}\n    for path, path_item in openapi_schema.get(\"paths\", {}).items():\n        for method, operation in path_item.items():\n            operation_id = operation.get(\"operationId\")\n            tags = operation.get(\"tags\", [])\n            # 分类存储操作ID\n```\n\n资料来源：[fastapi_mcp/server.py:35-60]()\n\n## HTTP 请求转发架构\n\n### 请求转发流程\n\n```mermaid\nsequenceDiagram\n    participant MCP as MCP Client\n    participant MCP_Server as FastApiMCP Server\n    participant HTTP_Client as httpx.AsyncClient\n    participant FastAPI as FastAPI App\n\n    MCP_Server->>FastAPI: 提取 OpenAPI Schema\n    MCP->>MCP_Server: 调用 MCP Tool\n    MCP_Server->>MCP_Server: 解析工具参数\n    MCP_Server->>HTTP_Client: 构造 HTTP 请求\n    HTTP_Client->>FastAPI: 转发请求\n    FastAPI-->>HTTP_Client: 返回响应\n    HTTP_Client-->>MCP_Server: 返回结果\n    MCP_Server-->>MCP: 返回 Tool Result\n```\n\n### HTTP 方法路由\n\n| HTTP 方法 | 调用方式 | 说明 |\n|-----------|----------|------|\n| GET | `client.get(path, params=query, headers=headers)` | 查询参数传递 |\n| POST | `client.post(path, params=query, headers=headers, json=body)` | JSON 请求体 |\n| PUT | `client.put(path, params=query, headers=headers, json=body)` | JSON 请求体 |\n| DELETE | `client.delete(path, params=query, headers=headers)` | 查询参数传递 |\n| PATCH | `client.patch(path, params=query, headers=headers, json=body)` | JSON 请求体 |\n\n资料来源：[fastapi_mcp/server.py:12-26]()\n\n### 自定义 HTTP 客户端\n\n框架支持注入自定义 `httpx.AsyncClient` 实例，用于满足特殊网络配置需求：\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\ncustom_client = httpx.AsyncClient(\n    timeout=60.0,\n    proxies={\"http://\": \"http://proxy.example.com\"},\n)\n\nmcp = FastApiMCP(\n    app,\n    http_client=custom_client,\n)\n```\n\n## 认证与授权系统\n\n### 认证配置架构\n\n```mermaid\ngraph LR\n    A[OAuthMetadata] -->|issuer| B[授权服务器标识]\n    A -->|authorization_endpoint| C[授权端点]\n    A -->|token_endpoint| D[令牌端点]\n    A -->|scopes_supported| E[支持的权限范围]\n    F[AuthConfig] -->|dependencies| G[FastAPI 依赖项]\n    F -->|oauth_metadata| H[自定义 OAuth 元数据]\n```\n\n### AuthConfig 数据模型\n\n| 字段 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `version` | `Literal[\"2025-03-26\"]` | `\"2025-03-26\"` | MCP 规范版本 |\n| `dependencies` | `Sequence[Depends]` | `None` | FastAPI 认证依赖链 |\n| `issuer` | `str` | `None` | OAuth 发行方 URL |\n| `oauth_metadata_url` | `StrHttpUrl` | `None` | OAuth 元数据端点 |\n| `authorize_url` | `StrHttpUrl` | `None` | 授权端点 URL |\n| `token_endpoint` | `StrHttpUrl` | `None` | 令牌端点 URL |\n\n资料来源：[fastapi_mcp/types.py:100-150]()\n\n### 认证使用示例\n\n```python\nfrom fastapi import Depends, HTTPException\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\nasync def authenticate_request(request: Request, token: str = Depends(token_auth_scheme)):\n    payload = verify_token(request, token)\n    if payload is None:\n        raise HTTPException(status_code=401, detail=\"Unauthorized\")\n    return payload\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(dependencies=[Depends(authenticate_request)]),\n)\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:20-35]()\n\n## 头部信息转发机制\n\n### 默认转发配置\n\n框架默认自动转发 `Authorization` 头部，可通过配置扩展：\n\n```python\nmcp = FastApiMCP(\n    app,\n    headers=[\"authorization\", \"x-custom-header\", \"x-request-id\"],\n)\n```\n\n### 头部转发流程\n\n```mermaid\ngraph TD\n    A[MCP Request] --> B[提取配置的 headers]\n    B --> C{headers 参数配置}\n    C -->|[\"authorization\"]| D[转发 Authorization]\n    C -->|[\"x-custom-header\"]| E[转发自定义头部]\n    C -->|未配置| F[默认转发 authorization]\n    D --> G[合并至 HTTP 请求]\n    E --> G\n    F --> G\n```\n\n资料来源：[fastapi_mcp/server.py:80-90]()\n\n## 工具描述生成\n\n### 描述信息构建流程\n\n框架从 OpenAPI schema 自动提取端点描述信息：\n\n```mermaid\ngraph TD\n    A[OpenAPI Schema] --> B[解析路径参数]\n    A --> C[解析查询参数]\n    A --> D[解析请求体]\n    A --> E[解析响应 schema]\n    B --> F[构建 Tool 描述]\n    C --> F\n    D --> F\n    E --> F\n```\n\n### 参数分类处理\n\n```python\n# 按位置分类参数\npath_params = []      # 路径参数 (in: path)\nquery_params = []     # 查询参数 (in: query)\nheader_params = []    # 请求头参数 (in: header)\n\nfor param in operation.get(\"parameters\", []):\n    param_name = param.get(\"name\")\n    param_in = param.get(\"in\")\n    required = param.get(\"required\", False)\n    \n    if param_in == \"path\":\n        path_params.append((param_name, param))\n    elif param_in == \"query\":\n        query_params.append((param_name, param))\n    elif param_in == \"header\":\n        header_params.append((param_name, param))\n```\n\n资料来源：[fastapi_mcp/openapi/convert.py:30-50]()\n\n## 目录结构\n\n```\nfastapi_mcp/\n├── __init__.py          # 公共 API 导出\n├── server.py            # FastApiMCP 主类实现\n├── types.py             # 数据模型定义\n└── openapi/\n    └── convert.py       # OpenAPI 转换逻辑\n```\n\n| 模块 | 导出内容 |\n|------|----------|\n| `fastapi_mcp.FastApiMCP` | 主服务器类 |\n| `fastapi_mcp.AuthConfig` | 认证配置类 |\n| `fastapi_mcp.OAuthMetadata` | OAuth 元数据类 |\n\n资料来源：[fastapi_mcp/__init__.py:1-25]()\n\n## 使用模式\n\n### 基础模式\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_mcp import FastApiMCP\n\napp = FastAPI()\n\n# 添加 MCP 服务器\nmcp = FastApiMCP(app)\n\n# 挂载到 FastAPI 应用\nmcp.mount_http()\n```\n\n### 高级过滤模式\n\n```python\n# 按操作 ID 过滤\nmcp = FastApiMCP(\n    app,\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 按标签过滤\nmcp = FastApiMCP(\n    app,\n    exclude_tags=[\"internal\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:15-30]()\n\n## 总结\n\nFastAPI-MCP 的系统架构采用模块化设计，核心通过 `FastApiMCP` 类协调以下组件：\n\n- **工具发现模块**：解析 OpenAPI schema，自动转换为 MCP 工具\n- **工具过滤模块**：支持基于操作 ID 和标签的灵活过滤\n- **请求转发模块**：将 MCP 调用转换为标准 HTTP 请求\n- **认证模块**：集成 FastAPI 依赖注入系统，支持 OAuth 2.0\n\n该架构实现了零配置集成，同时保留了高度的可定制性，满足从简单到复杂的各类应用场景需求。\n\n---\n\n<a id='page-transport'></a>\n\n## 传输层\n\n### 相关页面\n\n相关主题：[系统架构](#page-architecture), [部署选项](#page-deployment)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [examples/01_basic_usage_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/01_basic_usage_example.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n- [CONTRIBUTING.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n</details>\n\n# 传输层\n\nFastAPI-MCP 支持两种传输层协议，用于在 MCP 客户端和 FastAPI 应用之间进行通信。传输层是 MCP 服务器与外部客户端建立连接的核心组件，负责处理请求路由、消息传输和协议握手。\n\n## 传输层概述\n\nFastAPI-MCP 实现了 MCP 协议的传输层抽象，提供两种传输方式：\n\n| 传输类型 | 方法 | 说明 |\n|---------|------|------|\n| HTTP Streamable | `mount_http()` | 基于 HTTP 的流式传输，推荐的生产环境方案 |\n| SSE | `mount_sse()` | 基于 Server-Sent Events 的传输方式 |\n\n两种传输方式都遵循 MCP 协议规范，但在连接管理和消息传输机制上有所不同。`mount_http()` 是当前推荐的默认选择，而 `mount_sse()` 则提供了基于事件的实时通信能力。\n\n资料来源：[server.py:203-250]()\n\n## HTTP Streamable 传输\n\nHTTP Streamable 传输是 FastAPI-MCP 推荐的传输层实现。它基于 HTTP 协议，提供可靠的双向通信能力。\n\n### 工作原理\n\nHTTP Streamable 传输使用 FastAPI 的 ASGI 接口与 MCP 服务器进行交互。当 MCP 客户端发起连接请求时，HTTP 客户端会通过 `httpx.AsyncClient` 转发请求到 FastAPI 应用。\n\n```python\n# 基础使用示例\nfrom fastapi_mcp import FastApiMCP\n\nmcp = FastApiMCP(app)\nmcp.mount_http()  # 使用 HTTP Streamable 传输\n```\n\n资料来源：[examples/01_basic_usage_example.py:1-15]()\n\n### HTTP 客户端配置\n\n在初始化 `FastApiMCP` 时，可以通过 `http_client` 参数传入自定义的 `httpx.AsyncClient` 实例：\n\n```python\nimport httpx\nfrom fastapi_mcp import FastApiMCP\n\n# 自定义 HTTP 客户端\ncustom_client = httpx.AsyncClient(\n    timeout=30.0,\n    follow_redirects=True\n)\n\nmcp = FastApiMCP(\n    app,\n    http_client=custom_client\n)\nmcp.mount_http()\n```\n\n### 超时配置\n\n默认情况下，HTTP 请求超时设置为 10 秒。可以通过自定义客户端调整：\n\n```python\nmcp = FastApiMCP(\n    app,\n    http_client=httpx.AsyncClient(\n        timeout=60.0  # 自定义超时时间\n    )\n)\n```\n\n资料来源：[server.py:120-130]()\n\n## SSE 传输\n\nSSE (Server-Sent Events) 传输提供基于事件的单向服务器推送能力，适用于需要服务器主动推送消息的场景。\n\n### 端点注册\n\nSSE 传输在 FastAPI 应用中注册两个主要端点：\n\n| 端点 | HTTP 方法 | 用途 |\n|-----|----------|------|\n| `{mount_path}` | GET | MCP 连接建立端点 |\n| `{mount_path}/messages/` | POST | 消息处理端点 |\n\n### 工作流程\n\n```mermaid\ngraph TD\n    A[MCP 客户端] -->|建立 SSE 连接| B[/mcp GET 端点]\n    A -->|发送消息| C[/mcp/messages/ POST 端点]\n    B -->|SSE 流| A\n    C -->|响应| A\n    B --> D[FastApiSseTransport]\n    C --> D\n```\n\n资料来源：[server.py:210-240]()\n\n### SSE 挂载方法\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\nmcp = FastApiMCP(app)\nmcp.mount_sse(router=app, mount_path=\"/mcp\")\n```\n\n### SSE 传输参数\n\n| 参数 | 类型 | 说明 |\n|-----|------|------|\n| `router` | FastAPI \\| APIRouter | FastAPI 应用或路由实例 |\n| `mount_path` | str | SSE 端点的挂载路径 |\n| `dependencies` | Sequence[Depends] | 可选的依赖注入列表 |\n\n资料来源：[server.py:152-200]()\n\n## 传输层选择指南\n\n### 推荐场景\n\n```mermaid\ngraph LR\n    A[需要可靠双向通信] --> B[选择 HTTP Streamable]\n    C[需要服务端推送] --> D[选择 SSE]\n    E[生产环境部署] --> B\n    F[简单集成场景] --> B\n```\n\n| 场景 | 推荐传输 |\n|-----|---------|\n| 生产环境 | HTTP Streamable |\n| 需要服务端推送 | SSE |\n| 简单演示 | HTTP Streamable |\n| 与现有 MCP 客户端兼容 | HTTP Streamable |\n\n## 传输层与认证\n\n传输层支持与认证系统集成。可以通过依赖注入为传输端点添加认证保护：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)]\n    )\n)\nmcp.mount_http()\n```\n\n这种方式确保所有通过传输层访问的端点都需要进行身份验证。\n\n资料来源：[examples/08_auth_example_token_passthrough.py:1-50]()\n\n## 传输层初始化参数\n\n`FastApiMCP` 类中与传输层相关的初始化参数：\n\n| 参数 | 类型 | 默认值 | 说明 |\n|-----|------|-------|------|\n| `http_client` | `httpx.AsyncClient` | `None` | 自定义 HTTP 客户端 |\n| `headers` | `List[str]` | `[\"authorization\"]` | 转发到工具调用的 HTTP 头列表 |\n\n```python\nmcp = FastApiMCP(\n    app,\n    http_client=custom_client,\n    headers=[\"authorization\", \"x-custom-header\"]  # 自定义转发头\n)\n```\n\n资料来源：[server.py:100-120]()\n\n## 迁移指南\n\n### 废弃的 mount() 方法\n\n早期版本中的 `mount()` 方法已被废弃，应使用 `mount_http()` 或 `mount_sse()` 替代：\n\n```python\n# ❌ 已废弃\nmcp.mount(app, transport=\"sse\")\n\n# ✅ 推荐方式\nmcp.mount_http()\n# 或\nmcp.mount_sse(app, mount_path=\"/mcp\")\n```\n\n使用废弃方法时，系统会发出警告：\n\n```\nDeprecationWarning: mount() is deprecated and will be removed in a future version. \nUse mount_http() for HTTP transport (recommended) or mount_sse() for SSE transport instead.\n```\n\n资料来源：[server.py:250-270]()\n\n## 总结\n\nFastAPI-MCP 的传输层提供了灵活的双协议支持，开发者可以根据具体需求选择合适的传输方式。HTTP Streamable 传输是生产环境的推荐选择，提供稳定可靠的通信能力；SSE 传输则为需要服务端推送的场景提供了替代方案。\n\n---\n\n<a id='page-openapi-conversion'></a>\n\n## OpenAPI 到 MCP 转换\n\n### 相关页面\n\n相关主题：[系统架构](#page-architecture), [配置与自定义](#page-configuration)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/openapi/convert.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/openapi/convert.py)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [examples/02_full_schema_description_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/02_full_schema_description_example.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n</details>\n\n# OpenAPI 到 MCP 转换\n\n## 概述\n\nOpenAPI 到 MCP 转换是 FastAPI-MCP 框架的核心功能，负责将 FastAPI 应用的 OpenAPI schema 自动转换为 MCP (Model Context Protocol) 工具。该转换过程保留了 FastAPI 端点的完整类型信息、参数定义、请求体结构和响应模式，使得 MCP 客户端能够以类型安全的方式调用 FastAPI 服务。\n\n转换模块位于 `fastapi_mcp/openapi/` 目录下，主要由 `convert.py` 实现核心转换逻辑，`utils.py` 提供辅助工具函数。\n\n## 核心转换函数\n\n### convert_openapi_to_mcp_tools\n\n`convert_openapi_to_mcp_tools` 是整个转换流程的核心入口函数，定义于 `fastapi_mcp/openapi/convert.py`:\n\n```python\ndef convert_openapi_to_mcp_tools(\n    openapi_schema: Dict[str, Any],\n    describe_all_responses: bool = False,\n    describe_full_response_schema: bool = False,\n) -> Tuple[List[types.Tool], Dict[str, Dict[str, Any]]]:\n```\n\n**参数说明：**\n\n| 参数 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `openapi_schema` | `Dict[str, Any]` | 必需 | 完整的 OpenAPI schema 对象 |\n| `describe_all_responses` | `bool` | `False` | 是否在工具描述中包含所有可能的响应模式 |\n| `describe_full_response_schema` | `bool` | `False` | 是否在工具描述中包含完整的 JSON 响应 schema |\n\n**返回值：**\n\n返回一个元组 `(List[types.Tool], Dict[str, Dict[str, Any]])`，包含：\n- MCP tools 列表，用于 MCP 协议交互\n- operation ID 到操作详情的映射，用于后续 HTTP 执行\n\n资料来源：[fastapi_mcp/openapi/convert.py:30-48]()\n\n## 转换流程架构\n\n```mermaid\ngraph TD\n    A[OpenAPI Schema] --> B[resolve_schema_references]\n    B --> C[遍历所有 paths]\n    C --> D{检查 HTTP 方法}\n    D -->|get/post/put/delete/patch| E[提取 operationId]\n    D -->|其他方法| F[跳过并记录警告]\n    E --> G[获取操作元数据]\n    G --> H[构建工具描述]\n    H --> I[组织参数类型]\n    I --> J[处理请求体]\n    J --> K[生成 MCP Tool]\n    K --> L[返回工具列表]\n    \n    style F fill:#ffcccc\n    style L fill:#ccffcc\n```\n\n## 详细的转换步骤\n\n### 第一步：Schema 引用解析\n\n在开始遍历操作之前，转换器首先调用 `resolve_schema_references` 函数解析 OpenAPI schema 中的所有 `$ref` 引用：\n\n```python\nresolved_openapi_schema = resolve_schema_references(openapi_schema, openapi_schema)\n```\n\n这一步骤确保后续处理能够访问完整的 schema 定义，避免因引用未解析而导致的类型信息丢失。\n\n资料来源：[fastapi_mcp/openapi/convert.py:50]()\n\n### 第二步：路径与方法遍历\n\n转换器遍历 OpenAPI schema 中定义的所有路径，并为每个路径检查所有支持的 HTTP 方法：\n\n```python\nfor path, path_item in resolved_openapi_schema.get(\"paths\", {}).items():\n    for method, operation in path_item.items():\n        if method not in [\"get\", \"post\", \"put\", \"delete\", \"patch\"]:\n            logger.warning(f\"Skipping non-HTTP method: {method}\")\n            continue\n```\n\n**支持的 HTTP 方法：**\n\n| 方法 | 说明 | 工具调用方式 |\n|------|------|--------------|\n| `GET` | 获取资源 | `client.get(path, params=query, headers=headers)` |\n| `POST` | 创建资源 | `client.post(path, params=query, headers=headers, json=body)` |\n| `PUT` | 完全更新资源 | `client.put(path, params=query, headers=headers, json=body)` |\n| `DELETE` | 删除资源 | `client.delete(path, params=query, headers=headers)` |\n| `PATCH` | 部分更新资源 | `client.patch(path, params=query, headers=headers, json=body)` |\n\n资料来源：[fastapi_mcp/openapi/convert.py:53-58]()\n\n### 第三步：参数分类\n\n转换器将操作参数按位置分为四类：\n\n```python\npath_params = []\nquery_params = []\nheader_params = []\nbody_params = []\n\nfor param in operation.get(\"parameters\", []):\n    param_name = param.get(\"name\")\n    param_in = param.get(\"in\")\n    required = param.get(\"required\", False)\n\n    if param_in == \"path\":\n        path_params.append((param_name, param))\n    elif param_in == \"query\":\n        query_params.append((param_name, param))\n    elif param_in == \"header\":\n        header_params.append((param_name, param))\n```\n\n**参数分类表：**\n\n| 参数位置 | 变量名 | 说明 | 必填检查 |\n|----------|--------|------|----------|\n| `path` | `path_params` | URL 路径参数 | 始终为 `required=True` |\n| `query` | `query_params` | URL 查询字符串参数 | 可选 |\n| `header` | `header_params` | HTTP 请求头参数 | 可选 |\n| `body` | `body_params` | 请求体参数 | 需检查 `required` 字段 |\n\n资料来源：[fastapi_mcp/openapi/convert.py:78-92]()\n\n### 第四步：请求体处理\n\n当操作包含 `requestBody` 时，转换器解析其内容类型和 schema 定义：\n\n```python\nrequest_body = operation.get(\"requestBody\", {})\nif request_body and \"content\" in request_body:\n    content_type = next(iter(request_body[\"content\"]), None)\n    if content_type and \"schema\" in request_body[\"content\"][content_type]:\n        schema = request_body[\"content\"][content_type][\"schema\"]\n        if \"properties\" in schema:\n            for prop_name, prop_schema in schema[\"properties\"].items():\n                body_params.append((prop_name, prop_schema))\n```\n\n### 第五步：工具描述构建\n\n转换器为每个 MCP 工具生成详细的描述信息，包括端点路径、方法、参数和响应模式：\n\n```python\ntool_description += response_info\n```\n\n描述信息包含：\n- 端点路径和 HTTP 方法\n- 路径参数说明\n- 查询参数说明\n- 请求体结构（JSON Schema）\n- 响应模式（可选，取决于配置）\n\n## 响应描述控制\n\n### describe_all_responses 选项\n\n当 `describe_all_responses=True` 时，工具描述将包含该端点所有可能的响应模式，包括不同的状态码对应的 schema：\n\n```json\n{\n  \"200\": { \"description\": \"Successful Response\", \"content\": {...} },\n  \"422\": { \"description\": \"Validation Error\", \"content\": {...} }\n}\n```\n\n### describe_full_response_schema 选项\n\n当 `describe_full_response_schema=True` 时，工具描述将包含完整的 JSON Schema 而不仅仅是摘要信息，便于 MCP 客户端进行详细的类型推断。\n\n资料来源：[fastapi_mcp/openapi/convert.py:35-40]()\n\n## 工具函数模块\n\n### 辅助函数列表\n\n| 函数名 | 功能 |\n|--------|------|\n| `resolve_schema_references` | 递归解析 OpenAPI schema 中所有的 `$ref` 引用 |\n| `clean_schema_for_display` | 清理 schema，移除不适合显示的内部元数据 |\n| `generate_example_from_schema` | 根据 schema 定义生成示例数据 |\n| `get_single_param_type_from_schema` | 从 schema 中提取单一参数类型信息 |\n\n这些工具函数确保转换过程中的类型安全和信息完整性。\n\n## 过滤机制\n\n`FastApiMCP` 类支持对转换后的工具进行细粒度过滤：\n\n```python\ndef _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any]) -> List[types.Tool]:\n```\n\n**过滤选项：**\n\n| 选项 | 类型 | 说明 |\n|------|------|------|\n| `include_operations` | `List[str]` | 仅包含指定 operation ID 的工具 |\n| `exclude_operations` | `List[str]` | 排除指定 operation ID 的工具 |\n| `include_tags` | `List[str]` | 仅包含指定标签的工具 |\n| `exclude_tags` | `List[str]` | 排除指定标签的工具 |\n\n**使用限制：**\n- `include_operations` 和 `exclude_operations` 不可同时使用\n- `include_tags` 和 `exclude_tags` 不可同时使用\n- 操作过滤和标签过滤可以组合使用（使用贪婪匹配）\n\n资料来源：[fastapi_mcp/server.py:75-90]()\n\n## 完整使用示例\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_mcp import FastApiMCP\n\napp = FastAPI()\n\n# 默认转换所有端点\nmcp = FastApiMCP(app)\n\n# 自定义转换配置\nmcp = FastApiMCP(\n    app,\n    name=\"Custom MCP Server\",\n    describe_all_responses=True,\n    describe_full_response_schema=True,\n    include_operations=[\"get_item\", \"list_items\"],\n    exclude_operations=[\"delete_item\"],\n    headers=[\"authorization\", \"x-custom-header\"],\n)\n\n# 挂载 MCP 服务器\nmcp.mount()\n```\n\n资料来源：[examples/02_full_schema_description_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/02_full_schema_description_example.py)\n\n## MCP Tool 结构\n\n转换后的 MCP Tool 包含以下核心字段：\n\n| 字段 | 说明 |\n|------|------|\n| `name` | 工具名称（通常为 operationId） |\n| `description` | 工具描述，包含端点信息和参数说明 |\n| `inputSchema` | JSON Schema 格式的输入参数定义 |\n| `annotations` | 可选的注释信息 |\n\n## HTTP 执行映射\n\n对于每个转换后的工具，系统维护一个 `operation_map`，将工具名称映射到实际的执行信息：\n\n```python\noperation_map = {\n    \"get_item\": {\n        \"method\": \"get\",\n        \"path\": \"/items/{item_id}\",\n        \"operation_id\": \"get_item\"\n    },\n    \"list_items\": {\n        \"method\": \"get\",\n        \"path\": \"/items\",\n        \"operation_id\": \"list_items\"\n    }\n}\n```\n\n此映射用于后续通过 httpx 客户端实际执行 HTTP 请求。\n\n## 错误处理\n\n转换过程中遇到的问题会被记录但不会中断流程：\n\n- 非 HTTP 方法（如 `options`、`head`）会被跳过并记录警告\n- 缺少 `operationId` 的操作会被跳过\n- Schema 解析错误会被捕获并记录日志\n\n## 类型安全保证\n\nFastAPI-MCP 的转换过程通过以下机制确保类型安全：\n\n1. **Pydantic 模型验证**：使用 Pydantic 进行类型验证\n2. **引用解析**：确保所有 `$ref` 被正确解析\n3. **Schema 清理**：移除不兼容的字段，确保 JSON Schema 有效性\n4. **示例生成**：根据 schema 自动生成示例值，便于测试\n\n资料来源：[fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n\n## 总结\n\nOpenAPI 到 MCP 转换是 FastAPI-MCP 框架的桥梁，它：\n\n1. **自动化** - 无需手动定义 MCP 工具，OpenAPI schema 自动转换\n2. **类型安全** - 保留完整的类型信息，支持强类型调用\n3. **灵活可控** - 支持细粒度的端点过滤和描述控制\n4. **文档完整** - 自动保留并增强 FastAPI 端点的文档信息\n\n该模块使得开发者能够零配置地将现有的 FastAPI 应用暴露为 MCP 服务器，同时保持原有的类型安全性和开发体验。\n\n---\n\n<a id='page-authentication'></a>\n\n## 认证与授权\n\n### 相关页面\n\n相关主题：[系统架构](#page-architecture), [示例集](#page-examples)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/auth/proxy.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/auth/proxy.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n- [examples/09_auth_example_auth0.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/09_auth_example_auth0.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n</details>\n\n# 认证与授权\n\nFastAPI-MCP 内置了基于 FastAPI 依赖注入系统的认证与授权机制。这套机制允许开发者复用现有的 FastAPI 认证逻辑，无需额外配置即可保护 MCP 工具的访问。\n\n## 系统架构\n\n```mermaid\ngraph TD\n    A[MCP Client] --> B[FastAPI-MCP Server]\n    B --> C{FastAPI Dependencies}\n    C -->|验证通过| D[MCP Tool]\n    C -->|验证失败| E[401/403 错误]\n    F[OAuth Provider] -->|OAuth Flow| B\n    \n    subgraph \"认证配置层\"\n        G[AuthConfig]\n        H[OAuthMetadata]\n        I[Custom Metadata]\n    end\n```\n\n## 核心类型\n\n### AuthConfig\n\n`AuthConfig` 是配置 MCP 认证的核心类，位于 `fastapi_mcp/types.py`。支持 OAuth 2.0 授权流程和自定义元数据配置。\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `version` | `Literal[\"2025-03-26\"]` | MCP 规范版本，当前仅支持 `\"2025-03-26\"` |\n| `dependencies` | `Optional[Sequence[Depends]]` | FastAPI 依赖列表，用于身份验证 |\n| `setup_proxies` | `bool` | 是否设置 OAuth 代理端点 |\n| `client_id` | `Optional[str]` | OAuth 客户端 ID |\n| `client_secret` | `Optional[str]` | OAuth 客户端密钥 |\n| `issuer` | `Optional[str]` | OAuth 服务器签发者 |\n| `oauth_metadata_url` | `Optional[StrHttpUrl]` | OAuth 提供商元数据端点 URL |\n| `authorize_url` | `Optional[StrHttpUrl]` | 授权端点 URL |\n| `metadata_path` | `str` | 元数据端点路径，默认 `\"/.well-known/oauth-authorization-server\"` |\n| `audience` | `Optional[str]` | OAuth 受众 |\n| `default_scope` | `Optional[str]` | 默认权限范围 |\n| `custom_oauth_metadata` | `Optional[OAuthMetadataDict]` | 自定义 OAuth 元数据 |\n| `setup_fake_dynamic_registration` | `bool` | 是否设置虚假动态客户端注册端点 |\n\n资料来源：[fastapi_mcp/types.py:100-150]()\n\n### OAuthMetadata\n\nOAuth 2.0 服务器元数据结构，符合 RFC 8414 规范：\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `issuer` | `StrHttpUrl` | 授权服务器的签发者标识符 |\n| `authorization_endpoint` | `Optional[StrHttpUrl]` | 授权端点 URL |\n| `token_endpoint` | `StrHttpUrl` | 令牌端点 URL |\n| `scopes_supported` | `List[str]` | 支持的 OAuth 范围列表，默认 `[\"openid\", \"profile\", \"email\"]` |\n| `response_types_supported` | `List[str]` | 支持的响应类型 |\n\n资料来源：[fastapi_mcp/types.py:50-90]()\n\n## 认证流程\n\n### 基础 Token 验证\n\n最简单的认证方式是使用 FastAPI 的 `HTTPBearer` 进行 Token 验证：\n\n```mermaid\nsequenceDiagram\n    participant C as MCP Client\n    participant S as FastAPI-MCP\n    participant D as FastAPI Dependencies\n    \n    C->>S: 请求携带 Authorization Header\n    S->>D: 注入 dependencies 进行验证\n    D->>D: 验证 Bearer Token\n    alt Token 有效\n        D-->>S: 验证通过\n        S->>C: 执行 MCP Tool\n    else Token 无效\n        D-->>S: 401 Unauthorized\n        S->>C: 返回错误\n    end\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py]()\n\n### OAuth 授权流程\n\n当配置了完整的 OAuth 设置时，流程如下：\n\n```mermaid\ngraph LR\n    A[Client] -->|1. 请求工具| B[FastAPI-MCP]\n    B -->|2. Token 缺失/无效| C[OAuth Redirect]\n    C -->|3. 用户授权| D[Auth Provider]\n    D -->|4. Authorization Code| A\n    A -->|5. 交换 Token| D\n    D -->|6. Access Token| A\n    A -->|7. 请求工具 + Token| B\n    B -->|8. 执行工具| A\n```\n\n## 使用方式\n\n### 方式一：Token 验证（简单场景）\n\n适用于内部服务或测试环境，直接验证 Authorization Header 中的 Token：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\n@app.get(\"/private\")\nasync def private(token=Depends(token_auth_scheme)):\n    return token.credentials\n\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n\nmcp.mount_http()\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:30-45]()\n\n### 方式二：Auth0 集成（生产环境）\n\n生产环境推荐使用 Auth0 等专业 OAuth 提供商：\n\n```python\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\nmcp = FastApiMCP(\n    app,\n    name=\"MCP With Auth0\",\n    auth_config=AuthConfig(\n        issuer=f\"https://{settings.auth0_domain}/\",\n        authorize_url=f\"https://{settings.auth0_domain}/authorize\",\n        oauth_metadata_url=settings.auth0_oauth_metadata_url,\n        audience=settings.auth0_audience,\n        client_id=settings.auth0_client_id,\n        client_secret=settings.auth0_client_secret,\n        dependencies=[Depends(verify_auth)],\n        setup_proxies=True,\n    ),\n)\n```\n\n资料来源：[examples/09_auth_example_auth0.py:45-60]()\n\n### 方式三：自定义 OAuth 元数据\n\n当需要使用特定的 OAuth 提供商而非自动发现时：\n\n```python\nfrom fastapi_mcp.auth.proxy import setup_oauth_custom_metadata\n\nsetup_oauth_custom_metadata(\n    app=app,\n    auth_config=auth_config,\n    metadata=custom_oauth_metadata,\n    include_in_schema=False,\n)\n```\n\n资料来源：[fastapi_mcp/auth/proxy.py:25-45]()\n\n## OAuth 代理端点\n\nFastAPI-MCP 提供多个 OAuth 代理函数，用于搭建完整的授权服务：\n\n| 函数 | 功能 | 路径 |\n|------|------|------|\n| `setup_oauth_custom_metadata` | 提供自定义 OAuth 元数据 | `auth_config.metadata_path` |\n| `setup_oauth_metadata_proxy` | 代理 OAuth 提供商的元数据端点 | 默认 `/.well-known/oauth-authorization-server` |\n| `setup_oauth_authorize_proxy` | 代理授权端点 | 默认 `/oauth/authorize` |\n| `setup_oauth_fake_dynamic_register_endpoint` | 提供动态客户端注册 | `/oauth/register` |\n\n资料来源：[fastapi_mcp/auth/proxy.py:48-120]()\n\n### 元数据代理配置\n\n```python\nsetup_oauth_metadata_proxy(\n    app=app,\n    metadata_url=\"https://your-oauth-provider.com/.well-known/oauth-authorization-server\",\n    path=\"/.well-known/oauth-authorization-server\",\n    authorize_path=\"/oauth/authorize\",\n    register_path=\"/oauth/register\",\n)\n```\n\n### 授权代理配置\n\n```python\nsetup_oauth_authorize_proxy(\n    app=app,\n    client_id=\"your-client-id\",\n    authorize_url=\"https://your-provider.com/authorize\",\n    audience=\"your-audience\",\n    default_scope=\"openid profile\",\n)\n```\n\n### 动态客户端注册\n\n对于需要动态注册客户端的场景：\n\n```python\nsetup_oauth_fake_dynamic_register_endpoint(\n    app=app,\n    client_id=\"your-client-id\",\n    client_secret=\"your-client-secret\",\n)\n```\n\n## 在 FastApiMCP 中启用认证\n\n将 `AuthConfig` 传入 `FastApiMCP` 构造函数即可启用认证：\n\n```python\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP Server\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(my_auth_dependency)],\n        setup_proxies=True,\n        client_id=\"...\",\n        client_secret=\"...\",\n        issuer=\"https://auth.example.com\",\n    ),\n)\n```\n\n资料来源：[fastapi_mcp/server.py:180-220]()\n\n## 认证配置内部处理\n\n在 `FastApiMCP` 初始化时，会根据 `AuthConfig` 自动配置认证端点：\n\n```python\ndef _setup_auth_2025_03_26(self):\n    if self._auth_config:\n        if self._auth_config.custom_oauth_metadata:\n            setup_oauth_custom_metadata(...)\n        elif self._auth_config.setup_proxies:\n            setup_oauth_metadata_proxy(...)\n            setup_oauth_authorize_proxy(...)\n            if self._auth_config.setup_fake_dynamic_registration:\n                setup_oauth_fake_dynamic_register_endpoint(...)\n```\n\n资料来源：[fastapi_mcp/server.py:220-260]()\n\n## 最佳实践\n\n1. **生产环境使用 OAuth**：不要在生产环境使用简单的 Token 验证，应配置完整的 OAuth 流程\n2. **敏感信息管理**：使用环境变量存储 `client_id` 和 `client_secret`\n3. **依赖注入复用**：直接复用现有的 FastAPI 认证依赖，保持代码一致性\n4. **元数据端点**：确保 `metadata_path` 符合 OAuth 规范，默认值为 `/.well-known/oauth-authorization-server`\n\n---\n\n<a id='page-endpoint-filtering'></a>\n\n## 端点过滤与自定义\n\n### 相关页面\n\n相关主题：[OpenAPI 到 MCP 转换](#page-openapi-conversion), [配置与自定义](#page-configuration)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [CONTRIBUTING.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n- [CHANGELOG.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CHANGELOG.md)\n- [examples/shared/apps/items.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/shared/apps/items.py)\n</details>\n\n# 端点过滤与自定义\n\n## 概述\n\n端点过滤与自定义是 FastAPI-MCP 框架提供的重要功能，允许开发者精确控制哪些 FastAPI 端点被暴露为 MCP（Model Context Protocol）工具。通过灵活的配置选项，用户可以基于操作 ID（operationId）或标签（tags）对端点进行细粒度的筛选，从而实现按需暴露接口、保护敏感端点或构建特定的工具集。\n\n这一功能在 CHANGELOG.md 中被首次引入，作为支持\"refreshing\"功能的一部分，专门用于解决动态添加 FastAPI 路由后的端点管理问题。资料来源：[CHANGELOG.md]()\n\n## 核心概念\n\n### 操作 ID（Operation ID）\n\n每个 FastAPI 端点在 OpenAPI 规范中都有一个唯一的 `operationId`，用于标识该操作。FastAPI-MCP 利用这个标识符来精确定位和过滤特定的端点。\n\n### 标签（Tags）\n\n标签是 OpenAPI 规范中用于分组和组织端点的机制。一个端点可以拥有多个标签，这为批量过滤提供了便利的条件。\n\n## 过滤参数\n\nFastAPI-MCP 在 `FastApiMCP` 类中提供了四个核心过滤参数：\n\n| 参数名 | 类型 | 说明 | 互斥约束 |\n|--------|------|------|----------|\n| `include_operations` | `Optional[List[str]]` | 仅包含指定 operation ID 的端点 | 与 `exclude_operations` 互斥 |\n| `exclude_operations` | `Optional[List[str]]` | 排除指定 operation ID 的端点 | 与 `include_operations` 互斥 |\n| `include_tags` | `Optional[List[str]]` | 仅包含具有指定标签的端点 | 与 `exclude_tags` 互斥 |\n| `exclude_tags` | `Optional[List[str]]` | 排除具有指定标签的端点 | 与 `include_tags` 互斥 |\n\n资料来源：[fastapi_mcp/server.py:60-85]()\n\n## 过滤规则\n\n### 互斥规则\n\nFastAPI-MCP 对过滤参数实施了严格的互斥约束，以确保配置的一致性和可预测性：\n\n1. **操作 ID 级别**：不能同时使用 `include_operations` 和 `exclude_operations`\n2. **标签级别**：不能同时使用 `include_tags` 和 `exclude_tags`\n3. **跨级别组合**：可以同时使用操作 ID 过滤和标签过滤\n\n### 组合过滤行为\n\n当同时使用多种过滤条件时，FastAPI-MCP 采用**贪婪模式（greedy approach）**：任何满足任一条件的端点都会被包含在最终的工具列表中。\n\n```mermaid\ngraph TD\n    A[开始过滤流程] --> B{include_operations<br/>存在?}\n    B -->|是| C[根据 operation ID 包含]\n    B -->|否| D{exclude_operations<br/>存在?}\n    D -->|是| E[根据 operation ID 排除]\n    D -->|否| F{include_tags<br/>存在?}\n    F -->|是| G[根据标签包含]\n    F -->|否| H{exclude_tags<br/>存在?}\n    H -->|是| I[根据标签排除]\n    H -->|否| J[不进行过滤]\n    C --> K{同时存在<br/>标签过滤?}\n    E --> K\n    G --> L[贪婪模式:<br/>满足任一条件即包含]\n    I --> L\n    J --> L\n    K -->|是| L\n    L --> M[返回过滤后的工具列表]\n```\n\n资料来源：[fastapi_mcp/server.py:48-70]()\n\n## 过滤实现机制\n\n### 核心方法：`_filter_tools`\n\n`FastApiMCP` 类中的 `_filter_tools` 方法是执行过滤逻辑的核心实现。该方法接收两个参数：\n\n- `tools`：待过滤的工具列表\n- `openapi_schema`：完整的 OpenAPI 架构定义\n\n```python\ndef _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any]) -> List[types.Tool]:\n    \"\"\"\n    Filter tools based on operation IDs and tags.\n\n    Args:\n        tools: List of tools to filter\n        openapi_schema: The OpenAPI schema\n\n    Returns:\n        Filtered list of tools\n    \"\"\"\n    if (\n        self._include_operations is None\n        and self._exclude_operations is None\n        and self._include_tags is None\n        and self._exclude_tags is None\n    ):\n        return tools\n```\n\n资料来源：[fastapi_mcp/server.py:35-56]()\n\n### 构建标签到操作 ID 的映射\n\n过滤过程中，框架首先构建一个从标签到操作 ID 列表的映射：\n\n```python\noperations_by_tag: Dict[str, List[str]] = {}\nfor path, path_item in openapi_schema.get(\"paths\", {}).items():\n    for method, operation in path_item.items():\n        if method not in [\"get\", \"post\", \"put\", \"delete\", \"patch\"]:\n            continue\n\n        operation_id = operation.get(\"operationId\")\n        if not operation_id:\n            continue\n\n        tags = operation.get(\"tags\", [])\n        for tag in tags:\n            if tag not in operations_by_tag:\n                operations_by_tag[tag] = []\n            operations_by_tag[tag].append(operation_id)\n```\n\n资料来源：[fastapi_mcp/server.py:57-74]()\n\n## 使用示例\n\n### 按操作 ID 过滤\n\n#### 仅包含特定操作\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\n# 仅暴露 get_item 和 list_items 两个操作\ninclude_operations_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Included Operations\",\n    include_operations=[\"get_item\", \"list_items\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:18-24]()\n\n#### 排除特定操作\n\n```python\n# 排除 create_item、update_item 和 delete_item 操作\nexclude_operations_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Excluded Operations\",\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:27-32]()\n\n### 按标签过滤\n\n#### 仅包含特定标签\n\n```python\n# 仅暴露具有 'items' 标签的端点\ninclude_tags_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Included Tags\",\n    include_tags=[\"items\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:35-39]()\n\n#### 排除特定标签\n\n```python\n# 排除具有 'search' 标签的端点\nexclude_tags_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Excluded Tags\",\n    exclude_tags=[\"search\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:42-46]()\n\n### 组合过滤\n\n可以将操作 ID 过滤和标签过滤组合使用：\n\n```python\n# 包含具有 'search' 标签或 delete_item 操作的所有端点\ncombined_include_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Combined Include\",\n    include_operations=[\"delete_item\"],\n    include_tags=[\"search\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:49-55]()\n\n## 挂载与部署\n\n过滤后的 MCP 服务器可以通过 `mount_http` 方法挂载到不同的路径：\n\n```python\n# 为不同的过滤配置挂载独立的 MCP 端点\ninclude_operations_mcp.mount_http(mount_path=\"/include-operations-mcp\")\nexclude_operations_mcp.mount_http(mount_path=\"/exclude-operations-mcp\")\ninclude_tags_mcp.mount_http(mount_path=\"/include-tags-mcp\")\nexclude_tags_mcp.mount_http(mount_path=\"/exclude-tags-mcp\")\ncombined_include_mcp.mount_http(mount_path=\"/combined-include-mcp\")\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:58-63]()\n\n## 典型应用场景\n\n### 场景一：构建只读 API\n\n如果需要创建一个只读的 MCP 工具集，可以排除所有修改类操作：\n\n```python\nmcp_readonly = FastApiMCP(\n    app,\n    name=\"Read-Only API\",\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n### 场景二：按功能模块隔离\n\n根据业务模块隔离不同的 MCP 服务：\n\n```python\n# 仅包含搜索相关功能\nmcp_search = FastApiMCP(\n    app,\n    name=\"Search API\",\n    include_tags=[\"search\"],\n)\n\n# 仅包含物品管理功能\nmcp_items = FastApiMCP(\n    app,\n    name=\"Items API\",\n    include_tags=[\"items\"],\n)\n```\n\n### 场景三：权限分级\n\n通过标签组织不同权限级别的端点：\n\n```python\n# 管理员端点（排除公开端点）\nmcp_admin = FastApiMCP(\n    app,\n    name=\"Admin API\",\n    include_tags=[\"admin\"],\n    exclude_operations=[\"get_public_stats\"],  # 排除特定敏感操作\n)\n```\n\n## 注意事项\n\n### 1. operationId 必需\n\n过滤功能依赖 OpenAPI 规范中的 `operationId`。如果 FastAPI 端点未显式定义 `operationId`，FastAPI 会自动生成一个，但可能难以预测。建议显式定义：\n\n```python\n@app.get(\"/items/{item_id}\", operation_id=\"get_item\")\nasync def get_item(item_id: int):\n    return {\"item_id\": item_id}\n```\n\n### 2. 标签的作用域\n\n一个端点可以属于多个标签，只要满足任一过滤条件，该端点就会被包含。\n\n### 3. 无过滤参数时的行为\n\n如果未提供任何过滤参数（`include_operations`、`exclude_operations`、`include_tags`、`exclude_tags` 均为 `None`），则所有可发现的端点都将被暴露为 MCP 工具。\n\n## 相关文档\n\n- [基础用法示例](../examples/01_basic_usage_example.md)\n- [完整架构描述](./schema-description.md)\n- [认证配置](./authentication.md)\n- [工具命名配置](./tool-naming.mdx)\n\n## 更新日志\n\n| 版本 | 更新内容 |\n|------|----------|\n| 0.2.0 | 新增端点过滤能力，支持 `include_operations`、`exclude_operations`、`include_tags`、`exclude_tags` 参数 |\n\n---\n\n<a id='page-deployment'></a>\n\n## 部署选项\n\n### 相关页面\n\n相关主题：[传输层](#page-transport), [配置与自定义](#page-configuration)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [examples/04_separate_server_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/04_separate_server_example.py)\n- [examples/05_reregister_tools_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/05_reregister_tools_example.py)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n</details>\n\n# 部署选项\n\nFastAPI-MCP 提供了多种部署方式，以适应不同的应用场景和架构需求。本页面详细介绍如何将 MCP 服务器与现有的 FastAPI 应用集成，以及可用的传输协议和挂载选项。\n\n## 概述\n\nFastAPI-MCP 的部署架构基于以下几个核心组件：\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[FastApiMCP 实例]\n    B --> C[传输层]\n    C --> D[HTTP/SSE 传输]\n    C --> E[标准输入输出]\n    B --> F[MCP 工具注册]\n    F --> G[API 端点 → MCP 工具]\n```\n\n## HTTP 挂载部署\n\nHTTP 挂载是最常用的部署方式，允许将 MCP 服务器作为 FastAPI 应用的子路由挂载。\n\n### 基本挂载\n\n通过 `mount_http()` 方法将 MCP 端点挂载到指定路径：\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_mcp import FastApiMCP\n\napp = FastAPI(...)\n\nmcp = FastApiMCP(app, name=\"My MCP Server\")\nmcp.mount_http(mount_path=\"/mcp\")\n```\n\n### 自定义挂载路径\n\n可以为不同的 MCP 实例配置不同的挂载路径，实现多租户或分类服务：\n\n```python\n# 包含特定操作的 MCP\ninclude_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Included Operations\",\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 排除特定操作的 MCP\nexclude_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Excluded Operations\",\n    exclude_operations=[\"create_item\", \"update_item\"],\n)\n\n# 挂载到不同路径\ninclude_mcp.mount_http(mount_path=\"/include-operations-mcp\")\nexclude_mcp.mount_http(mount_path=\"/exclude-operations-mcp\")\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1-10](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n\n### 传输协议\n\nHTTP 挂载支持两种传输协议：\n\n| 协议 | 说明 | 默认端口 |\n|------|------|----------|\n| **SSE (Server-Sent Events)** | 适用于需要服务端推送的场景 | 是 |\n| **Streamable HTTP** | 支持流式响应和双向通信 | 可选 |\n\nSSE 传输通过 `FastApiSseTransport` 实现，提供以下端点：\n\n- `GET /{mount_path}` - MCP 连接端点\n- `POST /{mount_path}/messages/` - 消息处理端点\n\n资料来源：[fastapi_mcp/server.py:140-170](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n\n## 独立服务器部署\n\n对于需要独立运行的场景，FastAPI-MCP 支持将 MCP 服务器作为独立进程启动。\n\n### 使用方式\n\n独立服务器模式允许 MCP 直接作为独立服务运行：\n\n```python\nfrom examples.shared.apps.items import app\nfrom fastapi_mcp import FastApiMCP\n\nmcp = FastApiMCP(\n    app,\n    name=\"Separate Server\",\n    describe_all_responses=True,\n)\n\nif __name__ == \"__main__\":\n    mcp.run()\n```\n\n资料来源：[examples/04_separate_server_example.py:1-20](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/04_separate_server_example.py)\n\n### 独立运行流程\n\n```mermaid\ngraph LR\n    A[启动进程] --> B[MCP.run 初始化]\n    B --> C[创建 STDIO 传输]\n    C --> D[MCP 协议处理]\n    D --> E[接收工具调用请求]\n    E --> F[调用 FastAPI 端点]\n    F --> G[返回结果到 MCP 客户端]\n```\n\n## 工具动态注册\n\nFastAPI-MCP 支持在服务器运行期间动态注册和更新工具。\n\n### reregister_tools 方法\n\n`reregister_tools()` 方法允许在不重启服务器的情况下更新 MCP 工具列表：\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_mcp import FastApiMCP, Tool\n\napp = FastAPI(...)\n\nmcp = FastApiMCP(app, name=\"Dynamic Tools Server\")\n\n# 初始工具列表\ninitial_tools = [\n    Tool(\n        name=\"original_tool\",\n        description=\"An original tool\",\n        inputSchema={\"type\": \"object\", \"properties\": {}},\n    )\n]\n\n# 注册初始工具\nmcp.add_mcp_server(tools=initial_tools)\n\n# 动态添加新工具\nnew_tools = [\n    Tool(\n        name=\"dynamic_tool\",\n        description=\"A dynamically added tool\",\n        inputSchema={\n            \"type\": \"object\",\n            \"properties\": {\n                \"message\": {\"type\": \"string\", \"description\": \"A message\"}\n            },\n        },\n    )\n]\nmcp.reregister_tools(tools=new_tools)\n```\n\n资料来源：[examples/05_reregister_tools_example.py:1-50](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/05_reregister_tools_example.py)\n\n### 动态注册流程\n\n```mermaid\ngraph TD\n    A[运行时] --> B[创建新工具定义]\n    B --> C[调用 reregister_tools]\n    C --> D[更新 MCP 服务器工具列表]\n    D --> E[新工具立即生效]\n    E --> F[下次 list_tools 调用返回新列表]\n```\n\n## 部署配置参数\n\n### mount_http 参数\n\n| 参数 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `mount_path` | `str` | `\"/mcp\"` | MCP 端点挂载的基础路径 |\n| `transport` | `FastApiSseTransport` | 自动创建 | 传输协议实例 |\n| `dependencies` | `Sequence[Depends]` | `None` | 挂载路径的 FastAPI 依赖项 |\n\n资料来源：[fastapi_mcp/server.py:110-130](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n\n### 运行时参数\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `http_client` | `httpx.AsyncClient` | 自定义 HTTP 客户端 |\n| `headers` | `List[str]` | 转发的 HTTP 头列表，默认 `[\"authorization\"]` |\n| `include_operations` | `List[str]` | 仅包含指定的操作 ID |\n| `exclude_operations` | `List[str]` | 排除指定的操作 ID |\n\n资料来源：[fastapi_mcp/server.py:70-100](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n\n## 认证配置部署\n\n在部署时可以通过 `auth_config` 配置认证功能：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n\nmcp.mount_http()\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:1-30](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n\n## 多实例部署架构\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[主 MCP 实例<br/>包含全部工具]\n    A --> C[过滤 MCP 实例 1<br/>include_operations]\n    A --> D[过滤 MCP 实例 2<br/>include_tags]\n    B --> E[/mcp]\n    C --> F[/filtered-operations]\n    D --> G[/filtered-tags]\n    \n    style E fill:#90EE90\n    style F fill:#87CEEB\n    style G fill:#DDA0DD\n```\n\n## 部署环境要求\n\n| 要求 | 最低版本 | 推荐版本 |\n|------|----------|----------|\n| Python | 3.10+ | 3.12 |\n| FastAPI | - | 最新稳定版 |\n| httpx | - | 最新稳定版 |\n| MCP SDK | - | 兼容版本 |\n\n## 常见部署场景\n\n### 场景一：单一路由挂载\n\n适用于简单的微服务架构：\n\n```python\nmcp = FastApiMCP(app, name=\"Simple MCP\")\nmcp.mount_http(mount_path=\"/mcp\")\n```\n\n### 场景二：多实例隔离\n\n适用于需要按功能模块隔离访问权限的场景：\n\n```python\nadmin_mcp = FastApiMCP(app, include_tags=[\"admin\"])\nuser_mcp = FastApiMCP(app, include_tags=[\"user\"])\n\nadmin_mcp.mount_http(mount_path=\"/admin-mcp\")\nuser_mcp.mount_http(mount_path=\"/user-mcp\")\n```\n\n### 场景三：认证保护部署\n\n适用于需要保护敏感 API 的场景：\n\n```python\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(dependencies=[Depends(verify_token)])\n)\nmcp.mount_http()\n```\n\n## 下一步\n\n- 了解 [工具过滤配置](./filtering.md) 了解更多操作和标签过滤选项\n- 查看 [认证配置](./authentication.md) 了解完整的认证设置\n- 参考 [示例代码](../examples/index.md) 获取完整示例\n\n---\n\n<a id='page-configuration'></a>\n\n## 配置与自定义\n\n### 相关页面\n\n相关主题：[部署选项](#page-deployment), [示例集](#page-examples)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [examples/06_custom_mcp_router_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/06_custom_mcp_router_example.py)\n- [examples/07_configure_http_timeout_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/07_configure_http_timeout_example.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n</details>\n\n# 配置与自定义\n\nFastAPI-MCP 提供了丰富的配置选项，使开发者能够根据实际需求灵活定制 MCP 服务器的行为。本文详细介绍 FastAPI-MCP 的各项配置参数、挂载方式、认证配置以及工具过滤机制。\n\n## 核心配置参数\n\n`FastApiMCP` 类的构造函数是主要的配置入口，支持多种参数来控制 MCP 服务器的功能和行为。\n\n### 基础配置\n\n| 参数 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `name` | `str` | 必填 | MCP 服务器名称 |\n| `description` | `str` | `None` | 服务器描述信息 |\n| `describe_all_responses` | `bool` | `False` | 是否在工具描述中包含所有可能的响应 schema |\n| `describe_full_response_schema` | `bool` | `False` | 是否包含完整的 JSON schema 响应信息 |\n\n基础配置允许开发者为 MCP 服务器设置标识信息和响应描述的详细程度。当 `describe_all_responses` 设置为 `True` 时，工具描述将包含端点的所有可能响应状态码对应的 schema；当 `describe_full_response_schema` 设置为 `True` 时，会输出完整的 JSON schema 结构。资料来源：[fastapi_mcp/server.py:54-73]()\n\n### HTTP 客户端配置\n\n```python\nhttp_client: Annotated[\n    Optional[httpx.AsyncClient],\n    Doc(\"用于向 FastAPI 应用发起 API 调用的自定义 HTTP 客户端\"),\n] = None\n```\n\n通过 `http_client` 参数，开发者可以传入自定义的 `httpx.AsyncClient` 实例来自定义超时、代理、连接池等 HTTP 行为。资料来源：[fastapi_mcp/server.py:79-85]()\n\n### 标头转发配置\n\n```python\nheaders: Annotated[\n    List[str],\n    Doc(\"从 MCP 请求中转发到每个工具调用的 HTTP 标头名称列表\"),\n] = [\"authorization\"]\n```\n\n`headers` 参数控制哪些 HTTP 标头会被转发到后端 API 调用。默认情况下只转发 `authorization` 标头，开发者可以根据需要添加其他标头。资料来源：[fastapi_mcp/server.py:119-126]()\n\n## 挂载方式\n\nFastAPI-MCP 支持多种挂载方式，以适应不同的部署场景。\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[选择挂载方式]\n    B --> C[mount_http]\n    B --> D[mount_sse]\n    B --> E[mount - 已废弃]\n    \n    C --> F[HTTP 传输<br/>推荐方式]\n    D --> G[SSE 传输]\n    E --> H[兼容性保留]\n    \n    F --> I[高性能场景]\n    G --> J[实时推送场景]\n```\n\n### HTTP 传输（推荐）\n\n`mount_http()` 是推荐的挂载方式，提供更高的性能和更简单的部署体验：\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\nmcp = FastApiMCP(app, name=\"My MCP Server\")\nmcp.mount_http()\n```\n\n该方式会自动注册必要的端点来处理 MCP 协议的通信。资料来源：[fastapi_mcp/server.py:217-224]()\n\n### SSE 传输\n\n`mount_sse()` 使用 Server-Sent Events 进行通信：\n\n```python\nmcp.mount_sse(router=app, mount_path=\"/mcp\")\n```\n\nSSE 传输方式会在指定路径下注册 MCP 连接端点，适用于需要服务端推送功能的场景。资料来源：[examples/06_custom_mcp_router_example.py:1-25]()\n\n### 自定义路由器挂载\n\n可以通过 `mount_http()` 方法将 MCP 服务器挂载到特定的 `APIRouter` 上，从而实现自定义挂载路径：\n\n```python\nfrom fastapi import APIRouter\nfrom fastapi_mcp import FastApiMCP\n\nother_router = APIRouter(prefix=\"/other/route\")\napp.include_router(other_router)\n\nmcp = FastApiMCP(app)\nmcp.mount_http(other_router)\n```\n\n执行上述代码后，MCP 服务器将只在 `/other/route/mcp` 路径下可用，而不会挂载到应用根路径。资料来源：[examples/06_custom_mcp_router_example.py:11-18]()\n\n### 超时配置\n\n通过自定义 `httpx.AsyncClient` 可以配置 HTTP 请求超时时间：\n\n```python\nimport httpx\nfrom fastapi_mcp import FastApiMCP\n\ncustom_client = httpx.AsyncClient(\n    timeout=30.0  # 设置 30 秒超时\n)\n\nmcp = FastApiMCP(app, http_client=custom_client)\nmcp.mount_http()\n```\n\n默认超时时间为 10 秒，开发者应根据实际业务需求调整该值。资料来源：[fastapi_mcp/server.py:93-96]()\n\n## 认证配置\n\nFastAPI-MCP 利用 FastAPI 原生的依赖注入系统来实现认证功能。\n\n### AuthConfig 配置\n\n`AuthConfig` 类用于配置 MCP 服务器的认证行为：\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `dependencies` | `List[Depends]` | FastAPI 依赖项列表，用于验证请求身份 |\n\n### Bearer Token 认证示例\n\n以下示例展示如何配置基于 Bearer Token 的认证：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\n@app.get(\"/private\")\nasync def private(token=Depends(token_auth_scheme)):\n    return token.credentials\n\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n\nmcp.mount_http()\n```\n\n在此配置下，所有 MCP 工具调用都必须携带有效的 Authorization 标头。资料来源：[examples/08_auth_example_token_passthrough.py:1-45]()\n\n### 认证标头转发\n\n在 MCP 客户端配置中，需要通过标头传递认证信息：\n\n```json\n{\n  \"mcpServers\": {\n    \"remote-example\": {\n      \"command\": \"npx\",\n      \"args\": [\n        \"mcp-remote\",\n        \"http://localhost:8000/mcp\",\n        \"--header\",\n        \"Authorization:${AUTH_HEADER}\"\n      ]\n    }\n  }\n}\n```\n\n## 工具过滤机制\n\nFastAPI-MCP 提供了灵活的端点过滤功能，支持按操作 ID 和标签两种方式进行筛选。\n\n```mermaid\ngraph TD\n    A[OpenAPI Schema] --> B{过滤条件判断}\n    B --> C{include_operations<br/>已设置?}\n    C -->|是| D[按操作 ID 包含]\n    C -->|否| E{exclude_operations<br/>已设置?}\n    E -->|是| F[按操作 ID 排除]\n    E -->|否| G{include_tags<br/>已设置?}\n    G -->|是| H[按标签包含]\n    G -->|否| I{exclude_tags<br/>已设置?}\n    I -->|是| J[按标签排除]\n    I -->|否| K[返回全部工具]\n    \n    D --> L[过滤后的工具列表]\n    F --> L\n    H --> L\n    J --> L\n    K --> L\n```\n\n### 过滤参数说明\n\n| 参数 | 类型 | 说明 | 互斥约束 |\n|------|------|------|----------|\n| `include_operations` | `List[str]` | 仅包含指定操作 ID 的工具 | 与 `exclude_operations` 互斥 |\n| `exclude_operations` | `List[str]` | 排除指定操作 ID 的工具 | 与 `include_operations` 互斥 |\n| `include_tags` | `List[str]` | 仅包含指定标签的工具 | 与 `exclude_tags` 互斥 |\n| `exclude_tags` | `List[str]` | 排除指定标签的工具 | 与 `include_tags` 互斥 |\n\n资料来源：[fastapi_mcp/server.py:86-118]()\n\n### 使用示例\n\n**按操作 ID 过滤：**\n\n```python\n# 仅包含特定操作\ninclude_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 排除特定操作\nexclude_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n**按标签过滤：**\n\n```python\n# 仅包含特定标签\ninclude_tags_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    include_tags=[\"items\"],\n)\n\n# 排除特定标签\nexclude_tags_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    exclude_tags=[\"search\"],\n)\n```\n\n**组合过滤：**\n\n```python\n# 可以组合操作 ID 和标签过滤\ncombined_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Combined\",\n    include_operations=[\"get_item\"],\n    include_tags=[\"search\"],\n)\n```\n\n组合过滤采用贪婪策略，只要满足任一条件的端点都会被包含。资料来源：[examples/03_custom_exposed_endpoints_example.py:1-60]()\n\n## 响应 Schema 配置\n\n### 描述全部响应\n\n当 `describe_all_responses=True` 时，工具描述将包含端点的所有可能响应：\n\n```python\nmcp = FastApiMCP(\n    app,\n    name=\"Full Response MCP\",\n    describe_all_responses=True,\n)\n```\n\n### 完整 Schema 描述\n\n当 `describe_full_response_schema=True` 时，工具描述将包含完整的 JSON Schema：\n\n```python\nmcp = FastApiMCP(\n    app,\n    name=\"Full Schema MCP\",\n    describe_full_response_schema=True,\n)\n```\n\n## 依赖管理\n\n### 运行时依赖\n\n添加运行时所需的依赖包：\n\n```bash\nuv add new-package\n```\n\n### 开发依赖\n\n添加开发、测试或 CI 所需的依赖包：\n\n```bash\nuv add --group dev new-package\n```\n\n添加依赖后需要同时提交 `pyproject.toml` 和 `uv.lock` 文件。资料来源：[CONTRIBUTING.md:85-96]()\n\n## 配置最佳实践\n\n### 生产环境配置\n\n1. **显式设置超时**：根据业务需求配置合理的 HTTP 超时时间\n2. **配置认证**：生产环境应启用认证机制\n3. **过滤敏感端点**：使用 `exclude_operations` 排除管理类接口\n4. **配置标头转发**：仅转发必要的认证标头\n\n### 开发环境配置\n\n1. **启用完整 Schema**：开发时可设置 `describe_all_responses=True` 以获得更详细的文档\n2. **包含全部工具**：开发阶段不过滤任何端点\n3. **调整超时时间**：开发环境可设置更长的超时便于调试\n\n### 常用配置组合\n\n```python\n# 最小配置（仅必需参数）\nmcp = FastApiMCP(app, name=\"My API\")\n\n# 完整配置\nmcp = FastApiMCP(\n    app,\n    name=\"My API\",\n    description=\"Production MCP Server\",\n    describe_all_responses=True,\n    describe_full_response_schema=True,\n    include_tags=[\"api\"],\n    exclude_operations=[\"internal_debug\"],\n    auth_config=AuthConfig(dependencies=[Depends(token_auth_scheme)]),\n    headers=[\"authorization\", \"x-api-key\"],\n)\nmcp.mount_http()\n\n---\n\n<a id='page-examples'></a>\n\n## 示例集\n\n### 相关页面\n\n相关主题：[快速开始](#page-quickstart), [部署选项](#page-deployment), [认证与授权](#page-authentication)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [examples/01_basic_usage_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/01_basic_usage_example.py)\n- [examples/02_full_schema_description_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/02_full_schema_description_example.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [examples/04_separate_server_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/04_separate_server_example.py)\n- [examples/05_reregister_tools_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/05_reregister_tools_example.py)\n- [examples/06_custom_mcp_router_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/06_custom_mcp_router_example.py)\n- [examples/07_configure_http_timeout_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/07_configure_http_timeout_example.py)\n- [examples/09_auth_example_auth0.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/09_auth_example_auth0.py)\n- [examples/README.md](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/README.md)\n</details>\n\n# 示例集\n\nfastapi_mcp 项目提供了一套完整的示例代码，帮助开发者快速上手并深入理解该库的各项功能。示例集涵盖了从基础使用到高级配置的各种场景，是学习和实践 fastapi_mcp 的重要资源。\n\n## 示例概览\n\n示例目录位于仓库根目录的 `examples/` 文件夹下，每个示例都针对一个特定的功能点进行演示。所有示例都依赖共享的 FastAPI 应用组件，这些组件位于 `examples/shared/apps/items.py` 中定义了一个包含增删改查操作的 Items API。\n\n## 示例文件清单\n\n| 文件名 | 功能描述 | 难度等级 |\n|--------|----------|----------|\n| 01_basic_usage_example.py | 基础使用：如何将 MCP 服务器添加到 FastAPI 应用 | ⭐ 入门 |\n| 02_full_schema_description_example.py | 完整的 OpenAPI Schema 描述配置 | ⭐ 入门 |\n| 03_custom_exposed_endpoints_example.py | 自定义暴露的端点：通过 operation ID 和 tag 过滤 | ⭐⭐ 进阶 |\n| 04_separate_server_example.py | 独立 MCP 服务器运行方式 | ⭐⭐ 进阶 |\n| 05_reregister_tools_example.py | 重新注册 MCP 工具 | ⭐⭐ 进阶 |\n| 06_custom_mcp_router_example.py | 自定义 MCP 路由器配置 | ⭐⭐ 进阶 |\n| 07_configure_http_timeout_example.py | 配置 HTTP 请求超时时间 | ⭐⭐ 进阶 |\n| 08_auth_example_token_passthrough.py | 令牌透传认证示例 | ⭐⭐⭐ 高级 |\n| 09_auth_example_auth0.py | Auth0 认证集成示例 | ⭐⭐⭐ 高级 |\n\n## 核心概念\n\n### MCP 工具生成流程\n\nfastapi_mcp 的核心功能是将 FastAPI 应用中的 API 端点自动转换为 MCP（Model Context Protocol）工具。转换过程中会保留原有的请求模型、响应模型和文档描述。\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[FastApiMCP 初始化]\n    B --> C[解析 OpenAPI Schema]\n    C --> D[提取端点信息]\n    D --> E[转换端点为 MCP 工具]\n    E --> F[MCP 服务器]\n```\n\n### 基础使用示例\n\n最简化的使用方式只需三行代码即可将 MCP 功能集成到现有的 FastAPI 应用中：\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\n# 添加 MCP 服务器到 FastAPI app\nmcp = FastApiMCP(app)\n\n# 将 MCP 服务器挂载到 HTTP 传输层\nmcp.mount_http()\n```\n\n资料来源：[examples/01_basic_usage_example.py:1-13]()\n\n这种零配置的设计理念使得开发者无需修改现有业务代码，即可快速获得 MCP 能力。\n\n## 端点过滤配置\n\n在实际应用中，可能只需要暴露部分 API 端点作为 MCP 工具。fastapi_mcp 提供了多种过滤机制来控制暴露的端点。\n\n### 按 Operation ID 过滤\n\n通过 `include_operations` 和 `exclude_operations` 参数可以指定包含或排除特定的操作 ID：\n\n```python\n# 仅包含指定的操作 ID\ninclude_mcp = FastApiMCP(\n    app,\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 排除指定的操作 ID\nexclude_mcp = FastApiMCP(\n    app,\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n### 按 Tag 过滤\n\n通过 `include_tags` 和 `exclude_tags` 参数可以按 OpenAPI 中的 tag 进行过滤：\n\n```python\n# 仅包含 items tag 下的端点\ninclude_tags_mcp = FastApiMCP(\n    app,\n    include_tags=[\"items\"],\n)\n\n# 排除 search tag 下的端点\nexclude_tags_mcp = FastApiMCP(\n    app,\n    exclude_tags=[\"search\"],\n)\n```\n\n### 过滤规则说明\n\n| 规则 | 说明 |\n|------|------|\n| include_operations 与 exclude_operations | 互斥，不能同时使用 |\n| include_tags 与 exclude_tags | 互斥，不能同时使用 |\n| 混合使用 | 可以组合使用 operation 过滤和 tag 过滤，满足任一条件的端点都会被包含 |\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1-55]()\n\n## 认证配置\n\nfastapi_mcp 支持基于 OAuth 2.0 的认证功能，可以利用现有的 FastAPI 依赖注入机制来保护 MCP 端点。\n\n### 令牌透传认证\n\n最简单的认证方式是通过 Authorization 头部透传令牌：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\n@app.get(\"/private\")\nasync def private(token=Depends(token_auth_scheme)):\n    return token.credentials\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:1-47]()\n\n### MCP 客户端配置\n\n使用令牌透传时，需要在 MCP 客户端配置文件中设置头部：\n\n```json\n{\n  \"mcpServers\": {\n    \"remote-example\": {\n      \"command\": \"npx\",\n      \"args\": [\n        \"mcp-remote\",\n        \"http://localhost:8000/mcp\",\n        \"--header\",\n        \"Authorization:${AUTH_HEADER}\"\n      ]\n    },\n    \"env\": {\n      \"AUTH_HEADER\": \"Bearer <your-token>\"\n    }\n  }\n}\n```\n\n### Auth0 集成\n\n对于需要集成第三方 OAuth 提供者的场景，fastapi_mcp 提供了完整的 Auth0 集成示例：\n\n```python\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(\n        issuer=\"https://your-tenant.auth0.com\",\n        # 其他 OAuth 配置...\n    ),\n)\n```\n\n资料来源：[examples/09_auth_example_auth0.py]()\n\n## 高级配置\n\n### 独立 MCP 服务器\n\n除了挂载到 FastAPI 应用外，fastapi_mcp 也支持作为独立服务器运行，适用于需要单独部署 MCP 服务的场景。\n\n### HTTP 超时配置\n\n通过自定义 httpx.AsyncClient 实例，可以配置 HTTP 请求的超时时间：\n\n```python\nimport httpx\nfrom fastapi_mcp import FastApiMCP\n\ncustom_client = httpx.AsyncClient(timeout=30.0)\n\nmcp = FastApiMCP(\n    app,\n    http_client=custom_client,\n)\n```\n\n资料来源：[examples/07_configure_http_timeout_example.py]()\n\n### 工具重新注册\n\n对于需要动态更新 MCP 工具的场景，示例 05 演示了如何重新注册工具的方法。\n\n### 自定义 MCP 路由器\n\n示例 06 展示了如何使用自定义的 MCP 路由器来扩展功能。\n\n## 共享应用组件\n\n所有示例都依赖位于 `examples/shared/apps/items.py` 的共享 FastAPI 应用，这是一个包含 CRUD 操作的 Items RESTful API：\n\n| 端点 | 方法 | 功能 |\n|------|------|------|\n| /items | GET | 获取所有 Items |\n| /items/{item_id} | GET | 获取单个 Item |\n| /items | POST | 创建 Item |\n| /items/{item_id} | PUT | 更新 Item |\n| /items/{item_id} | DELETE | 删除 Item |\n| /items/search | GET | 搜索 Items |\n\n该应用使用 Pydantic 模型定义请求和响应结构，确保数据验证的完整性。\n\n## 运行示例\n\n### 环境准备\n\n示例代码需要以下环境条件：\n\n- Python 3.10+（推荐 3.12）\n- uv 包管理器\n\n### 启动命令\n\n每个示例都可以直接运行：\n\n```bash\ncd examples\nuv run python 01_basic_usage_example.py\n```\n\n服务器启动后，可以通过访问 `http://localhost:8000/docs` 查看 Swagger UI，或访问 `http://localhost:8000/mcp` 查看 MCP 端点。\n\n## 架构总览\n\n```mermaid\ngraph LR\n    subgraph \"FastAPI Application\"\n        A[REST Endpoints] --> B[Pydantic Models]\n        A --> C[Dependencies]\n    end\n    \n    subgraph \"FastApiMCP\"\n        D[OpenAPI Schema Parser] --> E[Tool Generator]\n        E --> F[MCP Server]\n    end\n    \n    G[MCP Clients] --> F\n    F --> H[HTTP Transport]\n    H --> A\n```\n\nfastapi_mcp 充当了 FastAPI 应用与 MCP 协议之间的桥梁，将原生 FastAPI 特性完整地保留到 MCP 工具定义中。\n\n## 总结\n\n示例集提供了从入门到高级的完整学习路径。开发者应当：\n\n1. 从 `01_basic_usage_example.py` 开始了解基础集成方式\n2. 参考 `03_custom_exposed_endpoints_example.py` 学习端点过滤\n3. 查看 `08_auth_example_token_passthrough.py` 和 `09_auth_example_auth0.py` 了解认证功能\n4. 根据具体需求查阅其他高级示例\n\n所有示例都遵循\"最小配置\"原则，开箱即用，同时提供充分的定制化能力满足生产环境需求。\n\n---\n\n---\n\n## Doramagic 踩坑日志\n\n项目：tadata-org/fastapi_mcp\n\n摘要：发现 22 个潜在踩坑项，其中 1 个为 high/blocking；最高优先级：配置坑 - 来源证据：[BUG] MCP session 404 in multi worker production environment。\n\n## 1. 配置坑 · 来源证据：[BUG] MCP session 404 in multi worker production environment\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：[BUG] MCP session 404 in multi worker production environment\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_f318cbe8fc55407da8cb88f5418cce0d | https://github.com/tadata-org/fastapi_mcp/issues/189 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 2. 安装坑 · 来源证据：v0.1.8\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.1.8\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_11a827f3808141e4bd7b0541a8628af0 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.1.8 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 3. 安装坑 · 来源证据：v0.2.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.2.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_a145fff6c53f4e709ef1bb7bc291216c | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.2.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 4. 安装坑 · 来源证据：v0.3.4\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.3.4\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_6dcb58f1897f46a188514e2714e5896d | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.4 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 5. 配置坑 · 可能修改宿主 AI 配置\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。\n- 对用户的影响：安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。\n- 建议检查：列出会写入的配置文件、目录和卸载/回滚步骤。\n- 防护动作：涉及宿主配置目录时必须给回滚路径，不能只给安装命令。\n- 证据：capability.host_targets | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | host_targets=mcp_host, claude, cursor\n\n## 6. 配置坑 · 来源证据：Suggestion: MCPWatch observability example for fastapi_mcp users\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：Suggestion: MCPWatch observability example for fastapi_mcp users\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_dfa72f41f3094dd5b2ffe188889f2b4f | https://github.com/tadata-org/fastapi_mcp/issues/303 | 来源类型 github_issue 暴露的待验证使用条件。\n\n## 7. 配置坑 · 来源证据：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_74e4280da33d49e1a3a8d576c7bb78a6 | https://github.com/tadata-org/fastapi_mcp/issues/304 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 8. 配置坑 · 来源证据：v0.3.6\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v0.3.6\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_bdc90006d16a437798ff2766d514f3d4 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.6 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 9. 能力坑 · 能力判断依赖假设\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：README/documentation is current enough for a first validation pass.\n- 对用户的影响：假设不成立时，用户拿不到承诺的能力。\n- 建议检查：将假设转成下游验证清单。\n- 防护动作：假设必须转成验证项；没有验证结果前不能写成事实。\n- 证据：capability.assumptions | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | README/documentation is current enough for a first validation pass.\n\n## 10. 维护坑 · 来源证据：[BUG] Description incorrectly passed as version to MCP Server\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：[BUG] Description incorrectly passed as version to MCP Server\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_2e599a8b03d649d8a47efb6b4d49f5ca | https://github.com/tadata-org/fastapi_mcp/issues/293 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 11. 维护坑 · 来源证据：v0.3.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.3.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_bc6b7bd2988b48d48920e4ffb259f147 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 12. 维护坑 · 来源证据：v0.3.3 - Fix OpenAPI Conversion Regression\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.3.3 - Fix OpenAPI Conversion Regression\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_79b96b9d35b9444c938c355c081410ac | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.3 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 13. 维护坑 · 来源证据：v0.4.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.4.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_4382c9c951e14187b76777ad8561ded9 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.4.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 14. 维护坑 · 维护活跃度未知\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：未记录 last_activity_observed。\n- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- 建议检查：补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 防护动作：维护活跃度未知时，推荐强度不能标为高信任。\n- 证据：evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | last_activity_observed missing\n\n## 15. 安全/权限坑 · 下游验证发现风险项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：下游已经要求复核，不能在页面中弱化。\n- 建议检查：进入安全/权限治理复核队列。\n- 防护动作：下游风险存在时必须保持 review/recommendation 降级。\n- 证据：downstream_validation.risk_items | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | no_demo; severity=medium\n\n## 16. 安全/权限坑 · 存在安全注意事项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：No sandbox install has been executed yet; downstream must verify before user use.\n- 对用户的影响：用户安装前需要知道权限边界和敏感操作。\n- 建议检查：转成明确权限清单和安全审查提示。\n- 防护动作：安全注意事项必须面向用户前置展示。\n- 证据：risks.safety_notes | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | No sandbox install has been executed yet; downstream must verify before user use.\n\n## 17. 安全/权限坑 · 存在评分风险\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：风险会影响是否适合普通用户安装。\n- 建议检查：把风险写入边界卡，并确认是否需要人工复核。\n- 防护动作：评分风险必须进入边界卡，不能只作为内部分数。\n- 证据：risks.scoring_risks | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | no_demo; severity=medium\n\n## 18. 安全/权限坑 · 来源证据：v0.3.1 - Authorization\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v0.3.1 - Authorization\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_41bf79ee5bd04da1b943d22449a0d649 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.1 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 19. 安全/权限坑 · 来源证据：v0.3.2\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v0.3.2\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_aa60828a6a6c4cc2b0b28fb72bf2ddad | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.2 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 20. 安全/权限坑 · 来源证据：v0.3.7\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v0.3.7\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_31faa7de6a364174958daaffa9d9204b | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.7 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 21. 维护坑 · issue/PR 响应质量未知\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：issue_or_pr_quality=unknown。\n- 对用户的影响：用户无法判断遇到问题后是否有人维护。\n- 建议检查：抽样最近 issue/PR，判断是否长期无人处理。\n- 防护动作：issue/PR 响应未知时，必须提示维护风险。\n- 证据：evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | issue_or_pr_quality=unknown\n\n## 22. 维护坑 · 发布节奏不明确\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：release_recency=unknown。\n- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。\n- 建议检查：确认最近 release/tag 和 README 安装命令是否一致。\n- 防护动作：发布节奏未知或过期时，安装说明必须标注可能漂移。\n- 证据：evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | release_recency=unknown\n\n<!-- canonical_name: tadata-org/fastapi_mcp; human_manual_source: deepwiki_human_wiki -->\n",
      "markdown_key": "fastapi-mcp",
      "pages": "draft",
      "source_refs": [
        {
          "evidence_id": "github_repo:944976593",
          "kind": "repo",
          "supports_claim_ids": [
            "claim_identity",
            "claim_distribution",
            "claim_capability"
          ],
          "url": "https://github.com/tadata-org/fastapi_mcp"
        },
        {
          "evidence_id": "art_99cbc803f3a64429a212f6cc476a29a1",
          "kind": "docs",
          "supports_claim_ids": [
            "claim_identity",
            "claim_distribution",
            "claim_capability"
          ],
          "url": "https://github.com/tadata-org/fastapi_mcp#readme"
        }
      ],
      "summary": "DeepWiki/Human Wiki 完整输出，末尾追加 Discovery Agent 踩坑日志。",
      "title": "fastapi_mcp 说明书",
      "toc": [
        "https://github.com/tadata-org/fastapi_mcp 项目说明书",
        "目录",
        "项目概览",
        "简介",
        "核心特性",
        "技术架构",
        "核心 API",
        "快速开始",
        "Doramagic 踩坑日志"
      ]
    }
  },
  "quality_gate": {
    "blocking_gaps": [],
    "category_confidence": "medium",
    "compile_status": "ready_for_review",
    "five_assets_present": true,
    "install_sandbox_verified": true,
    "missing_evidence": [],
    "next_action": "publish to Doramagic.ai project surfaces",
    "prompt_preview_boundary_ok": true,
    "publish_status": "publishable",
    "quick_start_verified": true,
    "repo_clone_verified": true,
    "repo_commit": "e5cad13cabfc725bbcb047e526816d887d96da62",
    "repo_inspection_error": null,
    "repo_inspection_files": [
      "pyproject.toml",
      "README.md",
      "uv.lock",
      "docs/docs.json",
      "docs/configurations/customization.mdx",
      "docs/configurations/tool-naming.mdx",
      "docs/getting-started/best-practices.mdx",
      "docs/getting-started/welcome.mdx",
      "docs/getting-started/installation.mdx",
      "docs/getting-started/quickstart.mdx",
      "docs/getting-started/FAQ.mdx",
      "docs/advanced/deploy.mdx",
      "docs/advanced/auth.mdx",
      "docs/advanced/transport.mdx",
      "docs/advanced/refresh.mdx",
      "docs/advanced/asgi.mdx",
      "examples/03_custom_exposed_endpoints_example.py",
      "examples/09_auth_example_auth0.py",
      "examples/05_reregister_tools_example.py",
      "examples/01_basic_usage_example.py",
      "examples/README.md",
      "examples/07_configure_http_timeout_example.py",
      "examples/__init__.py",
      "examples/04_separate_server_example.py",
      "examples/08_auth_example_token_passthrough.py",
      "examples/06_custom_mcp_router_example.py",
      "examples/02_full_schema_description_example.py",
      "examples/shared/setup.py",
      "examples/shared/auth.py",
      "examples/shared/__init__.py",
      "examples/shared/apps/items.py",
      "examples/shared/apps/__init__.py"
    ],
    "repo_inspection_verified": true,
    "review_reasons": [],
    "tag_count_ok": true,
    "unsupported_claims": []
  },
  "schema_version": "0.1",
  "user_assets": {
    "ai_context_pack": {
      "asset_id": "ai_context_pack",
      "filename": "AI_CONTEXT_PACK.md",
      "markdown": "# fastapi-mcp - Doramagic AI Context Pack\n\n> 定位：安装前体验与判断资产。它帮助宿主 AI 有一个好的开始，但不代表已经安装、执行或验证目标项目。\n\n## 充分原则\n\n- **充分原则，不是压缩原则**：AI Context Pack 应该充分到让宿主 AI 在开工前理解项目价值、能力边界、使用入口、风险和证据来源；它可以分层组织，但不以最短摘要为目标。\n- **压缩策略**：只压缩噪声和重复内容，不压缩会影响判断和开工质量的上下文。\n\n## 给宿主 AI 的使用方式\n\n你正在读取 Doramagic 为 fastapi-mcp 编译的 AI Context Pack。请把它当作开工前上下文：帮助用户理解适合谁、能做什么、如何开始、哪些必须安装后验证、风险在哪里。不要声称你已经安装、运行或执行了目标项目。\n\n## Claim 消费规则\n\n- **事实来源**：Repo Evidence + Claim/Evidence Graph；Human Wiki 只提供显著性、术语和叙事结构。\n- **事实最低状态**：`supported`\n- `supported`：可以作为项目事实使用，但回答中必须引用 claim_id 和证据路径。\n- `weak`：只能作为低置信度线索，必须要求用户继续核实。\n- `inferred`：只能用于风险提示或待确认问题，不能包装成项目事实。\n- `unverified`：不得作为事实使用，应明确说证据不足。\n- `contradicted`：必须展示冲突来源，不得替用户强行选择一个版本。\n\n## 它最适合谁\n\n- **想在安装前理解开源项目价值和边界的用户**：当前证据主要来自项目文档。 证据：`README.md` Claim：`clm_0002` supported 0.86\n\n## 它能做什么\n\n- **命令行启动或安装流程**（需要安装后验证）：项目文档中存在可执行命令，真实使用需要在本地或宿主环境中运行这些命令。 证据：`README.md` Claim：`clm_0001` supported 0.86\n\n## 怎么开始\n\n- `pip install fastapi-mcp` 证据：`README.md` Claim：`clm_0003` supported 0.86\n\n## 继续前判断卡\n\n- **当前建议**：先做权限沙盒试用\n- **为什么**：项目存在安装命令、宿主配置或本地写入线索，不建议直接进入主力环境，应先在隔离环境试装。\n\n### 30 秒判断\n\n- **现在怎么做**：先做权限沙盒试用\n- **最小安全下一步**：先跑 Prompt Preview；若仍要安装，只在隔离环境试装\n- **先别相信**：工具权限边界不能在安装前相信。\n- **继续会触碰**：命令执行、本地环境或项目文件、宿主 AI 上下文\n\n### 现在可以相信\n\n- **适合人群线索：想在安装前理解开源项目价值和边界的用户**（supported）：有 supported claim 或项目证据支撑，但仍不等于真实安装效果。 证据：`README.md` Claim：`clm_0002` supported 0.86\n- **能力存在：命令行启动或安装流程**（supported）：可以相信项目包含这类能力线索；是否适合你的具体任务仍要试用或安装后验证。 证据：`README.md` Claim：`clm_0001` supported 0.86\n- **存在 Quick Start / 安装命令线索**（supported）：可以相信项目文档出现过启动或安装入口；不要因此直接在主力环境运行。 证据：`README.md` Claim：`clm_0003` supported 0.86\n\n### 现在还不能相信\n\n- **工具权限边界不能在安装前相信。**（unverified）：MCP/tool 类项目通常会触碰文件、网络、浏览器或外部 API，必须真实检查权限和日志。\n- **真实输出质量不能在安装前相信。**（unverified）：Prompt Preview 只能展示引导方式，不能证明真实项目中的结果质量。\n- **宿主 AI 版本兼容性不能在安装前相信。**（unverified）：Claude、Cursor、Codex、Gemini 等宿主加载规则和版本差异必须在真实环境验证。\n- **不会污染现有宿主 AI 行为，不能直接相信。**（inferred）：Skill、plugin、AGENTS/CLAUDE/GEMINI 指令可能改变宿主 AI 的默认行为。\n- **可安全回滚不能默认相信。**（unverified）：除非项目明确提供卸载和恢复说明，否则必须先在隔离环境验证。\n- **真实安装后是否与用户当前宿主 AI 版本兼容？**（unverified）：兼容性只能通过实际宿主环境验证。\n- **项目输出质量是否满足用户具体任务？**（unverified）：安装前预览只能展示流程和边界，不能替代真实评测。\n- **安装命令是否需要网络、权限或全局写入？**（unverified）：这影响企业环境和个人环境的安装风险。 证据：`README.md`\n\n### 继续会触碰什么\n\n- **命令执行**：包管理器、网络下载、本地插件目录、项目配置或用户主目录。 原因：运行第一条命令就可能产生环境改动；必须先判断是否值得跑。 证据：`README.md`\n- **本地环境或项目文件**：安装结果、插件缓存、项目配置或本地依赖目录。 原因：安装前无法证明写入范围和回滚方式，需要隔离验证。 证据：`README.md`\n- **宿主 AI 上下文**：AI Context Pack、Prompt Preview、Skill 路由、风险规则和项目事实。 原因：导入上下文会影响宿主 AI 后续判断，必须避免把未验证项包装成事实。\n\n### 最小安全下一步\n\n- **先跑 Prompt Preview**：用安装前交互式试用判断工作方式是否匹配，不需要授权或改环境。（适用：任何项目都适用，尤其是输出质量未知时。）\n- **只在隔离目录或测试账号试装**：避免安装命令污染主力宿主 AI、真实项目或用户主目录。（适用：存在命令执行、插件配置或本地写入线索时。）\n- **安装后只验证一个最小任务**：先验证加载、兼容、输出质量和回滚，再决定是否深用。（适用：准备从试用进入真实工作流时。）\n\n### 退出方式\n\n- **保留安装前状态**：记录原始宿主配置和项目状态，后续才能判断是否可恢复。\n- **记录安装命令和写入路径**：没有明确卸载说明时，至少要知道哪些目录或配置需要手动清理。\n- **如果没有回滚路径，不进入主力环境**：不可回滚是继续前阻断项，不应靠信任或运气继续。\n\n## 哪些只能预览\n\n- 解释项目适合谁和能做什么\n- 基于项目文档演示典型对话流程\n- 帮助用户判断是否值得安装或继续研究\n\n## 哪些必须安装后验证\n\n- 真实安装 Skill、插件或 CLI\n- 执行脚本、修改本地文件或访问外部服务\n- 验证真实输出质量、性能和兼容性\n\n## 边界与风险判断卡\n\n- **把安装前预览误认为真实运行**：用户可能高估项目已经完成的配置、权限和兼容性验证。 处理方式：明确区分 prompt_preview_can_do 与 runtime_required。 Claim：`clm_0004` inferred 0.45\n- **命令执行会修改本地环境**：安装命令可能写入用户主目录、宿主插件目录或项目配置。 处理方式：先在隔离环境或测试账号中运行。 证据：`README.md` Claim：`clm_0005` supported 0.86\n- **待确认**：真实安装后是否与用户当前宿主 AI 版本兼容？。原因：兼容性只能通过实际宿主环境验证。\n- **待确认**：项目输出质量是否满足用户具体任务？。原因：安装前预览只能展示流程和边界，不能替代真实评测。\n- **待确认**：安装命令是否需要网络、权限或全局写入？。原因：这影响企业环境和个人环境的安装风险。\n\n## 开工前工作上下文\n\n### 加载顺序\n\n- 先读取 how_to_use.host_ai_instruction，建立安装前判断资产的边界。\n- 读取 claim_graph_summary，确认事实来自 Claim/Evidence Graph，而不是 Human Wiki 叙事。\n- 再读取 intended_users、capabilities 和 quick_start_candidates，判断用户是否匹配。\n- 需要执行具体任务时，优先查 role_skill_index，再查 evidence_index。\n- 遇到真实安装、文件修改、网络访问、性能或兼容性问题时，转入 risk_card 和 boundaries.runtime_required。\n\n### 任务路由\n\n- **命令行启动或安装流程**：先说明这是安装后验证能力，再给出安装前检查清单。 边界：必须真实安装或运行后验证。 证据：`README.md` Claim：`clm_0001` supported 0.86\n\n### 上下文规模\n\n- 文件总数：80\n- 重要文件覆盖：37/80\n- 证据索引条目：35\n- 角色 / Skill 条目：9\n\n### 证据不足时的处理\n\n- **missing_evidence**：说明证据不足，要求用户提供目标文件、README 段落或安装后验证记录；不要补全事实。\n- **out_of_scope_request**：说明该任务超出当前 AI Context Pack 证据范围，并建议用户先查看 Human Manual 或真实安装后验证。\n- **runtime_request**：给出安装前检查清单和命令来源，但不要替用户执行命令或声称已执行。\n- **source_conflict**：同时展示冲突来源，标记为待核实，不要强行选择一个版本。\n\n## Prompt Recipes\n\n### 适配判断\n\n- 目标：判断这个项目是否适合用户当前任务。\n- 预期输出：适配结论、关键理由、证据引用、安装前可预览内容、必须安装后验证内容、下一步建议。\n\n```text\n请基于 fastapi-mcp 的 AI Context Pack，先问我 3 个必要问题，然后判断它是否适合我的任务。回答必须包含：适合谁、能做什么、不能做什么、是否值得安装、证据来自哪里。所有项目事实必须引用 evidence_refs、source_paths 或 claim_id。\n```\n\n### 安装前体验\n\n- 目标：让用户在安装前感受核心工作流，同时避免把预览包装成真实能力或营销承诺。\n- 预期输出：一段带边界标签的体验剧本、安装后验证清单和谨慎建议；不含真实运行承诺或强营销表述。\n\n```text\n请把 fastapi-mcp 当作安装前体验资产，而不是已安装工具或真实运行环境。\n\n请严格输出四段：\n1. 先问我 3 个必要问题。\n2. 给出一段“体验剧本”：用 [安装前可预览]、[必须安装后验证]、[证据不足] 三种标签展示它可能如何引导工作流。\n3. 给出安装后验证清单：列出哪些能力只有真实安装、真实宿主加载、真实项目运行后才能确认。\n4. 给出谨慎建议：只能说“值得继续研究/试装”“先补充信息后再判断”或“不建议继续”，不得替项目背书。\n\n硬性边界：\n- 不要声称已经安装、运行、执行测试、修改文件或产生真实结果。\n- 不要写“自动适配”“确保通过”“完美适配”“强烈建议安装”等承诺性表达。\n- 如果描述安装后的工作方式，必须使用“如果安装成功且宿主正确加载 Skill，它可能会……”这种条件句。\n- 体验剧本只能写成“示例台词/假设流程”：使用“可能会询问/可能会建议/可能会展示”，不要写“已写入、已生成、已通过、正在运行、正在生成”。\n- Prompt Preview 不负责给安装命令；如用户准备试装，只能提示先阅读 Quick Start 和 Risk Card，并在隔离环境验证。\n- 所有项目事实必须来自 supported claim、evidence_refs 或 source_paths；inferred/unverified 只能作风险或待确认项。\n\n```\n\n### 角色 / Skill 选择\n\n- 目标：从项目里的角色或 Skill 中挑选最匹配的资产。\n- 预期输出：候选角色或 Skill 列表，每项包含适用场景、证据路径、风险边界和是否需要安装后验证。\n\n```text\n请读取 role_skill_index，根据我的目标任务推荐 3-5 个最相关的角色或 Skill。每个推荐都要说明适用场景、可能输出、风险边界和 evidence_refs。\n```\n\n### 风险预检\n\n- 目标：安装或引入前识别环境、权限、规则冲突和质量风险。\n- 预期输出：环境、权限、依赖、许可、宿主冲突、质量风险和未知项的检查清单。\n\n```text\n请基于 risk_card、boundaries 和 quick_start_candidates，给我一份安装前风险预检清单。不要替我执行命令，只说明我应该检查什么、为什么检查、失败会有什么影响。\n```\n\n### 宿主 AI 开工指令\n\n- 目标：把项目上下文转成一次对话开始前的宿主 AI 指令。\n- 预期输出：一段边界明确、证据引用明确、适合复制给宿主 AI 的开工前指令。\n\n```text\n请基于 fastapi-mcp 的 AI Context Pack，生成一段我可以粘贴给宿主 AI 的开工前指令。这段指令必须遵守 not_runtime=true，不能声称项目已经安装、运行或产生真实结果。\n```\n\n\n## 角色 / Skill 索引\n\n- 共索引 9 个角色 / Skill / 项目文档条目。\n\n- **Features**（project_doc）：Expose your FastAPI endpoints as Model Context Protocol MCP tools, with Auth! 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`README.md`\n- **FastAPI-MCP Examples**（project_doc）：The following examples demonstrate various features and usage patterns of FastAPI-MCP: 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`examples/README.md`\n- **Contributing to FastAPI-MCP**（project_doc）：First off, thank you for considering contributing to FastAPI-MCP! 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CONTRIBUTING.md`\n- **Describe your changes**（project_doc）：Issue ticket number and link if applicable 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`.github/pull_request_template.md`\n- **Changelog**（project_doc）：All notable changes to this project will be documented in this file. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`CHANGELOG.md`\n- **特点**（project_doc）：FastAPI-MCP 一个零配置工具，用于自动将 FastAPI 端点公开为模型上下文协议（MCP）工具。 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`README_zh-CN.md`\n- **Bug report**（project_doc）：Describe the bug A clear and concise description of what the bug is. 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`.github/ISSUE_TEMPLATE/bug_report.md`\n- **Documentation**（project_doc）： 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`.github/ISSUE_TEMPLATE/documentation.md`\n- **Feature request**（project_doc）：Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when ... 激活提示：当用户需要理解项目结构、安装方式或边界时参考。 证据：`.github/ISSUE_TEMPLATE/feature_request.md`\n\n## 证据索引\n\n- 共索引 35 条证据。\n\n- **Features**（documentation）：Expose your FastAPI endpoints as Model Context Protocol MCP tools, with Auth! 证据：`README.md`\n- **FastAPI-MCP Examples**（documentation）：The following examples demonstrate various features and usage patterns of FastAPI-MCP: 证据：`examples/README.md`\n- **Contributing to FastAPI-MCP**（documentation）：First off, thank you for considering contributing to FastAPI-MCP! 证据：`CONTRIBUTING.md`\n- **License**（source_file）：Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files the \"Software\" , to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 证据：`LICENSE`\n- **Describe your changes**（documentation）：Issue ticket number and link if applicable 证据：`.github/pull_request_template.md`\n- **Changelog**（documentation）：All notable changes to this project will be documented in this file. 证据：`CHANGELOG.md`\n- **特点**（documentation）：FastAPI-MCP 一个零配置工具，用于自动将 FastAPI 端点公开为模型上下文协议（MCP）工具。 证据：`README_zh-CN.md`\n- **Bug Report**（documentation）：Describe the bug A clear and concise description of what the bug is. 证据：`.github/ISSUE_TEMPLATE/bug_report.md`\n- **Documentation**（documentation）：--- name: Documentation about: Report an issue related to the fastapi-mcp documentation/examples title: '' labels: documentation assignees: '' --- 证据：`.github/ISSUE_TEMPLATE/documentation.md`\n- **Feature Request**（documentation）：Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when ... 证据：`.github/ISSUE_TEMPLATE/feature_request.md`\n- **Docs**（structured_config）：{ \"$schema\": \"https://mintlify.com/docs.json\", \"name\": \"FastAPI MCP\", \"background\": { \"color\": { \"dark\": \" 222831\", \"light\": \" EEEEEE\" }, \"decoration\": \"windows\" }, \"colors\": { \"primary\": \" 6d45dc\", \"light\": \" 9f8ded\", \"dark\": \" 6a42d7\" }, \"description\": \"Convert your FastAPI app into a MCP server with zero configuration\", \"favicon\": \"media/favicon.png\", \"navigation\": { \"groups\": { \"group\": \"Getting Started\", \"pages\": \"getting-started/welcome\", \"getting-started/installation\", \"getting-started/quickstart\", \"getting-started/FAQ\", \"getting-started/best-practices\" }, { \"group\": \"Configurations\", \"pages\": \"configurations/tool-naming\", \"configurations/customization\" }, { \"group\": \"Advanced Usage\"… 证据：`docs/docs.json`\n- **.coveragerc**（source_file）：run omit = examples/ tests/ concurrency = multiprocessing parallel = true sigterm = true data file = .coverage source = fastapi mcp 证据：`.coveragerc`\n- **Repomix output**（source_file）：Repomix output !repomix-output.txt !repomix-output.xml 证据：`.cursorignore`\n- **Codecov**（source_file）：coverage: status: project: default: base: pr target: auto threshold: 0.5% informational: false only pulls: true 证据：`.github/codecov.yml`\n- **Dependabot**（source_file）：version: 2 updates: - package-ecosystem: \"github-actions\" directory: \"/\" schedule: interval: \"weekly\" open-pull-requests-limit: 10 labels: - \"dependencies\" - \"github-actions\" 证据：`.github/dependabot.yml`\n- **Byte-compiled / optimized / DLL files**（source_file）：Byte-compiled / optimized / DLL files pycache / .py cod $py.class 证据：`.gitignore`\n- **.Pre Commit Config**（source_file）：repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - id: trailing-whitespace exclude: \\. md mdx $ - id: check-yaml - id: check-added-large-files 证据：`.pre-commit-config.yaml`\n- **.python-version**（source_file）：3.12 证据：`.python-version`\n- **Manifest**（source_file）：include LICENSE include README.md include INSTALL.md include pyproject.toml include setup.py 证据：`MANIFEST.in`\n- **Add MCP server to the FastAPI app**（source_file）：from examples.shared.apps.items import app The FastAPI app from examples.shared.setup import setup logging 证据：`examples/01_basic_usage_example.py`\n- **Add MCP server to the FastAPI app**（source_file）：\"\"\" This example shows how to describe the full response schema instead of just a response example. \"\"\" 证据：`examples/02_full_schema_description_example.py`\n- **Examples demonstrating how to filter MCP tools by operation IDs and tags**（source_file）：\"\"\" This example shows how to customize exposing endpoints by filtering operation IDs and tags. Notes on filtering: - You cannot use both include operations and exclude operations at the same time - You cannot use both include tags and exclude tags at the same time - You can combine operation filtering with tag filtering e.g., use include operations with include tags - When combining filters, a greedy approach will be taken. Endpoints matching either criteria will be included \"\"\" 证据：`examples/03_custom_exposed_endpoints_example.py`\n- **Take the FastAPI app only as a source for MCP server generation**（source_file）：\"\"\" This example shows how to run the MCP server and the FastAPI app separately. You can create an MCP server from one FastAPI app, and mount it to a different app. \"\"\" 证据：`examples/04_separate_server_example.py`\n- **This endpoint will not be registered as a tool, since it was added after the MCP instance was created**（source_file）：\"\"\" This example shows how to re-register tools if you add endpoints after the MCP server was created. \"\"\" 证据：`examples/05_reregister_tools_example.py`\n- **Mount the MCP server to a specific router.**（source_file）：\"\"\" This example shows how to mount the MCP server to a specific APIRouter, giving a custom mount path. \"\"\" 证据：`examples/06_custom_mcp_router_example.py`\n- **07 Configure Http Timeout Example**（source_file）：\"\"\" This example shows how to configure the HTTP client timeout for the MCP server. In case you have API endpoints that take longer than 5 seconds to respond, you can increase the timeout. \"\"\" 证据：`examples/07_configure_http_timeout_example.py`\n- **Scheme for the Authorization header**（source_file）：\"\"\" This example shows how to reject any request without a valid token passed in the Authorization header. 证据：`examples/08_auth_example_token_passthrough.py`\n- **Check if this is a JWE token encrypted token**（source_file）：from fastapi import FastAPI, Depends, HTTPException, Request, status from pydantic settings import BaseSettings from typing import Any import logging 证据：`examples/09_auth_example_auth0.py`\n- **Fallback for local development**（source_file）：\"\"\" FastAPI-MCP: Automatic MCP server generator for FastAPI applications. 证据：`fastapi_mcp/__init__.py`\n- **Validate operation and tag filtering options**（source_file）：import json import httpx from typing import Dict, Optional, Any, List, Union, Literal, Sequence from typing extensions import Annotated, Doc 证据：`fastapi_mcp/server.py`\n- **Always exclude unset and None fields, since clients don't take it well when**（source_file）：import time from typing import Any, Dict, Annotated, Union, Optional, Sequence, Literal, List from typing extensions import Doc from pydantic import BaseModel, ConfigDict, HttpUrl, field validator, model validator, from pydantic.main import IncEx from fastapi import params 证据：`fastapi_mcp/types.py`\n- **Mypy**（source_file）：mypy 证据：`mypy.ini`\n- **Pyproject**（source_file）：build-system requires = \"hatchling\", \"tomli\" build-backend = \"hatchling.build\" 证据：`pyproject.toml`\n- **Pytest**（source_file）：pytest addopts = -vvv --cov=. --cov-report xml --cov-report term-missing --cov-fail-under=80 --cov-config=.coveragerc asyncio mode = auto log cli = true log cli level = DEBUG log cli format = % asctime s - % name s - % levelname s - % message s 证据：`pytest.ini`\n- **Add the parent directory to the path**（source_file）：import sys import os import pytest import coverage 证据：`tests/conftest.py`\n\n## 宿主 AI 必须遵守的规则\n\n- **把本资产当作开工前上下文，而不是运行环境。**：AI Context Pack 只包含证据化项目理解，不包含目标项目的可执行状态。 证据：`README.md`, `examples/README.md`, `CONTRIBUTING.md`\n- **回答用户时区分可预览内容与必须安装后才能验证的内容。**：安装前体验的消费者价值来自降低误装和误判，而不是伪装成真实运行。 证据：`README.md`, `examples/README.md`, `CONTRIBUTING.md`\n\n## 用户开工前应该回答的问题\n\n- 你准备在哪个宿主 AI 或本地环境中使用它？\n- 你只是想先体验工作流，还是准备真实安装？\n- 你最在意的是安装成本、输出质量、还是和现有规则的冲突？\n\n## 验收标准\n\n- 所有能力声明都能回指到 evidence_refs 中的文件路径。\n- AI_CONTEXT_PACK.md 没有把预览包装成真实运行。\n- 用户能在 3 分钟内看懂适合谁、能做什么、如何开始和风险边界。\n\n---\n\n## Doramagic Context Augmentation\n\n下面内容用于强化 Repomix/AI Context Pack 主体。Human Manual 只提供阅读骨架；踩坑日志会被转成宿主 AI 必须遵守的工作约束。\n\n## Human Manual 骨架\n\n使用规则：这里只是项目阅读路线和显著性信号，不是事实权威。具体事实仍必须回到 repo evidence / Claim Graph。\n\n宿主 AI 硬性规则：\n- 不得把页标题、章节顺序、摘要或 importance 当作项目事实证据。\n- 解释 Human Manual 骨架时，必须明确说它只是阅读路线/显著性信号。\n- 能力、安装、兼容性、运行状态和风险判断必须引用 repo evidence、source path 或 Claim Graph。\n\n- **项目概览**：importance `high`\n  - source_paths: README.md, fastapi_mcp/__init__.py, CHANGELOG.md\n- **快速开始**：importance `high`\n  - source_paths: examples/01_basic_usage_example.py, examples/shared/apps/items.py, docs/getting-started/quickstart.mdx\n- **系统架构**：importance `high`\n  - source_paths: fastapi_mcp/server.py, fastapi_mcp/types.py, docs/advanced/asgi.mdx\n- **传输层**：importance `high`\n  - source_paths: fastapi_mcp/transport/http.py, fastapi_mcp/transport/sse.py, docs/advanced/transport.mdx\n- **OpenAPI 到 MCP 转换**：importance `high`\n  - source_paths: fastapi_mcp/openapi/convert.py, fastapi_mcp/openapi/utils.py, examples/02_full_schema_description_example.py\n- **认证与授权**：importance `high`\n  - source_paths: fastapi_mcp/auth/proxy.py, examples/09_auth_example_auth0.py, examples/08_auth_example_token_passthrough.py, docs/advanced/auth.mdx\n- **端点过滤与自定义**：importance `medium`\n  - source_paths: fastapi_mcp/server.py, examples/03_custom_exposed_endpoints_example.py, docs/configurations/tool-naming.mdx\n- **部署选项**：importance `high`\n  - source_paths: examples/04_separate_server_example.py, examples/05_reregister_tools_example.py, docs/advanced/deploy.mdx, docs/advanced/refresh.mdx\n\n## Repo Inspection Evidence / 源码检查证据\n\n- repo_clone_verified: true\n- repo_inspection_verified: true\n- repo_commit: `e5cad13cabfc725bbcb047e526816d887d96da62`\n- inspected_files: `pyproject.toml`, `README.md`, `uv.lock`, `docs/docs.json`, `docs/configurations/customization.mdx`, `docs/configurations/tool-naming.mdx`, `docs/getting-started/best-practices.mdx`, `docs/getting-started/welcome.mdx`, `docs/getting-started/installation.mdx`, `docs/getting-started/quickstart.mdx`, `docs/getting-started/FAQ.mdx`, `docs/advanced/deploy.mdx`, `docs/advanced/auth.mdx`, `docs/advanced/transport.mdx`, `docs/advanced/refresh.mdx`, `docs/advanced/asgi.mdx`, `examples/03_custom_exposed_endpoints_example.py`, `examples/09_auth_example_auth0.py`, `examples/05_reregister_tools_example.py`, `examples/01_basic_usage_example.py`\n\n宿主 AI 硬性规则：\n- 没有 repo_clone_verified=true 时，不得声称已经读过源码。\n- 没有 repo_inspection_verified=true 时，不得把 README/docs/package 文件判断写成事实。\n- 没有 quick_start_verified=true 时，不得声称 Quick Start 已跑通。\n\n## Doramagic Pitfall Constraints / 踩坑约束\n\n这些规则来自 Doramagic 发现、验证或编译过程中的项目专属坑点。宿主 AI 必须把它们当作工作约束，而不是普通说明文字。\n\n### Constraint 1: 来源证据：[BUG] MCP session 404 in multi worker production environment\n\n- Trigger: GitHub 社区证据显示该项目存在一个配置相关的待验证问题：[BUG] MCP session 404 in multi worker production environment\n- Host AI rule: 来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- Why it matters: 可能影响升级、迁移或版本选择。\n- Evidence: community_evidence:github | cevd_f318cbe8fc55407da8cb88f5418cce0d | https://github.com/tadata-org/fastapi_mcp/issues/189 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 2: 来源证据：v0.1.8\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.1.8\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_11a827f3808141e4bd7b0541a8628af0 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.1.8 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 3: 来源证据：v0.2.0\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.2.0\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能影响升级、迁移或版本选择。\n- Evidence: community_evidence:github | cevd_a145fff6c53f4e709ef1bb7bc291216c | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.2.0 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 4: 来源证据：v0.3.4\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.3.4\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能影响升级、迁移或版本选择。\n- Evidence: community_evidence:github | cevd_6dcb58f1897f46a188514e2714e5896d | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.4 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 5: 可能修改宿主 AI 配置\n\n- Trigger: 项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。\n- Host AI rule: 列出会写入的配置文件、目录和卸载/回滚步骤。\n- Why it matters: 安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。\n- Evidence: capability.host_targets | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | host_targets=mcp_host, claude, cursor\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 6: 来源证据：Suggestion: MCPWatch observability example for fastapi_mcp users\n\n- Trigger: GitHub 社区证据显示该项目存在一个配置相关的待验证问题：Suggestion: MCPWatch observability example for fastapi_mcp users\n- Host AI rule: 来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_dfa72f41f3094dd5b2ffe188889f2b4f | https://github.com/tadata-org/fastapi_mcp/issues/303 | 来源类型 github_issue 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 7: 来源证据：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters\n\n- Trigger: GitHub 社区证据显示该项目存在一个配置相关的待验证问题：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters\n- Host AI rule: 来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_74e4280da33d49e1a3a8d576c7bb78a6 | https://github.com/tadata-org/fastapi_mcp/issues/304 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 8: 来源证据：v0.3.6\n\n- Trigger: GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v0.3.6\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_bdc90006d16a437798ff2766d514f3d4 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.6 | 来源类型 github_release 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 9: 能力判断依赖假设\n\n- Trigger: README/documentation is current enough for a first validation pass.\n- Host AI rule: 将假设转成下游验证清单。\n- Why it matters: 假设不成立时，用户拿不到承诺的能力。\n- Evidence: capability.assumptions | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | README/documentation is current enough for a first validation pass.\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 10: 来源证据：[BUG] Description incorrectly passed as version to MCP Server\n\n- Trigger: GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：[BUG] Description incorrectly passed as version to MCP Server\n- Host AI rule: 来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_2e599a8b03d649d8a47efb6b4d49f5ca | https://github.com/tadata-org/fastapi_mcp/issues/293 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n",
      "summary": "给宿主 AI 的上下文和工作边界。",
      "title": "AI Context Pack / 带给我的 AI"
    },
    "boundary_risk_card": {
      "asset_id": "boundary_risk_card",
      "filename": "BOUNDARY_RISK_CARD.md",
      "markdown": "# Boundary & Risk Card / 安装前决策卡\n\n项目：tadata-org/fastapi_mcp\n\n## Doramagic 试用结论\n\n当前结论：可以进入发布前推荐检查；首次使用仍应从最小权限、临时目录和可回滚配置开始。\n\n## 用户现在可以做\n\n- 可以先阅读 Human Manual，理解项目目的和主要工作流。\n- 可以复制 Prompt Preview 做安装前体验；这只验证交互感，不代表真实运行。\n- 可以把官方 Quick Start 命令放到隔离环境中验证，不要直接进主力环境。\n\n## 现在不要做\n\n- 不要把 Prompt Preview 当成项目实际运行结果。\n- 不要把 metadata-only validation 当成沙箱安装验证。\n- 不要把未验证能力写成“已支持、已跑通、可放心安装”。\n- 不要在首次试用时交出生产数据、私人文件、真实密钥或主力配置目录。\n\n## 安装前检查\n\n- 宿主 AI 是否匹配：mcp_host, claude, cursor\n- 官方安装入口状态：已发现官方入口\n- 是否在临时目录、临时宿主或容器中验证：必须是\n- 是否能回滚配置改动：必须能\n- 是否需要 API Key、网络访问、读写文件或修改宿主配置：未确认前按高风险处理\n- 是否记录了安装命令、实际输出和失败日志：必须记录\n\n## 当前阻塞项\n\n- 无阻塞项。\n\n## 项目专属踩坑\n\n- 来源证据：[BUG] MCP session 404 in multi worker production environment（high）：可能影响升级、迁移或版本选择。 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 来源证据：v0.1.8（medium）：可能增加新用户试用和生产接入成本。 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 来源证据：v0.2.0（medium）：可能影响升级、迁移或版本选择。 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 来源证据：v0.3.4（medium）：可能影响升级、迁移或版本选择。 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 可能修改宿主 AI 配置（medium）：安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。 建议检查：列出会写入的配置文件、目录和卸载/回滚步骤。\n\n## 风险与权限提示\n\n- no_demo: medium\n\n## 证据缺口\n\n- 暂未发现结构化证据缺口。\n",
      "summary": "安装、权限、验证和推荐前风险。",
      "title": "Boundary & Risk Card / 边界与风险卡"
    },
    "human_manual": {
      "asset_id": "human_manual",
      "filename": "HUMAN_MANUAL.md",
      "markdown": "# https://github.com/tadata-org/fastapi_mcp 项目说明书\n\n生成时间：2026-05-11 16:52:13 UTC\n\n## 目录\n\n- [项目概览](#page-overview)\n- [快速开始](#page-quickstart)\n- [系统架构](#page-architecture)\n- [传输层](#page-transport)\n- [OpenAPI 到 MCP 转换](#page-openapi-conversion)\n- [认证与授权](#page-authentication)\n- [端点过滤与自定义](#page-endpoint-filtering)\n- [部署选项](#page-deployment)\n- [配置与自定义](#page-configuration)\n- [示例集](#page-examples)\n\n<a id='page-overview'></a>\n\n## 项目概览\n\n### 相关页面\n\n相关主题：[系统架构](#page-architecture), [快速开始](#page-quickstart)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n- [fastapi_mcp/__init__.py](https://github.com/tadata-org/fapi_mcp/blob/main/fastapi_mcp/__init__.py)\n- [CHANGELOG.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CHANGELOG.md)\n- [CONTRIBUTING.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n</details>\n\n# 项目概览\n\n## 简介\n\n**FastAPI-MCP** 是一个将 FastAPI 应用程序自动转换为 MCP（Model Context Protocol）服务器的框架。该项目由 [Tadata Inc.](https://github.com/tadata-org) 开发，采用 MIT 开源许可证，为开发者提供了一种无缝集成 AI 助手能力到现有 FastAPI 应用的解决方案。\n\n资料来源：[README.md:1](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n\n## 核心特性\n\nFastAPI-MCP 具有以下设计目标和技术特点：\n\n| 特性 | 描述 |\n|------|------|\n| 内置认证 | 支持使用现有的 FastAPI 依赖项进行身份验证 |\n| FastAPI 原生 | 不仅仅是 OpenAPI 到 MCP 的简单转换器 |\n| 零配置/最小配置 | 只需指向 FastAPI 应用即可运行 |\n| Schema 保持 | 保留请求模型和响应模型的完整类型定义 |\n| 文档保留 | 端点文档与 Swagger 中完全一致 |\n| 灵活部署 | 支持将 MCP 服务器挂载到 FastAPI 应用 |\n\n资料来源：[README.md:24-31](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n\n## 技术架构\n\n### 整体架构\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[FastApiMCP]\n    B --> C[MCP 服务器]\n    C --> D[HTTP 端点 /mcp]\n    B --> E[工具发现]\n    E --> F[OpenAPI Schema 解析]\n    F --> G[MCP Tools]\n    B --> H[请求处理]\n    H --> I[httpx.AsyncClient]\n    I --> A\n```\n\n### 核心模块结构\n\n```\nfastapi_mcp/\n├── __init__.py      # 包入口，导出公共API\n├── server.py        # FastApiMCP 主类实现\n├── types.py         # 类型定义（AuthConfig、OAuthMetadata）\n└── openapi/\n    └── convert.py   # OpenAPI Schema 转换逻辑\n```\n\n资料来源：[fastapi_mcp/__init__.py:1-17](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/__init__.py)\n\n## 核心 API\n\n### 公开导出\n\n`fastapi_mcp/__init__.py` 导出了以下核心组件：\n\n```python\nfrom fastapi_mcp import FastApiMCP, AuthConfig, OAuthMetadata\n```\n\n| 组件 | 用途 |\n|------|------|\n| `FastApiMCP` | 主类，用于创建和管理 MCP 服务器 |\n| `AuthConfig` | 认证配置类 |\n| `OAuthMetadata` | OAuth 2.0 元数据类 |\n\n资料来源：[fastapi_mcp/__init__.py:12-16](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/__init__.py)\n\n### 类型定义\n\n`fastapi_mcp/types.py` 定义了以下关键类型：\n\n#### HTTPRequestInfo\n\n```python\nclass HTTPRequestInfo(BaseType):\n    method: str\n    path: str\n    headers: Dict[str, str]\n    cookies: Dict[str, str]\n    query_params: Dict[str, str]\n    body: Any\n```\n\n#### AuthConfig\n\n认证配置类，支持 OAuth 2.0 授权流程：\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `version` | Literal[\"2025-03-26\"] | MCP 规范版本 |\n| `dependencies` | Optional[Sequence[Depends]] | FastAPI 认证依赖项 |\n| `issuer` | Optional[str] | OAuth 2.0 发行方标识 |\n| `oauth_metadata_url` | Optional[StrHttpUrl] | OAuth 元数据端点 URL |\n| `authorize_url` | Optional[StrHttpUrl] | 授权端点 URL |\n| `token_endpoint` | Optional[StrHttpUrl] | 令牌端点 URL |\n\n资料来源：[fastapi_mcp/types.py:80-120](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n\n## 快速开始\n\n### 环境要求\n\n| 要求 | 版本 |\n|------|------|\n| Python | 3.10+（推荐 3.12） |\n| 包管理器 | uv |\n\n资料来源：[README.md:36-39](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n\n### 基础用法\n\n```python\nfrom examples.shared.apps.items import app  # FastAPI 应用\nfrom fastapi_mcp import FastApiMCP\n\n# 创建 MCP 服务器\nmcp = FastApiMCP(app)\n\n# 挂载到 FastAPI 应用\nmcp.mount_http()\n\nif __name__ == \"__main__\":\n    import uvicorn\n    uvicorn.run(app, host=\"0.0.0.0\", port=8000)\n```\n\n资料来源：[examples/01_basic_usage_example.py:1-14](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/01_basic_usage_example.py)\n\n## 高级功能\n\n### 工具过滤\n\n支持通过操作 ID 和标签过滤暴露的 MCP 工具：\n\n```python\n# 通过操作 ID 过滤（包含模式）\nmcp = FastApiMCP(\n    app,\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 通过操作 ID 过滤（排除模式）\nmcp = FastApiMCP(\n    app,\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n\n# 通过标签过滤\nmcp = FastApiMCP(\n    app,\n    include_tags=[\"items\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:18-37](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n\n### 认证配置\n\nFastAPI-MCP 支持基于 FastAPI 依赖项的认证机制：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:30-40](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n\n## 版本历史\n\n| 版本 | 日期 | 主要变更 |\n|------|------|----------|\n| 0.2.0 | - | 移除 CLI，改用运行时集成；添加 `add_mcp_server` 函数 |\n| 0.1.1 | 2024-07-03 | 修复 PEP 604 联合类型语法兼容性 |\n| 0.1.0 | 2024-03-08 | 初始版本发布 |\n\n资料来源：[CHANGELOG.md:1-30](https://github.com/tadata-org/fastapi_mcp/blob/main/CHANGELOG.md)\n\n## 开发指南\n\n### 环境搭建\n\n```bash\n# 1. 安装 uv\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n\n# 2. 克隆仓库\ngit clone https://github.com/YOUR-USERNAME/fastapi_mcp.git\ncd fastapi_mcp\n\n# 3. 同步依赖\nuv sync\n\n# 4. 安装预提交钩子\nuv run pre-commit install\n```\n\n资料来源：[CONTRIBUTING.md:12-26](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n\n### 代码质量检查\n\n| 工具 | 用途 |\n|------|------|\n| ruff | 代码检查和格式化 |\n| mypy | 类型检查 |\n| pytest | 测试框架 |\n\n```bash\n# 运行所有测试\npytest\n\n# 类型检查\nmypy .\n\n# 代码格式化检查\nruff check .\nruff format .\n```\n\n资料来源：[CONTRIBUTING.md:60-75](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n\n## 许可证\n\nMIT License。Copyright (c) 2025 Tadata Inc.\n\n资料来源：[README.md:42](https://github.com/tadata-org/fastapi_mcp/blob/main/README.md)\n\n---\n\n<a id='page-quickstart'></a>\n\n## 快速开始\n\n### 相关页面\n\n相关主题：[项目概览](#page-overview), [示例集](#page-examples)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [examples/01_basic_usage_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/01_basic_usage_example.py)\n- [examples/02_full_schema_description_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/02_full_schema_description_example.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n- [examples/shared/apps/items.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/shared/apps/items.py)\n- [CONTRIBUTING.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n</details>\n\n# 快速开始\n\n本文档面向希望快速上手 **FastAPI-MCP** 的开发者。FastAPI-MCP 是一个将 FastAPI 应用无缝转换为 MCP（Model Context Protocol）服务器的库，使 FastAPI 应用能够作为 MCP 工具被 AI 模型调用。\n\n## 环境要求\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n| 要求 | 版本 | 说明 |\n|------|------|------|\n| Python | 3.10+（推荐 3.12） | 项目依赖类型注解等特性 |\n| uv | 最新稳定版 | 高性能 Python 包管理器 |\n\n资料来源：[CONTRIBUTING.md:1]()\n\n### 安装 uv\n\n如果尚未安装 uv，请参考 [uv 官方安装指南](https://docs.astral.sh/uv/getting-started/installation/)。\n\n## 项目初始化\n\n### 克隆项目\n\n首先，从 GitHub fork 并克隆仓库：\n\n```bash\ngit clone https://github.com/YOUR-USERNAME/fastapi_mcp.git\ncd fastapi-mcp\n\n# 添加上游远程仓库\ngit remote add upstream https://github.com/tadata-org/fastapi_mcp.git\n```\n\n资料来源：[CONTRIBUTING.md:1]()\n\n### 创建虚拟环境并安装依赖\n\n使用 `uv sync` 自动创建虚拟环境并安装所有依赖：\n\n```bash\nuv sync\n```\n\n资料来源：[CONTRIBUTING.md:1]()\n\n### 安装预提交钩子\n\n项目使用 pre-commit 工具自动运行代码检查：\n\n```bash\nuv run pre-commit install\nuv run pre-commit run\n```\n\n资料来源：[CONTRIBUTING.md:1]()\n\n## 基础使用\n\n### 基本示例\n\n以下示例展示将 FastAPI 应用转换为 MCP 服务器的最简方式：\n\n```python\nfrom examples.shared.apps.items import app  # FastAPI 应用\nfrom examples.shared.setup import setup_logging\nfrom fastapi_mcp import FastApiMCP\n\nsetup_logging()\n\n# 创建 MCP 服务器\nmcp = FastApiMCP(app)\n\n# 挂载 MCP 服务器\nmcp.mount_http()\n\nif __name__ == \"__main__\":\n    import uvicorn\n    uvicorn.run(app, host=\"0.0.0.0\", port=8000)\n```\n\n资料来源：[examples/01_basic_usage_example.py:1]()\n\n### 工作流程\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[创建 FastApiMCP 实例]\n    B --> C[挂载 MCP 端点]\n    C --> D[启动 Uvicorn 服务器]\n    D --> E[访问 MCP 端点]\n```\n\n## 核心配置参数\n\n`FastApiMCP` 类支持多种配置选项：\n\n| 参数 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `name` | `str` | - | MCP 服务器名称 |\n| `description` | `str` | - | 服务器描述 |\n| `describe_full_response_schema` | `bool` | `False` | 是否在工具描述中包含完整响应 JSON Schema |\n| `describe_all_responses` | `bool` | `False` | 是否描述所有可能的响应（包括错误响应） |\n| `include_operations` | `List[str]` | `None` | 要包含的操作 ID 列表 |\n| `exclude_operations` | `List[str]` | `None` | 要排除的操作 ID 列表 |\n| `include_tags` | `List[str]` | `None` | 要包含的标签列表 |\n| `exclude_tags` | `List[str]` | `None` | 要排除的标签列表 |\n| `headers` | `List[str]` | `[\"authorization\"]` | 要转发到工具调用的 HTTP 头列表 |\n\n资料来源：[fastapi_mcp/server.py:1]()\n\n### 完整 Schema 描述\n\n如需在工具描述中包含完整的响应 Schema，使用以下配置：\n\n```python\nmcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    description=\"MCP 服务器示例\",\n    describe_full_response_schema=True,\n    describe_all_responses=True,\n)\n\nmcp.mount_http()\n```\n\n资料来源：[examples/02_full_schema_description_example.py:1]()\n\n## 操作过滤\n\n### 按操作 ID 过滤\n\n可以选择性地暴露特定操作：\n\n```python\n# 仅包含指定操作\ninclude_mcp = FastApiMCP(\n    app,\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 排除指定操作\nexclude_mcp = FastApiMCP(\n    app,\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1]()\n\n### 按标签过滤\n\n也可以按 FastAPI 的标签进行过滤：\n\n```python\n# 仅包含 items 标签的操作\nitems_mcp = FastApiMCP(\n    app,\n    include_tags=[\"items\"],\n)\n\n# 排除 search 标签的操作\nexclude_search_mcp = FastApiMCP(\n    app,\n    exclude_tags=[\"search\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1]()\n\n### 过滤规则说明\n\n| 规则 | 说明 |\n|------|------|\n| `include_operations` 和 `exclude_operations` | 互斥，不能同时使用 |\n| `include_tags` 和 `exclude_tags` | 互斥，不能同时使用 |\n| 操作过滤 + 标签过滤 | 可以组合使用，匹配任一条件的操作都会被包含 |\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1]()\n\n## 认证配置\n\n### 令牌传递认证\n\nFastAPI-MCP 支持通过 HTTP 头传递认证令牌：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\n@app.get(\"/private\")\nasync def private(token=Depends(token_auth_scheme)):\n    return token.credentials\n\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n\nmcp.mount_http()\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:1]()\n\n### AuthConfig 配置选项\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `version` | `Literal[\"2025-03-26\"]` | MCP 规范版本 |\n| `dependencies` | `Sequence[params.Depends]` | FastAPI 认证依赖 |\n\n资料来源：[fastapi_mcp/types.py:1]()\n\n## 示例 FastAPI 应用\n\n以下是一个完整的 CRUD 示例应用结构：\n\n```python\nfrom fastapi import FastAPI, HTTPException, Query\nfrom pydantic import BaseModel\nfrom typing import List, Optional\n\napp = FastAPI()\n\nclass Item(BaseModel):\n    id: int\n    name: str\n    description: Optional[str] = None\n    price: float\n    tags: List[str] = []\n\nitems_db = {}\n\n@app.post(\"/items/\", response_model=Item)\nasync def create_item(item: Item):\n    items_db[item.id] = item\n    return item\n\n@app.get(\"/items/{item_id}\", response_model=Item)\nasync def get_item(item_id: int):\n    if item_id not in items_db:\n        raise HTTPException(status_code=404, detail=\"Item not found\")\n    return items_db[item_id]\n\n@app.get(\"/items/\", response_model=List[Item])\nasync def list_items():\n    return list(items_db.values())\n\n@app.put(\"/items/{item_id}\", response_model=Item)\nasync def update_item(item_id: int, item: Item):\n    if item_id not in items_db:\n        raise HTTPException(status_code=404, detail=\"Item not found\")\n    item.id = item_id\n    items_db[item_id] = item\n    return item\n\n@app.delete(\"/items/{item_id}\")\nasync def delete_item(item_id: int):\n    if item_id not in items_db:\n        raise HTTPException(status_code=404, detail=\"Item not found\")\n    del items_db[item_id]\n    return {\"message\": \"Item deleted successfully\"}\n\n@app.get(\"/items/search/\", response_model=List[Item])\nasync def search_items(\n    q: Optional[str] = Query(None),\n    min_price: Optional[float] = Query(None),\n    max_price: Optional[float] = Query(None),\n    tags: List[str] = Query([]),\n):\n    results = list(items_db.values())\n    # 搜索逻辑...\n    return results\n```\n\n资料来源：[examples/shared/apps/items.py:1]()\n\n## 运行测试\n\n### 代码检查\n\n在提交代码前，运行以下检查确保代码质量：\n\n```bash\n# 类型检查\nmypy .\n\n# 运行测试\npytest\n\n# 代码格式化和检查\nruff check .\nruff format .\n```\n\n资料来源：[CONTRIBUTING.md:1]()\n\n### 使用预提交\n\n如果已安装 pre-commit 钩子，这些检查会在每次提交时自动运行：\n\n```bash\nuv run pre-commit run\n```\n\n## 挂载 MCP 端点\n\n### 自定义挂载路径\n\n可以为 MCP 服务器指定不同的挂载路径：\n\n```python\nmcp.mount_http(mount_path=\"/mcp\")\n```\n\n### 多端点挂载\n\n可以同时挂载多个 MCP 服务器实例：\n\n```python\nmcp1 = FastApiMCP(app, name=\"Server 1\")\nmcp2 = FastApiMCP(app, name=\"Server 2\")\n\nmcp1.mount_http(mount_path=\"/mcp1\")\nmcp2.mount_http(mount_path=\"/mcp2\")\n```\n\n## 下一步\n\n- 参考 [示例代码](../examples/) 了解更高级的用法\n- 查看 [贡献指南](../CONTRIBUTING.md) 参与项目开发\n- 访问 [项目仓库](https://github.com/tadata-org/fastapi_mcp) 获取最新资讯\n\n---\n\n<a id='page-architecture'></a>\n\n## 系统架构\n\n### 相关页面\n\n相关主题：[传输层](#page-transport), [OpenAPI 到 MCP 转换](#page-openapi-conversion)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [fastapi_mcp/__init__.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/__init__.py)\n- [fastapi_mcp/openapi/convert.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/openapi/convert.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n- [examples/shared/apps/items.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/shared/apps/items.py)\n</details>\n\n# 系统架构\n\n## 概述\n\nFastAPI-MCP 是一个将 FastAPI 应用自动转换为 MCP（Model Context Protocol）服务器的框架。其核心架构围绕 `FastApiMCP` 类展开，通过 OpenAPI schema 提取、工具过滤、HTTP 请求转发和认证集成四大核心模块实现功能。\n\n系统采用零配置设计理念，开发者只需将现有的 FastAPI 应用传入 `FastApiMCP`，即可自动生成兼容 MCP 协议的服务端点。框架支持灵活的工具过滤机制、多种认证配置方式以及自定义 HTTP 客户端注入。\n\n## 核心组件\n\n### 组件关系图\n\n```mermaid\ngraph TD\n    A[FastAPI App] --> B[FastApiMCP]\n    B --> C[OpenAPI Schema 解析]\n    C --> D[工具转换引擎]\n    D --> E[MCP 工具列表]\n    E --> F[工具过滤器]\n    F --> G[最终 MCP 工具集]\n    H[HTTP 请求转发器] --> G\n    I[认证配置] --> H\n    J[自定义 HTTP Client] --> H\n```\n\n### 主要类结构\n\n| 组件 | 文件位置 | 职责 |\n|------|----------|------|\n| `FastApiMCP` | `fastapi_mcp/server.py` | 主服务器类，核心逻辑入口 |\n| `AuthConfig` | `fastapi_mcp/types.py` | 认证配置数据模型 |\n| `OAuthMetadata` | `fastapi_mcp/types.py` | OAuth 2.0 元数据 |\n| `HTTPRequestInfo` | `fastapi_mcp/types.py` | HTTP 请求信息封装 |\n\n## 工具发现与过滤机制\n\n### 工具过滤流程\n\n```mermaid\ngraph TD\n    A[OpenAPI Schema] --> B{include_operations?}\n    B -->|有值| C[过滤至指定操作ID]\n    B -->|无值| D{exclude_operations?}\n    D -->|有值| E[排除指定操作ID]\n    D -->|无值| F{include_tags?}\n    F -->|有值| G[过滤至指定标签]\n    F -->|无值| H{exclude_tags?}\n    H -->|有值| I[排除指定标签]\n    H -->|无值| J[返回全部工具]\n    C --> J\n    E --> J\n    G --> J\n    I --> J\n```\n\n### 过滤配置参数\n\n| 参数名 | 类型 | 说明 | 互斥参数 |\n|--------|------|------|----------|\n| `include_operations` | `List[str]` | 仅包含指定的操作 ID | `exclude_operations` |\n| `exclude_operations` | `List[str]` | 排除指定的操作 ID | `include_operations` |\n| `include_tags` | `List[str]` | 仅包含指定标签的端点 | `exclude_tags` |\n| `exclude_tags` | `List[str]` | 排除指定标签的端点 | `include_tags` |\n\n资料来源：[fastapi_mcp/server.py:50-75]()\n\n### 过滤实现逻辑\n\n```python\ndef _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any]) -> List[types.Tool]:\n    if (\n        self._include_operations is None\n        and self._exclude_operations is None\n        and self._include_tags is None\n        and self._exclude_tags is None\n    ):\n        return tools\n    # 构建按标签分组操作ID的映射\n    operations_by_tag: Dict[str, List[str]] = {}\n    for path, path_item in openapi_schema.get(\"paths\", {}).items():\n        for method, operation in path_item.items():\n            operation_id = operation.get(\"operationId\")\n            tags = operation.get(\"tags\", [])\n            # 分类存储操作ID\n```\n\n资料来源：[fastapi_mcp/server.py:35-60]()\n\n## HTTP 请求转发架构\n\n### 请求转发流程\n\n```mermaid\nsequenceDiagram\n    participant MCP as MCP Client\n    participant MCP_Server as FastApiMCP Server\n    participant HTTP_Client as httpx.AsyncClient\n    participant FastAPI as FastAPI App\n\n    MCP_Server->>FastAPI: 提取 OpenAPI Schema\n    MCP->>MCP_Server: 调用 MCP Tool\n    MCP_Server->>MCP_Server: 解析工具参数\n    MCP_Server->>HTTP_Client: 构造 HTTP 请求\n    HTTP_Client->>FastAPI: 转发请求\n    FastAPI-->>HTTP_Client: 返回响应\n    HTTP_Client-->>MCP_Server: 返回结果\n    MCP_Server-->>MCP: 返回 Tool Result\n```\n\n### HTTP 方法路由\n\n| HTTP 方法 | 调用方式 | 说明 |\n|-----------|----------|------|\n| GET | `client.get(path, params=query, headers=headers)` | 查询参数传递 |\n| POST | `client.post(path, params=query, headers=headers, json=body)` | JSON 请求体 |\n| PUT | `client.put(path, params=query, headers=headers, json=body)` | JSON 请求体 |\n| DELETE | `client.delete(path, params=query, headers=headers)` | 查询参数传递 |\n| PATCH | `client.patch(path, params=query, headers=headers, json=body)` | JSON 请求体 |\n\n资料来源：[fastapi_mcp/server.py:12-26]()\n\n### 自定义 HTTP 客户端\n\n框架支持注入自定义 `httpx.AsyncClient` 实例，用于满足特殊网络配置需求：\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\ncustom_client = httpx.AsyncClient(\n    timeout=60.0,\n    proxies={\"http://\": \"http://proxy.example.com\"},\n)\n\nmcp = FastApiMCP(\n    app,\n    http_client=custom_client,\n)\n```\n\n## 认证与授权系统\n\n### 认证配置架构\n\n```mermaid\ngraph LR\n    A[OAuthMetadata] -->|issuer| B[授权服务器标识]\n    A -->|authorization_endpoint| C[授权端点]\n    A -->|token_endpoint| D[令牌端点]\n    A -->|scopes_supported| E[支持的权限范围]\n    F[AuthConfig] -->|dependencies| G[FastAPI 依赖项]\n    F -->|oauth_metadata| H[自定义 OAuth 元数据]\n```\n\n### AuthConfig 数据模型\n\n| 字段 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `version` | `Literal[\"2025-03-26\"]` | `\"2025-03-26\"` | MCP 规范版本 |\n| `dependencies` | `Sequence[Depends]` | `None` | FastAPI 认证依赖链 |\n| `issuer` | `str` | `None` | OAuth 发行方 URL |\n| `oauth_metadata_url` | `StrHttpUrl` | `None` | OAuth 元数据端点 |\n| `authorize_url` | `StrHttpUrl` | `None` | 授权端点 URL |\n| `token_endpoint` | `StrHttpUrl` | `None` | 令牌端点 URL |\n\n资料来源：[fastapi_mcp/types.py:100-150]()\n\n### 认证使用示例\n\n```python\nfrom fastapi import Depends, HTTPException\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\nasync def authenticate_request(request: Request, token: str = Depends(token_auth_scheme)):\n    payload = verify_token(request, token)\n    if payload is None:\n        raise HTTPException(status_code=401, detail=\"Unauthorized\")\n    return payload\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(dependencies=[Depends(authenticate_request)]),\n)\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:20-35]()\n\n## 头部信息转发机制\n\n### 默认转发配置\n\n框架默认自动转发 `Authorization` 头部，可通过配置扩展：\n\n```python\nmcp = FastApiMCP(\n    app,\n    headers=[\"authorization\", \"x-custom-header\", \"x-request-id\"],\n)\n```\n\n### 头部转发流程\n\n```mermaid\ngraph TD\n    A[MCP Request] --> B[提取配置的 headers]\n    B --> C{headers 参数配置}\n    C -->|[\"authorization\"]| D[转发 Authorization]\n    C -->|[\"x-custom-header\"]| E[转发自定义头部]\n    C -->|未配置| F[默认转发 authorization]\n    D --> G[合并至 HTTP 请求]\n    E --> G\n    F --> G\n```\n\n资料来源：[fastapi_mcp/server.py:80-90]()\n\n## 工具描述生成\n\n### 描述信息构建流程\n\n框架从 OpenAPI schema 自动提取端点描述信息：\n\n```mermaid\ngraph TD\n    A[OpenAPI Schema] --> B[解析路径参数]\n    A --> C[解析查询参数]\n    A --> D[解析请求体]\n    A --> E[解析响应 schema]\n    B --> F[构建 Tool 描述]\n    C --> F\n    D --> F\n    E --> F\n```\n\n### 参数分类处理\n\n```python\n# 按位置分类参数\npath_params = []      # 路径参数 (in: path)\nquery_params = []     # 查询参数 (in: query)\nheader_params = []    # 请求头参数 (in: header)\n\nfor param in operation.get(\"parameters\", []):\n    param_name = param.get(\"name\")\n    param_in = param.get(\"in\")\n    required = param.get(\"required\", False)\n    \n    if param_in == \"path\":\n        path_params.append((param_name, param))\n    elif param_in == \"query\":\n        query_params.append((param_name, param))\n    elif param_in == \"header\":\n        header_params.append((param_name, param))\n```\n\n资料来源：[fastapi_mcp/openapi/convert.py:30-50]()\n\n## 目录结构\n\n```\nfastapi_mcp/\n├── __init__.py          # 公共 API 导出\n├── server.py            # FastApiMCP 主类实现\n├── types.py             # 数据模型定义\n└── openapi/\n    └── convert.py       # OpenAPI 转换逻辑\n```\n\n| 模块 | 导出内容 |\n|------|----------|\n| `fastapi_mcp.FastApiMCP` | 主服务器类 |\n| `fastapi_mcp.AuthConfig` | 认证配置类 |\n| `fastapi_mcp.OAuthMetadata` | OAuth 元数据类 |\n\n资料来源：[fastapi_mcp/__init__.py:1-25]()\n\n## 使用模式\n\n### 基础模式\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_mcp import FastApiMCP\n\napp = FastAPI()\n\n# 添加 MCP 服务器\nmcp = FastApiMCP(app)\n\n# 挂载到 FastAPI 应用\nmcp.mount_http()\n```\n\n### 高级过滤模式\n\n```python\n# 按操作 ID 过滤\nmcp = FastApiMCP(\n    app,\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 按标签过滤\nmcp = FastApiMCP(\n    app,\n    exclude_tags=[\"internal\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:15-30]()\n\n## 总结\n\nFastAPI-MCP 的系统架构采用模块化设计，核心通过 `FastApiMCP` 类协调以下组件：\n\n- **工具发现模块**：解析 OpenAPI schema，自动转换为 MCP 工具\n- **工具过滤模块**：支持基于操作 ID 和标签的灵活过滤\n- **请求转发模块**：将 MCP 调用转换为标准 HTTP 请求\n- **认证模块**：集成 FastAPI 依赖注入系统，支持 OAuth 2.0\n\n该架构实现了零配置集成，同时保留了高度的可定制性，满足从简单到复杂的各类应用场景需求。\n\n---\n\n<a id='page-transport'></a>\n\n## 传输层\n\n### 相关页面\n\n相关主题：[系统架构](#page-architecture), [部署选项](#page-deployment)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [examples/01_basic_usage_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/01_basic_usage_example.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n- [CONTRIBUTING.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n</details>\n\n# 传输层\n\nFastAPI-MCP 支持两种传输层协议，用于在 MCP 客户端和 FastAPI 应用之间进行通信。传输层是 MCP 服务器与外部客户端建立连接的核心组件，负责处理请求路由、消息传输和协议握手。\n\n## 传输层概述\n\nFastAPI-MCP 实现了 MCP 协议的传输层抽象，提供两种传输方式：\n\n| 传输类型 | 方法 | 说明 |\n|---------|------|------|\n| HTTP Streamable | `mount_http()` | 基于 HTTP 的流式传输，推荐的生产环境方案 |\n| SSE | `mount_sse()` | 基于 Server-Sent Events 的传输方式 |\n\n两种传输方式都遵循 MCP 协议规范，但在连接管理和消息传输机制上有所不同。`mount_http()` 是当前推荐的默认选择，而 `mount_sse()` 则提供了基于事件的实时通信能力。\n\n资料来源：[server.py:203-250]()\n\n## HTTP Streamable 传输\n\nHTTP Streamable 传输是 FastAPI-MCP 推荐的传输层实现。它基于 HTTP 协议，提供可靠的双向通信能力。\n\n### 工作原理\n\nHTTP Streamable 传输使用 FastAPI 的 ASGI 接口与 MCP 服务器进行交互。当 MCP 客户端发起连接请求时，HTTP 客户端会通过 `httpx.AsyncClient` 转发请求到 FastAPI 应用。\n\n```python\n# 基础使用示例\nfrom fastapi_mcp import FastApiMCP\n\nmcp = FastApiMCP(app)\nmcp.mount_http()  # 使用 HTTP Streamable 传输\n```\n\n资料来源：[examples/01_basic_usage_example.py:1-15]()\n\n### HTTP 客户端配置\n\n在初始化 `FastApiMCP` 时，可以通过 `http_client` 参数传入自定义的 `httpx.AsyncClient` 实例：\n\n```python\nimport httpx\nfrom fastapi_mcp import FastApiMCP\n\n# 自定义 HTTP 客户端\ncustom_client = httpx.AsyncClient(\n    timeout=30.0,\n    follow_redirects=True\n)\n\nmcp = FastApiMCP(\n    app,\n    http_client=custom_client\n)\nmcp.mount_http()\n```\n\n### 超时配置\n\n默认情况下，HTTP 请求超时设置为 10 秒。可以通过自定义客户端调整：\n\n```python\nmcp = FastApiMCP(\n    app,\n    http_client=httpx.AsyncClient(\n        timeout=60.0  # 自定义超时时间\n    )\n)\n```\n\n资料来源：[server.py:120-130]()\n\n## SSE 传输\n\nSSE (Server-Sent Events) 传输提供基于事件的单向服务器推送能力，适用于需要服务器主动推送消息的场景。\n\n### 端点注册\n\nSSE 传输在 FastAPI 应用中注册两个主要端点：\n\n| 端点 | HTTP 方法 | 用途 |\n|-----|----------|------|\n| `{mount_path}` | GET | MCP 连接建立端点 |\n| `{mount_path}/messages/` | POST | 消息处理端点 |\n\n### 工作流程\n\n```mermaid\ngraph TD\n    A[MCP 客户端] -->|建立 SSE 连接| B[/mcp GET 端点]\n    A -->|发送消息| C[/mcp/messages/ POST 端点]\n    B -->|SSE 流| A\n    C -->|响应| A\n    B --> D[FastApiSseTransport]\n    C --> D\n```\n\n资料来源：[server.py:210-240]()\n\n### SSE 挂载方法\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\nmcp = FastApiMCP(app)\nmcp.mount_sse(router=app, mount_path=\"/mcp\")\n```\n\n### SSE 传输参数\n\n| 参数 | 类型 | 说明 |\n|-----|------|------|\n| `router` | FastAPI \\| APIRouter | FastAPI 应用或路由实例 |\n| `mount_path` | str | SSE 端点的挂载路径 |\n| `dependencies` | Sequence[Depends] | 可选的依赖注入列表 |\n\n资料来源：[server.py:152-200]()\n\n## 传输层选择指南\n\n### 推荐场景\n\n```mermaid\ngraph LR\n    A[需要可靠双向通信] --> B[选择 HTTP Streamable]\n    C[需要服务端推送] --> D[选择 SSE]\n    E[生产环境部署] --> B\n    F[简单集成场景] --> B\n```\n\n| 场景 | 推荐传输 |\n|-----|---------|\n| 生产环境 | HTTP Streamable |\n| 需要服务端推送 | SSE |\n| 简单演示 | HTTP Streamable |\n| 与现有 MCP 客户端兼容 | HTTP Streamable |\n\n## 传输层与认证\n\n传输层支持与认证系统集成。可以通过依赖注入为传输端点添加认证保护：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)]\n    )\n)\nmcp.mount_http()\n```\n\n这种方式确保所有通过传输层访问的端点都需要进行身份验证。\n\n资料来源：[examples/08_auth_example_token_passthrough.py:1-50]()\n\n## 传输层初始化参数\n\n`FastApiMCP` 类中与传输层相关的初始化参数：\n\n| 参数 | 类型 | 默认值 | 说明 |\n|-----|------|-------|------|\n| `http_client` | `httpx.AsyncClient` | `None` | 自定义 HTTP 客户端 |\n| `headers` | `List[str]` | `[\"authorization\"]` | 转发到工具调用的 HTTP 头列表 |\n\n```python\nmcp = FastApiMCP(\n    app,\n    http_client=custom_client,\n    headers=[\"authorization\", \"x-custom-header\"]  # 自定义转发头\n)\n```\n\n资料来源：[server.py:100-120]()\n\n## 迁移指南\n\n### 废弃的 mount() 方法\n\n早期版本中的 `mount()` 方法已被废弃，应使用 `mount_http()` 或 `mount_sse()` 替代：\n\n```python\n# ❌ 已废弃\nmcp.mount(app, transport=\"sse\")\n\n# ✅ 推荐方式\nmcp.mount_http()\n# 或\nmcp.mount_sse(app, mount_path=\"/mcp\")\n```\n\n使用废弃方法时，系统会发出警告：\n\n```\nDeprecationWarning: mount() is deprecated and will be removed in a future version. \nUse mount_http() for HTTP transport (recommended) or mount_sse() for SSE transport instead.\n```\n\n资料来源：[server.py:250-270]()\n\n## 总结\n\nFastAPI-MCP 的传输层提供了灵活的双协议支持，开发者可以根据具体需求选择合适的传输方式。HTTP Streamable 传输是生产环境的推荐选择，提供稳定可靠的通信能力；SSE 传输则为需要服务端推送的场景提供了替代方案。\n\n---\n\n<a id='page-openapi-conversion'></a>\n\n## OpenAPI 到 MCP 转换\n\n### 相关页面\n\n相关主题：[系统架构](#page-architecture), [配置与自定义](#page-configuration)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/openapi/convert.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/openapi/convert.py)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [examples/02_full_schema_description_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/02_full_schema_description_example.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n</details>\n\n# OpenAPI 到 MCP 转换\n\n## 概述\n\nOpenAPI 到 MCP 转换是 FastAPI-MCP 框架的核心功能，负责将 FastAPI 应用的 OpenAPI schema 自动转换为 MCP (Model Context Protocol) 工具。该转换过程保留了 FastAPI 端点的完整类型信息、参数定义、请求体结构和响应模式，使得 MCP 客户端能够以类型安全的方式调用 FastAPI 服务。\n\n转换模块位于 `fastapi_mcp/openapi/` 目录下，主要由 `convert.py` 实现核心转换逻辑，`utils.py` 提供辅助工具函数。\n\n## 核心转换函数\n\n### convert_openapi_to_mcp_tools\n\n`convert_openapi_to_mcp_tools` 是整个转换流程的核心入口函数，定义于 `fastapi_mcp/openapi/convert.py`:\n\n```python\ndef convert_openapi_to_mcp_tools(\n    openapi_schema: Dict[str, Any],\n    describe_all_responses: bool = False,\n    describe_full_response_schema: bool = False,\n) -> Tuple[List[types.Tool], Dict[str, Dict[str, Any]]]:\n```\n\n**参数说明：**\n\n| 参数 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `openapi_schema` | `Dict[str, Any]` | 必需 | 完整的 OpenAPI schema 对象 |\n| `describe_all_responses` | `bool` | `False` | 是否在工具描述中包含所有可能的响应模式 |\n| `describe_full_response_schema` | `bool` | `False` | 是否在工具描述中包含完整的 JSON 响应 schema |\n\n**返回值：**\n\n返回一个元组 `(List[types.Tool], Dict[str, Dict[str, Any]])`，包含：\n- MCP tools 列表，用于 MCP 协议交互\n- operation ID 到操作详情的映射，用于后续 HTTP 执行\n\n资料来源：[fastapi_mcp/openapi/convert.py:30-48]()\n\n## 转换流程架构\n\n```mermaid\ngraph TD\n    A[OpenAPI Schema] --> B[resolve_schema_references]\n    B --> C[遍历所有 paths]\n    C --> D{检查 HTTP 方法}\n    D -->|get/post/put/delete/patch| E[提取 operationId]\n    D -->|其他方法| F[跳过并记录警告]\n    E --> G[获取操作元数据]\n    G --> H[构建工具描述]\n    H --> I[组织参数类型]\n    I --> J[处理请求体]\n    J --> K[生成 MCP Tool]\n    K --> L[返回工具列表]\n    \n    style F fill:#ffcccc\n    style L fill:#ccffcc\n```\n\n## 详细的转换步骤\n\n### 第一步：Schema 引用解析\n\n在开始遍历操作之前，转换器首先调用 `resolve_schema_references` 函数解析 OpenAPI schema 中的所有 `$ref` 引用：\n\n```python\nresolved_openapi_schema = resolve_schema_references(openapi_schema, openapi_schema)\n```\n\n这一步骤确保后续处理能够访问完整的 schema 定义，避免因引用未解析而导致的类型信息丢失。\n\n资料来源：[fastapi_mcp/openapi/convert.py:50]()\n\n### 第二步：路径与方法遍历\n\n转换器遍历 OpenAPI schema 中定义的所有路径，并为每个路径检查所有支持的 HTTP 方法：\n\n```python\nfor path, path_item in resolved_openapi_schema.get(\"paths\", {}).items():\n    for method, operation in path_item.items():\n        if method not in [\"get\", \"post\", \"put\", \"delete\", \"patch\"]:\n            logger.warning(f\"Skipping non-HTTP method: {method}\")\n            continue\n```\n\n**支持的 HTTP 方法：**\n\n| 方法 | 说明 | 工具调用方式 |\n|------|------|--------------|\n| `GET` | 获取资源 | `client.get(path, params=query, headers=headers)` |\n| `POST` | 创建资源 | `client.post(path, params=query, headers=headers, json=body)` |\n| `PUT` | 完全更新资源 | `client.put(path, params=query, headers=headers, json=body)` |\n| `DELETE` | 删除资源 | `client.delete(path, params=query, headers=headers)` |\n| `PATCH` | 部分更新资源 | `client.patch(path, params=query, headers=headers, json=body)` |\n\n资料来源：[fastapi_mcp/openapi/convert.py:53-58]()\n\n### 第三步：参数分类\n\n转换器将操作参数按位置分为四类：\n\n```python\npath_params = []\nquery_params = []\nheader_params = []\nbody_params = []\n\nfor param in operation.get(\"parameters\", []):\n    param_name = param.get(\"name\")\n    param_in = param.get(\"in\")\n    required = param.get(\"required\", False)\n\n    if param_in == \"path\":\n        path_params.append((param_name, param))\n    elif param_in == \"query\":\n        query_params.append((param_name, param))\n    elif param_in == \"header\":\n        header_params.append((param_name, param))\n```\n\n**参数分类表：**\n\n| 参数位置 | 变量名 | 说明 | 必填检查 |\n|----------|--------|------|----------|\n| `path` | `path_params` | URL 路径参数 | 始终为 `required=True` |\n| `query` | `query_params` | URL 查询字符串参数 | 可选 |\n| `header` | `header_params` | HTTP 请求头参数 | 可选 |\n| `body` | `body_params` | 请求体参数 | 需检查 `required` 字段 |\n\n资料来源：[fastapi_mcp/openapi/convert.py:78-92]()\n\n### 第四步：请求体处理\n\n当操作包含 `requestBody` 时，转换器解析其内容类型和 schema 定义：\n\n```python\nrequest_body = operation.get(\"requestBody\", {})\nif request_body and \"content\" in request_body:\n    content_type = next(iter(request_body[\"content\"]), None)\n    if content_type and \"schema\" in request_body[\"content\"][content_type]:\n        schema = request_body[\"content\"][content_type][\"schema\"]\n        if \"properties\" in schema:\n            for prop_name, prop_schema in schema[\"properties\"].items():\n                body_params.append((prop_name, prop_schema))\n```\n\n### 第五步：工具描述构建\n\n转换器为每个 MCP 工具生成详细的描述信息，包括端点路径、方法、参数和响应模式：\n\n```python\ntool_description += response_info\n```\n\n描述信息包含：\n- 端点路径和 HTTP 方法\n- 路径参数说明\n- 查询参数说明\n- 请求体结构（JSON Schema）\n- 响应模式（可选，取决于配置）\n\n## 响应描述控制\n\n### describe_all_responses 选项\n\n当 `describe_all_responses=True` 时，工具描述将包含该端点所有可能的响应模式，包括不同的状态码对应的 schema：\n\n```json\n{\n  \"200\": { \"description\": \"Successful Response\", \"content\": {...} },\n  \"422\": { \"description\": \"Validation Error\", \"content\": {...} }\n}\n```\n\n### describe_full_response_schema 选项\n\n当 `describe_full_response_schema=True` 时，工具描述将包含完整的 JSON Schema 而不仅仅是摘要信息，便于 MCP 客户端进行详细的类型推断。\n\n资料来源：[fastapi_mcp/openapi/convert.py:35-40]()\n\n## 工具函数模块\n\n### 辅助函数列表\n\n| 函数名 | 功能 |\n|--------|------|\n| `resolve_schema_references` | 递归解析 OpenAPI schema 中所有的 `$ref` 引用 |\n| `clean_schema_for_display` | 清理 schema，移除不适合显示的内部元数据 |\n| `generate_example_from_schema` | 根据 schema 定义生成示例数据 |\n| `get_single_param_type_from_schema` | 从 schema 中提取单一参数类型信息 |\n\n这些工具函数确保转换过程中的类型安全和信息完整性。\n\n## 过滤机制\n\n`FastApiMCP` 类支持对转换后的工具进行细粒度过滤：\n\n```python\ndef _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any]) -> List[types.Tool]:\n```\n\n**过滤选项：**\n\n| 选项 | 类型 | 说明 |\n|------|------|------|\n| `include_operations` | `List[str]` | 仅包含指定 operation ID 的工具 |\n| `exclude_operations` | `List[str]` | 排除指定 operation ID 的工具 |\n| `include_tags` | `List[str]` | 仅包含指定标签的工具 |\n| `exclude_tags` | `List[str]` | 排除指定标签的工具 |\n\n**使用限制：**\n- `include_operations` 和 `exclude_operations` 不可同时使用\n- `include_tags` 和 `exclude_tags` 不可同时使用\n- 操作过滤和标签过滤可以组合使用（使用贪婪匹配）\n\n资料来源：[fastapi_mcp/server.py:75-90]()\n\n## 完整使用示例\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_mcp import FastApiMCP\n\napp = FastAPI()\n\n# 默认转换所有端点\nmcp = FastApiMCP(app)\n\n# 自定义转换配置\nmcp = FastApiMCP(\n    app,\n    name=\"Custom MCP Server\",\n    describe_all_responses=True,\n    describe_full_response_schema=True,\n    include_operations=[\"get_item\", \"list_items\"],\n    exclude_operations=[\"delete_item\"],\n    headers=[\"authorization\", \"x-custom-header\"],\n)\n\n# 挂载 MCP 服务器\nmcp.mount()\n```\n\n资料来源：[examples/02_full_schema_description_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/02_full_schema_description_example.py)\n\n## MCP Tool 结构\n\n转换后的 MCP Tool 包含以下核心字段：\n\n| 字段 | 说明 |\n|------|------|\n| `name` | 工具名称（通常为 operationId） |\n| `description` | 工具描述，包含端点信息和参数说明 |\n| `inputSchema` | JSON Schema 格式的输入参数定义 |\n| `annotations` | 可选的注释信息 |\n\n## HTTP 执行映射\n\n对于每个转换后的工具，系统维护一个 `operation_map`，将工具名称映射到实际的执行信息：\n\n```python\noperation_map = {\n    \"get_item\": {\n        \"method\": \"get\",\n        \"path\": \"/items/{item_id}\",\n        \"operation_id\": \"get_item\"\n    },\n    \"list_items\": {\n        \"method\": \"get\",\n        \"path\": \"/items\",\n        \"operation_id\": \"list_items\"\n    }\n}\n```\n\n此映射用于后续通过 httpx 客户端实际执行 HTTP 请求。\n\n## 错误处理\n\n转换过程中遇到的问题会被记录但不会中断流程：\n\n- 非 HTTP 方法（如 `options`、`head`）会被跳过并记录警告\n- 缺少 `operationId` 的操作会被跳过\n- Schema 解析错误会被捕获并记录日志\n\n## 类型安全保证\n\nFastAPI-MCP 的转换过程通过以下机制确保类型安全：\n\n1. **Pydantic 模型验证**：使用 Pydantic 进行类型验证\n2. **引用解析**：确保所有 `$ref` 被正确解析\n3. **Schema 清理**：移除不兼容的字段，确保 JSON Schema 有效性\n4. **示例生成**：根据 schema 自动生成示例值，便于测试\n\n资料来源：[fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n\n## 总结\n\nOpenAPI 到 MCP 转换是 FastAPI-MCP 框架的桥梁，它：\n\n1. **自动化** - 无需手动定义 MCP 工具，OpenAPI schema 自动转换\n2. **类型安全** - 保留完整的类型信息，支持强类型调用\n3. **灵活可控** - 支持细粒度的端点过滤和描述控制\n4. **文档完整** - 自动保留并增强 FastAPI 端点的文档信息\n\n该模块使得开发者能够零配置地将现有的 FastAPI 应用暴露为 MCP 服务器，同时保持原有的类型安全性和开发体验。\n\n---\n\n<a id='page-authentication'></a>\n\n## 认证与授权\n\n### 相关页面\n\n相关主题：[系统架构](#page-architecture), [示例集](#page-examples)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/auth/proxy.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/auth/proxy.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n- [examples/09_auth_example_auth0.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/09_auth_example_auth0.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n</details>\n\n# 认证与授权\n\nFastAPI-MCP 内置了基于 FastAPI 依赖注入系统的认证与授权机制。这套机制允许开发者复用现有的 FastAPI 认证逻辑，无需额外配置即可保护 MCP 工具的访问。\n\n## 系统架构\n\n```mermaid\ngraph TD\n    A[MCP Client] --> B[FastAPI-MCP Server]\n    B --> C{FastAPI Dependencies}\n    C -->|验证通过| D[MCP Tool]\n    C -->|验证失败| E[401/403 错误]\n    F[OAuth Provider] -->|OAuth Flow| B\n    \n    subgraph \"认证配置层\"\n        G[AuthConfig]\n        H[OAuthMetadata]\n        I[Custom Metadata]\n    end\n```\n\n## 核心类型\n\n### AuthConfig\n\n`AuthConfig` 是配置 MCP 认证的核心类，位于 `fastapi_mcp/types.py`。支持 OAuth 2.0 授权流程和自定义元数据配置。\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `version` | `Literal[\"2025-03-26\"]` | MCP 规范版本，当前仅支持 `\"2025-03-26\"` |\n| `dependencies` | `Optional[Sequence[Depends]]` | FastAPI 依赖列表，用于身份验证 |\n| `setup_proxies` | `bool` | 是否设置 OAuth 代理端点 |\n| `client_id` | `Optional[str]` | OAuth 客户端 ID |\n| `client_secret` | `Optional[str]` | OAuth 客户端密钥 |\n| `issuer` | `Optional[str]` | OAuth 服务器签发者 |\n| `oauth_metadata_url` | `Optional[StrHttpUrl]` | OAuth 提供商元数据端点 URL |\n| `authorize_url` | `Optional[StrHttpUrl]` | 授权端点 URL |\n| `metadata_path` | `str` | 元数据端点路径，默认 `\"/.well-known/oauth-authorization-server\"` |\n| `audience` | `Optional[str]` | OAuth 受众 |\n| `default_scope` | `Optional[str]` | 默认权限范围 |\n| `custom_oauth_metadata` | `Optional[OAuthMetadataDict]` | 自定义 OAuth 元数据 |\n| `setup_fake_dynamic_registration` | `bool` | 是否设置虚假动态客户端注册端点 |\n\n资料来源：[fastapi_mcp/types.py:100-150]()\n\n### OAuthMetadata\n\nOAuth 2.0 服务器元数据结构，符合 RFC 8414 规范：\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `issuer` | `StrHttpUrl` | 授权服务器的签发者标识符 |\n| `authorization_endpoint` | `Optional[StrHttpUrl]` | 授权端点 URL |\n| `token_endpoint` | `StrHttpUrl` | 令牌端点 URL |\n| `scopes_supported` | `List[str]` | 支持的 OAuth 范围列表，默认 `[\"openid\", \"profile\", \"email\"]` |\n| `response_types_supported` | `List[str]` | 支持的响应类型 |\n\n资料来源：[fastapi_mcp/types.py:50-90]()\n\n## 认证流程\n\n### 基础 Token 验证\n\n最简单的认证方式是使用 FastAPI 的 `HTTPBearer` 进行 Token 验证：\n\n```mermaid\nsequenceDiagram\n    participant C as MCP Client\n    participant S as FastAPI-MCP\n    participant D as FastAPI Dependencies\n    \n    C->>S: 请求携带 Authorization Header\n    S->>D: 注入 dependencies 进行验证\n    D->>D: 验证 Bearer Token\n    alt Token 有效\n        D-->>S: 验证通过\n        S->>C: 执行 MCP Tool\n    else Token 无效\n        D-->>S: 401 Unauthorized\n        S->>C: 返回错误\n    end\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py]()\n\n### OAuth 授权流程\n\n当配置了完整的 OAuth 设置时，流程如下：\n\n```mermaid\ngraph LR\n    A[Client] -->|1. 请求工具| B[FastAPI-MCP]\n    B -->|2. Token 缺失/无效| C[OAuth Redirect]\n    C -->|3. 用户授权| D[Auth Provider]\n    D -->|4. Authorization Code| A\n    A -->|5. 交换 Token| D\n    D -->|6. Access Token| A\n    A -->|7. 请求工具 + Token| B\n    B -->|8. 执行工具| A\n```\n\n## 使用方式\n\n### 方式一：Token 验证（简单场景）\n\n适用于内部服务或测试环境，直接验证 Authorization Header 中的 Token：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\n@app.get(\"/private\")\nasync def private(token=Depends(token_auth_scheme)):\n    return token.credentials\n\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n\nmcp.mount_http()\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:30-45]()\n\n### 方式二：Auth0 集成（生产环境）\n\n生产环境推荐使用 Auth0 等专业 OAuth 提供商：\n\n```python\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\nmcp = FastApiMCP(\n    app,\n    name=\"MCP With Auth0\",\n    auth_config=AuthConfig(\n        issuer=f\"https://{settings.auth0_domain}/\",\n        authorize_url=f\"https://{settings.auth0_domain}/authorize\",\n        oauth_metadata_url=settings.auth0_oauth_metadata_url,\n        audience=settings.auth0_audience,\n        client_id=settings.auth0_client_id,\n        client_secret=settings.auth0_client_secret,\n        dependencies=[Depends(verify_auth)],\n        setup_proxies=True,\n    ),\n)\n```\n\n资料来源：[examples/09_auth_example_auth0.py:45-60]()\n\n### 方式三：自定义 OAuth 元数据\n\n当需要使用特定的 OAuth 提供商而非自动发现时：\n\n```python\nfrom fastapi_mcp.auth.proxy import setup_oauth_custom_metadata\n\nsetup_oauth_custom_metadata(\n    app=app,\n    auth_config=auth_config,\n    metadata=custom_oauth_metadata,\n    include_in_schema=False,\n)\n```\n\n资料来源：[fastapi_mcp/auth/proxy.py:25-45]()\n\n## OAuth 代理端点\n\nFastAPI-MCP 提供多个 OAuth 代理函数，用于搭建完整的授权服务：\n\n| 函数 | 功能 | 路径 |\n|------|------|------|\n| `setup_oauth_custom_metadata` | 提供自定义 OAuth 元数据 | `auth_config.metadata_path` |\n| `setup_oauth_metadata_proxy` | 代理 OAuth 提供商的元数据端点 | 默认 `/.well-known/oauth-authorization-server` |\n| `setup_oauth_authorize_proxy` | 代理授权端点 | 默认 `/oauth/authorize` |\n| `setup_oauth_fake_dynamic_register_endpoint` | 提供动态客户端注册 | `/oauth/register` |\n\n资料来源：[fastapi_mcp/auth/proxy.py:48-120]()\n\n### 元数据代理配置\n\n```python\nsetup_oauth_metadata_proxy(\n    app=app,\n    metadata_url=\"https://your-oauth-provider.com/.well-known/oauth-authorization-server\",\n    path=\"/.well-known/oauth-authorization-server\",\n    authorize_path=\"/oauth/authorize\",\n    register_path=\"/oauth/register\",\n)\n```\n\n### 授权代理配置\n\n```python\nsetup_oauth_authorize_proxy(\n    app=app,\n    client_id=\"your-client-id\",\n    authorize_url=\"https://your-provider.com/authorize\",\n    audience=\"your-audience\",\n    default_scope=\"openid profile\",\n)\n```\n\n### 动态客户端注册\n\n对于需要动态注册客户端的场景：\n\n```python\nsetup_oauth_fake_dynamic_register_endpoint(\n    app=app,\n    client_id=\"your-client-id\",\n    client_secret=\"your-client-secret\",\n)\n```\n\n## 在 FastApiMCP 中启用认证\n\n将 `AuthConfig` 传入 `FastApiMCP` 构造函数即可启用认证：\n\n```python\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP Server\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(my_auth_dependency)],\n        setup_proxies=True,\n        client_id=\"...\",\n        client_secret=\"...\",\n        issuer=\"https://auth.example.com\",\n    ),\n)\n```\n\n资料来源：[fastapi_mcp/server.py:180-220]()\n\n## 认证配置内部处理\n\n在 `FastApiMCP` 初始化时，会根据 `AuthConfig` 自动配置认证端点：\n\n```python\ndef _setup_auth_2025_03_26(self):\n    if self._auth_config:\n        if self._auth_config.custom_oauth_metadata:\n            setup_oauth_custom_metadata(...)\n        elif self._auth_config.setup_proxies:\n            setup_oauth_metadata_proxy(...)\n            setup_oauth_authorize_proxy(...)\n            if self._auth_config.setup_fake_dynamic_registration:\n                setup_oauth_fake_dynamic_register_endpoint(...)\n```\n\n资料来源：[fastapi_mcp/server.py:220-260]()\n\n## 最佳实践\n\n1. **生产环境使用 OAuth**：不要在生产环境使用简单的 Token 验证，应配置完整的 OAuth 流程\n2. **敏感信息管理**：使用环境变量存储 `client_id` 和 `client_secret`\n3. **依赖注入复用**：直接复用现有的 FastAPI 认证依赖，保持代码一致性\n4. **元数据端点**：确保 `metadata_path` 符合 OAuth 规范，默认值为 `/.well-known/oauth-authorization-server`\n\n---\n\n<a id='page-endpoint-filtering'></a>\n\n## 端点过滤与自定义\n\n### 相关页面\n\n相关主题：[OpenAPI 到 MCP 转换](#page-openapi-conversion), [配置与自定义](#page-configuration)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [CONTRIBUTING.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CONTRIBUTING.md)\n- [CHANGELOG.md](https://github.com/tadata-org/fastapi_mcp/blob/main/CHANGELOG.md)\n- [examples/shared/apps/items.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/shared/apps/items.py)\n</details>\n\n# 端点过滤与自定义\n\n## 概述\n\n端点过滤与自定义是 FastAPI-MCP 框架提供的重要功能，允许开发者精确控制哪些 FastAPI 端点被暴露为 MCP（Model Context Protocol）工具。通过灵活的配置选项，用户可以基于操作 ID（operationId）或标签（tags）对端点进行细粒度的筛选，从而实现按需暴露接口、保护敏感端点或构建特定的工具集。\n\n这一功能在 CHANGELOG.md 中被首次引入，作为支持\"refreshing\"功能的一部分，专门用于解决动态添加 FastAPI 路由后的端点管理问题。资料来源：[CHANGELOG.md]()\n\n## 核心概念\n\n### 操作 ID（Operation ID）\n\n每个 FastAPI 端点在 OpenAPI 规范中都有一个唯一的 `operationId`，用于标识该操作。FastAPI-MCP 利用这个标识符来精确定位和过滤特定的端点。\n\n### 标签（Tags）\n\n标签是 OpenAPI 规范中用于分组和组织端点的机制。一个端点可以拥有多个标签，这为批量过滤提供了便利的条件。\n\n## 过滤参数\n\nFastAPI-MCP 在 `FastApiMCP` 类中提供了四个核心过滤参数：\n\n| 参数名 | 类型 | 说明 | 互斥约束 |\n|--------|------|------|----------|\n| `include_operations` | `Optional[List[str]]` | 仅包含指定 operation ID 的端点 | 与 `exclude_operations` 互斥 |\n| `exclude_operations` | `Optional[List[str]]` | 排除指定 operation ID 的端点 | 与 `include_operations` 互斥 |\n| `include_tags` | `Optional[List[str]]` | 仅包含具有指定标签的端点 | 与 `exclude_tags` 互斥 |\n| `exclude_tags` | `Optional[List[str]]` | 排除具有指定标签的端点 | 与 `include_tags` 互斥 |\n\n资料来源：[fastapi_mcp/server.py:60-85]()\n\n## 过滤规则\n\n### 互斥规则\n\nFastAPI-MCP 对过滤参数实施了严格的互斥约束，以确保配置的一致性和可预测性：\n\n1. **操作 ID 级别**：不能同时使用 `include_operations` 和 `exclude_operations`\n2. **标签级别**：不能同时使用 `include_tags` 和 `exclude_tags`\n3. **跨级别组合**：可以同时使用操作 ID 过滤和标签过滤\n\n### 组合过滤行为\n\n当同时使用多种过滤条件时，FastAPI-MCP 采用**贪婪模式（greedy approach）**：任何满足任一条件的端点都会被包含在最终的工具列表中。\n\n```mermaid\ngraph TD\n    A[开始过滤流程] --> B{include_operations<br/>存在?}\n    B -->|是| C[根据 operation ID 包含]\n    B -->|否| D{exclude_operations<br/>存在?}\n    D -->|是| E[根据 operation ID 排除]\n    D -->|否| F{include_tags<br/>存在?}\n    F -->|是| G[根据标签包含]\n    F -->|否| H{exclude_tags<br/>存在?}\n    H -->|是| I[根据标签排除]\n    H -->|否| J[不进行过滤]\n    C --> K{同时存在<br/>标签过滤?}\n    E --> K\n    G --> L[贪婪模式:<br/>满足任一条件即包含]\n    I --> L\n    J --> L\n    K -->|是| L\n    L --> M[返回过滤后的工具列表]\n```\n\n资料来源：[fastapi_mcp/server.py:48-70]()\n\n## 过滤实现机制\n\n### 核心方法：`_filter_tools`\n\n`FastApiMCP` 类中的 `_filter_tools` 方法是执行过滤逻辑的核心实现。该方法接收两个参数：\n\n- `tools`：待过滤的工具列表\n- `openapi_schema`：完整的 OpenAPI 架构定义\n\n```python\ndef _filter_tools(self, tools: List[types.Tool], openapi_schema: Dict[str, Any]) -> List[types.Tool]:\n    \"\"\"\n    Filter tools based on operation IDs and tags.\n\n    Args:\n        tools: List of tools to filter\n        openapi_schema: The OpenAPI schema\n\n    Returns:\n        Filtered list of tools\n    \"\"\"\n    if (\n        self._include_operations is None\n        and self._exclude_operations is None\n        and self._include_tags is None\n        and self._exclude_tags is None\n    ):\n        return tools\n```\n\n资料来源：[fastapi_mcp/server.py:35-56]()\n\n### 构建标签到操作 ID 的映射\n\n过滤过程中，框架首先构建一个从标签到操作 ID 列表的映射：\n\n```python\noperations_by_tag: Dict[str, List[str]] = {}\nfor path, path_item in openapi_schema.get(\"paths\", {}).items():\n    for method, operation in path_item.items():\n        if method not in [\"get\", \"post\", \"put\", \"delete\", \"patch\"]:\n            continue\n\n        operation_id = operation.get(\"operationId\")\n        if not operation_id:\n            continue\n\n        tags = operation.get(\"tags\", [])\n        for tag in tags:\n            if tag not in operations_by_tag:\n                operations_by_tag[tag] = []\n            operations_by_tag[tag].append(operation_id)\n```\n\n资料来源：[fastapi_mcp/server.py:57-74]()\n\n## 使用示例\n\n### 按操作 ID 过滤\n\n#### 仅包含特定操作\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\n# 仅暴露 get_item 和 list_items 两个操作\ninclude_operations_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Included Operations\",\n    include_operations=[\"get_item\", \"list_items\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:18-24]()\n\n#### 排除特定操作\n\n```python\n# 排除 create_item、update_item 和 delete_item 操作\nexclude_operations_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Excluded Operations\",\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:27-32]()\n\n### 按标签过滤\n\n#### 仅包含特定标签\n\n```python\n# 仅暴露具有 'items' 标签的端点\ninclude_tags_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Included Tags\",\n    include_tags=[\"items\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:35-39]()\n\n#### 排除特定标签\n\n```python\n# 排除具有 'search' 标签的端点\nexclude_tags_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Excluded Tags\",\n    exclude_tags=[\"search\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:42-46]()\n\n### 组合过滤\n\n可以将操作 ID 过滤和标签过滤组合使用：\n\n```python\n# 包含具有 'search' 标签或 delete_item 操作的所有端点\ncombined_include_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Combined Include\",\n    include_operations=[\"delete_item\"],\n    include_tags=[\"search\"],\n)\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:49-55]()\n\n## 挂载与部署\n\n过滤后的 MCP 服务器可以通过 `mount_http` 方法挂载到不同的路径：\n\n```python\n# 为不同的过滤配置挂载独立的 MCP 端点\ninclude_operations_mcp.mount_http(mount_path=\"/include-operations-mcp\")\nexclude_operations_mcp.mount_http(mount_path=\"/exclude-operations-mcp\")\ninclude_tags_mcp.mount_http(mount_path=\"/include-tags-mcp\")\nexclude_tags_mcp.mount_http(mount_path=\"/exclude-tags-mcp\")\ncombined_include_mcp.mount_http(mount_path=\"/combined-include-mcp\")\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:58-63]()\n\n## 典型应用场景\n\n### 场景一：构建只读 API\n\n如果需要创建一个只读的 MCP 工具集，可以排除所有修改类操作：\n\n```python\nmcp_readonly = FastApiMCP(\n    app,\n    name=\"Read-Only API\",\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n### 场景二：按功能模块隔离\n\n根据业务模块隔离不同的 MCP 服务：\n\n```python\n# 仅包含搜索相关功能\nmcp_search = FastApiMCP(\n    app,\n    name=\"Search API\",\n    include_tags=[\"search\"],\n)\n\n# 仅包含物品管理功能\nmcp_items = FastApiMCP(\n    app,\n    name=\"Items API\",\n    include_tags=[\"items\"],\n)\n```\n\n### 场景三：权限分级\n\n通过标签组织不同权限级别的端点：\n\n```python\n# 管理员端点（排除公开端点）\nmcp_admin = FastApiMCP(\n    app,\n    name=\"Admin API\",\n    include_tags=[\"admin\"],\n    exclude_operations=[\"get_public_stats\"],  # 排除特定敏感操作\n)\n```\n\n## 注意事项\n\n### 1. operationId 必需\n\n过滤功能依赖 OpenAPI 规范中的 `operationId`。如果 FastAPI 端点未显式定义 `operationId`，FastAPI 会自动生成一个，但可能难以预测。建议显式定义：\n\n```python\n@app.get(\"/items/{item_id}\", operation_id=\"get_item\")\nasync def get_item(item_id: int):\n    return {\"item_id\": item_id}\n```\n\n### 2. 标签的作用域\n\n一个端点可以属于多个标签，只要满足任一过滤条件，该端点就会被包含。\n\n### 3. 无过滤参数时的行为\n\n如果未提供任何过滤参数（`include_operations`、`exclude_operations`、`include_tags`、`exclude_tags` 均为 `None`），则所有可发现的端点都将被暴露为 MCP 工具。\n\n## 相关文档\n\n- [基础用法示例](../examples/01_basic_usage_example.md)\n- [完整架构描述](./schema-description.md)\n- [认证配置](./authentication.md)\n- [工具命名配置](./tool-naming.mdx)\n\n## 更新日志\n\n| 版本 | 更新内容 |\n|------|----------|\n| 0.2.0 | 新增端点过滤能力，支持 `include_operations`、`exclude_operations`、`include_tags`、`exclude_tags` 参数 |\n\n---\n\n<a id='page-deployment'></a>\n\n## 部署选项\n\n### 相关页面\n\n相关主题：[传输层](#page-transport), [配置与自定义](#page-configuration)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [examples/04_separate_server_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/04_separate_server_example.py)\n- [examples/05_reregister_tools_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/05_reregister_tools_example.py)\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [fastapi_mcp/types.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/types.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n</details>\n\n# 部署选项\n\nFastAPI-MCP 提供了多种部署方式，以适应不同的应用场景和架构需求。本页面详细介绍如何将 MCP 服务器与现有的 FastAPI 应用集成，以及可用的传输协议和挂载选项。\n\n## 概述\n\nFastAPI-MCP 的部署架构基于以下几个核心组件：\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[FastApiMCP 实例]\n    B --> C[传输层]\n    C --> D[HTTP/SSE 传输]\n    C --> E[标准输入输出]\n    B --> F[MCP 工具注册]\n    F --> G[API 端点 → MCP 工具]\n```\n\n## HTTP 挂载部署\n\nHTTP 挂载是最常用的部署方式，允许将 MCP 服务器作为 FastAPI 应用的子路由挂载。\n\n### 基本挂载\n\n通过 `mount_http()` 方法将 MCP 端点挂载到指定路径：\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_mcp import FastApiMCP\n\napp = FastAPI(...)\n\nmcp = FastApiMCP(app, name=\"My MCP Server\")\nmcp.mount_http(mount_path=\"/mcp\")\n```\n\n### 自定义挂载路径\n\n可以为不同的 MCP 实例配置不同的挂载路径，实现多租户或分类服务：\n\n```python\n# 包含特定操作的 MCP\ninclude_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Included Operations\",\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 排除特定操作的 MCP\nexclude_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Excluded Operations\",\n    exclude_operations=[\"create_item\", \"update_item\"],\n)\n\n# 挂载到不同路径\ninclude_mcp.mount_http(mount_path=\"/include-operations-mcp\")\nexclude_mcp.mount_http(mount_path=\"/exclude-operations-mcp\")\n```\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1-10](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n\n### 传输协议\n\nHTTP 挂载支持两种传输协议：\n\n| 协议 | 说明 | 默认端口 |\n|------|------|----------|\n| **SSE (Server-Sent Events)** | 适用于需要服务端推送的场景 | 是 |\n| **Streamable HTTP** | 支持流式响应和双向通信 | 可选 |\n\nSSE 传输通过 `FastApiSseTransport` 实现，提供以下端点：\n\n- `GET /{mount_path}` - MCP 连接端点\n- `POST /{mount_path}/messages/` - 消息处理端点\n\n资料来源：[fastapi_mcp/server.py:140-170](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n\n## 独立服务器部署\n\n对于需要独立运行的场景，FastAPI-MCP 支持将 MCP 服务器作为独立进程启动。\n\n### 使用方式\n\n独立服务器模式允许 MCP 直接作为独立服务运行：\n\n```python\nfrom examples.shared.apps.items import app\nfrom fastapi_mcp import FastApiMCP\n\nmcp = FastApiMCP(\n    app,\n    name=\"Separate Server\",\n    describe_all_responses=True,\n)\n\nif __name__ == \"__main__\":\n    mcp.run()\n```\n\n资料来源：[examples/04_separate_server_example.py:1-20](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/04_separate_server_example.py)\n\n### 独立运行流程\n\n```mermaid\ngraph LR\n    A[启动进程] --> B[MCP.run 初始化]\n    B --> C[创建 STDIO 传输]\n    C --> D[MCP 协议处理]\n    D --> E[接收工具调用请求]\n    E --> F[调用 FastAPI 端点]\n    F --> G[返回结果到 MCP 客户端]\n```\n\n## 工具动态注册\n\nFastAPI-MCP 支持在服务器运行期间动态注册和更新工具。\n\n### reregister_tools 方法\n\n`reregister_tools()` 方法允许在不重启服务器的情况下更新 MCP 工具列表：\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_mcp import FastApiMCP, Tool\n\napp = FastAPI(...)\n\nmcp = FastApiMCP(app, name=\"Dynamic Tools Server\")\n\n# 初始工具列表\ninitial_tools = [\n    Tool(\n        name=\"original_tool\",\n        description=\"An original tool\",\n        inputSchema={\"type\": \"object\", \"properties\": {}},\n    )\n]\n\n# 注册初始工具\nmcp.add_mcp_server(tools=initial_tools)\n\n# 动态添加新工具\nnew_tools = [\n    Tool(\n        name=\"dynamic_tool\",\n        description=\"A dynamically added tool\",\n        inputSchema={\n            \"type\": \"object\",\n            \"properties\": {\n                \"message\": {\"type\": \"string\", \"description\": \"A message\"}\n            },\n        },\n    )\n]\nmcp.reregister_tools(tools=new_tools)\n```\n\n资料来源：[examples/05_reregister_tools_example.py:1-50](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/05_reregister_tools_example.py)\n\n### 动态注册流程\n\n```mermaid\ngraph TD\n    A[运行时] --> B[创建新工具定义]\n    B --> C[调用 reregister_tools]\n    C --> D[更新 MCP 服务器工具列表]\n    D --> E[新工具立即生效]\n    E --> F[下次 list_tools 调用返回新列表]\n```\n\n## 部署配置参数\n\n### mount_http 参数\n\n| 参数 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `mount_path` | `str` | `\"/mcp\"` | MCP 端点挂载的基础路径 |\n| `transport` | `FastApiSseTransport` | 自动创建 | 传输协议实例 |\n| `dependencies` | `Sequence[Depends]` | `None` | 挂载路径的 FastAPI 依赖项 |\n\n资料来源：[fastapi_mcp/server.py:110-130](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n\n### 运行时参数\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `http_client` | `httpx.AsyncClient` | 自定义 HTTP 客户端 |\n| `headers` | `List[str]` | 转发的 HTTP 头列表，默认 `[\"authorization\"]` |\n| `include_operations` | `List[str]` | 仅包含指定的操作 ID |\n| `exclude_operations` | `List[str]` | 排除指定的操作 ID |\n\n资料来源：[fastapi_mcp/server.py:70-100](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n\n## 认证配置部署\n\n在部署时可以通过 `auth_config` 配置认证功能：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n\nmcp.mount_http()\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:1-30](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n\n## 多实例部署架构\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[主 MCP 实例<br/>包含全部工具]\n    A --> C[过滤 MCP 实例 1<br/>include_operations]\n    A --> D[过滤 MCP 实例 2<br/>include_tags]\n    B --> E[/mcp]\n    C --> F[/filtered-operations]\n    D --> G[/filtered-tags]\n    \n    style E fill:#90EE90\n    style F fill:#87CEEB\n    style G fill:#DDA0DD\n```\n\n## 部署环境要求\n\n| 要求 | 最低版本 | 推荐版本 |\n|------|----------|----------|\n| Python | 3.10+ | 3.12 |\n| FastAPI | - | 最新稳定版 |\n| httpx | - | 最新稳定版 |\n| MCP SDK | - | 兼容版本 |\n\n## 常见部署场景\n\n### 场景一：单一路由挂载\n\n适用于简单的微服务架构：\n\n```python\nmcp = FastApiMCP(app, name=\"Simple MCP\")\nmcp.mount_http(mount_path=\"/mcp\")\n```\n\n### 场景二：多实例隔离\n\n适用于需要按功能模块隔离访问权限的场景：\n\n```python\nadmin_mcp = FastApiMCP(app, include_tags=[\"admin\"])\nuser_mcp = FastApiMCP(app, include_tags=[\"user\"])\n\nadmin_mcp.mount_http(mount_path=\"/admin-mcp\")\nuser_mcp.mount_http(mount_path=\"/user-mcp\")\n```\n\n### 场景三：认证保护部署\n\n适用于需要保护敏感 API 的场景：\n\n```python\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(dependencies=[Depends(verify_token)])\n)\nmcp.mount_http()\n```\n\n## 下一步\n\n- 了解 [工具过滤配置](./filtering.md) 了解更多操作和标签过滤选项\n- 查看 [认证配置](./authentication.md) 了解完整的认证设置\n- 参考 [示例代码](../examples/index.md) 获取完整示例\n\n---\n\n<a id='page-configuration'></a>\n\n## 配置与自定义\n\n### 相关页面\n\n相关主题：[部署选项](#page-deployment), [示例集](#page-examples)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [fastapi_mcp/server.py](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py)\n- [examples/06_custom_mcp_router_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/06_custom_mcp_router_example.py)\n- [examples/07_configure_http_timeout_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/07_configure_http_timeout_example.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [examples/08_auth_example_token_passthrough.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/08_auth_example_token_passthrough.py)\n</details>\n\n# 配置与自定义\n\nFastAPI-MCP 提供了丰富的配置选项，使开发者能够根据实际需求灵活定制 MCP 服务器的行为。本文详细介绍 FastAPI-MCP 的各项配置参数、挂载方式、认证配置以及工具过滤机制。\n\n## 核心配置参数\n\n`FastApiMCP` 类的构造函数是主要的配置入口，支持多种参数来控制 MCP 服务器的功能和行为。\n\n### 基础配置\n\n| 参数 | 类型 | 默认值 | 说明 |\n|------|------|--------|------|\n| `name` | `str` | 必填 | MCP 服务器名称 |\n| `description` | `str` | `None` | 服务器描述信息 |\n| `describe_all_responses` | `bool` | `False` | 是否在工具描述中包含所有可能的响应 schema |\n| `describe_full_response_schema` | `bool` | `False` | 是否包含完整的 JSON schema 响应信息 |\n\n基础配置允许开发者为 MCP 服务器设置标识信息和响应描述的详细程度。当 `describe_all_responses` 设置为 `True` 时，工具描述将包含端点的所有可能响应状态码对应的 schema；当 `describe_full_response_schema` 设置为 `True` 时，会输出完整的 JSON schema 结构。资料来源：[fastapi_mcp/server.py:54-73]()\n\n### HTTP 客户端配置\n\n```python\nhttp_client: Annotated[\n    Optional[httpx.AsyncClient],\n    Doc(\"用于向 FastAPI 应用发起 API 调用的自定义 HTTP 客户端\"),\n] = None\n```\n\n通过 `http_client` 参数，开发者可以传入自定义的 `httpx.AsyncClient` 实例来自定义超时、代理、连接池等 HTTP 行为。资料来源：[fastapi_mcp/server.py:79-85]()\n\n### 标头转发配置\n\n```python\nheaders: Annotated[\n    List[str],\n    Doc(\"从 MCP 请求中转发到每个工具调用的 HTTP 标头名称列表\"),\n] = [\"authorization\"]\n```\n\n`headers` 参数控制哪些 HTTP 标头会被转发到后端 API 调用。默认情况下只转发 `authorization` 标头，开发者可以根据需要添加其他标头。资料来源：[fastapi_mcp/server.py:119-126]()\n\n## 挂载方式\n\nFastAPI-MCP 支持多种挂载方式，以适应不同的部署场景。\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[选择挂载方式]\n    B --> C[mount_http]\n    B --> D[mount_sse]\n    B --> E[mount - 已废弃]\n    \n    C --> F[HTTP 传输<br/>推荐方式]\n    D --> G[SSE 传输]\n    E --> H[兼容性保留]\n    \n    F --> I[高性能场景]\n    G --> J[实时推送场景]\n```\n\n### HTTP 传输（推荐）\n\n`mount_http()` 是推荐的挂载方式，提供更高的性能和更简单的部署体验：\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\nmcp = FastApiMCP(app, name=\"My MCP Server\")\nmcp.mount_http()\n```\n\n该方式会自动注册必要的端点来处理 MCP 协议的通信。资料来源：[fastapi_mcp/server.py:217-224]()\n\n### SSE 传输\n\n`mount_sse()` 使用 Server-Sent Events 进行通信：\n\n```python\nmcp.mount_sse(router=app, mount_path=\"/mcp\")\n```\n\nSSE 传输方式会在指定路径下注册 MCP 连接端点，适用于需要服务端推送功能的场景。资料来源：[examples/06_custom_mcp_router_example.py:1-25]()\n\n### 自定义路由器挂载\n\n可以通过 `mount_http()` 方法将 MCP 服务器挂载到特定的 `APIRouter` 上，从而实现自定义挂载路径：\n\n```python\nfrom fastapi import APIRouter\nfrom fastapi_mcp import FastApiMCP\n\nother_router = APIRouter(prefix=\"/other/route\")\napp.include_router(other_router)\n\nmcp = FastApiMCP(app)\nmcp.mount_http(other_router)\n```\n\n执行上述代码后，MCP 服务器将只在 `/other/route/mcp` 路径下可用，而不会挂载到应用根路径。资料来源：[examples/06_custom_mcp_router_example.py:11-18]()\n\n### 超时配置\n\n通过自定义 `httpx.AsyncClient` 可以配置 HTTP 请求超时时间：\n\n```python\nimport httpx\nfrom fastapi_mcp import FastApiMCP\n\ncustom_client = httpx.AsyncClient(\n    timeout=30.0  # 设置 30 秒超时\n)\n\nmcp = FastApiMCP(app, http_client=custom_client)\nmcp.mount_http()\n```\n\n默认超时时间为 10 秒，开发者应根据实际业务需求调整该值。资料来源：[fastapi_mcp/server.py:93-96]()\n\n## 认证配置\n\nFastAPI-MCP 利用 FastAPI 原生的依赖注入系统来实现认证功能。\n\n### AuthConfig 配置\n\n`AuthConfig` 类用于配置 MCP 服务器的认证行为：\n\n| 参数 | 类型 | 说明 |\n|------|------|------|\n| `dependencies` | `List[Depends]` | FastAPI 依赖项列表，用于验证请求身份 |\n\n### Bearer Token 认证示例\n\n以下示例展示如何配置基于 Bearer Token 的认证：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\n@app.get(\"/private\")\nasync def private(token=Depends(token_auth_scheme)):\n    return token.credentials\n\nmcp = FastApiMCP(\n    app,\n    name=\"Protected MCP\",\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n\nmcp.mount_http()\n```\n\n在此配置下，所有 MCP 工具调用都必须携带有效的 Authorization 标头。资料来源：[examples/08_auth_example_token_passthrough.py:1-45]()\n\n### 认证标头转发\n\n在 MCP 客户端配置中，需要通过标头传递认证信息：\n\n```json\n{\n  \"mcpServers\": {\n    \"remote-example\": {\n      \"command\": \"npx\",\n      \"args\": [\n        \"mcp-remote\",\n        \"http://localhost:8000/mcp\",\n        \"--header\",\n        \"Authorization:${AUTH_HEADER}\"\n      ]\n    }\n  }\n}\n```\n\n## 工具过滤机制\n\nFastAPI-MCP 提供了灵活的端点过滤功能，支持按操作 ID 和标签两种方式进行筛选。\n\n```mermaid\ngraph TD\n    A[OpenAPI Schema] --> B{过滤条件判断}\n    B --> C{include_operations<br/>已设置?}\n    C -->|是| D[按操作 ID 包含]\n    C -->|否| E{exclude_operations<br/>已设置?}\n    E -->|是| F[按操作 ID 排除]\n    E -->|否| G{include_tags<br/>已设置?}\n    G -->|是| H[按标签包含]\n    G -->|否| I{exclude_tags<br/>已设置?}\n    I -->|是| J[按标签排除]\n    I -->|否| K[返回全部工具]\n    \n    D --> L[过滤后的工具列表]\n    F --> L\n    H --> L\n    J --> L\n    K --> L\n```\n\n### 过滤参数说明\n\n| 参数 | 类型 | 说明 | 互斥约束 |\n|------|------|------|----------|\n| `include_operations` | `List[str]` | 仅包含指定操作 ID 的工具 | 与 `exclude_operations` 互斥 |\n| `exclude_operations` | `List[str]` | 排除指定操作 ID 的工具 | 与 `include_operations` 互斥 |\n| `include_tags` | `List[str]` | 仅包含指定标签的工具 | 与 `exclude_tags` 互斥 |\n| `exclude_tags` | `List[str]` | 排除指定标签的工具 | 与 `include_tags` 互斥 |\n\n资料来源：[fastapi_mcp/server.py:86-118]()\n\n### 使用示例\n\n**按操作 ID 过滤：**\n\n```python\n# 仅包含特定操作\ninclude_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 排除特定操作\nexclude_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n**按标签过滤：**\n\n```python\n# 仅包含特定标签\ninclude_tags_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    include_tags=[\"items\"],\n)\n\n# 排除特定标签\nexclude_tags_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP\",\n    exclude_tags=[\"search\"],\n)\n```\n\n**组合过滤：**\n\n```python\n# 可以组合操作 ID 和标签过滤\ncombined_mcp = FastApiMCP(\n    app,\n    name=\"Item API MCP - Combined\",\n    include_operations=[\"get_item\"],\n    include_tags=[\"search\"],\n)\n```\n\n组合过滤采用贪婪策略，只要满足任一条件的端点都会被包含。资料来源：[examples/03_custom_exposed_endpoints_example.py:1-60]()\n\n## 响应 Schema 配置\n\n### 描述全部响应\n\n当 `describe_all_responses=True` 时，工具描述将包含端点的所有可能响应：\n\n```python\nmcp = FastApiMCP(\n    app,\n    name=\"Full Response MCP\",\n    describe_all_responses=True,\n)\n```\n\n### 完整 Schema 描述\n\n当 `describe_full_response_schema=True` 时，工具描述将包含完整的 JSON Schema：\n\n```python\nmcp = FastApiMCP(\n    app,\n    name=\"Full Schema MCP\",\n    describe_full_response_schema=True,\n)\n```\n\n## 依赖管理\n\n### 运行时依赖\n\n添加运行时所需的依赖包：\n\n```bash\nuv add new-package\n```\n\n### 开发依赖\n\n添加开发、测试或 CI 所需的依赖包：\n\n```bash\nuv add --group dev new-package\n```\n\n添加依赖后需要同时提交 `pyproject.toml` 和 `uv.lock` 文件。资料来源：[CONTRIBUTING.md:85-96]()\n\n## 配置最佳实践\n\n### 生产环境配置\n\n1. **显式设置超时**：根据业务需求配置合理的 HTTP 超时时间\n2. **配置认证**：生产环境应启用认证机制\n3. **过滤敏感端点**：使用 `exclude_operations` 排除管理类接口\n4. **配置标头转发**：仅转发必要的认证标头\n\n### 开发环境配置\n\n1. **启用完整 Schema**：开发时可设置 `describe_all_responses=True` 以获得更详细的文档\n2. **包含全部工具**：开发阶段不过滤任何端点\n3. **调整超时时间**：开发环境可设置更长的超时便于调试\n\n### 常用配置组合\n\n```python\n# 最小配置（仅必需参数）\nmcp = FastApiMCP(app, name=\"My API\")\n\n# 完整配置\nmcp = FastApiMCP(\n    app,\n    name=\"My API\",\n    description=\"Production MCP Server\",\n    describe_all_responses=True,\n    describe_full_response_schema=True,\n    include_tags=[\"api\"],\n    exclude_operations=[\"internal_debug\"],\n    auth_config=AuthConfig(dependencies=[Depends(token_auth_scheme)]),\n    headers=[\"authorization\", \"x-api-key\"],\n)\nmcp.mount_http()\n\n---\n\n<a id='page-examples'></a>\n\n## 示例集\n\n### 相关页面\n\n相关主题：[快速开始](#page-quickstart), [部署选项](#page-deployment), [认证与授权](#page-authentication)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [examples/01_basic_usage_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/01_basic_usage_example.py)\n- [examples/02_full_schema_description_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/02_full_schema_description_example.py)\n- [examples/03_custom_exposed_endpoints_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/03_custom_exposed_endpoints_example.py)\n- [examples/04_separate_server_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/04_separate_server_example.py)\n- [examples/05_reregister_tools_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/05_reregister_tools_example.py)\n- [examples/06_custom_mcp_router_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/06_custom_mcp_router_example.py)\n- [examples/07_configure_http_timeout_example.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/07_configure_http_timeout_example.py)\n- [examples/09_auth_example_auth0.py](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/09_auth_example_auth0.py)\n- [examples/README.md](https://github.com/tadata-org/fastapi_mcp/blob/main/examples/README.md)\n</details>\n\n# 示例集\n\nfastapi_mcp 项目提供了一套完整的示例代码，帮助开发者快速上手并深入理解该库的各项功能。示例集涵盖了从基础使用到高级配置的各种场景，是学习和实践 fastapi_mcp 的重要资源。\n\n## 示例概览\n\n示例目录位于仓库根目录的 `examples/` 文件夹下，每个示例都针对一个特定的功能点进行演示。所有示例都依赖共享的 FastAPI 应用组件，这些组件位于 `examples/shared/apps/items.py` 中定义了一个包含增删改查操作的 Items API。\n\n## 示例文件清单\n\n| 文件名 | 功能描述 | 难度等级 |\n|--------|----------|----------|\n| 01_basic_usage_example.py | 基础使用：如何将 MCP 服务器添加到 FastAPI 应用 | ⭐ 入门 |\n| 02_full_schema_description_example.py | 完整的 OpenAPI Schema 描述配置 | ⭐ 入门 |\n| 03_custom_exposed_endpoints_example.py | 自定义暴露的端点：通过 operation ID 和 tag 过滤 | ⭐⭐ 进阶 |\n| 04_separate_server_example.py | 独立 MCP 服务器运行方式 | ⭐⭐ 进阶 |\n| 05_reregister_tools_example.py | 重新注册 MCP 工具 | ⭐⭐ 进阶 |\n| 06_custom_mcp_router_example.py | 自定义 MCP 路由器配置 | ⭐⭐ 进阶 |\n| 07_configure_http_timeout_example.py | 配置 HTTP 请求超时时间 | ⭐⭐ 进阶 |\n| 08_auth_example_token_passthrough.py | 令牌透传认证示例 | ⭐⭐⭐ 高级 |\n| 09_auth_example_auth0.py | Auth0 认证集成示例 | ⭐⭐⭐ 高级 |\n\n## 核心概念\n\n### MCP 工具生成流程\n\nfastapi_mcp 的核心功能是将 FastAPI 应用中的 API 端点自动转换为 MCP（Model Context Protocol）工具。转换过程中会保留原有的请求模型、响应模型和文档描述。\n\n```mermaid\ngraph TD\n    A[FastAPI 应用] --> B[FastApiMCP 初始化]\n    B --> C[解析 OpenAPI Schema]\n    C --> D[提取端点信息]\n    D --> E[转换端点为 MCP 工具]\n    E --> F[MCP 服务器]\n```\n\n### 基础使用示例\n\n最简化的使用方式只需三行代码即可将 MCP 功能集成到现有的 FastAPI 应用中：\n\n```python\nfrom fastapi_mcp import FastApiMCP\n\n# 添加 MCP 服务器到 FastAPI app\nmcp = FastApiMCP(app)\n\n# 将 MCP 服务器挂载到 HTTP 传输层\nmcp.mount_http()\n```\n\n资料来源：[examples/01_basic_usage_example.py:1-13]()\n\n这种零配置的设计理念使得开发者无需修改现有业务代码，即可快速获得 MCP 能力。\n\n## 端点过滤配置\n\n在实际应用中，可能只需要暴露部分 API 端点作为 MCP 工具。fastapi_mcp 提供了多种过滤机制来控制暴露的端点。\n\n### 按 Operation ID 过滤\n\n通过 `include_operations` 和 `exclude_operations` 参数可以指定包含或排除特定的操作 ID：\n\n```python\n# 仅包含指定的操作 ID\ninclude_mcp = FastApiMCP(\n    app,\n    include_operations=[\"get_item\", \"list_items\"],\n)\n\n# 排除指定的操作 ID\nexclude_mcp = FastApiMCP(\n    app,\n    exclude_operations=[\"create_item\", \"update_item\", \"delete_item\"],\n)\n```\n\n### 按 Tag 过滤\n\n通过 `include_tags` 和 `exclude_tags` 参数可以按 OpenAPI 中的 tag 进行过滤：\n\n```python\n# 仅包含 items tag 下的端点\ninclude_tags_mcp = FastApiMCP(\n    app,\n    include_tags=[\"items\"],\n)\n\n# 排除 search tag 下的端点\nexclude_tags_mcp = FastApiMCP(\n    app,\n    exclude_tags=[\"search\"],\n)\n```\n\n### 过滤规则说明\n\n| 规则 | 说明 |\n|------|------|\n| include_operations 与 exclude_operations | 互斥，不能同时使用 |\n| include_tags 与 exclude_tags | 互斥，不能同时使用 |\n| 混合使用 | 可以组合使用 operation 过滤和 tag 过滤，满足任一条件的端点都会被包含 |\n\n资料来源：[examples/03_custom_exposed_endpoints_example.py:1-55]()\n\n## 认证配置\n\nfastapi_mcp 支持基于 OAuth 2.0 的认证功能，可以利用现有的 FastAPI 依赖注入机制来保护 MCP 端点。\n\n### 令牌透传认证\n\n最简单的认证方式是通过 Authorization 头部透传令牌：\n\n```python\nfrom fastapi import Depends\nfrom fastapi.security import HTTPBearer\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\ntoken_auth_scheme = HTTPBearer()\n\n@app.get(\"/private\")\nasync def private(token=Depends(token_auth_scheme)):\n    return token.credentials\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(\n        dependencies=[Depends(token_auth_scheme)],\n    ),\n)\n```\n\n资料来源：[examples/08_auth_example_token_passthrough.py:1-47]()\n\n### MCP 客户端配置\n\n使用令牌透传时，需要在 MCP 客户端配置文件中设置头部：\n\n```json\n{\n  \"mcpServers\": {\n    \"remote-example\": {\n      \"command\": \"npx\",\n      \"args\": [\n        \"mcp-remote\",\n        \"http://localhost:8000/mcp\",\n        \"--header\",\n        \"Authorization:${AUTH_HEADER}\"\n      ]\n    },\n    \"env\": {\n      \"AUTH_HEADER\": \"Bearer <your-token>\"\n    }\n  }\n}\n```\n\n### Auth0 集成\n\n对于需要集成第三方 OAuth 提供者的场景，fastapi_mcp 提供了完整的 Auth0 集成示例：\n\n```python\nfrom fastapi_mcp import FastApiMCP, AuthConfig\n\nmcp = FastApiMCP(\n    app,\n    auth_config=AuthConfig(\n        issuer=\"https://your-tenant.auth0.com\",\n        # 其他 OAuth 配置...\n    ),\n)\n```\n\n资料来源：[examples/09_auth_example_auth0.py]()\n\n## 高级配置\n\n### 独立 MCP 服务器\n\n除了挂载到 FastAPI 应用外，fastapi_mcp 也支持作为独立服务器运行，适用于需要单独部署 MCP 服务的场景。\n\n### HTTP 超时配置\n\n通过自定义 httpx.AsyncClient 实例，可以配置 HTTP 请求的超时时间：\n\n```python\nimport httpx\nfrom fastapi_mcp import FastApiMCP\n\ncustom_client = httpx.AsyncClient(timeout=30.0)\n\nmcp = FastApiMCP(\n    app,\n    http_client=custom_client,\n)\n```\n\n资料来源：[examples/07_configure_http_timeout_example.py]()\n\n### 工具重新注册\n\n对于需要动态更新 MCP 工具的场景，示例 05 演示了如何重新注册工具的方法。\n\n### 自定义 MCP 路由器\n\n示例 06 展示了如何使用自定义的 MCP 路由器来扩展功能。\n\n## 共享应用组件\n\n所有示例都依赖位于 `examples/shared/apps/items.py` 的共享 FastAPI 应用，这是一个包含 CRUD 操作的 Items RESTful API：\n\n| 端点 | 方法 | 功能 |\n|------|------|------|\n| /items | GET | 获取所有 Items |\n| /items/{item_id} | GET | 获取单个 Item |\n| /items | POST | 创建 Item |\n| /items/{item_id} | PUT | 更新 Item |\n| /items/{item_id} | DELETE | 删除 Item |\n| /items/search | GET | 搜索 Items |\n\n该应用使用 Pydantic 模型定义请求和响应结构，确保数据验证的完整性。\n\n## 运行示例\n\n### 环境准备\n\n示例代码需要以下环境条件：\n\n- Python 3.10+（推荐 3.12）\n- uv 包管理器\n\n### 启动命令\n\n每个示例都可以直接运行：\n\n```bash\ncd examples\nuv run python 01_basic_usage_example.py\n```\n\n服务器启动后，可以通过访问 `http://localhost:8000/docs` 查看 Swagger UI，或访问 `http://localhost:8000/mcp` 查看 MCP 端点。\n\n## 架构总览\n\n```mermaid\ngraph LR\n    subgraph \"FastAPI Application\"\n        A[REST Endpoints] --> B[Pydantic Models]\n        A --> C[Dependencies]\n    end\n    \n    subgraph \"FastApiMCP\"\n        D[OpenAPI Schema Parser] --> E[Tool Generator]\n        E --> F[MCP Server]\n    end\n    \n    G[MCP Clients] --> F\n    F --> H[HTTP Transport]\n    H --> A\n```\n\nfastapi_mcp 充当了 FastAPI 应用与 MCP 协议之间的桥梁，将原生 FastAPI 特性完整地保留到 MCP 工具定义中。\n\n## 总结\n\n示例集提供了从入门到高级的完整学习路径。开发者应当：\n\n1. 从 `01_basic_usage_example.py` 开始了解基础集成方式\n2. 参考 `03_custom_exposed_endpoints_example.py` 学习端点过滤\n3. 查看 `08_auth_example_token_passthrough.py` 和 `09_auth_example_auth0.py` 了解认证功能\n4. 根据具体需求查阅其他高级示例\n\n所有示例都遵循\"最小配置\"原则，开箱即用，同时提供充分的定制化能力满足生产环境需求。\n\n---\n\n---\n\n## Doramagic 踩坑日志\n\n项目：tadata-org/fastapi_mcp\n\n摘要：发现 22 个潜在踩坑项，其中 1 个为 high/blocking；最高优先级：配置坑 - 来源证据：[BUG] MCP session 404 in multi worker production environment。\n\n## 1. 配置坑 · 来源证据：[BUG] MCP session 404 in multi worker production environment\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：[BUG] MCP session 404 in multi worker production environment\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_f318cbe8fc55407da8cb88f5418cce0d | https://github.com/tadata-org/fastapi_mcp/issues/189 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 2. 安装坑 · 来源证据：v0.1.8\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.1.8\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_11a827f3808141e4bd7b0541a8628af0 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.1.8 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 3. 安装坑 · 来源证据：v0.2.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.2.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_a145fff6c53f4e709ef1bb7bc291216c | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.2.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 4. 安装坑 · 来源证据：v0.3.4\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.3.4\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_6dcb58f1897f46a188514e2714e5896d | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.4 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 5. 配置坑 · 可能修改宿主 AI 配置\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。\n- 对用户的影响：安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。\n- 建议检查：列出会写入的配置文件、目录和卸载/回滚步骤。\n- 防护动作：涉及宿主配置目录时必须给回滚路径，不能只给安装命令。\n- 证据：capability.host_targets | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | host_targets=mcp_host, claude, cursor\n\n## 6. 配置坑 · 来源证据：Suggestion: MCPWatch observability example for fastapi_mcp users\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：Suggestion: MCPWatch observability example for fastapi_mcp users\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_dfa72f41f3094dd5b2ffe188889f2b4f | https://github.com/tadata-org/fastapi_mcp/issues/303 | 来源类型 github_issue 暴露的待验证使用条件。\n\n## 7. 配置坑 · 来源证据：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_74e4280da33d49e1a3a8d576c7bb78a6 | https://github.com/tadata-org/fastapi_mcp/issues/304 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 8. 配置坑 · 来源证据：v0.3.6\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v0.3.6\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_bdc90006d16a437798ff2766d514f3d4 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.6 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 9. 能力坑 · 能力判断依赖假设\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：README/documentation is current enough for a first validation pass.\n- 对用户的影响：假设不成立时，用户拿不到承诺的能力。\n- 建议检查：将假设转成下游验证清单。\n- 防护动作：假设必须转成验证项；没有验证结果前不能写成事实。\n- 证据：capability.assumptions | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | README/documentation is current enough for a first validation pass.\n\n## 10. 维护坑 · 来源证据：[BUG] Description incorrectly passed as version to MCP Server\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：[BUG] Description incorrectly passed as version to MCP Server\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_2e599a8b03d649d8a47efb6b4d49f5ca | https://github.com/tadata-org/fastapi_mcp/issues/293 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 11. 维护坑 · 来源证据：v0.3.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.3.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_bc6b7bd2988b48d48920e4ffb259f147 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 12. 维护坑 · 来源证据：v0.3.3 - Fix OpenAPI Conversion Regression\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.3.3 - Fix OpenAPI Conversion Regression\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_79b96b9d35b9444c938c355c081410ac | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.3 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 13. 维护坑 · 来源证据：v0.4.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.4.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_4382c9c951e14187b76777ad8561ded9 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.4.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 14. 维护坑 · 维护活跃度未知\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：未记录 last_activity_observed。\n- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- 建议检查：补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 防护动作：维护活跃度未知时，推荐强度不能标为高信任。\n- 证据：evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | last_activity_observed missing\n\n## 15. 安全/权限坑 · 下游验证发现风险项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：下游已经要求复核，不能在页面中弱化。\n- 建议检查：进入安全/权限治理复核队列。\n- 防护动作：下游风险存在时必须保持 review/recommendation 降级。\n- 证据：downstream_validation.risk_items | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | no_demo; severity=medium\n\n## 16. 安全/权限坑 · 存在安全注意事项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：No sandbox install has been executed yet; downstream must verify before user use.\n- 对用户的影响：用户安装前需要知道权限边界和敏感操作。\n- 建议检查：转成明确权限清单和安全审查提示。\n- 防护动作：安全注意事项必须面向用户前置展示。\n- 证据：risks.safety_notes | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | No sandbox install has been executed yet; downstream must verify before user use.\n\n## 17. 安全/权限坑 · 存在评分风险\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：风险会影响是否适合普通用户安装。\n- 建议检查：把风险写入边界卡，并确认是否需要人工复核。\n- 防护动作：评分风险必须进入边界卡，不能只作为内部分数。\n- 证据：risks.scoring_risks | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | no_demo; severity=medium\n\n## 18. 安全/权限坑 · 来源证据：v0.3.1 - Authorization\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v0.3.1 - Authorization\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_41bf79ee5bd04da1b943d22449a0d649 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.1 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 19. 安全/权限坑 · 来源证据：v0.3.2\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v0.3.2\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_aa60828a6a6c4cc2b0b28fb72bf2ddad | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.2 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 20. 安全/权限坑 · 来源证据：v0.3.7\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v0.3.7\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_31faa7de6a364174958daaffa9d9204b | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.7 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 21. 维护坑 · issue/PR 响应质量未知\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：issue_or_pr_quality=unknown。\n- 对用户的影响：用户无法判断遇到问题后是否有人维护。\n- 建议检查：抽样最近 issue/PR，判断是否长期无人处理。\n- 防护动作：issue/PR 响应未知时，必须提示维护风险。\n- 证据：evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | issue_or_pr_quality=unknown\n\n## 22. 维护坑 · 发布节奏不明确\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：release_recency=unknown。\n- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。\n- 建议检查：确认最近 release/tag 和 README 安装命令是否一致。\n- 防护动作：发布节奏未知或过期时，安装说明必须标注可能漂移。\n- 证据：evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | release_recency=unknown\n\n<!-- canonical_name: tadata-org/fastapi_mcp; human_manual_source: deepwiki_human_wiki -->\n",
      "summary": "DeepWiki/Human Wiki 完整输出，末尾追加 Discovery Agent 踩坑日志。",
      "title": "Human Manual / 人类版说明书"
    },
    "pitfall_log": {
      "asset_id": "pitfall_log",
      "filename": "PITFALL_LOG.md",
      "markdown": "# Pitfall Log / 踩坑日志\n\n项目：tadata-org/fastapi_mcp\n\n摘要：发现 22 个潜在踩坑项，其中 1 个为 high/blocking；最高优先级：配置坑 - 来源证据：[BUG] MCP session 404 in multi worker production environment。\n\n## 1. 配置坑 · 来源证据：[BUG] MCP session 404 in multi worker production environment\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：[BUG] MCP session 404 in multi worker production environment\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_f318cbe8fc55407da8cb88f5418cce0d | https://github.com/tadata-org/fastapi_mcp/issues/189 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 2. 安装坑 · 来源证据：v0.1.8\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.1.8\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_11a827f3808141e4bd7b0541a8628af0 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.1.8 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 3. 安装坑 · 来源证据：v0.2.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.2.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_a145fff6c53f4e709ef1bb7bc291216c | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.2.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 4. 安装坑 · 来源证据：v0.3.4\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v0.3.4\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_6dcb58f1897f46a188514e2714e5896d | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.4 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 5. 配置坑 · 可能修改宿主 AI 配置\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：项目面向 Claude/Cursor/Codex/Gemini/OpenCode 等宿主，或安装命令涉及用户配置目录。\n- 对用户的影响：安装可能改变本机 AI 工具行为，用户需要知道写入位置和回滚方法。\n- 建议检查：列出会写入的配置文件、目录和卸载/回滚步骤。\n- 防护动作：涉及宿主配置目录时必须给回滚路径，不能只给安装命令。\n- 证据：capability.host_targets | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | host_targets=mcp_host, claude, cursor\n\n## 6. 配置坑 · 来源证据：Suggestion: MCPWatch observability example for fastapi_mcp users\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：Suggestion: MCPWatch observability example for fastapi_mcp users\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_dfa72f41f3094dd5b2ffe188889f2b4f | https://github.com/tadata-org/fastapi_mcp/issues/303 | 来源类型 github_issue 暴露的待验证使用条件。\n\n## 7. 配置坑 · 来源证据：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：clean_schema_for_display() strips anyOf and loses items for Optional[List[X]] parameters\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_74e4280da33d49e1a3a8d576c7bb78a6 | https://github.com/tadata-org/fastapi_mcp/issues/304 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 8. 配置坑 · 来源证据：v0.3.6\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：v0.3.6\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_bdc90006d16a437798ff2766d514f3d4 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.6 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 9. 能力坑 · 能力判断依赖假设\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：README/documentation is current enough for a first validation pass.\n- 对用户的影响：假设不成立时，用户拿不到承诺的能力。\n- 建议检查：将假设转成下游验证清单。\n- 防护动作：假设必须转成验证项；没有验证结果前不能写成事实。\n- 证据：capability.assumptions | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | README/documentation is current enough for a first validation pass.\n\n## 10. 维护坑 · 来源证据：[BUG] Description incorrectly passed as version to MCP Server\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：[BUG] Description incorrectly passed as version to MCP Server\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_2e599a8b03d649d8a47efb6b4d49f5ca | https://github.com/tadata-org/fastapi_mcp/issues/293 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 11. 维护坑 · 来源证据：v0.3.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.3.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_bc6b7bd2988b48d48920e4ffb259f147 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 12. 维护坑 · 来源证据：v0.3.3 - Fix OpenAPI Conversion Regression\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.3.3 - Fix OpenAPI Conversion Regression\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_79b96b9d35b9444c938c355c081410ac | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.3 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 13. 维护坑 · 来源证据：v0.4.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个维护/版本相关的待验证问题：v0.4.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_4382c9c951e14187b76777ad8561ded9 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.4.0 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 14. 维护坑 · 维护活跃度未知\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：未记录 last_activity_observed。\n- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- 建议检查：补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 防护动作：维护活跃度未知时，推荐强度不能标为高信任。\n- 证据：evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | last_activity_observed missing\n\n## 15. 安全/权限坑 · 下游验证发现风险项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：下游已经要求复核，不能在页面中弱化。\n- 建议检查：进入安全/权限治理复核队列。\n- 防护动作：下游风险存在时必须保持 review/recommendation 降级。\n- 证据：downstream_validation.risk_items | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | no_demo; severity=medium\n\n## 16. 安全/权限坑 · 存在安全注意事项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：No sandbox install has been executed yet; downstream must verify before user use.\n- 对用户的影响：用户安装前需要知道权限边界和敏感操作。\n- 建议检查：转成明确权限清单和安全审查提示。\n- 防护动作：安全注意事项必须面向用户前置展示。\n- 证据：risks.safety_notes | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | No sandbox install has been executed yet; downstream must verify before user use.\n\n## 17. 安全/权限坑 · 存在评分风险\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：风险会影响是否适合普通用户安装。\n- 建议检查：把风险写入边界卡，并确认是否需要人工复核。\n- 防护动作：评分风险必须进入边界卡，不能只作为内部分数。\n- 证据：risks.scoring_risks | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | no_demo; severity=medium\n\n## 18. 安全/权限坑 · 来源证据：v0.3.1 - Authorization\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v0.3.1 - Authorization\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_41bf79ee5bd04da1b943d22449a0d649 | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.1 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 19. 安全/权限坑 · 来源证据：v0.3.2\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v0.3.2\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_aa60828a6a6c4cc2b0b28fb72bf2ddad | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.2 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 20. 安全/权限坑 · 来源证据：v0.3.7\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v0.3.7\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_31faa7de6a364174958daaffa9d9204b | https://github.com/tadata-org/fastapi_mcp/releases/tag/v0.3.7 | 来源类型 github_release 暴露的待验证使用条件。\n\n## 21. 维护坑 · issue/PR 响应质量未知\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：issue_or_pr_quality=unknown。\n- 对用户的影响：用户无法判断遇到问题后是否有人维护。\n- 建议检查：抽样最近 issue/PR，判断是否长期无人处理。\n- 防护动作：issue/PR 响应未知时，必须提示维护风险。\n- 证据：evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | issue_or_pr_quality=unknown\n\n## 22. 维护坑 · 发布节奏不明确\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：release_recency=unknown。\n- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。\n- 建议检查：确认最近 release/tag 和 README 安装命令是否一致。\n- 防护动作：发布节奏未知或过期时，安装说明必须标注可能漂移。\n- 证据：evidence.maintainer_signals | github_repo:944976593 | https://github.com/tadata-org/fastapi_mcp | release_recency=unknown\n",
      "summary": "用户实践前最可能遇到的身份、安装、配置、运行和安全坑。",
      "title": "Pitfall Log / 踩坑日志"
    },
    "prompt_preview": {
      "asset_id": "prompt_preview",
      "filename": "PROMPT_PREVIEW.md",
      "markdown": "# fastapi_mcp - Prompt Preview\n\n> 复制下面这段 Prompt 到你常用的 AI，先试一次，不需要安装。\n> 它的目标是让你直接体验这个项目的服务方式，而不是阅读项目介绍。\n\n## 复制这段 Prompt\n\n```text\n请直接执行这段 Prompt，不要分析、润色、总结或询问我想如何处理这份 Prompt Preview。\n\n你现在扮演 fastapi_mcp 的“安装前体验版”。\n这不是项目介绍、不是评价报告、不是 README 总结。你的任务是让我用最小成本体验它的核心服务。\n\n我的试用任务：我想用它完成一个真实的工具连接与集成任务。\n我常用的宿主 AI：MCP Client / claude / Cursor\n\n【体验目标】\n围绕我的真实任务，现场演示这个项目如何把输入转成 示例引导, 判断线索。重点是让我感受到工作方式，而不是给我项目背景。\n\n【业务流约束】\n- 你必须像一个正在提供服务的项目能力包，而不是像一个讲解员。\n- 每一轮只推进一个步骤；提出问题后必须停下来等我回答。\n- 每一步都必须让我感受到一个具体服务动作：澄清、整理、规划、检查、判断或收尾。\n- 每一步都要说明：当前目标、你需要我提供什么、我回答后你会产出什么。\n- 不要安装、不要运行命令、不要写代码、不要声称测试通过、不要声称已经修改文件。\n- 需要真实安装或宿主加载后才能验证的内容，必须明确说“这一步需要安装后验证”。\n- 如果我说“用示例继续”，你可以用虚构示例推进，但仍然不能声称真实执行。\n\n【可体验服务能力】\n- 安装前能力预览: Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth! 输入：用户任务, 当前 AI 对话上下文；输出：示例引导, 判断线索。\n\n【必须安装后才可验证的能力】\n- 命令行启动或安装流程: 项目文档中存在可执行命令，真实使用需要在本地或宿主环境中运行这些命令。 输入：终端环境, 包管理器, 项目依赖；输出：安装结果, 列表/更新/运行结果。\n\n【核心服务流】\n请严格按这个顺序带我体验。不要一次性输出完整流程：\n1. page-overview：项目概览。围绕“项目概览”模拟一次用户任务，不展示安装或运行结果。\n2. page-quickstart：快速开始。围绕“快速开始”模拟一次用户任务，不展示安装或运行结果。\n3. page-architecture：系统架构。围绕“系统架构”模拟一次用户任务，不展示安装或运行结果。\n4. page-transport：传输层。围绕“传输层”模拟一次用户任务，不展示安装或运行结果。\n5. page-openapi-conversion：OpenAPI 到 MCP 转换。围绕“OpenAPI 到 MCP 转换”模拟一次用户任务，不展示安装或运行结果。\n\n【核心能力体验剧本】\n每一步都必须按“输入 -> 服务动作 -> 中间产物”执行。不要只说流程名：\n1. page-overview\n输入：用户提供的“项目概览”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n2. page-quickstart\n输入：用户提供的“快速开始”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n3. page-architecture\n输入：用户提供的“系统架构”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n4. page-transport\n输入：用户提供的“传输层”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n5. page-openapi-conversion\n输入：用户提供的“OpenAPI 到 MCP 转换”相关信息。\n服务动作：模拟项目在这一步的核心判断和整理方式。\n中间产物：一个可检查的小结果。\n\n【项目服务规则】\n这些规则决定你如何服务用户。不要解释规则本身，而要在每一步执行时遵守：\n- 先确认用户任务、输入材料和成功标准，再模拟项目能力。\n- 每一步都必须形成可检查的小产物，并等待用户确认后再继续。\n- 凡是需要安装、调用工具或访问外部服务的能力，都必须标记为安装后验证。\n\n【每一步的服务约束】\n- Step 1 / page-overview：Step 1 必须围绕“项目概览”形成一个小中间产物，并等待用户确认。\n- Step 2 / page-quickstart：Step 2 必须围绕“快速开始”形成一个小中间产物，并等待用户确认。\n- Step 3 / page-architecture：Step 3 必须围绕“系统架构”形成一个小中间产物，并等待用户确认。\n- Step 4 / page-transport：Step 4 必须围绕“传输层”形成一个小中间产物，并等待用户确认。\n- Step 5 / page-openapi-conversion：Step 5 必须围绕“OpenAPI 到 MCP 转换”形成一个小中间产物，并等待用户确认。\n\n【边界与风险】\n- 不要声称已经安装、运行、调用 API、读写本地文件或完成真实任务。\n- 安装前预览只能展示工作方式，不能证明兼容性、性能或输出质量。\n- 涉及安装、插件加载、工具调用或外部服务的能力必须安装后验证。\n\n【可追溯依据】\n这些路径只用于你内部校验或在我追问“依据是什么”时简要引用。不要在首次回复主动展开：\n- https://github.com/tadata-org/fastapi_mcp\n- https://github.com/tadata-org/fastapi_mcp#readme\n- README.md\n- fastapi_mcp/__init__.py\n- CHANGELOG.md\n- examples/01_basic_usage_example.py\n- examples/shared/apps/items.py\n- docs/getting-started/quickstart.mdx\n- fastapi_mcp/server.py\n- fastapi_mcp/types.py\n- docs/advanced/asgi.mdx\n- fastapi_mcp/transport/http.py\n\n【首次问题规则】\n- 首次三问必须先确认用户目标、成功标准和边界，不要提前进入工具、安装或实现细节。\n- 如果后续需要技术条件、文件路径或运行环境，必须等用户确认目标后再追问。\n\n首次回复必须只输出下面 4 个部分：\n1. 体验开始：用 1 句话说明你将带我体验 fastapi_mcp 的核心服务。\n2. 当前步骤：明确进入 Step 1，并说明这一步要解决什么。\n3. 你会如何服务我：说明你会先改变我完成任务的哪个动作。\n4. 只问我 3 个问题，然后停下等待回答。\n\n首次回复禁止输出：后续完整流程、证据清单、安装命令、项目评价、营销文案、已经安装或运行的说法。\n\nStep 1 / brainstorming 的二轮协议：\n- 我回答首次三问后，你仍然停留在 Step 1 / brainstorming，不要进入 Step 2。\n- 第二次回复必须产出 6 个部分：澄清后的任务定义、成功标准、边界条件、\n  2-3 个可选方案、每个方案的权衡、推荐方案。\n- 第二次回复最后必须问我是否确认推荐方案；只有我明确确认后，才能进入下一步。\n- 第二次回复禁止输出 git worktree、代码计划、测试文件、命令或真实执行结果。\n\n后续对话规则：\n- 我回答后，你先完成当前步骤的中间产物并等待确认；只有我确认后，才能进入下一步。\n- 每一步都要生成一个小的中间产物，例如澄清后的目标、计划草案、测试意图、验证清单或继续/停止判断。\n- 所有演示都写成“我会建议/我会引导/这一步会形成”，不要写成已经真实执行。\n- 不要声称已经测试通过、文件已修改、命令已运行或结果已产生。\n- 如果某个能力必须安装后验证，请直接说“这一步需要安装后验证”。\n- 如果证据不足，请明确说“证据不足”，不要补事实。\n```\n",
      "summary": "不安装项目也能感受能力节奏的安全试用 Prompt。",
      "title": "Prompt Preview / 安装前试用 Prompt"
    },
    "quick_start": {
      "asset_id": "quick_start",
      "filename": "QUICK_START.md",
      "markdown": "# Quick Start / 官方入口\n\n项目：tadata-org/fastapi_mcp\n\n## 官方安装入口\n\n### Python / pip · 官方安装入口\n\n```bash\npip install fastapi-mcp\n```\n\n来源：https://github.com/tadata-org/fastapi_mcp#readme\n\n## 来源\n\n- repo: https://github.com/tadata-org/fastapi_mcp\n- docs: https://github.com/tadata-org/fastapi_mcp#readme\n",
      "summary": "从项目官方 README 或安装文档提取的开工入口。",
      "title": "Quick Start / 官方入口"
    }
  },
  "validation_id": "dval_246d8351a869475d81589da59486f339"
}
