Skip to content

Commit 504cdce

Browse files
committed
minor #2 Add readme and license headers (Nyholm, chr-hertel)
This PR was merged into the main branch. Discussion ---------- Add readme and license headers | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | yes | Issues | | License | MIT Commits ------- 726ef9a refactor: switch to Symfony AI namespace da16b7c add readme and license headers
2 parents 1741c85 + 726ef9a commit 504cdce

File tree

74 files changed

+1093
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1093
-336
lines changed

.doctor-rst.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
rules:
2+
american_english: ~
3+
argument_variable_must_match_type: ~
4+
avoid_repetetive_words: ~
5+
# be_kind_to_newcomers: ~
6+
blank_line_after_anchor: ~
7+
# blank_line_after_colon: ~
8+
blank_line_after_directive: ~
9+
# blank_line_after_filepath_in_code_block: ~
10+
# blank_line_after_filepath_in_php_code_block: ~
11+
# blank_line_after_filepath_in_twig_code_block: ~
12+
# blank_line_after_filepath_in_xml_code_block: ~
13+
# blank_line_after_filepath_in_yaml_code_block: ~
14+
blank_line_before_directive: ~
15+
# composer_dev_option_at_the_end: ~
16+
composer_dev_option_not_at_the_end: ~
17+
correct_code_block_directive_based_on_the_content: ~
18+
deprecated_directive_major_version:
19+
major_version: 2
20+
deprecated_directive_min_version:
21+
min_version: '2.0'
22+
deprecated_directive_should_have_version: ~
23+
ensure_bash_prompt_before_composer_command: ~
24+
ensure_exactly_one_space_before_directive_type: ~
25+
ensure_exactly_one_space_between_link_definition_and_link: ~
26+
ensure_link_definition_contains_valid_url: ~
27+
ensure_order_of_code_blocks_in_configuration_block: ~
28+
extend_abstract_admin: ~
29+
extend_abstract_controller: ~
30+
# extend_controller: ~
31+
extension_xlf_instead_of_xliff: ~
32+
# filename_uses_dashes_only: ~
33+
# filename_uses_underscores_only: ~
34+
final_admin_classes: ~
35+
final_admin_extension_classes: ~
36+
forbidden_directives:
37+
directives:
38+
- '.. index::'
39+
indention: ~
40+
kernel_instead_of_app_kernel: ~
41+
# line_length: ~
42+
lowercase_as_in_use_statements: ~
43+
max_blank_lines:
44+
max: 2
45+
max_colons: ~
46+
no_admin_yaml: ~
47+
no_app_bundle: ~
48+
no_app_console: ~
49+
# no_bash_prompt: ~
50+
no_blank_line_after_filepath_in_code_block: ~
51+
no_blank_line_after_filepath_in_php_code_block: ~
52+
no_blank_line_after_filepath_in_twig_code_block: ~
53+
no_blank_line_after_filepath_in_xml_code_block: ~
54+
no_blank_line_after_filepath_in_yaml_code_block: ~
55+
no_brackets_in_method_directive: ~
56+
no_composer_phar: ~
57+
no_composer_req: ~
58+
no_config_yaml: ~
59+
# no_contraction: ~
60+
no_directive_after_shorthand: ~
61+
no_explicit_use_of_code_block_php: ~
62+
no_inheritdoc_in_code_examples: ~
63+
no_merge_conflict: ~
64+
no_namespace_after_use_statements: ~
65+
no_php_open_tag_in_code_block_php_directive: ~
66+
# no_php_prefix_before_bin_console: ~
67+
# no_php_prefix_before_composer: ~
68+
# no_space_before_self_xml_closing_tag: ~
69+
only_backslashes_in_namespace_in_php_code_block: ~
70+
only_backslashes_in_use_statements_in_php_code_block: ~
71+
ordered_use_statements: ~
72+
# php_open_tag_in_code_block_php_directive: ~
73+
php_prefix_before_bin_console: ~
74+
replace_code_block_types: ~
75+
replacement: ~
76+
short_array_syntax: ~
77+
# space_before_self_xml_closing_tag: ~
78+
space_between_label_and_link_in_doc: ~
79+
space_between_label_and_link_in_ref: ~
80+
string_replacement: ~
81+
title_underline_length_must_match_title_length: ~
82+
typo: ~
83+
unused_links: ~
84+
use_deprecated_directive_instead_of_versionadded: ~
85+
use_https_xsd_urls: ~
86+
# use_named_constructor_without_new_keyword_rule: ~
87+
valid_inline_highlighted_namespaces: ~
88+
valid_use_statements: ~
89+
versionadded_directive_major_version:
90+
major_version: 2
91+
versionadded_directive_min_version:
92+
min_version: '2.0'
93+
versionadded_directive_should_have_version: ~
94+
yaml_instead_of_yml_suffix: ~
95+
yarn_dev_option_at_the_end: ~
96+
# yarn_dev_option_not_at_the_end: ~

.php-cs-fixer.dist.php

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,54 @@
11
<?php
22

