MCP

本页目录

将外部 Model Context Protocol (MCP) 服务器连接到您的 Antigravity SDK Agent。

在使用 Antigravity SDK 构建的 Python 应用程序中,MCP 服务器(stdio 或 Streamable HTTP)与内置工具和自定义 Python 函数一起在统一执行管道下以编程方式连接。

以编程方式配置 MCP 服务器

您可以使用 LocalAgentConfig 或 McpStdioServer 在应用程序的 McpStreamableHttpServer 中以编程方式定义 MCP 服务器。

例如,您可以配置 Agent 以使用 stdio 连接到外部 SQLite MCP 服务器:

import asyncio
from google.antigravity import Agent, LocalAgentConfig
from google.antigravity.types import McpStdioServer

config = LocalAgentConfig(
    mcp_servers=[
        McpStdioServer(
            name="sqlite-explorer",
            command="node",
            args=["/usr/local/bin/sqlite-mcp-server.js"],
            env={"SQLITE_DB_PATH": "/var/data/app.db"},
        )
    ]
)

async def main():
    async with Agent(config) as agent:
        response = await agent.chat("Query database metrics.")
        print(await response.text())

if __name__ == "__main__":
    asyncio.run(main())

有关 Antigravity 套件中 MCP 协议功能的更多详细信息,请查看中央 Model Context Protocol 指南。

示例代码

有关完整的工作代码示例,请查看 GitHub 存储库: