Controller of MCP function calling.

IMcpLlmController is a controller of MCP function calling, containing not only the application of function calling schemas, but also identifier name of the application and execute executor of MCP functions.

Here is an example of using IMcpLlmController type for AI agent development of performing AI function calling to e-commerce API functions through @agentica.

import { Agentica, assertMcpController } from "@wrtnlabs/agentica";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";

const client = new Client({
name: "calculator",
version: "1.0.0",
});
await client.connect(new StdioClientTransport({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-github"],
env: {
GITHUB_PERSONAL_ACCESS_TOKEN: process.env.GITHUB_PERSONAL_ACCESS_TOKEN,
// Add other environment variables as needed
}
}));

const agent = new Agentica({
model: "chatgpt",
vendor: {
api: new OpenAI({ apiKey: "*****"})
model: "gpt-4o-mini"
},
controllers: [
await assertMcpController({
name: "calculator",
model: "chatgpt",
client,
}),
],
});
await agent.conversate("What can you do?");

For reference, this IMcpLlmController type is designed for MCP servers. If you want to make a controller of another protocol like HTTP or TypeScript, use below types instead:

interface IMcpLlmController<Model extends Model> {
    application: IMcpLlmApplication<Model>;
    client: Client<
        {
            method: string;
            params?: {
                _meta?: { progressToken?: string
                | number; [key: string]: unknown };
                [key: string]: unknown;
            };
        },
        {
            method: string;
            params?: { _meta?: { [key: string]: unknown }; [key: string]: unknown };
        },
        { _meta?: { [key: string]: unknown }; [key: string]: unknown },
    >;
    name: string;
    protocol: "mcp";
}

Type Parameters

Properties

Application schema of function calling.

client: Client<
    {
        method: string;
        params?: {
            _meta?: { progressToken?: string
            | number; [key: string]: unknown };
            [key: string]: unknown;
        };
    },
    {
        method: string;
        params?: { _meta?: { [key: string]: unknown }; [key: string]: unknown };
    },
    { _meta?: { [key: string]: unknown }; [key: string]: unknown },
>

MCP client for connection.

You have to install @modelcontextprotocol/sdk package to use this type properly. If not, this type would work as an any type, so that you can't validate it.

name: string

Identifier name of the controller.

protocol: "mcp"

Protocol discriminator.