MCP 应用与 AG-UI 的兼容性

MAF 不提供 MCP 应用特定的配置或运行时行为。 MCP 应用支持由 MAF AG-UI 终结点外部的中间件实现,该终结点将继续接收标准 AG-UI 请求。

对于中间件设置和兼容性要求,请使用所选 AG-UI 客户端或中间件的文档。

代理框架 Python AG-UI 终结点与 AG-UI 生态系统的 MCP 应用功能兼容。 MCP 应用允许前端应用程序将 MCP 支持的工具和资源与 AG-UI 代理一起嵌入 — Python端无需更改。

Architecture

MCP 应用程序的支持由 CopilotKit 的 TypeScript MCPAppsMiddleware(@ag-ui/mcp-apps-middleware)提供,这一组件位于前端与 Agent Framework 后端之间。

┌─────────────────────────┐
│  Frontend               │
│  (CopilotKit / AG-UI)   │
└────────┬────────────────┘
         │
         ▼
┌─────────────────────────┐
│  CopilotKit Runtime /   │
│  Node.js Proxy          │
│  + MCPAppsMiddleware    │
└────────┬────────────────┘
         │ AG-UI protocol
         ▼
┌─────────────────────────┐
│  Agent Framework        │
│  FastAPI AG-UI Endpoint │
└─────────────────────────┘

中间件层负责处理 MCP 工具发现、iframe 代理的资源请求和 ui/resourceUri 解析。 Python AG-UI终结点接收标准 AG-UI 请求,并且不知道 MCP 应用层。

保留标准Python终结点

MCP 应用集成由 TypeScript 中间件处理。 Python终结点不需要特定于 MCP 应用的行为,但 Agent Framework 1.23 仍需要标准 AG-UI 授权所有权声明:

from agent_framework import Agent
from agent_framework.ag_ui import add_agent_framework_fastapi_endpoint
from fastapi import FastAPI

app = FastAPI()
agent = Agent(name="my-agent", instructions="...", client=chat_client)

# Local/single-user example. Shared services must use authorization_scope_resolver.
add_agent_framework_fastapi_endpoint(app, agent, "/", single_user=True)

此方法与 MCP 应用与所有其他 AG-UI Python 集成的工作方式一致 - MCP 应用层始终位于 TypeScript 中间件中,而不是在Python后端中。

设置中间件

若要将 MCP 应用与 Agent Framework 后端配合使用,请设置一个 CopilotKit 运行时或 Node.js 代理,包含 MCPAppsMiddleware,并指向 Python 端点:

// Example Node.js proxy configuration (TypeScript)
import { MCPAppsMiddleware } from "@ag-ui/mcp-apps-middleware";

const middleware = new MCPAppsMiddleware({
  agents: [
    {
      name: "my-agent",
      url: "http://localhost:8888/",  // Your MAF AG-UI endpoint
    },
  ],
  mcpApps: [
    // MCP app configurations
  ],
});

有关完整设置说明,请参阅 CopilotKit MCP 应用文档 和 AG-UI 代理协议文档。

不在范围内的内容

以下各项明确不属于 Python AG-UI 集成的一部分:

  • No Python MCPAppsMiddleware:MCP 应用中间件仅在 TypeScript 层中运行。
  • FastAPI 不处理通过 iframe 代理的 MCP 请求:资源代理由 Node.js 中间件处理。
  • 没有 Python 端的 ui/resourceUri 发现:资源 URI 解析由中间件处理。

如果应用程序不需要 MCP 应用中间件层,则代理框架 AG-UI 终结点直接与任何 AG-UI 兼容的客户端配合使用。

后续步骤

其他资源

MAF Go 不提供 MCP 应用特定的配置或运行时行为。 MCP 应用支持由 MAF AG-UI 终结点外部的中间件实现。