-
-
Notifications
You must be signed in to change notification settings - Fork 57
[MCP SDK] Add server capabilities toSymfony\AI\McpSdk\Server\RequestHandler\InitializeHandler
#305
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
Open
ineersa
wants to merge
7
commits into
symfony:main
Choose a base branch
from
ineersa:capabilities-and-initialize-handler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+459
−26
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
21d731c
InitializeHandler and capabilities
ineersa ab299d8
PHPStan fixes
ineersa 53639d5
Fabbot fixes
ineersa 88cbfda
Fabbot turn off for push
ineersa 8a874f5
Removed unnecessary comments
ineersa 6c553a9
Code review fixes, removed suffix
ineersa 2a024f1
Code review fixes, cs-fixer with proper config
ineersa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/mcp-sdk/src/Capability/Completion/CompletionCapability.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?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 Symfony\AI\McpSdk\Capability\Completion; | ||
|
||
/** | ||
* Present if the server supports argument autocompletion suggestions. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-completions | ||
*/ | ||
final class CompletionCapability | ||
{ | ||
public function __construct( | ||
) { | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?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 Symfony\AI\McpSdk\Capability\Logging; | ||
|
||
/** | ||
* Present if the server supports sending log messages to the client. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-logging | ||
*/ | ||
final class LoggingCapability | ||
{ | ||
public function __construct( | ||
) { | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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 Symfony\AI\McpSdk\Capability\Prompt; | ||
|
||
/** | ||
* Present if the server offers any prompt templates. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-logging | ||
*/ | ||
final readonly class PromptCapability | ||
{ | ||
public function __construct( | ||
/** Whether this server supports notifications for changes to the prompt list. */ | ||
public ?bool $listChanged = null, | ||
) { | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/mcp-sdk/src/Capability/Resource/ResourceCapability.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?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 Symfony\AI\McpSdk\Capability\Resource; | ||
|
||
/** | ||
* Present if the server offers any resources to read. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-resources | ||
*/ | ||
final readonly class ResourceCapability | ||
{ | ||
public function __construct( | ||
/** Whether this server supports notifications for changes to the resource list. */ | ||
public ?bool $subscribe = null, | ||
/** Whether this server supports subscribing to resource updates. */ | ||
public ?bool $listChanged = null, | ||
) { | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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 Symfony\AI\McpSdk\Capability\Server; | ||
|
||
/** | ||
* Describes the name and version of an MCP implementation, with an optional title for UI representation. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#implementation | ||
*/ | ||
final readonly class Implementation | ||
{ | ||
public function __construct( | ||
public string $name = 'app', | ||
public string $version = 'dev', | ||
) { | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?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 Symfony\AI\McpSdk\Capability\Server; | ||
|
||
enum ProtocolVersion: string | ||
{ | ||
case V2024_11_05 = '2024-11-05'; | ||
case V2025_03_26 = '2025-03-26'; | ||
case V2025_06_18 = '2025-06-18'; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?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 Symfony\AI\McpSdk\Capability\Server; | ||
|
||
use Symfony\AI\McpSdk\Capability\Completion\CompletionCapability; | ||
use Symfony\AI\McpSdk\Capability\Logging\LoggingCapability; | ||
use Symfony\AI\McpSdk\Capability\Prompt\PromptCapability; | ||
use Symfony\AI\McpSdk\Capability\Resource\ResourceCapability; | ||
use Symfony\AI\McpSdk\Capability\Tool\ToolCapability; | ||
|
||
/** | ||
* Capabilities that a server may support. Known capabilities are defined here, in this schema, | ||
* but this is not a closed set: any server can define its own, additional capabilities. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities | ||
*/ | ||
final readonly class ServerCapabilities implements \JsonSerializable | ||
{ | ||
/** | ||
* @param array<string, array<string, mixed>>|null $experimental | ||
*/ | ||
public function __construct( | ||
/** | ||
* Present if the server supports sending log messages to the client. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-logging | ||
*/ | ||
public ?LoggingCapability $logging = null, | ||
/** | ||
* Present if the server offers any prompt templates. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-prompts | ||
*/ | ||
public ?PromptCapability $prompts = null, | ||
/** | ||
* Present if the server offers any resources to read. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-resources | ||
*/ | ||
public ?ResourceCapability $resources = null, | ||
/** | ||
* Present if the server offers any tools to call. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-tools | ||
*/ | ||
public ?ToolCapability $tools = null, | ||
/** | ||
* Present if the server supports argument autocompletion suggestions. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-completions | ||
*/ | ||
public ?CompletionCapability $completions = null, | ||
/** | ||
* @var array<string, array<string, mixed>>|null | ||
*/ | ||
public ?array $experimental = null, | ||
) { | ||
} | ||
|
||
/** | ||
* @return array{ | ||
* logging?: LoggingCapability, | ||
* prompts?: PromptCapability, | ||
* resources?: ResourceCapability, | ||
* tools?: ToolCapability, | ||
* completions?: CompletionCapability, | ||
* experimental?: array<string, array<string, mixed>> | ||
* } | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return array_filter((array) $this, fn ($value) => null !== $value); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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 Symfony\AI\McpSdk\Capability\Tool; | ||
|
||
/** | ||
* Present if the server offers any tools to call. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/schema#servercapabilities-tools | ||
*/ | ||
final readonly class ToolCapability | ||
{ | ||
public function __construct( | ||
/** Whether this server supports notifications for changes to the tool list. */ | ||
public ?bool $listChanged = null, | ||
) { | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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 Symfony\AI\McpSdk\Field; | ||
|
||
/** | ||
* The _meta property/parameter is reserved by MCP to allow clients and servers to attach additional metadata to their interactions. Certain key names are reserved by MCP for protocol-level metadata, as specified below; implementations MUST NOT make assumptions about values at these keys. Additionally, definitions in the schema may reserve particular names for purpose-specific metadata, as declared in those definitions. Key name format: valid _meta key names have two segments: an optional prefix, and a name. Prefix: | ||
* | ||
* If specified, MUST be a series of labels separated by dots (.), followed by a slash (/). | ||
* Labels MUST start with a letter and end with a letter or digit; interior characters can be letters, digits, or hyphens (-). | ||
* Any prefix beginning with zero or more valid labels, followed by modelcontextprotocol or mcp, followed by any valid label, is reserved for MCP use. | ||
* For example: modelcontextprotocol.io/, mcp.dev/, api.modelcontextprotocol.org/, and tools.mcp.com/ are all reserved. | ||
* | ||
* Name: | ||
* | ||
* Unless empty, MUST begin and end with an alphanumeric character ([a-z0-9A-Z]). | ||
* MAY contain hyphens (-), underscores (_), dots (.), and alphanumerics in between. | ||
* | ||
* @see https://modelcontextprotocol.io/specification/2025-06-18/basic/index#general-fields | ||
*/ | ||
final readonly class MetaField | ||
{ | ||
/** | ||
* @param array<string, mixed> $meta | ||
*/ | ||
public function __construct( | ||
public array $meta, | ||
) { | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look nice, ideally it would be better to use centralized solution in
\Symfony\AI\McpSdk\Message\Response::jsonSerialize
.Serializer with
AbstractObjectNormalizer::SKIP_NULL_VALUES
would fit perfectly, but it's not in dependencies list.