Skip to content

Commit e2afccd

Browse files
glaciotechPeter Liddlemattt
authored
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 <[email protected]> Co-authored-by: Mattt <[email protected]>
1 parent 63fd276 commit e2afccd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Sources/MCP/Server/Server.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,18 @@ public actor Server {
128128
public nonisolated var name: String { serverInfo.name }
129129
/// The server version
130130
public nonisolated var version: String { serverInfo.version }
131+
/// Instructions describing how to use the server and its features
132+
///
133+
/// This can be used by clients to improve the LLM's understanding of
134+
/// available tools, resources, etc.
135+
/// It can be thought of like a "hint" to the model.
136+
/// For example, this information MAY be added to the system prompt.
137+
public nonisolated let instructions: String?
131138
/// The server capabilities
132139
public var capabilities: Capabilities
133140
/// The server configuration
134141
public var configuration: Configuration
142+
135143

136144
/// Request handlers
137145
private var methodHandlers: [String: RequestHandlerBox] = [:]
@@ -154,12 +162,14 @@ public actor Server {
154162
public init(
155163
name: String,
156164
version: String,
165+
instructions: String? = nil,
157166
capabilities: Server.Capabilities = .init(),
158167
configuration: Configuration = .default
159168
) {
160169
self.serverInfo = Server.Info(name: name, version: version)
161170
self.capabilities = capabilities
162171
self.configuration = configuration
172+
self.instructions = instructions
163173
}
164174

165175
/// Start the server
@@ -574,7 +584,7 @@ public actor Server {
574584
protocolVersion: negotiatedProtocolVersion,
575585
capabilities: await self.capabilities,
576586
serverInfo: self.serverInfo,
577-
instructions: nil
587+
instructions: self.instructions
578588
)
579589
}
580590

0 commit comments

Comments
 (0)