-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathMcpConfig.java
More file actions
47 lines (42 loc) · 1.86 KB
/
McpConfig.java
File metadata and controls
47 lines (42 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.example.calculator;
import io.modelcontextprotocol.json.jackson.JacksonMcpJsonMapper;
import io.modelcontextprotocol.server.McpServer;
import io.modelcontextprotocol.server.McpSyncServer;
import io.modelcontextprotocol.server.transport.WebFluxStreamableServerTransportProvider;
import io.modelcontextprotocol.spec.McpSchema;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
@Configuration
public class McpConfig {
@Bean
WebFluxStreamableServerTransportProvider mcpTransportProvider(ObjectMapper mapper) {
return WebFluxStreamableServerTransportProvider.builder()
.jsonMapper(new JacksonMcpJsonMapper(mapper))
.messageEndpoint("/mcp")
.build();
}
@Bean
RouterFunction<?> mcpRouterFunction(WebFluxStreamableServerTransportProvider transportProvider) {
return transportProvider.getRouterFunction();
}
@Bean
McpSyncServer mcpServer(WebFluxStreamableServerTransportProvider transportProvider,
CalculatorTools tools,
CalculatorResources resources,
CalculatorPrompts prompts) {
return McpServer.sync(transportProvider)
.serverInfo("Calculator", "1.0.0")
.capabilities(McpSchema.ServerCapabilities.builder()
.tools(true)
.resources(false, true)
.prompts(true)
.logging()
.build())
.tools(tools.specification())
.resources(resources.specification())
.prompts(prompts.specifications())
.build();
}
}