Skip to main content
The Model Context Protocol (MCP) is an open standard for connecting AI applications with external data sources and tools. AG-Kit provides comprehensive MCP integration support, enabling you to easily extend your Agent’s capabilities.

What is MCP?

MCP uses a client-server architecture that allows AI applications to securely access external resources:
  • MCP Servers: Provide tools, data sources, and prompt templates
  • MCP Clients: AI applications that consume these resources (like AG-Kit Agents)

Use Cases

1. Connect to Existing Tool Ecosystems

Many development tools and services already provide MCP servers that you can use directly in AG-Kit:

2. Expose AG-Kit Tools

Wrap your AG-Kit tools as MCP servers for use by other AI applications:
  • Internal Tool Sharing: Reuse tools across teams
  • Cross-Platform Integration: Interoperate with other AI frameworks
  • Service Deployment: Provide tools as standalone services

Quick Start

Using External MCP Tools

The most common scenario is connecting to existing MCP servers to access their tools:
import { createMCPToolkit } from '@ag-kit/tools';

// Create MCP toolkit using object mapping (recommended)
const mcpToolkit = await createMCPToolkit({
  playwright: {
    command: 'npx',
    args: ['@playwright/mcp@latest']
  }
});

// Get tools (automatically loaded after addServer)
const tools = mcpToolkit.getTools();

Exposing AG-Kit Tools

Expose your AG-Kit tools as an MCP server:
import { AGKitMCPServer } from '@ag-kit/tools/mcp';
import { tool } from '@ag-kit/tools';
import { z } from 'zod';

// Create AG-Kit tool
const weatherTool = tool(
  async ({ city, units = 'celsius' }) => {
    // Simulate weather API call
    const weatherData = {
      city,
      temperature: units === 'celsius' ? 22 : 72,
      condition: 'sunny',
      humidity: 65
    };

    return {
      success: true,
      data: weatherData
    };
  },
  {
    name: 'get_weather',
    description: 'Get weather information for a specified city',
    schema: z.object({
      city: z.string().describe('City name'),
      units: z.enum(['celsius', 'fahrenheit']).default('celsius')
    })
  }
);

// Create MCP server
const server = new AGKitMCPServer({
  name: 'weather-service',
  version: '1.0.0'
});

// Register tool
server.registerTool(weatherTool);

// Start server
await server.run({ type: 'stdio' });

Connection Types

Standard Input/Output (Stdio)

The most common connection type, suitable for local tools and command-line programs:
// Using object mapping format (recommended)
const toolkit = await createMCPToolkit({
  'python-tools': {
    command: 'python',
    args: ['-m', 'my_mcp_server'],
    timeout: 10000
  },
  'node-tools': {
    command: 'npx',
    args: ['@company/mcp-server']
  }
});

HTTP Connection

Suitable for remote services and web applications:

Memory Connection

Used for testing and in-process communication:

Real-World Examples

Multi-Server Integration

In real projects, you may need to connect multiple MCP servers to gain different capabilities:

Error Handling and Monitoring

Production environments require comprehensive error handling and monitoring:

Next Steps

Need Advanced Features?This guide covers basic MCP integration. For production features like connection pooling, retry policies, event monitoring, schema transformation, and performance optimization, see the complete MCP reference.

Complete MCP Reference

Advanced features, MCPClientManager, and production configuration

Built-in Toolkits

Discover pre-built toolkit collections for common use cases

Function Tools

Learn how to create custom tools from TypeScript functions

MCP Server Registry

Discover available MCP servers from the community