Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8a834c7
refactor: New SessionManager and Session to replace ClientManager and…
CodeWithKyrian Jun 5, 2025
ad0fe21
feat: add support for batch request processing
CodeWithKyrian Jun 5, 2025
bb32c09
refactor: Align MCP element definitions and content types with 2025-0…
CodeWithKyrian Jun 5, 2025
edd7dee
feat: added new StreamableHttpTransport with resumability
CodeWithKyrian Jun 6, 2025
771ac3c
refactor: Enhance session management and error handling
CodeWithKyrian Jun 7, 2025
5fb3036
refactor: simplify stream management in StreamableHttpServerTransport
CodeWithKyrian Jun 8, 2025
c274420
lint: Format project
CodeWithKyrian Jun 8, 2025
2f660d2
feat: Improve session garbage collection and new registry event system
CodeWithKyrian Jun 8, 2025
dc05ca6
feat(core): Integrate php-mcp/schema package for core DTOs and messages
CodeWithKyrian Jun 10, 2025
f49ff78
refactor: rename RequestHandler to Dispatcher for better semantic cla…
CodeWithKyrian Jun 10, 2025
a6fbb96
feat: Implement argument completion provider registration for MCP ele…
CodeWithKyrian Jun 10, 2025
74575ca
refactor: use Parser for JSON-RPC message parsing across transports
CodeWithKyrian Jun 12, 2025
b51fe79
fix: allow controlling the error code for POST error responses
CodeWithKyrian Jun 16, 2025
abfeb2c
refactor(core)!: Introduce RegisteredElement objects to encapsulate e…
CodeWithKyrian Jun 16, 2025
5b4fb27
feat: improve enum handling for unit enums when preparing element arg…
CodeWithKyrian Jun 17, 2025
f9ccb59
feat: use PSR20 ClockInterface for session handling
CodeWithKyrian Jun 18, 2025
348028b
feat(tests): Comprehensive test suite refactor and new integration tests
CodeWithKyrian Jun 18, 2025
7e029ca
chore: use VCS repository for schema
CodeWithKyrian Jun 18, 2025
c459d92
fix(tests): use dynamic port for http integration tests
CodeWithKyrian Jun 18, 2025
72f85f5
refactor(Protocol): streamline capability checks for server features
CodeWithKyrian Jun 18, 2025
951ec4a
feat: Enhance Schema attribute with comprehensive JSON Schema support
CodeWithKyrian Jun 19, 2025
d1771b9
lint: Format code using PHP CS Fixer
CodeWithKyrian Jun 19, 2025
20b630c
chore: Remove pest-plugin-drift dependency and adjust max-parallel se…
CodeWithKyrian Jun 19, 2025
c3ea065
chore: Add new example to showcase using the Schema Attribute
CodeWithKyrian Jun 19, 2025
ba62387
chore: use v1.0 for php-mcp/schema
CodeWithKyrian Jun 19, 2025
662eb31
refactor: simplify session and cache configuration API
CodeWithKyrian Jun 19, 2025
c9350f2
docs: comprehensive README update for 2025-03-26 protocol
CodeWithKyrian Jun 21, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
php: [8.1, 8.2, 8.3, 8.4]
max-parallel: 4
max-parallel: 2

name: Tests PHP${{ matrix.php }}

