Back to Blog
mcp
3 min read
AI-powered content

Connecting Custom Tools: Exposing Private APIs via Custom MCP Servers

Learn how to build and connect a custom Model Context Protocol (MCP) server to Google Antigravity 2.0 to expose proprietary databases and APIs as agent tools.

mcp, google-antigravity, api-integration

Out of the box, Google Antigravity 2.0 is equipped with core tools for reading files, running shell scripts, and conducting web searches. But in a real-world enterprise codebase, agents need access to custom resources—such as internal API gateways, production error tracking logs, or proprietary database schemas.

To allow agents to communicate with any software resource, Antigravity integrates with the Model Context Protocol (MCP).

In this tutorial, we will build a custom MCP server in Python and connect it directly to Antigravity as a brand new agent tool.


What is Model Context Protocol (MCP)?

Model Context Protocol is an open-source protocol developed to standardize how LLM-powered applications interact with external tools and data sources. Think of it as the USB-C port for AI agents.

Instead of writing custom API integration code for every tool, you write a standard MCP server. Any MCP-compatible agent (like Antigravity or Claude Code) can instantly discover its available tools and schemas.


Step 1: Building a Custom MCP Server in Python

We will write a simple MCP server that queries a local system monitor (CPU and RAM metrics) and exposes this diagnostic data to our coding agent.

First, initialize a new Python file mcp_sysmon.py and install the MCP Python SDK:

pip install mcp

Now, write the server code:

# mcp_sysmon.py
import psutil
from mcp.server.fastmcp import FastMCP

# Initialize FastMCP Server
mcp = FastMCP("SystemMonitor")

@mcp.tool()
def get_system_metrics() -> str:
    """
    Retrieves current CPU and Memory usage metrics from the developer's machine.
    """
    cpu_percent = psutil.cpu_percent(interval=1)
    memory = psutil.virtual_memory()
    
    return (
        f"CPU Usage: {cpu_percent}%\n"
        f"Memory Usage: {memory.percent}% (Used: {memory.used / (1024**3):.2f} GB / Total: {memory.total / (1024**3):.2f} GB)"
    )

if __name__ == "__main__":
    mcp.run()

This short script declares a tool get_system_metrics. The docstring is critical: the LLM reads the docstring to understand when and how to invoke this tool.


Step 2: Registering the Server in Antigravity

Antigravity resolves its MCP servers through the global config file or project-specific configurations. To register our new server, add it to your configuration directory:

Open or edit ~/.gemini/antigravity/mcp_config.json:

{
  "mcpServers": {
    "system-monitor": {
      "command": "python",
      "args": [
        "/absolute/path/to/mcp_sysmon.py"
      ]
    }
  }
}

Step 3: Verifying the Tool

Start your Antigravity agent CLI. Once initialized, the agent will dynamically query the registered server. You can verify it by running a prompt:

Developer: "Can you check if my local system has enough memory available to run the test suite?"

Antigravity will identify that CPU/RAM metrics are needed, execute the get_system_metrics tool via the MCP protocol, and output the diagnostics directly in your shell:

[system-monitor/get_system_metrics] Invoked.
-> CPU Usage: 14.5%
-> Memory Usage: 62.4% (Used: 9.98 GB / Total: 16.00 GB)

The agent will respond:

"Yes, you have 6.02 GB of free memory, which is ample to execute the local testing suite."


Conclusion: Designing Custom Agents

With MCP, the barrier to teaching AI agents about your custom corporate tools is completely gone. By packaging databases, APIs, or custom script suites into MCP endpoints, you turn Antigravity into a specialized, domain-expert engineer for your specific stack.


For Day 4, we will look into the economics of agentic programming and see how to slash API token bills using Gemini's Context Caching.

mcpgoogle-antigravityapi-integrationcustom-tools

Related Content

Articles

Related Tools

Related Workflows