MCPs Guide
Model Context Protocol (MCP) connections let agents call external services while keeping credentials and transport details centralized. Use this guide when you need to create, manage, or validate MCP configurations across REST, the Python SDK, and the CLI.
Compare REST, SDK, and CLI support in the AIP capability matrix.
aip mcps commands accept either the MCP ID or a unique name. If multiple connections share similar names, prefer the explicit ID in scripts to avoid updating the wrong record.
MCP Patterns
Direct MCP Definition (Recommended)
Define and attach MCPs directly to agents:
from glaip_sdk import Agent, MCP
weather_mcp = MCP(
name="weather",
transport="http",
config={"url": "https://weather.example.com/mcp"},
authentication={
"type": "api-key",
"key": "X-API-Key",
"value": "secret-key",
}
)
agent = Agent(
name="weather-bot",
instruction="You help users check the weather",
mcps=[weather_mcp]
)Conditional MCP inclusion:
You can reference MCPs by name string or using MCP.from_native():
Use this pattern for:
Attaching MCPs to specific agents
Conditional MCP inclusion
Simple integrations
MCP Registry Management (Secondary)
Use the SDK Client for managing the MCP registry and cross-environment governance. This is a secondary pattern; prefer defining MCPs directly and attaching them to Agent instances for day-to-day application code.
Use this pattern for:
Managing the MCP registry
Listing and searching MCPs
Testing MCP connections
MCP governance across environments
Create an MCP Configuration
When to use: Establish a new integration endpoint or clone settings from staging to production.
Using file references:
See Using files with the CLI for file-based workflows and import examples.
See Using files with the CLI for field details and override behaviour.
The CLI loads every supported field from the file, then applies any CLI flags you pass on top of that data. This lets you tweak a few values (for example a new name or transport) without editing the file:
Merge rules:
Values inside
weather-mcp.jsonform the baseline request (name, transport, config, authentication, metadata, etc.).Flags you provide alongside
--importoverride the file values one by one (e.g.,--transport httpreplaces the file’s transport).If the file already supplies required fields like
nameandtransport, you can omit those flags entirely; the CLI falls back to the file contents.
Example weather-mcp.json:
Using files with the CLI
Inline vs file inputs: Any JSON flag (e.g.,
--config,--auth) accepts either inline JSON or a file reference using@path/to/file.json. File inputs are parsed with the same validation as inline payloads.Importing full definitions: Supply
--import <file>to recreate an MCP from an export. The CLI loads every supported field from the file (name, transport, config, authentication,mcp_metadata, etc.).Flag overrides: CLI flags provided alongside
--importoverride the matching keys in the file. Leaving a flag out keeps the file’s value. When the file already contains required fields likenameandtransport, those flags become optional.
Example config file:
Example auth file:
Example import file:
Command examples:
Rotate Credentials or Update Configs
When to use: Refresh secrets before they expire or tweak transport parameters without downtime.
Validate Connections Before Saving
When to use: Confirm the connector responds and auth works before exposing it to agents.
Test connectivity without persisting a record:
Common errors and fixes
401 Unauthorized when validating
API key lacks MCP permissions or connector secrets expired.
Issue a runner/creator key or rotate the provider secret under Rotate Credentials.
404 or connection refused during validation
Base URL incorrect or firewall blocking outbound traffic.
Confirm the URL, allowlist the host, or test from a network that can reach the provider.
Connector saves but tools list is empty
Provider exposes no MCP tools or scope is limited.
Run discovery with elevated scopes or confirm the provider exports MCP metadata.
Agents timeout when calling the MCP
Runtime overrides missing, or concurrency exceeds provider limits.
Use per-run overrides for busy periods and tune agent timeout settings.
Discover MCP Tools
When to use: Inspect which tool definitions become available once the connector is active.
Get tools from a saved MCP:
Get tools from a config file (without saving to DB):
Get just tool names for allowed_tools config:
Example config file (mcp-config.json):
Attach discovered tool IDs to agents just like native or custom uploads.
Restrict Agent Tool Access (Allow List)
When to use: Limit which MCP tools an agent can access instead of allowing all tools from the MCP.
Tool names in allowed_tools must match exactly. Use Discover MCP Tools to find the correct tool names before configuring the allow list.
Configure Tool Filtering at Agent Level
Configuration rules:
Omit
allowed_toolsor set tonullor empty list[]— allows all MCP tools (default)Set to
["tool1", "tool2"]— allows only listed tools
Combining with authentication:
Update Existing Agent Tool Access
Runtime Overrides During Agent Runs
When to use: Supply per-run credentials, tool restrictions, or endpoints that differ from the stored defaults.
Override authentication:
Override allowed tools:
Configuration layers (resolution order):
Runtime config (highest priority) — per-execution overrides
Agent config — stored in agent
mcp_configsMCP config (lowest priority) — base MCP settings
Runtime overrides are processed in-memory for the run and do not modify stored MCP or agent records. CLI support is under development; use the SDK or REST API for now.
MCP Maintenance
When to use: Audit or retire connectors after incidents, vendor changes, or environment migrations.
Soft delete via
DELETE /mcps/{id}.List MCPs with
GET /mcpsoraip mcps list.Combine MCP tooling with the Tools guide when you want to import remote tools into agent definitions.
Best Practices
When to use: Align your organisation on safe defaults that reduce downtime and credential leaks.
Store secrets securely — use environment variables when invoking CLI or REST workflows; avoid committing secrets to JSON.
Validate before saving — run
aip mcps connect --from-file ...or/mcps/connectto catch network or auth issues early.Document tool discovery — record which MCP tool IDs power each agent so teammates can maintain the integration.
Monitor timeouts — many services expose their own rate or timeout limits; set
config.timeoutaccordingly and surface errors in run logs.
Related Documentation
Tools guide — attach native, custom, and MCP-discovered tools.
Agents guide — manage agent lifecycle and runtime overrides.
Automation & scripting — script MCP promotion in CI pipelines.
Last updated