MCP Connector

Connect the tools provided by Model Context Protocol (MCP) servers to your agent.

🚨 IMPORTANT: Repository Migration Notice

MCP (Model Context Protocol) is an open source standard designed by Anthropic to connect your agents to external service providers, such as your application database or external APIs.

Thanks to this protocol you can make tools exposed by an external server available to your agent.

Companies can build MCP servers to allow developers to connect Agents to their platforms. Here are a couple of directories with most used MCP servers:

How it works

Neuron provides you with the McpConnector class that you can instantiate passing the MCP server configuration.

use NeuronAI\MCP\McpConnector;

class MyAgent extends Agent 
{
    ...
    
    protected function tools(): array
    {
        return [
            ...McpConnector::make([
                'command' => 'php',
                'args' => ['/home/code/mcp_server.php'],
            ])->tools(),
        ];
    }
}

You should create an McpConnector instance for each MCP server you want to interact to.

Neuron automatically discovers the tools exposed by the server and connects them to your agent.

When the agent decides to run a tool, Neuron will generate the appropriate request to call the tool on the MCP servers and return the result to the LLM to continue the task. It feels exactly like with your own defined tools, but you can access a huge archive of predefined actions your agent can perform with just one line of code.

Local MCP Server

If you want to connect with an MCP server installed locally on your machine or VM, you can use the "command" style configuration.

use NeuronAI\MCP\McpConnector;

class MyAgent extends Agent 
{
    ...
    
    protected function tools(): array
    {
        return [
            ...McpConnector::make([
                'command' => 'php',
                'args' => ['/home/code/mcp_server.php'],
            ])->tools(),
        ];
    }
}

Remote MCP Server

Remote servers are accessible via URLs and typically require authentication. You can use the token field in the configuration array, which will be used as an authorization token to communicate with the server:

use NeuronAI\MCP\McpConnector;

class MyAgent extends Agent 
{
    ...
    
    protected function tools(): array
    {
        return [
            ...McpConnector::make([
                'url' => 'https://mcp.example.com',
                'token' => 'BEARER_TOKEN',
                'timeout' => 30,
            ])->tools(),
        ];
    }
}

Monitoring & Debugging

To stay updated about your Agent decision making process, you can connect the Inspector monitoring dashboard to monitor tool selection and execution in real-time.

After you sign up at the link above, make sure to set the INSPECTOR_INGESTION_KEY variable in the application environment file to start monitoring:

.env
INSPECTOR_INGESTION_KEY=nwse877auxxxxxxxxxxxxxxxxxxxxxxxxxxxx

When your agent runs you will be able to explore the execution timeline in the dashboard.

Filter the list of tools

During connection with complex MCP servers they can includes tools that could lead to undesired behavior in specific contexts. The exclude() and only() methods address this challenge elegantly, allowing developers to connect with comprehensive MCP servers while maintaining fine-grained control over available capabilities you want to provide to your agent.

This becomes particularly useful when working with specialized agents that need specific capabilities but you want to reduce the probability of an agent mistake, and reduce tokens consumption.

These methods accept a list of tool names that you do or do not want to associate with the agent.

class MyAgent extends Agent 
{
    ...
    
    protected function tools()
    {
        return [
            // EXCLUDE: discard certain tools
            ...McpConnector::make([
                'url' => 'https://mcp.example.com',
            ])->exclude([
                'tool_name_1',
                'tool_name_2',
            ])->tools(),
            
            // ONLY: Select the tools you want to include
            ...McpConnector::make([
                'url' => 'https://mcp.example.com',
            ])->only([
                'tool_name_1',
                'tool_name_2',
            ])->tools(),
        ];
    }
}

Last updated