MCP

Connect Twig AI agents to external tools, data sources, and services using the Model Context Protocol.

Overview

The Model Context Protocol (MCP) is an open protocol that standardizes how AI applications connect to external data sources and tools. MCP enables Twig agents to access real-time data, execute actions, and integrate with third-party services beyond their built-in capabilities.

Key Benefits

  • Extensibility: Add custom tools and data sources without modifying agent code

  • Standardization: Use a consistent protocol across different integrations

  • Real-time Data: Access live data from external systems during conversations

  • Tool Execution: Enable agents to perform actions in external systems

  • Modular Architecture: Add or remove capabilities dynamically

Architecture

MCP follows a client-server architecture:

┌─────────────┐         ┌─────────────┐         ┌─────────────┐
│   Twig AI   │  MCP    │ MCP Server  │         │  External   │
│   Agent     │◄───────►│  (Host)     │◄───────►│  Services   │
└─────────────┘         └─────────────┘         └─────────────┘
  (MCP Client)           (Protocol)              (Data/Tools)
  • MCP Client: Twig AI agent that requests data or tools

  • MCP Server: Host that provides resources and tools to the agent

  • Resources: Data sources (files, databases, APIs)

  • Tools: Actions the agent can execute

Getting Started

Prerequisites

  • Twig AI account with API access

  • MCP server implementation (or use pre-built servers)

  • Understanding of Twig REST API

Quick Setup

  1. Choose or Build an MCP Server

    • Use pre-built servers for common integrations

    • Build custom servers for proprietary systems

  2. Configure Connection

    • Register your MCP server endpoint

    • Set up authentication credentials

    • Define available resources and tools

  3. Enable for Agents

    • Assign MCP capabilities to specific agents

    • Configure which resources agents can access

    • Test the integration

MCP Concepts

Resources

Resources are data sources that agents can query:

  • Files: Documents, PDFs, spreadsheets

  • Databases: SQL, NoSQL, vector databases

  • APIs: REST, GraphQL endpoints

  • Real-time Streams: Logs, metrics, events

Example Resource:

Tools

Tools are actions agents can execute:

  • Data Operations: Search, filter, aggregate

  • System Actions: Create tickets, send emails

  • Calculations: Complex computations, data transformations

  • Integrations: Trigger workflows in external systems

Example Tool:

Prompts

Prompts are reusable templates for common agent interactions:

Configuration

Connecting an MCP Server

API Endpoint

Request Body

Response

Assigning to Agents

Enable MCP for specific agents:

Using MCP Resources

Query Resources

Agents automatically query MCP resources when relevant:

User Question:

Agent Behavior:

  1. Identifies need for policy document

  2. Queries MCP server for file:///docs/refund-policy.pdf

  3. Retrieves content

  4. Generates response using retrieved data

Manual Resource Access

Explicitly request resources via API:

Using MCP Tools

Automatic Tool Execution

Agents decide when to use tools based on context:

User Request:

Agent Actions:

  1. Identifies need to create ticket

  2. Calls create_support_ticket tool

  3. Receives confirmation

  4. Reports back to user

Tool Execution Flow

Response:

Pre-built MCP Servers

Available Integrations

Server
Resources
Tools
Status

Zendesk

Tickets, Articles

Create/Update Tickets

Stable

Salesforce

Accounts, Contacts, Cases

Create Records

Beta

GitHub

Repositories, Issues, PRs

Create Issues

Stable

Google Drive

Documents, Sheets

Read Files

Stable

Slack

Messages, Channels

Send Messages

Beta

PostgreSQL

Tables, Views

Query Data

Stable

MongoDB

Collections

Query/Aggregate

Beta

Installing Pre-built Servers

Building Custom MCP Servers

Server Implementation

Create a server that implements the MCP protocol:

Required Endpoints:

  • POST /mcp/initialize - Handshake and capability negotiation

  • GET /mcp/resources/list - List available resources

  • POST /mcp/resources/read - Read specific resource

  • GET /mcp/tools/list - List available tools

  • POST /mcp/tools/call - Execute a tool

Example: Node.js Server

Python Server Example

Security & Permissions

Authentication

MCP servers support multiple auth methods:

Bearer Token

OAuth 2.0

API Key

Access Control

Restrict agent access to specific resources:

Audit Logging

All MCP interactions are logged:

Monitoring & Debugging

Server Health

Check MCP server status:

Debug Mode

Enable detailed logging for troubleshooting:

Common Issues

Connection Failures

  • Verify server endpoint is accessible

  • Check authentication credentials

  • Ensure firewall rules allow traffic

Tool Execution Errors

  • Validate tool input schema

  • Check server-side error logs

  • Test tool independently

Resource Access Denied

  • Review agent permissions

  • Verify resource URIs are correct

  • Check MCP server access controls

Best Practices

Resource Design

Good Practices:

  • Use descriptive resource URIs

  • Provide clear descriptions

  • Include relevant metadata

  • Cache frequently accessed resources

Avoid:

  • Exposing sensitive data without auth

  • Large resources without pagination

  • Ambiguous resource naming

Tool Design

Good Practices:

  • Clear, action-oriented tool names

  • Comprehensive input schemas

  • Detailed descriptions

  • Idempotent operations when possible

Avoid:

  • Destructive operations without confirmation

  • Tools with unclear side effects

  • Missing error handling

Performance

  • Cache MCP responses when appropriate

  • Implement timeouts for tool calls

  • Use pagination for large datasets

  • Monitor resource query latency

Security

  • Always use HTTPS for MCP endpoints

  • Rotate credentials regularly

  • Implement rate limiting on servers

  • Audit tool executions

  • Use least-privilege access

Examples

Customer Support Integration

Enable agents to access support tickets and create new ones:

Setup:

Usage:

Database Analytics

Query live database metrics:

Response:

API Reference

List MCP Servers

Get Server Details

Update Server Configuration

Remove Server

Test Connection

SDK Support

TypeScript/JavaScript

Python (Coming Soon)

Resources

Documentation

Tools & Libraries

Community

Next Steps

For custom MCP server development, refer to the official MCP documentationarrow-up-right and our code examplesarrow-up-right.

Last updated