Skip to content

Conversation

@wachterjohannes
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
Docs? no
Issues N/A
License MIT

Summary

This PR adds a new mcp:tools:call command that enables executing MCP tools directly from the command line with JSON input parameters. This complements the existing mcp:tools:list and mcp:tools:inspect commands, providing a complete CLI workflow for tool discovery, inspection, and execution.

Features

  • Execute MCP tools with JSON parameter input
  • Automatic JSON schema validation against tool input schemas
  • Two output formats:
    • Pretty format (default): Human-readable output with clear headers, descriptions, and formatted results
    • JSON format: Machine-parseable output for scripting and automation
  • Validate-only mode for testing parameters without execution
  • Comprehensive error handling for invalid tools, malformed JSON, and schema validation failures
  • Clear execution headers showing tool name, description, and extension

Usage Examples

Execute tool with parameters

$ vendor/bin/mate mcp:tools:call monolog-search '{"term": "about"}'

Executing Tool: monolog-search
==============================

 Search log entries by text term with optional level, channel, environment, and date filters
 Extension: symfony/ai-monolog-mate-extension

Result
------

 {"datetime":"2026-01-16T18:28:19+00:00","channel":"console","level":"CRITICAL","message":"Error thrown while running command \"about --profiler\". Message: \"The \"--profiler\" option does not exist.\"","context":{...},"source_file":"dev.log","line_number":21}
 {"datetime":"2026-01-16T18:28:19+00:00","channel":"console","level":"DEBUG","message":"Command \"about --profiler\" exited with code \"1\"","context":{...},"source_file":"dev.log","line_number":22}

Execute tool with empty parameters

$ vendor/bin/mate mcp:tools:call php-version "{}"

Executing Tool: php-version
===========================

 Get the version of PHP
 Extension: symfony/ai-mate

Result
------

 8.4.15

JSON output format

$ vendor/bin/mate mcp:tools:call php-version '{}' --format=json
"8.4.15"
``

### Validate parameters without execution

```bash
$ vendor/bin/mate mcp:tools:call monolog-search '{"term": "test"}' --validate-only

 [OK] Validation successful

Implementation Details

  • Reuses the same capability collection system as mcp:tools:list and mcp:tools:inspect
  • Validates JSON input against tool input schemas (required fields and type checking)
  • Properly handles schema default values for optional parameters
  • Resolves tool handlers from the Symfony DI container
  • Supports both ClassName::method and ClassName (for __invoke) handler formats
  • Includes comprehensive test coverage (5 test cases)

@carsonbot carsonbot changed the title Add mcp:tools:call command for tool execution via JSON input Add mcp:tools:call command for tool execution via JSON input Jan 16, 2026
"twig/twig": "^3.22"
},
"require-dev": {
"mcp/sdk": "0.3.0 as 0.2.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is currently needed to run the newest versions of mate (requires 0.3)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is only for development, i would rather not add this

it get's split into https://github.com/symfony/ai-demo as well - which currently only runs on ^0.2 versions of mate - so that issue is not relevant there i guess

@wachterjohannes wachterjohannes changed the title Add mcp:tools:call command for tool execution via JSON input [Mate] Add mcp:tools:call command for tool execution via JSON input Jan 16, 2026
@wachterjohannes wachterjohannes force-pushed the feature/mcp-tools-call-command branch 2 times, most recently from b408aa3 to a803352 Compare January 16, 2026 18:56
Execute MCP tools directly from command line with JSON parameters.

Features:
- Accept tool name and JSON input as required arguments
- Parse and validate JSON input against tool schema
- Resolve and invoke tool handlers from DI container
- Support pretty (default) and JSON output formats
- Validate-only mode for testing parameters
- Comprehensive error handling for invalid tools, JSON, and schema validation
@wachterjohannes wachterjohannes force-pushed the feature/mcp-tools-call-command branch from a803352 to bf1b304 Compare January 16, 2026 18:57
@chr-hertel chr-hertel added the Mate Issues & PRs about the AI Mate component label Jan 18, 2026
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated - please revert here

Comment on lines +311 to +317
if ($this->isAssociativeArray($result)) {
$io->definitionList(...array_map(fn ($key, $value) => [$key => $this->formatValue($value)], array_keys($result), $result));
} else {
foreach ($result as $item) {
$io->text($this->formatValue($item));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that custom isAssociativeArray is similar but inverted to array_is_list?

Suggested change
if ($this->isAssociativeArray($result)) {
$io->definitionList(...array_map(fn ($key, $value) => [$key => $this->formatValue($value)], array_keys($result), $result));
} else {
foreach ($result as $item) {
$io->text($this->formatValue($item));
}
}
if (array_is_list($result)) {
foreach ($result as $item) {
$io->text($this->formatValue($item));
}
} else {
$io->definitionList(...array_map(fn ($key, $value) => [$key => $this->formatValue($value)], array_keys($result), $result));
}

@chr-hertel
Copy link
Member

Not sure about this - from a theory point of view. You're skipping almost the entire SDK infrastructure and features for tools - which raises a couple of issues for tools that:

  • rely on RequestContext as argument
  • interact with the client-side for sampling or elicitations

I would recommend to go through the entire stack there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature Mate Issues & PRs about the AI Mate component Status: Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants