MCP Plugin
The MCP Plugin acts as a mediator between the Brain framework and an MCP server. It connects to an MCP server—either locally via stdio or remotely via SSE—retrieves available tools and converts them into actions that the Brain Framework can execute. The actions are generated dynamically based on the MCP server’s capabilities.
There are two ways to configure the plugin:
- Stdio Mode: For local MCP servers using process-based communication.
- SSE Mode: For remote MCP servers using Server-Sent Events.
Installation
Section titled “Installation”Install the plugin:
npm i @iqai/plugin-mcp
pnpm add @iqai/plugin-mcp
yarn add @iqai/plugin-mcp
Configuration
Section titled “Configuration”Configure the plugin with the following parameters:
Param Name | Description | Required |
---|---|---|
name | Name of the MCP plugin | Yes |
description | Description of the plugin | Yes |
transport | Transport configuration object (see below) | Yes |
handleResponse | Custom handler for processing tool call results | No |
disableToolChaining | Disable automatic tool chaining behavior | No |
toolChainingTemplate | Custom template for tool chaining prompt | No |
Transport Configuration
Section titled “Transport Configuration”Configure the plugin for either stdio or sse modes.
Stdio Mode
Section titled “Stdio Mode”Use stdio mode when you want to run a local MCP server as a separate process.
Param Name | Description |
---|---|
mode | Must be set to "stdio" |
command | Command to run the local MCP server process |
args | Arguments for the local MCP server process (string list) |
SSE Mode
Section titled “SSE Mode”Use sse mode to connect to a remote MCP server via Server-Sent Events.
Param Name | Description |
---|---|
mode | Must be set to "sse" |
serverUrl | The base URL of the remote MCP server |
headers | Headers to include (if any) in the request to the remote server |
Import and initialize the plugin using the createMcpPlugin
method.
For a Local MCP Server (Stdio Mode)
Section titled “For a Local MCP Server (Stdio Mode)”import { createMcpPlugin } from "@iqai/plugin-mcp";
// Initialize the plugin with stdio configurationconst pluginFs = await createMcpPlugin({ name: "file-system", description: "File system MCP server", transport: { mode: "stdio", command: "npx", args: [ "-y", "@modelcontextprotocol/server-filesystem", "/home/user/", "/home/user/Desktop", ], }});
For a Remote MCP Server (SSE Mode)
Section titled “For a Remote MCP Server (SSE Mode)”import { createMcpPlugin } from "@iqai/plugin-mcp";
// Initialize the plugin with sse configurationconst plugin = await createMcpPlugin({ name: "remote-mcp-tools", description: "Remote MCP server tools", transport: { mode: "sse", serverUrl: "YOUR_SERVER_URL", headers: {} }});
Once initialized, the plugin dynamically generates actions based on the MCP server’s available tools, prompts, and resources.
Automatic Tool Chaining
Section titled “Automatic Tool Chaining”The plugin features automatic tool chaining, which enables more powerful interactions between tools:
- When a tool returns a file path, the system can automatically use filesystem tools if available to read the content
- Structured data outputs from one tool can serve as inputs to another tool
- Complex workflows can be automated without requiring explicit tool invocation for each step
For example, if a tool generates a code file and returns its path, the system will automatically detect this and can:
- Read the file content using filesystem tools if available by a plugin or via filesystem mcp server.
- Present the code with proper formatting
- Suggest further actions based on the file type
Error Handling
Section titled “Error Handling”The plugin manages various error scenarios, such as:
- Connection failures to the MCP server.
- Invalid tool, prompt, or resource requests.
- Network errors or unexpected server responses.
Errors are logged and relayed as informative messages to the Brain UI.
Security Considerations
Section titled “Security Considerations”For SSE mode:
- Ensure you are connecting to a trusted MCP server.
- Use HTTPS endpoints for secure communication.
- Validate all configuration parameters to avoid misconfigurations.
Learn More About MCP
Section titled “Learn More About MCP”For more details on the Model Context Protocol and available server implementations, check out these resources:
-
MCP Servers on GitHub: Explore a collection of MCP server implementations at github.com/modelcontextprotocol/servers .
-
Introduction to MCP: Learn about the core concepts and benefits of MCP at modelcontextprotocol.io/introduction .