Skip to content

Commit 3ae67e7

Browse files
jameswardtzolov
authored andcommitted
feat(mcp): Add instructions support to MCP server
Add the ability to configure instructions for MCP servers that provide guidance to clients on how to interact with the server. - New instructions property in McpServerProperties - Passing instructions to the server builder in McpServerAutoConfiguration - Updated tests to verify instructions configuration works correctly Signed-off-by: James Ward <[email protected]>
1 parent 07a2643 commit 3ae67e7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpServerAutoConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ public McpSyncServer mcpSyncServer(McpServerTransportProvider transportProvider,
223223

224224
serverBuilder.capabilities(capabilitiesBuilder.build());
225225

226+
serverBuilder.instructions(serverProperties.getInstructions());
227+
226228
return serverBuilder.build();
227229
}
228230

@@ -322,6 +324,8 @@ public McpAsyncServer mcpAsyncServer(McpServerTransportProvider transportProvide
322324

323325
serverBuilder.capabilities(capabilitiesBuilder.build());
324326

327+
serverBuilder.instructions(serverProperties.getInstructions());
328+
325329
return serverBuilder.build();
326330
}
327331

auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpServerProperties.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public class McpServerProperties {
7272
*/
7373
private String version = "1.0.0";
7474

75+
/**
76+
* The instructions of the MCP server instance.
77+
* <p>
78+
* These instructions are used to provide guidance to the client on how to interact
79+
* with this server.
80+
*/
81+
private String instructions = null;
82+
7583
/**
7684
* Enable/disable notifications for resource changes. Only relevant for MCP servers
7785
* with resource capabilities.
@@ -180,6 +188,14 @@ public void setVersion(String version) {
180188
this.version = version;
181189
}
182190

191+
public String getInstructions() {
192+
return this.instructions;
193+
}
194+
195+
public void setInstructions(String instructions) {
196+
this.instructions = instructions;
197+
}
198+
183199
public boolean isResourceChangeNotification() {
184200
return this.resourceChangeNotification;
185201
}

auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/test/java/org/springframework/ai/mcp/server/autoconfigure/McpServerAutoConfigurationIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,15 @@ void defaultConfiguration() {
7373
void asyncConfiguration() {
7474
this.contextRunner
7575
.withPropertyValues("spring.ai.mcp.server.type=ASYNC", "spring.ai.mcp.server.name=test-server",
76-
"spring.ai.mcp.server.version=2.0.0")
76+
"spring.ai.mcp.server.version=2.0.0", "spring.ai.mcp.server.instructions=My MCP Server")
7777
.run(context -> {
7878
assertThat(context).hasSingleBean(McpAsyncServer.class);
7979
assertThat(context).doesNotHaveBean(McpSyncServer.class);
8080

8181
McpServerProperties properties = context.getBean(McpServerProperties.class);
8282
assertThat(properties.getName()).isEqualTo("test-server");
8383
assertThat(properties.getVersion()).isEqualTo("2.0.0");
84+
assertThat(properties.getInstructions()).isEqualTo("My MCP Server");
8485
assertThat(properties.getType()).isEqualTo(McpServerProperties.ServerType.ASYNC);
8586
});
8687
}

0 commit comments

Comments
 (0)