Skip to main content

Custom Tools via MCP

Extend Xagent’s capabilities by integrating custom tools through MCP (Model Context Protocol).

What is MCP?

MCP (Model Context Protocol) is a protocol for connecting AI assistants to external tools and data sources. It enables:
  • Dynamic tool loading - Load tools from external servers
  • Service integration - Connect to any HTTP service
  • Custom functionality - Add specialized capabilities
  • Multi-tenant support - User-isolated tool access

How MCP Tools Work

When an agent needs to use a custom tool:
  1. Request - Agent generates tool call request
  2. MCP Routing - MCP adapter routes to appropriate MCP server
  3. Execution - MCP server executes the tool
  4. Response - Results returned through MCP adapter
  5. Output - Agent uses tool results in response

MCP Tool Types

Built-in MCP Support

Xagent includes built-in MCP tools for common scenarios: Agent Tools
  • Use published agents as tools
  • Task delegation and composition
  • Multi-agent workflows
Server Requirements
  • HTTP endpoint
  • JSON request/response format
  • Tool discovery endpoint

Using MCP Tools

Enabling MCP Tools

To use MCP tools in your agents:
  1. Go to Build page
  2. Create or edit an agent
  3. In the Tools section:
    • Enable mcp tool category
    • Agent can now access MCP tools

Configuration

MCP tools are configured at the system level:
  • MCP servers registered in Xagent settings
  • Tools automatically available to agents with MCP enabled
  • User permissions control tool access

Agent Usage

Once enabled, agents can:
  • Discover available MCP tools
  • Call tools with appropriate parameters
  • Handle tool results
  • Chain MCP tools with other tools

Building MCP Servers

MCP Server Requirements

An MCP server must implement: Tool Discovery Endpoint
Response:
Tool Execution Endpoint
Request:
Response:

Example MCP Server

Simple Python MCP server example:

Deploying MCP Servers

Options:
  1. Internal Server - Host within your network
    • Fastest performance
    • Full control
    • Direct database access
  2. Cloud Service - Deploy to cloud (AWS, GCP, Azure)
    • Scalable
    • Accessible from anywhere
    • Managed infrastructure
  3. Serverless - Use AWS Lambda, Google Cloud Functions
    • Pay-per-use
    • Auto-scaling
    • No server management

Security Considerations

Authentication

MCP Server Authentication:
  • API keys in request headers
  • OAuth2 tokens
  • Mutual TLS
Example:

Authorization

User-Level Access Control:
  • MCP tools respect user permissions
  • Tools filtered by allowed_collections
  • Admin-controlled tool availability

Best Practices

  • Validate inputs - Sanitize all parameters
  • Rate limiting - Prevent abuse
  • Logging - Track tool usage
  • Error handling - Return clear error messages
  • Timeouts - Set appropriate timeouts

Troubleshooting

MCP Tools Not Available

Check:
  • MCP server is running and accessible
  • Server registered in Xagent settings
  • Agent has mcp tool category enabled
  • User has permission to access tools

Tool Calls Failing

Verify:
  • Tool endpoint is correct
  • Parameters match expected schema
  • Authentication is configured
  • Network connectivity to MCP server

Slow Tool Execution

Optimize:
  • Check MCP server performance
  • Reduce response payload size
  • Use caching for frequently accessed data
  • Consider server location/latency

Advanced Features

Tool Composition

Chain MCP tools with other tools:

Agent-as-Tool

Publish agents as tools for other agents:
  • Create specialized agents
  • Publish them
  • Other agents can use them as tools
  • Enables multi-agent workflows

Dynamic Tool Discovery

MCP servers can:
  • Add/remove tools dynamically
  • Update tool descriptions
  • Change parameters
  • Xagent discovers changes automatically

Resources

Next Steps