3-
$finder = (new PhpCsFixer\Finder())
4-
->in('src')
5-
->exclude(['var', 'vendor'])
6-
;
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Symfony package.
7+
*
8+
* (c) Fabien Potencier <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
if (!file_exists(__DIR__.'/src')) {
15+
exit(0);
16+
}
17+
18+
$fileHeaderParts = [
19+
<<<'EOF'
20+
This file is part of the Symfony package.
21+
22+
(c) Fabien Potencier <[email protected]>
23+
24+
EOF,
25+
<<<'EOF'
26+
27+
For the full copyright and license information, please view the LICENSE
28+
file that was distributed with this source code.
29+
EOF,
30+
];
731

832
return (new PhpCsFixer\Config())
33+
// @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7777
34+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
935
->setRules([
36+
'@PHP71Migration' => true,
37+
'@PHPUnit75Migration:risky' => true,
1038
'@Symfony' => true,
39+
'@Symfony:risky' => true,
40+
'protected_to_private' => false,
41+
'declare_strict_types' => true,
42+
'header_comment' => [
43+
'header' => implode('', $fileHeaderParts),
44+
],
1145
])
12-
->setFinder($finder)
46+
->setRiskyAllowed(true)
47+
->setFinder(
48+
(new PhpCsFixer\Finder())
49+
->in(__DIR__.'/src')
50+
->append([__FILE__])
51+
->notPath('#/Fixtures/#')
52+
)
53+
->setCacheFile('.php-cs-fixer.cache')
1354
;

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Contributing
2+
------------
3+
4+
Symfony is an open source, community-driven project.
5+
6+
If you'd like to contribute, please read the following documents:
7+
8+
* [Reviewing issues/pull requests][0]
9+
* [Reporting a Bug][1]
10+
* [Submitting a Patch][2]
11+
* [Symfony Core Team][3]
12+
* [Security Issues][4]
13+
* [Running Symfony Tests][5]
14+
* [Our Backwards Compatibility Promise][6]
15+
* [Coding Standards][7]
16+
* [Conventions][8]
17+
18+
[0]: https://symfony.com/doc/current/contributing/community/reviews.html
19+
[1]: https://symfony.com/doc/current/contributing/code/bugs.html
20+
[2]: https://symfony.com/doc/current/contributing/code/patches.html
21+
[3]: https://symfony.com/doc/current/contributing/code/core_team.html
22+
[4]: https://symfony.com/doc/current/contributing/code/security.html
23+
[5]: https://symfony.com/doc/current/contributing/code/tests.html
24+
[6]: https://symfony.com/doc/current/contributing/code/bc.html
25+
[7]: https://symfony.com/doc/current/contributing/code/standards.html
26+
[8]: https://symfony.com/doc/current/contributing/code/conventions.html

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<p align="center"><a href="https://symfony.com" target="_blank">
2+
<img src="https://symfony.com/logos/symfony_dynamic_01.svg" alt="Symfony Logo">
3+
</a></p>
4+
5+
<h3 align="center">
6+
Symfony AI
7+
</h3>
8+
9+
Symfony AI is a set of packages that integrate AI capabilities into PHP applications.
10+
11+
## Sponsor
12+
13+
Help Symfony by [sponsoring][2] its development!
14+
15+
## Contributing
16+
17+
Thank you for considering contributing to Symfony AI! You can find the [contribution guide here](CONTRIBUTING.md).
18+
19+
[1]: https://symfony.com/backers
20+
[2]: https://symfony.com/sponsor

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"require-dev": {
88
"php": ">=8.1",
99
"symfony/filesystem": "^6.4|^7.0",
10-
"symfony/finder": "^6.4|^7.0"
10+
"symfony/finder": "^6.4|^7.0",
11+
"php-cs-fixer/shim": "^3.75"
1112
}
1213
}

src/mcp-sdk/README.md

Lines changed: 14 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,26 @@
1-
# Model Context Protocol PHP SDK [WIP]
1+
# Model Context Protocol PHP SDK
22

