Skip to content

Commit e7ab8a9

Browse files
feat: add instructions in server initialization result
This update introduces an optional instructions parameter to the Configuration class, allowing for the provision of usage instructions for the server's features, enhancing the InitializeResult with instructions for improved client understanding.
1 parent 3c5b48d commit e7ab8a9

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Configuration
2626
* @param CacheInterface|null $cache Optional PSR-16 Cache instance for registry/state.
2727
* @param ContainerInterface $container PSR-11 DI Container for resolving handlers/dependencies.
2828
* @param int $paginationLimit Maximum number of items to return for list methods.
29+
* @param string|null $instructions Instructions describing how to use the server and its features.
2930
*/
3031
public function __construct(
3132
public readonly Implementation $serverInfo,
@@ -35,5 +36,6 @@ public function __construct(
3536
public readonly ?CacheInterface $cache,
3637
public readonly ContainerInterface $container,
3738
public readonly int $paginationLimit = 50,
39+
public readonly ?string $instructions = null,
3840
) {}
3941
}

src/Dispatcher.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ public function handleInitialize(InitializeRequest $request, SessionInterface $s
132132

133133
$serverInfo = $this->configuration->serverInfo;
134134
$capabilities = $this->configuration->capabilities;
135+
$instructions = $this->configuration->instructions;
135136

136-
return new InitializeResult($protocolVersion, $capabilities, $serverInfo);
137+
return new InitializeResult($protocolVersion, $capabilities, $serverInfo, $instructions);
137138
}
138139

139140
public function handlePing(PingRequest $request): EmptyResult

src/ServerBuilder.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ final class ServerBuilder
5252

5353
private ?int $paginationLimit = 50;
5454

55+
private ?string $instructions = null;
56+
5557
/** @var array<
5658
* array{handler: array|string,
5759
* name: string|null,
@@ -120,6 +122,20 @@ public function withPaginationLimit(int $paginationLimit): self
120122
return $this;
121123
}
122124

125+
/**
126+
* Configures the instructions describing how to use the server and its features.
127+
*
128+
* This can be used by clients to improve the LLM's understanding of available tools, resources,
129+
* etc. It can be thought of like a "hint" to the model. For example, this information MAY
130+
* be added to the system prompt.
131+
*/
132+
public function withInstructions(string $instructions): self
133+
{
134+
$this->instructions = $instructions;
135+
136+
return $this;
137+
}
138+
123139
/**
124140
* Provides a PSR-3 logger instance. Defaults to NullLogger.
125141
*/
@@ -257,7 +273,8 @@ public function build(): Server
257273
loop: $loop,
258274
cache: $cache,
259275
container: $container,
260-
paginationLimit: $this->paginationLimit ?? 50
276+
paginationLimit: $this->paginationLimit ?? 50,
277+
instructions: $this->instructions,
261278
);
262279

263280
$sessionHandler = $this->createSessionHandler();

0 commit comments

Comments
 (0)