Search by

adachsoft / mcp-tool

Arkadiusz Adach

AI SPI tool exposing configured Model Context Protocol (MCP) servers and their tools to AI agents.

Package info

gitlab.com/a.adach/mcp-tool

Issues

pkg:composer/adachsoft/mcp-tool

Statistics

Installs: 11

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-28 18:31 UTC

This package is auto-updated.

Last update: 2026-11-28 17:32:06 UTC


README

adachsoft/mcp-tool exposes configured Model Context Protocol (MCP) servers through the AI tool interface.

It implements the AI tool SPI of adachsoft/ai-tool-call, so it can be registered as a tool in any agent runtime that consumes the SPI.

Features

  • Exposes a single mcp_tool tool with operations for servers, tools, and calls:
    • list_servers — lists the configured MCP servers without contacting them,
    • list_tools — lists tools exposed by one configured server,
    • call_tool — invokes a specific tool on a configured server.
  • Reads server definitions from application configuration (timeout_seconds, servers, max_result_chars).
  • Supports per-server and per-operation timeouts, validated against a fixed policy.
  • Supports OAuth-protected servers: token retrieval and reactive token refresh on 401 responses.
  • Truncates oversized call output and reports truncation metadata.

Requirements

  • PHP >= 8.3
  • Composer 2
  • A configured MCP client implementing AdachSoft\McpContracts\Client\McpClientInterface

Installation

composer require adachsoft/mcp-tool

Integration

Create the tool through AdachSoft\McpTool\Tool\McpToolFactory and register the returned instance in your AI tool dispatcher:

use AdachSoft\McpTool\Config\McpServerConfigParser;
use AdachSoft\McpTool\Tool\McpToolFactory;

$factory = new McpToolFactory($mcpClient, new McpServerConfigParser());

$tool = $factory->create(new ConfigMap([
    'timeout_seconds' => 60,
    'servers' => [
        ['id' => 'weather_server', 'url' => 'https://example.com/mcp'],
    ],
]));

The servers value may be a PHP array or a JSON-encoded string. The tool returned by the factory can then be invoked through the AI tool SPI with operation, server_id, tool_name, and arguments parameters.

Usage

Invoke the tool through the AI tool SPI by wrapping the operation parameters in a ToolCallRequestDto:

use AdachSoft\AiToolCall\SPI\Collection\KeyValueMap;
use AdachSoft\AiToolCall\SPI\Dto\ToolCallRequestDto;

$result = $tool->callTool(new ToolCallRequestDto('mcp_tool', new KeyValueMap([
    'operation' => 'list_tools',
    'server_id' => 'weather_server',
    'timeout' => 30,
])));

Supported operations are list_servers, list_tools, and call_tool. See docs/examples/basic-usage.md for a complete example.

Timeout configuration

The top-level timeout_seconds option sets the default timeout for configured servers. Its default value is 60 seconds when the option is omitted.

A server can override this value with its own timeout_seconds option. An operation can override the effective server timeout with the optional timeout parameter used with list_servers, list_tools, or call_tool.

Timeout values must be integers from 1 to 300 seconds. Values outside this range are rejected before the MCP request is sent.

Example:

{
  "timeout_seconds": 60,
  "servers": [
    {
      "id": "weather_server",
      "url": "https://example.com/mcp",
      "timeout_seconds": 120
    }
  ]
}

The configured or operation-specific timeout is applied to the MCP HTTP request, including session initialization.