Skip to main content
AG-Kit provides comprehensive support for the Model Context Protocol (MCP), enabling seamless integration with external tools and services while exposing AG-Kit tools to other MCP-compatible applications.

AG-Kit MCP Support

Client Implementation

Connect to existing MCP servers and use their tools:
import { createMCPToolkit } from '@ag-kit/tools';
import { Agent } from '@ag-kit/agents';

const toolkit = await createMCPToolkit({
  filesystem: {
    command: 'npx',
    args: ['@modelcontextprotocol/server-filesystem', './workspace']
  }
});

const tools = toolkit.getTools();
const agent = new Agent({
  name: 'mcp-agent',
  model: provider,
  tools,
  instructions: 'You can access filesystem tools via MCP.'
});

Server Implementation

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

const weatherTool = tool(
  async ({ city }) => {
    return { city, temperature: 22, condition: 'sunny' };
  },
  {
    name: 'get_weather',
    description: 'Get weather information',
    schema: z.object({
      city: z.string().describe('City name')
    })
  }
);

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

server.registerTool(weatherTool);
await server.run({ type: 'stdio' });

Connection Types

  • Stdio: Local command-line tools
  • HTTP: Remote web services
  • Memory: Testing and in-process communication

Key Features

  • Tool Discovery: Automatic tool registration and discovery
  • Type Safety: Strongly typed tool definitions
  • Multiple Transports: Support for stdio, HTTP, and memory connections
  • Error Handling: Built-in error handling and recovery

Next Steps