File tree Expand file tree Collapse file tree 3 files changed +30
-10
lines changed
src/mcp-sdk/src/Server/RequestHandler Expand file tree Collapse file tree 3 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,14 @@ public function __construct(
27
27
public function createResponse (Request $ message ): Response
28
28
{
29
29
$ nextCursor = null ;
30
- $ prompts = array_map (function (MetadataInterface $ metadata ) use (&$ nextCursor ) {
30
+ $ prompts = [];
31
+
32
+ $ metadataList = $ this ->collection ->getMetadata (
33
+ $ this ->pageSize ,
34
+ $ message ->params ['cursor ' ] ?? null
35
+ );
36
+
37
+ foreach ($ metadataList as $ metadata ) {
31
38
$ nextCursor = $ metadata ->getName ();
32
39
$ result = [
33
40
'name ' => $ metadata ->getName (),
@@ -55,8 +62,8 @@ public function createResponse(Request $message): Response
55
62
$ result ['arguments ' ] = $ arguments ;
56
63
}
57
64
58
- return $ result ;
59
- }, $ this -> collection -> getMetadata ( $ this -> pageSize , $ message -> params [ ' cursor ' ] ?? null ));
65
+ $ prompts [] = $ result ;
66
+ }
60
67
61
68
$ result = [
62
69
'prompts ' => $ prompts ,
Original file line number Diff line number Diff line change @@ -27,7 +27,14 @@ public function __construct(
27
27
public function createResponse (Request $ message ): Response
28
28
{
29
29
$ nextCursor = null ;
30
- $ resources = array_map (function (MetadataInterface $ metadata ) use (&$ nextCursor ) {
30
+ $ resources = [];
31
+
32
+ $ metadataList = $ this ->collection ->getMetadata (
33
+ $ this ->pageSize ,
34
+ $ message ->params ['cursor ' ] ?? null
35
+ );
36
+
37
+ foreach ($ metadataList as $ metadata ) {
31
38
$ nextCursor = $ metadata ->getUri ();
32
39
$ result = [
33
40
'uri ' => $ metadata ->getUri (),
@@ -49,8 +56,8 @@ public function createResponse(Request $message): Response
49
56
$ result ['size ' ] = $ size ;
50
57
}
51
58
52
- return $ result ;
53
- }, $ this -> collection -> getMetadata ( $ this -> pageSize , $ message -> params [ ' cursor ' ] ?? null ));
59
+ $ resources [] = $ result ;
60
+ }
54
61
55
62
$ result = [
56
63
'resources ' => $ resources ,
Original file line number Diff line number Diff line change @@ -27,19 +27,25 @@ public function __construct(
27
27
public function createResponse (Request $ message ): Response
28
28
{
29
29
$ nextCursor = null ;
30
- $ tools = array_map (function (MetadataInterface $ tool ) use (&$ nextCursor ) {
30
+ $ tools = [];
31
+
32
+ $ metadataList = $ this ->collection ->getMetadata (
33
+ $ this ->pageSize ,
34
+ $ message ->params ['cursor ' ] ?? null
35
+ );
36
+
37
+ foreach ($ metadataList as $ tool ) {
31
38
$ nextCursor = $ tool ->getName ();
32
39
$ inputSchema = $ tool ->getInputSchema ();
33
-
34
- return [
40
+ $ tools [] = [
35
41
'name ' => $ tool ->getName (),
36
42
'description ' => $ tool ->getDescription (),
37
43
'inputSchema ' => [] === $ inputSchema ? [
38
44
'type ' => 'object ' ,
39
45
'$schema ' => 'http://json-schema.org/draft-07/schema# ' ,
40
46
] : $ inputSchema ,
41
47
];
42
- }, $ this -> collection -> getMetadata ( $ this -> pageSize , $ message -> params [ ' cursor ' ] ?? null ));
48
+ }
43
49
44
50
$ result = [
45
51
'tools ' => $ tools ,
You can’t perform that action at this time.
0 commit comments