---
title: "Connect to external tools with MCP"
description: "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."
sidebar:
  label: "Connect external tools with MCP"
seo:
  title: "Connect to external tools with MCP | Autohand Code Agent SDK"
  description: "Learn how to connect to external tools with MCP (Model Context Protocol) in the Autohand Code Agent SDK across TypeScript, Python, Java, Go, Swift, and Rust."
---

## 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.

:::note
**Note:** MCP integration is available in the TypeScript SDK. Support for other languages is coming soon.
:::

## Using MCP Servers

Configure MCP servers to give agents access to external tools.

```ts title="TypeScript"
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"],
    },
  ],
});
```

```python title="Python"
# MCP support coming soon to Python SDK
```

```java title="Java"
// MCP support coming soon to Java SDK
```

```go title="Go"
// MCP support coming soon to Go SDK
```

```swift title="Swift"
// MCP support coming soon to Swift SDK
```

```rust title="Rust"
// MCP support coming soon to Rust SDK
```

## Popular MCP Servers

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

:::note
**Learn more:** See the [MCP documentation](/guides/mcp) for a complete list of available servers and how to use them.
:::

## Custom MCP Servers

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

```ts title="TypeScript"
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);
```

```python title="Python"
# MCP server creation coming soon
```

```java title="Java"
// MCP server creation coming soon
```

```go title="Go"
// MCP server creation coming soon
```

```swift title="Swift"
// MCP server creation coming soon
```

```rust title="Rust"
// 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
