AgentForge

MCP Integration Guide

Practical guide to integrating MCP tools with AgentForge agents.

Using External MCP Tools

Connect to an MCP server and use its tools:

import { MCPClient, fromMCPTool, defineAgent } from '@ahzan-agentforge/core';

// 1. Connect to an MCP server
const client = new MCPClient({
  command: 'npx',
  args: ['@modelcontextprotocol/server-filesystem', '/data'],
});

await client.connect();

// 2. Get tools
const mcpTools = await client.listTools();
const tools = mcpTools.map(fromMCPTool);

// 3. Use in an agent
const agent = defineAgent({
  name: 'file-agent',
  description: 'Agent with file system access via MCP',
  tools: [...tools, ...myOtherTools],
  llm,
  systemPrompt: 'You can read and write files.',
});

Exposing Your Tools via MCP

Make your AgentForge tools available to other AI tools:

import { MCPServer, defineTool } from '@ahzan-agentforge/core';
import { z } from 'zod';

const searchTool = defineTool({
  name: 'search',
  description: 'Search the knowledge base',
  input: z.object({ query: z.string() }),
  output: z.object({ results: z.array(z.string()) }),
  execute: async ({ query }) => ({ results: ['result1'] }),
});

const server = new MCPServer({
  name: 'my-tools',
  version: '1.0.0',
  tools: [searchTool],
});

await server.start();
// Now other MCP clients can connect and use your tools

Combining MCP with Native Tools

const agent = defineAgent({
  name: 'hybrid-agent',
  description: 'Agent with both native and MCP tools',
  tools: [
    // Native AgentForge tools
    mySearchTool,
    myProcessTool,
    // MCP tools from external servers
    ...fileSystemTools,
    ...databaseTools,
  ],
  llm,
  systemPrompt: '...',
});

Next Steps