Expand Down
1,399 changes: 1,041 additions & 358 deletions README.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"require": {
"php": ">=8.1",
"opis/json-schema": "^2.4",
"php-mcp/schema": "^1.0",
"phpdocumentor/reflection-docblock": "^5.6",
"psr/clock": "^1.0",
"psr/container": "^1.0 || ^2.0",
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
"react/event-loop": "^1.5",
Expand All @@ -29,6 +30,7 @@
"mockery/mockery": "^1.6",
"pestphp/pest": "^2.36.0|^3.5.0",
"react/async": "^4.0",
"react/child-process": "^0.6.6",
"symfony/var-dumper": "^6.4.11|^7.1.5"
},
"suggest": {
Expand Down
17 changes: 12 additions & 5 deletions examples/02-discovery-http-userprofile/McpElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mcp\HttpUserProfileExample;

use PhpMcp\Server\Attributes\CompletionProvider;
use PhpMcp\Server\Attributes\McpPrompt;
use PhpMcp\Server\Attributes\McpResource;
use PhpMcp\Server\Attributes\McpResourceTemplate;
Expand Down Expand Up @@ -40,8 +41,11 @@ public function __construct(LoggerInterface $logger)
description: 'Get profile information for a specific user ID.',
mimeType: 'application/json'
)]
public function getUserProfile(string $userId): array
{

public function getUserProfile(
#[CompletionProvider(providerClass: UserIdCompletionProvider::class)]
string $userId
): array {
$this->logger->info('Reading resource: user profile', ['userId' => $userId]);
if (! isset($this->users[$userId])) {
// Throwing an exception that Processor can turn into an error response
Expand Down Expand Up @@ -87,7 +91,7 @@ public function sendWelcomeMessage(string $userId, ?string $customMessage = null
$user = $this->users[$userId];
$message = "Welcome, {$user['name']}!";
if ($customMessage) {
$message .= ' '.$customMessage;
$message .= ' ' . $customMessage;
}
// Simulate sending
$this->logger->info("Simulated sending message to {$user['email']}: {$message}");
Expand All @@ -105,8 +109,11 @@ public function sendWelcomeMessage(string $userId, ?string $customMessage = null
* @throws McpServerException If user not found.
*/
#[McpPrompt(name: 'generate_bio_prompt')]
public function generateBio(string $userId, string $tone = 'professional'): array
{
public function generateBio(
#[CompletionProvider(providerClass: UserIdCompletionProvider::class)]
string $userId,
string $tone = 'professional'
): array {
$this->logger->info('Executing prompt: generate_bio', ['userId' => $userId, 'tone' => $tone]);
if (! isset($this->users[$userId])) {
throw McpServerException::invalidParams("User not found for bio prompt: {$userId}");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Mcp\HttpUserProfileExample;

use PhpMcp\Server\Contracts\CompletionProviderInterface;
use PhpMcp\Server\Contracts\SessionInterface;

class UserIdCompletionProvider implements CompletionProviderInterface
{
public function getCompletions(string $currentValue, SessionInterface $session): array
{
$availableUserIds = ['101', '102', '103'];
$filteredUserIds = array_filter($availableUserIds, fn(string $userId) => str_contains($userId, $currentValue));

return $filteredUserIds;
}
}
18 changes: 9 additions & 9 deletions examples/02-discovery-http-userprofile/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
chdir(__DIR__);
require_once '../../vendor/autoload.php';
require_once 'McpElements.php';
require_once 'UserIdCompletionProvider.php';

use PhpMcp\Schema\ServerCapabilities;
use PhpMcp\Server\Defaults\BasicContainer;
use PhpMcp\Server\Server;
use PhpMcp\Server\Transports\HttpServerTransport;
use PhpMcp\Server\Transports\StreamableHttpServerTransport;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;

Expand All @@ -64,27 +67,24 @@ public function log($level, \Stringable|string $message, array $context = []): v

$server = Server::make()
->withServerInfo('HTTP User Profiles', '1.0.0')
->withCapabilities(ServerCapabilities::make(completions: true, logging: true))
->withLogger($logger)
->withContainer($container)
->build();

$server->discover(__DIR__, ['.']);

$transport = new HttpServerTransport(
host: '127.0.0.1',
port: 8080,
mcpPathPrefix: 'mcp'
);
$transport = new HttpServerTransport('127.0.0.1', 8080, 'mcp');
// $transport = new StreamableHttpServerTransport('127.0.0.1', 8080, 'mcp');

$server->listen($transport);

$logger->info('Server listener stopped gracefully.');
exit(0);

} catch (\Throwable $e) {
fwrite(STDERR, "[MCP SERVER CRITICAL ERROR]\n");
fwrite(STDERR, 'Error: '.$e->getMessage()."\n");
fwrite(STDERR, 'File: '.$e->getFile().':'.$e->getLine()."\n");
fwrite(STDERR, $e->getTraceAsString()."\n");
fwrite(STDERR, 'Error: ' . $e->getMessage() . "\n");
fwrite(STDERR, 'File: ' . $e->getFile() . ':' . $e->getLine() . "\n");
fwrite(STDERR, $e->getTraceAsString() . "\n");
exit(1);
}
6 changes: 4 additions & 2 deletions examples/06-custom-dependencies-stdio/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ public function log($level, \Stringable|string $message, array $context = []): v

$logger->info('Server listener stopped gracefully.');
exit(0);

} catch (\Throwable $e) {
fwrite(STDERR, "[MCP SERVER CRITICAL ERROR]\n".$e."\n");
fwrite(STDERR, "[MCP SERVER CRITICAL ERROR]\n");
fwrite(STDERR, 'Error: ' . $e->getMessage() . "\n");
fwrite(STDERR, 'File: ' . $e->getFile() . ':' . $e->getLine() . "\n");
fwrite(STDERR, $e->getTraceAsString() . "\n");
exit(1);
}
Loading