[Server] Use getDescription to get all descriptions. (#188)

* Remove `getSummary` method and update descriptions in snapshots and code

* Add changelog entry

---------

Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
This commit is contained in:
落月 2026-01-12 05:08:05 +08:00 • committed by GitHub
commit 2c16b3e084
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 16 additions and 42 deletions

View file

@ -9,6 +9,7 @@ All notable changes to `mcp/sdk` will be documented in this file.
* Add validation of the input parameters given to a Tool. * Add validation of the input parameters given to a Tool.
* Rename `Mcp\Capability\Registry\ResourceReference::$schema` to `Mcp\Capability\Registry\ResourceReference::$resource`. * Rename `Mcp\Capability\Registry\ResourceReference::$schema` to `Mcp\Capability\Registry\ResourceReference::$resource`.
* Introduce `SchemaGeneratorInterface` and `DiscovererInterface` to allow custom schema generation and discovery implementations. * Introduce `SchemaGeneratorInterface` and `DiscovererInterface` to allow custom schema generation and discovery implementations.
* Remove `DocBlockParser::getSummary()` method, use `DocBlockParser::getDescription()` instead.
0.2.2 0.2.2
----- -----

View file

@ -222,7 +222,7 @@ final class Discoverer implements DiscovererInterface
case McpTool::class: case McpTool::class:
$docBlock = $this->docBlockParser->parseDocBlock($method->getDocComment() ?? null); $docBlock = $this->docBlockParser->parseDocBlock($method->getDocComment() ?? null);
$name = $instance->name ?? ('__invoke' === $methodName ? $classShortName : $methodName); $name = $instance->name ?? ('__invoke' === $methodName ? $classShortName : $methodName);
$description = $instance->description ?? $this->docBlockParser->getSummary($docBlock) ?? null; $description = $instance->description ?? $this->docBlockParser->getDescription($docBlock) ?? null;
$inputSchema = $this->schemaGenerator->generate($method); $inputSchema = $this->schemaGenerator->generate($method);
$outputSchema = $this->schemaGenerator->generateOutputSchema($method); $outputSchema = $this->schemaGenerator->generateOutputSchema($method);
$tool = new Tool( $tool = new Tool(
@ -241,7 +241,7 @@ final class Discoverer implements DiscovererInterface
case McpResource::class: case McpResource::class:
$docBlock = $this->docBlockParser->parseDocBlock($method->getDocComment() ?? null); $docBlock = $this->docBlockParser->parseDocBlock($method->getDocComment() ?? null);
$name = $instance->name ?? ('__invoke' === $methodName ? $classShortName : $methodName); $name = $instance->name ?? ('__invoke' === $methodName ? $classShortName : $methodName);
$description = $instance->description ?? $this->docBlockParser->getSummary($docBlock) ?? null; $description = $instance->description ?? $this->docBlockParser->getDescription($docBlock) ?? null;
$resource = new Resource( $resource = new Resource(
$instance->uri, $instance->uri,
$name, $name,
@ -260,7 +260,7 @@ final class Discoverer implements DiscovererInterface
case McpPrompt::class: case McpPrompt::class:
$docBlock = $this->docBlockParser->parseDocBlock($method->getDocComment() ?? null); $docBlock = $this->docBlockParser->parseDocBlock($method->getDocComment() ?? null);
$name = $instance->name ?? ('__invoke' === $methodName ? $classShortName : $methodName); $name = $instance->name ?? ('__invoke' === $methodName ? $classShortName : $methodName);
$description = $instance->description ?? $this->docBlockParser->getSummary($docBlock) ?? null; $description = $instance->description ?? $this->docBlockParser->getDescription($docBlock) ?? null;
$arguments = []; $arguments = [];
$paramTags = $this->docBlockParser->getParamTags($docBlock); $paramTags = $this->docBlockParser->getParamTags($docBlock);
foreach ($method->getParameters() as $param) { foreach ($method->getParameters() as $param) {
@ -280,7 +280,7 @@ final class Discoverer implements DiscovererInterface
case McpResourceTemplate::class: case McpResourceTemplate::class:
$docBlock = $this->docBlockParser->parseDocBlock($method->getDocComment() ?? null); $docBlock = $this->docBlockParser->parseDocBlock($method->getDocComment() ?? null);
$name = $instance->name ?? ('__invoke' === $methodName ? $classShortName : $methodName); $name = $instance->name ?? ('__invoke' === $methodName ? $classShortName : $methodName);
$description = $instance->description ?? $this->docBlockParser->getSummary($docBlock) ?? null; $description = $instance->description ?? $this->docBlockParser->getDescription($docBlock) ?? null;
$mimeType = $instance->mimeType; $mimeType = $instance->mimeType;
$annotations = $instance->annotations; $annotations = $instance->annotations;
$meta = $instance->meta ?? null; $meta = $instance->meta ?? null;

View file

@ -55,19 +55,6 @@ class DocBlockParser
} }
} }
/**
* Gets the summary line from a DocBlock.
*/
public function getSummary(?DocBlock $docBlock): ?string
{
if (!$docBlock) {
return null;
}
$summary = trim($docBlock->getSummary());
return $summary ?: null; // Return null if empty after trimming
}
/** /**
* Gets the description from a DocBlock (summary + description body). * Gets the description from a DocBlock (summary + description body).
*/ */

View file

@ -108,7 +108,7 @@ final class ArrayLoader implements LoaderInterface
$docBlock = $docBlockParser->parseDocBlock($reflection->getDocComment() ?? null); $docBlock = $docBlockParser->parseDocBlock($reflection->getDocComment() ?? null);
$name = $data['name'] ?? ('__invoke' === $methodName ? $classShortName : $methodName); $name = $data['name'] ?? ('__invoke' === $methodName ? $classShortName : $methodName);
$description = $data['description'] ?? $docBlockParser->getSummary($docBlock) ?? null; $description = $data['description'] ?? $docBlockParser->getDescription($docBlock) ?? null;
} }
$inputSchema = $data['inputSchema'] ?? $schemaGenerator->generate($reflection); $inputSchema = $data['inputSchema'] ?? $schemaGenerator->generate($reflection);
@ -149,7 +149,7 @@ final class ArrayLoader implements LoaderInterface
$docBlock = $docBlockParser->parseDocBlock($reflection->getDocComment() ?? null); $docBlock = $docBlockParser->parseDocBlock($reflection->getDocComment() ?? null);
$name = $data['name'] ?? ('__invoke' === $methodName ? $classShortName : $methodName); $name = $data['name'] ?? ('__invoke' === $methodName ? $classShortName : $methodName);
$description = $data['description'] ?? $docBlockParser->getSummary($docBlock) ?? null; $description = $data['description'] ?? $docBlockParser->getDescription($docBlock) ?? null;
} }
$resource = new Resource( $resource = new Resource(
@ -189,7 +189,7 @@ final class ArrayLoader implements LoaderInterface
$docBlock = $docBlockParser->parseDocBlock($reflection->getDocComment() ?? null); $docBlock = $docBlockParser->parseDocBlock($reflection->getDocComment() ?? null);
$name = $data['name'] ?? ('__invoke' === $methodName ? $classShortName : $methodName); $name = $data['name'] ?? ('__invoke' === $methodName ? $classShortName : $methodName);
$description = $data['description'] ?? $docBlockParser->getSummary($docBlock) ?? null; $description = $data['description'] ?? $docBlockParser->getDescription($docBlock) ?? null;
} }
$template = new ResourceTemplate( $template = new ResourceTemplate(
@ -228,7 +228,7 @@ final class ArrayLoader implements LoaderInterface
$docBlock = $docBlockParser->parseDocBlock($reflection->getDocComment() ?? null); $docBlock = $docBlockParser->parseDocBlock($reflection->getDocComment() ?? null);
$name = $data['name'] ?? ('__invoke' === $methodName ? $classShortName : $methodName); $name = $data['name'] ?? ('__invoke' === $methodName ? $classShortName : $methodName);
$description = $data['description'] ?? $docBlockParser->getSummary($docBlock) ?? null; $description = $data['description'] ?? $docBlockParser->getDescription($docBlock) ?? null;
} }
$arguments = []; $arguments = [];

