Skip to content
Esc
↑↓navigate↵open⌘Jpreview
Start
On this page

Connect to external tools with MCP

MCP (Model Context Protocol) is a standard for connecting AI agents to external tools and data sources. Use MCP to extend your agents with capabilities like web research, database access, API integrations, and more.

What is MCP?

MCP provides a standardized way for agents to discover and use external tools. MCP servers expose tools that agents can call, with proper schema definitions and execution handling.

Using MCP Servers

Configure MCP servers to give agents access to external tools.

import { Agent, MCPServerConfig } from '@autohandai/agent-sdk';

const agent = new Agent({
  name: "Researcher",
  instructions: "Research topics using web search and external APIs.",
  mcpServers: [
    {
      name: "brave-search",
      command: "npx",
      args: ["-y", "@modelcontextprotocol/server-brave-search"],
    },
    {
      name: "filesystem",
      command: "npx",
      args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"],
    },
  ],
});
# MCP support coming soon to Python SDK
// MCP support coming soon to Java SDK
// MCP support coming soon to Go SDK
// MCP support coming soon to Swift SDK
// MCP support coming soon to Rust SDK

There are many community-maintained MCP servers available:

  • Brave Search: Web search capabilities
  • Filesystem: Access to local and remote filesystems
  • GitHub: Repository operations and code search
  • PostgreSQL: Database query and management
  • Slack: Messaging and notifications
  • Puppeteer: Web automation and scraping
  • Memory: Persistent memory and state management

Custom MCP Servers

You can build your own MCP servers to expose custom tools to agents.

import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server(
  {
    name: "my-custom-server",
    version: "1.0.0",
  },
  {
    capabilities: {
      tools: {},
    },
  }
);

// Define a custom tool
server.setRequestHandler(ListToolsRequestSchema, async () => {
  return {
    tools: [
      {
        name: "my_custom_tool",
        description: "Description of what this tool does",
        inputSchema: {
          type: "object",
          properties: {
            param1: {
              type: "string",
              description: "Parameter description",
            },
          },
          required: ["param1"],
        },
      },
    ],
  };
});

// Handle tool execution
server.setRequestHandler(CallToolRequestSchema, async (request) => {
  const { name, arguments: args } = request.params;

  if (name === "my_custom_tool") {
    // Execute your custom logic
    return {
      content: [
        {
          type: "text",
          text: `Tool executed with param1: ${args.param1}`,
        },
      ],
    };
  }

  throw new Error(`Unknown tool: ${name}`);
});

async function main() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
}

main().catch(console.error);
# MCP server creation coming soon
// MCP server creation coming soon
// MCP server creation coming soon
// MCP server creation coming soon
// MCP server creation coming soon

Use Cases

  • Web Research: Use Brave Search MCP to gather information from the web
  • Database Access: Query databases directly with PostgreSQL MCP
  • API Integration: Connect to external APIs through custom MCP servers
  • File Operations: Access remote filesystems with Filesystem MCP
  • Notifications: Send Slack messages or emails via MCP
  • Web Automation: Scrape websites with Puppeteer MCP

Best Practices

  • Validate tool outputs: Always validate MCP tool results before using them
  • Handle errors gracefully: MCP servers may be unavailable or return errors
  • Use appropriate permissions: Configure permissions for MCP tools that modify state
  • Monitor usage: Track which MCP tools are being used and how frequently
  • Secure credentials: Store API keys and credentials securely, not in code

Last updated on

Was this helpful?

Send Feedback

Help us improve this documentation page. Your feedback is valuable.

We'll only contact you if we need clarification