Add plumbing to set instructions on Server (#145)

* Add plumbing to set instructions on Server

* Use instructions description from MCP schema

---------

Co-authored-by: Peter Liddle <development.peter@liddle.network>
Co-authored-by: Mattt <mattt@me.com>
This commit is contained in:
Glacio 2025-08-10 07:52:28 -05:00 • committed by GitHub
commit e2afccdcaa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -128,10 +128,18 @@ public actor Server {
public nonisolated var name: String { serverInfo.name }
/// The server version
public nonisolated var version: String { serverInfo.version }
/// Instructions describing how to use the server and its features
///
/// This can be used by clients to improve the LLM's understanding of
/// available tools, resources, etc.
/// It can be thought of like a "hint" to the model.
/// For example, this information MAY be added to the system prompt.
public nonisolated let instructions: String?
/// The server capabilities
public var capabilities: Capabilities
/// The server configuration
public var configuration: Configuration
/// Request handlers
private var methodHandlers: [String: RequestHandlerBox] = [:]
@ -154,12 +162,14 @@ public actor Server {
public init(
name: String,
version: String,
instructions: String? = nil,
capabilities: Server.Capabilities = .init(),
configuration: Configuration = .default
) {
self.serverInfo = Server.Info(name: name, version: version)
self.capabilities = capabilities
self.configuration = configuration
self.instructions = instructions
}
/// Start the server
@ -574,7 +584,7 @@ public actor Server {
protocolVersion: negotiatedProtocolVersion,
capabilities: await self.capabilities,
serverInfo: self.serverInfo,
instructions: nil
instructions: self.instructions
)
}