Skip to content

Commit 57d39f1

Browse files
committed
feature #227 [MCP SDK][MCP Bundle] Add parameter for pagination and allow disabling pagination (xavierleune)
This PR was merged into the main branch. Discussion ---------- [MCP SDK][MCP Bundle] Add parameter for pagination and allow disabling pagination | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | Fix #10 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT The page size was hardcoded to 20 elements, now users can configure it in the mcp bundle. Passing null value will disable pagination and fetch all entries. Commits ------- a6c80d5 [MCP SDK] [MCP Bundle] Add parameter for pagination and allow disabling pagination
2 parents ab882c8 + a6c80d5 commit 57d39f1

File tree

6 files changed

+8
-6
lines changed

6 files changed

+8
-6
lines changed

src/mcp-bundle/config/options.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
->children()
1717
->scalarNode('app')->defaultValue('app')->end()
1818
->scalarNode('version')->defaultValue('0.0.1')->end()
19+
->scalarNode('page_size')->defaultValue(20)->end()
1920
// ->arrayNode('servers')
2021
// ->useAttributeAsKey('name')
2122
// ->arrayPrototype()

src/mcp-bundle/config/services.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
->set('mcp.server.request_handler.tool_list', ToolListHandler::class)
4545
->args([
4646
service('mcp.tool_collection'),
47-
20,
47+
param('mcp.page_size'),
4848
])
4949
->tag('mcp.server.request_handler')
5050

src/mcp-bundle/src/McpBundle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
3939

4040
$builder->setParameter('mcp.app', $config['app']);
4141
$builder->setParameter('mcp.version', $config['version']);
42+
$builder->setParameter('mcp.page_size', $config['page_size']);
4243

4344
if (isset($config['client_transports'])) {
4445
$this->configureClient($config['client_transports'], $builder);

src/mcp-sdk/src/Capability/Tool/CollectionInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
interface CollectionInterface
1717
{
1818
/**
19-
* @param int $count the number of metadata items to return
19+
* @param int|null $count the number of metadata items to return, null returns all items
2020
*
2121
* @return iterable<MetadataInterface>
2222
*
2323
* @throws InvalidCursorException if no item with $lastIdentifier was found
2424
*/
25-
public function getMetadata(int $count, ?string $lastIdentifier = null): iterable;
25+
public function getMetadata(?int $count, ?string $lastIdentifier = null): iterable;
2626
}

src/mcp-sdk/src/Capability/ToolChain.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(
3434
) {
3535
}
3636

37-
public function getMetadata(int $count, ?string $lastIdentifier = null): iterable
37+
public function getMetadata(?int $count, ?string $lastIdentifier = null): iterable
3838
{
3939
$found = null === $lastIdentifier;
4040
foreach ($this->items as $item) {
@@ -48,7 +48,7 @@ public function getMetadata(int $count, ?string $lastIdentifier = null): iterabl
4848
}
4949

5050
yield $item;
51-
if (--$count <= 0) {
51+
if (null !== $count && 0 >= --$count) {
5252
break;
5353
}
5454
}

src/mcp-sdk/src/Server/RequestHandler/ToolListHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class ToolListHandler extends BaseRequestHandler
1919
{
2020
public function __construct(
2121
private readonly CollectionInterface $collection,
22-
private readonly int $pageSize = 20,
22+
private readonly ?int $pageSize = 20,
2323
) {
2424
}
2525

0 commit comments

Comments
 (0)