Skip to content

Commit 1b1fd20

Browse files
chr-hertelCodeWithKyrian
authored andcommitted
docs: add more about building servers and updating front readme
1 parent 3dcd2f7 commit 1b1fd20

File tree

3 files changed

+134
-24
lines changed

3 files changed

+134
-24
lines changed

README.md

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# MCP PHP SDK
22

3-
The official PHP SDK for Model Context Protocol (MCP). It provides a framework-agnostic API for implementing MCP servers in PHP.
3+
The official PHP SDK for Model Context Protocol (MCP). It provides a framework-agnostic API for implementing MCP servers
4+
and clients in PHP.
45

56
> [!IMPORTANT]
6-
> Currently, we are still in the process of merging [Symfony's MCP SDK](https://github.com/symfony/mcp-sdk) and
7-
> [PHP-MCP](https://github.com/php-mcp) components. Not all code paths are fully tested or complete, and this package
8-
> may still contain duplicate functionality or dead code.
7+
> Currently, the SDK is still in active development and not all components of the MCP specification are implemented.
98
>
109
> If you want to help us stabilize the SDK, please see the
1110
> [issue tracker](https://github.com/modelcontextprotocol/php-sdk/issues).
@@ -21,29 +20,17 @@ Until the first major release, this SDK is considered
2120
## 🚧 Roadmap
2221

2322
Features
24-
- [x] Bring back PHP-MCP examples
25-
- [x] Glue handler, registry and reference handlers
26-
- [x] Revive `ServerBuilder`
27-
- [x] Revive transports
28-
- [x] Streamable Transport https://github.com/modelcontextprotocol/php-sdk/issues/7
29-
- [ ] ~~Http/SSE-based Transport https://github.com/modelcontextprotocol/php-sdk/issues/8~~
30-
- [ ] Support pagination
31-
- [ ] Support Schema validation
32-
- [ ] Support multiple versions of the MCP specification https://github.com/modelcontextprotocol/php-sdk/issues/14
33-
- [ ] (Re-)Implement missing Notification & Request Handlers https://github.com/modelcontextprotocol/php-sdk/issues/9
23+
- [ ] Stabilize server component with all needed handlers and functional tests
24+
- [ ] Extend documentation, including integration pointer for popular frameworks
25+
- [ ] Implement Client component
26+
- [ ] Support multiple schema versions
3427

3528
## Installation
3629

3730
```bash
3831
composer require mcp/sdk
3932
```
4033

41-
Since this package has no tagged releases yet, it is required to extend your `composer.json`:
42-
```json
43-
"minimum-stability": "dev",
44-
"prefer-stable": true
45-
```
46-
4734
## ⚡ Quick Start: Stdio Server with Discovery
4835

4936
This example demonstrates the most common usage pattern - a `stdio` server using attribute discovery.
@@ -111,16 +98,19 @@ Add to your client configuration (e.g., `mcp.json`):
11198
Your AI assistant can now call:
11299
- `add_numbers` - Add two integers
113100

101+
For more examples, see the [examples directory](examples).
102+
114103
## Documentation
115104

116-
- [SDK documentation](doc/index.rst)
105+
- [SDK documentation](docs/index.md)
117106
- [Model Context Protocol documentation](https://modelcontextprotocol.io)
118107
- [Model Context Protocol specification](https://spec.modelcontextprotocol.io)
119108
- [Officially supported servers](https://github.com/modelcontextprotocol/servers)
120109

121-
## Examples of MCP Tools that use this SDK
110+
## PHP libraries using the MCP SDK
122111

123-
- https://github.com/pronskiy/mcp
112+
* https://github.com/pronskiy/mcp - additional DX layer
113+
* https://github.com/symfony/mcp-bundle - Symfony integration bundle
124114

125115
## Contributing
126116

@@ -130,7 +120,9 @@ the project. See the [contributing guide](CONTRIBUTING.md) to get started before
130120
[send pull requests](https://github.com/modelcontextprotocol/php-sdk/pulls).
131121

132122
## Credits
133-
The starting point for this SDK was the [PHP-MCP](https://github.com/php-mcp/server) project, initiated by [Kyrian Obikwelu](https://github.com/CodeWithKyrian). We are grateful for the work done by Kyrian and other contributors to that repository, which created a solid foundation for this SDK.
123+
Starting point for this SDK was the [PHP-MCP](https://github.com/php-mcp/server) project, initiated by
124+
[Kyrian Obikwelu](https://github.com/CodeWithKyrian), and the [Symfony AI initiative](https://github.com/symfony/ai).
125+
We are grateful for the work done by both projects and their contributors, which created a solid foundation for this SDK.
134126

135127
## License
136128

docs/index.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# MCP PHP SDK
2+
3+
To understand the basics of the Model Context Protocol (MCP), we highly recommend reading the main
4+
[MCP documentation](https://modelcontextprotocol.io) first.
5+
6+
## Building an MCP Server
7+
8+
This SDK provides a way to build an MCP server and wire it up with various capabilities implemented in your application.
9+
Therefore, we differentiate between the core server architecture and its extension points for registering MCP elements.
10+
11+
### Server Setup
12+
13+
The server needs to be configured with some basic information and the discovery of MCP elements. On top, you need to
14+
decide for a transport the server should be connected to, and in the end listen. Which is a long running process in the
15+
end.
16+
For easing the setup of a server, we provide a fluent builder interface:
17+
18+
**ServerBuilder**
19+
20+
```php
21+
use Mcp\Server\ServerBuilder;
22+
23+
$server = ServerBuilder::make()
24+
->setServerInfo('My Server', '1.0.0', 'A description of my server.')
25+
->setDiscovery(__DIR__, ['.']) // Scan current directory recursively for MCP elements
26+
->build();
27+
```
28+
There are more options available on the builder, see [Server Builder documentation](docs/server-builder.md) for details.
29+
30+
**Transport**
31+
32+
The transport is responsible for the communication between the server and the client. The SDK comes with two built-in
33+
transports: `StdioTransport` and `StreamableHttpTransport`.
34+
35+
```php
36+
use Mcp\Server\Transport\StdioTransport;
37+
38+
# STDIO Transport
39+
$transport = new StdioTransport();
40+
41+
# Streamable HTTP Transport
42+
$transport = new StreamableHttpTransport($request, $psr17Factory, $psr17Factory);
43+
44+
# Connect the transport to the server
45+
$server->connect(new StdioTransport());
46+
47+
# Start listening (blocking call)
48+
$server->listen();
49+
```
50+
51+
### Implementing MCP Elements
52+
53+
MCP elements are the building blocks of an MCP server. They implement the actual capabilities that can be called by
54+
the client. The SDK comes with a set of attributes and service classes for discovery, that make it handy to register
55+
your code as MCP elements.
56+
57+
```php
58+
final class MyServiceClass
59+
{
60+
#[McpTool('foo_bar', 'This is my Foo Bar tool.')]
61+
public function foo(string $bar): string
62+
{
63+
return sprintf('Foo %s', $bar);
64+
}
65+
}
66+
```
67+
68+
More about that can be found in the [Server Builder documentation](docs/server-builder.md).
69+
70+
## Building an MCP Client
71+
72+
Building an MCP Client is currently not supported by this SDK, but part of our roadmap.

docs/server-builder.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Server Builder
2+
3+
The `ServerBuilder` is an optional factory class, that makes it easier to create and configure a `Server` instance,
4+
including the registration of MCP elements/capabilities.
5+
6+
## Basic Server Configuration
7+
8+
There is a set of basic server configuration, that is required by the specification, and should always be set:
9+
* Name
10+
* Version
11+
* Description (optional)
12+
13+
This can be set via `setServerInfo`:
14+
```php
15+
$server = ServerBuilder::make()
16+
->setServerInfo('My MCP Server', '0.1')
17+
```
18+
19+
## Service Dependencies
20+
21+
All service dependencies are optional and if not set explicitly the builder defaults to skipping them or instantiating
22+
default implementations.
23+
24+
This includes
25+
* Logger, as an instance of `Psr\Log\LoggerInterface`
26+
* Container, as an instance of `Psr\Container\ContainerInterface`
27+
* and more.
28+
29+
```php
30+
$server = ServerBuilder::make()
31+
->setLogger($yourLogger)
32+
->setContainer($yourContainer)
33+
```
34+
35+
## Register Capabilities
36+
37+
There are two ways of registering MCP elements as capabilities on your server: automated discovery based on file system
38+
& PHP attributes, and adding them explicitly.
39+
40+
### Discovery
41+
42+
TODO, incl. caching
43+
44+
### Explicit Registration
45+
46+
TODO

0 commit comments

Comments
 (0)