Skip to content

Commit 399369f

Browse files
MCP Demo
Addressed comments lint Apply suggestion from @chr-hertel Co-authored-by: Christopher Hertel <[email protected]> revert .gitignore Addressed comments revert README for testing Update demo/README.md Co-authored-by: Oskar Stark <[email protected]> Update demo/README.md Co-authored-by: Oskar Stark <[email protected]> Update demo/README.md Co-authored-by: Christopher Hertel <[email protected]>
1 parent d15c375 commit 399369f

File tree

8 files changed

+255
-15
lines changed

8 files changed

+255
-15
lines changed

demo/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,32 @@ docker compose exec app bin/console app:blog:query
9090
* 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.
9191
* You can reset the chat context by hitting the `Reset` button in the top right corner.
9292
* You find three different usage scenarios in the upper navbar.
93+
94+
### MCP
95+
96+
Demo MCP server added with a `current-time` tool to return the current time, with an optional format string.
97+
98+
To add the server, add the following configuration to your MCP Client's settings, e.g. your IDE:
99+
```json
100+
{
101+
"servers": {
102+
"symfony": {
103+
"command": "php",
104+
"args": [
105+
"/your/full/path/to/bin/console",
106+
"mcp:server"
107+
]
108+
}
109+
}
110+
}
111+
```
112+
113+
#### Testing the MCP Server
114+
115+
You can test the MCP server by running the following command to start the MCP client:
116+
117+
```shell
118+
php bin/console mcp:server
119+
```
120+
121+
Then, paste `{"method":"tools/list","jsonrpc":"2.0","id":1}` to list the tools available on the MCP server.

demo/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"symfony/flex": "^2.5",
2626
"symfony/framework-bundle": "7.3.*",
2727
"symfony/http-client": "7.3.*",
28+
"symfony/mcp-bundle": "@dev",
2829
"symfony/monolog-bundle": "^3.10",
2930
"symfony/runtime": "7.3.*",
3031
"symfony/twig-bundle": "7.3.*",

demo/composer.lock

Lines changed: 151 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/config/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
Symfony\UX\Icons\UXIconsBundle::class => ['all' => true],
2424
Symfony\UX\Typed\TypedBundle::class => ['all' => true],
2525
Symfony\AI\AIBundle\AIBundle::class => ['all' => true],
26+
Symfony\AI\McpBundle\McpBundle::class => ['all' => true],
2627
];

demo/config/packages/mcp.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mcp:
2+
app: demo-app
3+
version: 0.0.1
4+
client_transports:
5+
stdio: true

demo/config/services.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ services:
1818
- '../src/DependencyInjection/'
1919
- '../src/Entity/'
2020
- '../src/Kernel.php'
21+
22+
Symfony\AI\McpSdk\Capability\Tool\ToolExecutorInterface:
23+
class: Symfony\AI\McpSdk\Capability\ToolChain
24+
arguments:
25+
- ['@App\MCP\Tools\CurrentTimeTool']
26+
27+
Symfony\AI\McpSdk\Capability\Tool\CollectionInterface:
28+
alias: Symfony\AI\McpSdk\Capability\Tool\ToolExecutorInterface
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace App\MCP\Tools;
13+
14+
use Symfony\AI\McpSdk\Capability\Tool\MetadataInterface;
15+
use Symfony\AI\McpSdk\Capability\Tool\ToolCall;
16+
use Symfony\AI\McpSdk\Capability\Tool\ToolCallResult;
17+
use Symfony\AI\McpSdk\Capability\Tool\ToolExecutorInterface;
18+
19+
/**
20+
* @author Tom Hart <[email protected]>
21+
*/
22+
class CurrentTimeTool implements MetadataInterface, ToolExecutorInterface
23+
{
24+
public function call(ToolCall $input): ToolCallResult
25+
{
26+
$format = $input->arguments['format'] ?? 'Y-m-d H:i:s';
27+
28+
return new ToolCallResult(
29+
(new \DateTime('now', new \DateTimeZone('UTC')))->format($format)
30+
);
31+
}
32+
33+
public function getName(): string
34+
{
35+
return 'current-time';
36+
}
37+
38+
public function getDescription(): string
39+
{
40+
return 'Returns the current time in UTC';
41+
}
42+
43+
public function getInputSchema(): array
44+
{
45+
return [
46+
'type' => 'object',
47+
'properties' => [
48+
'format' => [
49+
'type' => 'string',
50+
'description' => 'The format of the time, e.g. "Y-m-d H:i:s"',
51+
'default' => 'Y-m-d H:i:s',
52+
],
53+
],
54+
'required' => ['format'],
55+
];
56+
}
57+
}

demo/symfony.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
"src/Kernel.php"
135135
]
136136
},
137+
"symfony/mcp-bundle": {
138+
"version": "dev-main"
139+
},
137140
"symfony/monolog-bundle": {
138141
"version": "3.10",
139142
"recipe": {

0 commit comments

Comments
 (0)