Skip to content

MCP Demo #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,32 @@ docker compose exec app bin/console app:blog:query
* The UI is coupled to a [Twig LiveComponent](https://symfony.com/bundles/ux-live-component/current/index.html), that integrates different `Chat` implementations on top of the user's session.
* You can reset the chat context by hitting the `Reset` button in the top right corner.
* You find three different usage scenarios in the upper navbar.

### MCP

Demo MCP server added with a `current-time` tool to return the current time, with an optional format string.

To add the server, add the following configuration to your MCP Client's settings, e.g. your IDE:
```json
{
"servers": {
"symfony": {
"command": "php",
"args": [
"/your/full/path/to/bin/console",
"mcp:server"
]
}
}
}
```

#### Testing the MCP Server

You can test the MCP server by running the following command to start the MCP client:

```shell
php bin/console mcp:server
```

Then, paste `{"method":"tools/list","jsonrpc":"2.0","id":1}` to list the tools available on the MCP server.
1 change: 1 addition & 0 deletions demo/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"symfony/flex": "^2.5",
"symfony/framework-bundle": "7.3.*",
"symfony/http-client": "7.3.*",
"symfony/mcp-bundle": "@dev",
"symfony/monolog-bundle": "^3.10",
"symfony/runtime": "7.3.*",
"symfony/twig-bundle": "7.3.*",
Expand Down
166 changes: 151 additions & 15 deletions demo/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions demo/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
Symfony\UX\Icons\UXIconsBundle::class => ['all' => true],
Symfony\UX\Typed\TypedBundle::class => ['all' => true],
Symfony\AI\AIBundle\AIBundle::class => ['all' => true],
Symfony\AI\McpBundle\McpBundle::class => ['all' => true],
];
5 changes: 5 additions & 0 deletions demo/config/packages/mcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mcp:
app: demo-app
version: 0.0.1
client_transports:
stdio: true
8 changes: 8 additions & 0 deletions demo/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ services:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'

Symfony\AI\McpSdk\Capability\Tool\ToolExecutorInterface:
class: Symfony\AI\McpSdk\Capability\ToolChain
arguments:
- ['@App\MCP\Tools\CurrentTimeTool']
Copy link
Contributor

Choose a reason for hiding this comment

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

Off topic, but it would be nice if this is configurable via the bundle config

cc @Nyholm

Copy link
Author

@TomHart TomHart Jul 19, 2025

Choose a reason for hiding this comment

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

Can you pass a service reference in bundle config? E.g.

mcp:
  tools:
    - '@App\MCP\Tools\CurrentTimeTool'

Would a tag + compiler pass perhaps be a cleaner way of doing this?

  App\MCP\Tools\CurrentTimeTool:
    tags:
      - { name: mcp_tool_executor }
      - { name: mcp_tool_metadata }

or just name: mcp_tool


Symfony\AI\McpSdk\Capability\Tool\CollectionInterface:
alias: Symfony\AI\McpSdk\Capability\Tool\ToolExecutorInterface
57 changes: 57 additions & 0 deletions demo/src/MCP/Tools/CurrentTimeTool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\MCP\Tools;

use Symfony\AI\McpSdk\Capability\Tool\MetadataInterface;
use Symfony\AI\McpSdk\Capability\Tool\ToolCall;
use Symfony\AI\McpSdk\Capability\Tool\ToolCallResult;
use Symfony\AI\McpSdk\Capability\Tool\ToolExecutorInterface;

/**
* @author Tom Hart <[email protected]>
*/
class CurrentTimeTool implements MetadataInterface, ToolExecutorInterface
{
public function call(ToolCall $input): ToolCallResult
{
$format = $input->arguments['format'] ?? 'Y-m-d H:i:s';

return new ToolCallResult(
(new \DateTime('now', new \DateTimeZone('UTC')))->format($format)
);
}

public function getName(): string
{
return 'current-time';
}

public function getDescription(): string
{
return 'Returns the current time in UTC';
}

public function getInputSchema(): array
{
return [
'type' => 'object',
'properties' => [
'format' => [
'type' => 'string',
'description' => 'The format of the time, e.g. "Y-m-d H:i:s"',
'default' => 'Y-m-d H:i:s',
],
],
'required' => ['format'],
];
}
}
3 changes: 3 additions & 0 deletions demo/symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
"src/Kernel.php"
]
},
"symfony/mcp-bundle": {
"version": "dev-main"
},
"symfony/monolog-bundle": {
"version": "3.10",
"recipe": {
Expand Down