View file

@ -3,7 +3,7 @@
{ {
"name": "priority_config_discovered", "name": "priority_config_discovered",
"uri": "config://priority", "uri": "config://priority",
"description": "A resource discovered via attributes." "description": "A resource discovered via attributes.\n\nThis will be overridden by a manual registration with the same URI."
} }
] ]
} }

View file

@ -2,7 +2,7 @@
"tools": [ "tools": [
{ {
"name": "schedule_event", "name": "schedule_event",
"description": "Schedules a new event.", "description": "Schedules a new event.\n\nThe inputSchema for this tool will reflect all parameter types and defaults.",
"inputSchema": { "inputSchema": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -25,7 +25,7 @@
}, },
{ {
"name": "send_welcome", "name": "send_welcome",
"description": "Sends a welcome message to a user.", "description": "Sends a welcome message to a user.\n\n(This is a placeholder - in a real app, it might queue an email).",
"inputSchema": { "inputSchema": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -32,7 +32,7 @@
}, },
{ {
"name": "calculate_range", "name": "calculate_range",
"description": "Performs mathematical operations with numeric constraints.", "description": "Performs mathematical operations with numeric constraints.\n\nDemonstrates: METHOD-LEVEL Schema",
"inputSchema": { "inputSchema": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -2,7 +2,7 @@
"tools": [ "tools": [
{ {
"name": "calculate", "name": "calculate",
"description": "Performs a calculation based on the operation.", "description": "Performs a calculation based on the operation.\n\nSupports 'add', 'subtract', 'multiply', 'divide'.\nObeys the 'precision' and 'allow_negative' settings from the config resource.",
"icons": [ "icons": [
{ {
"mimeType": "image/svg+xml", "mimeType": "image/svg+xml",
@ -37,7 +37,7 @@
}, },
{ {
"name": "update_setting", "name": "update_setting",
"description": "Updates a specific configuration setting.", "description": "Updates a specific configuration setting.\n\nNote: This requires more robust validation in a real app.",
"inputSchema": { "inputSchema": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -2,7 +2,7 @@
"tools": [ "tools": [
{ {
"name": "process_data_by_mode", "name": "process_data_by_mode",
"description": "Performs an action that can be modified by an environment variable.", "description": "Performs an action that can be modified by an environment variable.\n\nThe MCP client should set 'APP_MODE' in its 'env' config for this server.",
"inputSchema": { "inputSchema": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -27,19 +27,6 @@ class DocBlockParserTest extends TestCase
$this->parser = new DocBlockParser(); $this->parser = new DocBlockParser();
} }
public function testGetSummaryReturnsCorrectSummary()
{
$method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithSummaryOnly');
$docComment = $method->getDocComment() ?: null;
$docBlock = $this->parser->parseDocBlock($docComment);
$this->assertEquals('Simple summary line.', $this->parser->getSummary($docBlock));
$method2 = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithSummaryAndDescription');
$docComment2 = $method2->getDocComment() ?: null;
$docBlock2 = $this->parser->parseDocBlock($docComment2);
$this->assertEquals('Summary line here.', $this->parser->getSummary($docBlock2));
}
public function testGetDescriptionReturnsCorrectDescription() public function testGetDescriptionReturnsCorrectDescription()
{ {
$method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithSummaryAndDescription'); $method = new \ReflectionMethod(DocBlockTestFixture::class, 'methodWithSummaryAndDescription');
@ -129,7 +116,6 @@ class DocBlockParserTest extends TestCase
$docBlock = $this->parser->parseDocBlock($docComment); $docBlock = $this->parser->parseDocBlock($docComment);
$this->assertNull($docBlock); $this->assertNull($docBlock);
$this->assertNull($this->parser->getSummary($docBlock));
$this->assertNull($this->parser->getDescription($docBlock)); $this->assertNull($this->parser->getDescription($docBlock));
$this->assertEmpty($this->parser->getParamTags($docBlock)); $this->assertEmpty($this->parser->getParamTags($docBlock));
} }