33
Model Context Protocol SDK for Client and Server applications in PHP.
4-
**Currently only support Tool Calls as Server via Server-Sent Events (SSE) and STDIO.**
5-
6-
See [Demo App](https://github.com/php-llm/mcp-demo) for a working example and [MCP Bundle](https://github.com/php-llm/mcp-bundle) for Symfony integration.
74

85
## Installation
96

107
```bash
11-
composer require php-llm/mcp-sdk
12-
```
13-
14-
## Usage with Symfony
15-
16-
Server integration points for are tailored to Symfony Console and HttpFoundation (Laravel compatible).
17-
18-
### Console Command for STDIO Server
19-
20-
```php
21-
namespace App\Command;
22-
23-
use PhpLlm\McpSdk\Server;
24-
use PhpLlm\McpSdk\Server\Transport\Stdio\SymfonyConsoleTransport;
25-
use Symfony\Component\Console\Attribute\AsCommand;
26-
use Symfony\Component\Console\Command\Command;
27-
use Symfony\Component\Console\Input\InputInterface;
28-
use Symfony\Component\Console\Output\OutputInterface;
29-
30-
#[AsCommand('mcp', 'Starts an MCP server')]
31-
final class McpCommand extends Command
32-
{
33-
public function __construct(
34-
private readonly Server $server,
35-
) {
36-
parent::__construct();
37-
}
38-
39-
protected function execute(InputInterface $input, OutputInterface $output): int
40-
{
41-
$this->server->connect(
42-
new SymfonyConsoleTransport($input, $output)
43-
);
44-
45-
return Command::SUCCESS;
46-
}
47-
}
8+
composer require symfony/mcp-sdk
489
```
4910

50-
### Controller for Server-Sent Events Server
11+
This is a low level SDK that implements the [Model Context Protocol](https://modelcontextprotocol.io/)
12+
(MCP). The protocol is used by LLM model to build "plugins" and give them extra
13+
context. Example the logged in users' latest order.
5114

52-
```php
53-
namespace App\Controller;
15+
**This repository is a READ-ONLY sub-tree split**. See
16+
https://github.com/symfony/ai to create issues or submit pull requests.
5417

55-
use PhpLlm\McpSdk\Server;
56-
use PhpLlm\McpSdk\Server\Transport\Sse\Store\CachePoolStore;
57-
use PhpLlm\McpSdk\Server\Transport\Sse\StreamTransport;
58-
use Symfony\Component\HttpFoundation\Request;
59-
use Symfony\Component\HttpFoundation\Response;
60-
use Symfony\Component\HttpFoundation\StreamedResponse;
61-
use Symfony\Component\HttpKernel\Attribute\AsController;
62-
use Symfony\Component\Routing\Attribute\Route;
63-
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
64-
use Symfony\Component\Uid\Uuid;
18+
## Resources
6519

66-
#[AsController]
67-
#[Route('/mcp', name: 'mcp_')]
68-
final readonly class McpController
69-
{
70-
public function __construct(
71-
private Server $server,
72-
private CachePoolStore $store,
73-
private UrlGeneratorInterface $urlGenerator,
74-
) {
75-
}
20+
- [Documentation](doc/index.rst)
21+
- [Report issues](https://github.com/symfony/ai/issues) and
22+
[send Pull Requests](https://github.com/symfony/ai/pulls)
23+
in the [main Symfony AI repository](https://github.com/symfony/ai)
7624

77-
#[Route('/sse', name: 'sse', methods: ['GET'])]
78-
public function sse(): StreamedResponse
79-
{
80-
$id = Uuid::v4();
81-
$endpoint = $this->urlGenerator->generate('mcp_messages', ['id' => $id], UrlGeneratorInterface::ABSOLUTE_URL);
82-
$transport = new StreamTransport($endpoint, $this->store, $id);
83-
84-
return new StreamedResponse(fn() => $this->server->connect($transport), headers: [
85-
'Content-Type' => 'text/event-stream',
86-
'Cache-Control' => 'no-cache',
87-
'X-Accel-Buffering' => 'no',
88-
]);
89-
}
90-
91-
#[Route('/messages/{id}', name: 'messages', methods: ['POST'])]
92-
public function messages(Request $request, Uuid $id): Response
93-
{
94-
$this->store->push($id, $request->getContent());
95-
96-
return new Response();
97-
}
98-
}
99-
```
100-
101-
### Exposing Tools
102-
103-
Under the hood the SDK uses [LLM Chain](https://github.com/php-llm/llm-chain)'s `ToolBox` to register, analyze and
104-
execute tools. In combination with its [Symfony Bundle](https://github.com/php-llm/llm-chain-bundle) you can expose
105-
tools with `#[AsTool]` attribute.
106-
107-
```php
108-
use PhpLlm\LlmChain\ToolBox\Attribute\AsTool;
109-
110-
#[AsTool('company_name', 'Provides the name of your company')]
111-
final class CompanyName
112-
{
113-
public function __invoke(): string
114-
{
115-
return 'ACME Corp.'
116-
}
117-
}
118-
```
119-
See [LLM Chain Documentation](https://github.com/php-llm/llm-chain?tab=readme-ov-file#tools) for more information.
25+
[1]: https://symfony.com/backers
26+
[3]: https://symfony.com/sponsor

src/mcp-sdk/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "php-llm/mcp-sdk",
2+
"name": "symfony/mcp-sdk",
33
"type": "library",
44
"description": "Model Context Protocol SDK for Client and Server applications in PHP",
55
"license": "MIT",
@@ -31,12 +31,12 @@
3131
},
3232
"autoload": {
3333
"psr-4": {
34-
"PhpLlm\\McpSdk\\": "src/"
34+
"Symfony\\AI\\McpSdk\\": "src/"
3535
}
3636
},
3737
"autoload-dev": {
3838
"psr-4": {
39-
"PhpLlm\\McpSdk\\Tests\\": "tests/"
39+
"Symfony\\AI\\McpSdk\\Tests\\": "tests/"
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)