Skip to main content
Beta: This feature is in beta. The API schema may change as we iterate on the design.
MCP (Model Context Protocol) is an open standard that enables AI agents to interact with external tools and services. By passing MCP server configurations in your converse requests, you can extend the agent’s capabilities with custom tools. MCP servers are configured per-request. The agent will discover available tools from each server and use them as needed to complete the user’s request.

Basic Usage

import os
from datagrid_ai import Datagrid

client = Datagrid(api_key=os.environ.get("DATAGRID_API_KEY"))

response = client.converse(
    prompt="Tell me about my projects",
    config={
        "mcp_servers": [
            {
                "type": "inline_mcp",
                "server_label": "project-api",
                "server_url": "https://mcp.mycompany.com",
                "server_description": "Project management API",
                "authorization": "Bearer your-api-token"
            }
        ]
    }
)

print(response.content[0].text)

Configuration Options

FieldTypeRequiredDescription
typestringYesMust be "inline_mcp" for server configs passed in the request
server_labelstringYesUnique identifier for the server (max 64 characters). Used for tool namespacing.
server_urlstringYesHTTPS URL of the MCP streamable HTTP endpoint
server_descriptionstringNoDescription of what the server provides (max 500 characters)
authorizationstringNoValue sent in the Authorization header when calling the MCP server (e.g., "Bearer token")

Multiple Servers

You can connect multiple MCP servers in a single request. Each server’s tools will be available to the agent:
response = client.converse(
    prompt="Get the weather forecast and add it to my calendar",
    config={
        "mcp_servers": [
            {
                "type": "inline_mcp",
                "server_label": "weather",
                "server_url": "https://mcp.example.com/weather",
                "authorization": "Bearer weather-token"
            },
            {
                "type": "inline_mcp",
                "server_label": "calendar",
                "server_url": "https://mcp.example.com/calendar",
                "authorization": "Bearer calendar-token"
            }
        ]
    }
)

How It Works

When you pass an MCP server in a converse request, Datagrid handles the full MCP lifecycle automatically:
  1. Initialization: Datagrid sends initialize to negotiate protocol version and capabilities, then confirms with notifications/initialized
  2. Tool Discovery: Datagrid calls tools/list to discover available tools, with MCP-Session-Id and MCP-Protocol-Version headers
  3. Tool Execution: When the agent decides to use a tool, Datagrid calls tools/call with the appropriate parameters and session headers
  4. Session Recovery: If a session expires, Datagrid automatically re-initializes and retries the request
  5. Credential Isolation: Authorization values are scoped per server and never shared between servers
References:

Security

  • HTTPS Required: All MCP server URLs must use HTTPS
  • SSRF Protection: Requests to private IP addresses, localhost, and internal domains are blocked
  • Credential Isolation: Authorization tokens are isolated per-server and never shared between servers
  • Ephemeral: Server configurations are not persisted - they only exist for the duration of the request

Building MCP Servers

To create an MCP server compatible with Datagrid, implement the Model Context Protocol specification using streamable HTTP transport. Your server must handle the following methods:
  • initialize - Negotiates protocol version and capabilities. Return MCP-Session-Id in the response header.
  • notifications/initialized - Accepts the initialization completion notification
  • tools/list - Returns available tools and their JSON Schema definitions
  • tools/call - Executes a tool and returns the result
All requests after initialize will include MCP-Session-Id and MCP-Protocol-Version headers.
Frameworks like FastMCP and the official MCP SDK handle initialize, session management, and transport automatically. See Build an MCP Server to get started.