Move mcp-json into mcp-core, add OSGi support
Co-authored-by: Luca Chang <131398524+LucaButBoring@users.noreply.github.com> Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
This commit is contained in:
parent
be5ec12e1b
commit
c3b9ab09ea
10 changed files with 368 additions and 353 deletions
|
|
@ -25,6 +25,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
|||
import org.springframework.web.reactive.function.client.WebClientResponseException;
|
||||
|
||||
import io.modelcontextprotocol.client.McpAsyncClient;
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
import io.modelcontextprotocol.json.TypeRef;
|
||||
import io.modelcontextprotocol.spec.ClosedMcpTransportSession;
|
||||
|
|
@ -615,8 +616,9 @@ public class WebClientStreamableHttpTransport implements McpClientTransport {
|
|||
* @return a new instance of {@link WebClientStreamableHttpTransport}
|
||||
*/
|
||||
public WebClientStreamableHttpTransport build() {
|
||||
return new WebClientStreamableHttpTransport(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper,
|
||||
webClientBuilder, endpoint, resumableStreams, openConnectionOnStartup, supportedProtocolVersions);
|
||||
return new WebClientStreamableHttpTransport(
|
||||
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, webClientBuilder,
|
||||
endpoint, resumableStreams, openConnectionOnStartup, supportedProtocolVersions);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
import io.modelcontextprotocol.json.TypeRef;
|
||||
|
||||
|
|
@ -404,7 +405,7 @@ public class WebFluxSseClientTransport implements McpClientTransport {
|
|||
*/
|
||||
public WebFluxSseClientTransport build() {
|
||||
return new WebFluxSseClientTransport(webClientBuilder,
|
||||
jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, sseEndpoint);
|
||||
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, sseEndpoint);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import io.modelcontextprotocol.common.McpTransportContext;
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
import io.modelcontextprotocol.json.TypeRef;
|
||||
import io.modelcontextprotocol.server.McpTransportContextExtractor;
|
||||
|
|
@ -561,8 +562,9 @@ public class WebFluxSseServerTransportProvider implements McpServerTransportProv
|
|||
*/
|
||||
public WebFluxSseServerTransportProvider build() {
|
||||
Assert.notNull(messageEndpoint, "Message endpoint must be set");
|
||||
return new WebFluxSseServerTransportProvider(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper,
|
||||
baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
|
||||
return new WebFluxSseServerTransportProvider(
|
||||
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, baseUrl,
|
||||
messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package io.modelcontextprotocol.server.transport;
|
||||
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
import io.modelcontextprotocol.common.McpTransportContext;
|
||||
import io.modelcontextprotocol.server.McpStatelessServerHandler;
|
||||
|
|
@ -244,8 +245,9 @@ public class WebFluxStatelessServerTransport implements McpStatelessServerTransp
|
|||
*/
|
||||
public WebFluxStatelessServerTransport build() {
|
||||
Assert.notNull(mcpEndpoint, "Message endpoint must be set");
|
||||
return new WebFluxStatelessServerTransport(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper,
|
||||
mcpEndpoint, contextExtractor, securityValidator);
|
||||
return new WebFluxStatelessServerTransport(
|
||||
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
|
||||
contextExtractor, securityValidator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package io.modelcontextprotocol.server.transport;
|
||||
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
import io.modelcontextprotocol.json.TypeRef;
|
||||
import io.modelcontextprotocol.common.McpTransportContext;
|
||||
|
|
@ -532,8 +533,8 @@ public class WebFluxStreamableServerTransportProvider implements McpStreamableSe
|
|||
public WebFluxStreamableServerTransportProvider build() {
|
||||
Assert.notNull(mcpEndpoint, "Message endpoint must be set");
|
||||
return new WebFluxStreamableServerTransportProvider(
|
||||
jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, mcpEndpoint, contextExtractor,
|
||||
disallowDelete, keepAliveInterval, securityValidator);
|
||||
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
|
||||
contextExtractor, disallowDelete, keepAliveInterval, securityValidator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package io.modelcontextprotocol.utils;
|
||||
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
|
||||
public final class McpJsonMapperUtils {
|
||||
|
|
@ -7,6 +8,6 @@ public final class McpJsonMapperUtils {
|
|||
private McpJsonMapperUtils() {
|
||||
}
|
||||
|
||||
public static final McpJsonMapper JSON_MAPPER = McpJsonMapper.createDefault();
|
||||
public static final McpJsonMapper JSON_MAPPER = McpJsonDefaults.getDefaultMcpJsonMapper();
|
||||
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import io.modelcontextprotocol.common.McpTransportContext;
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
import io.modelcontextprotocol.json.TypeRef;
|
||||
import io.modelcontextprotocol.server.McpTransportContextExtractor;
|
||||
|
|
@ -599,8 +600,9 @@ public class WebMvcSseServerTransportProvider implements McpServerTransportProvi
|
|||
if (messageEndpoint == null) {
|
||||
throw new IllegalStateException("MessageEndpoint must be set");
|
||||
}
|
||||
return new WebMvcSseServerTransportProvider(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper,
|
||||
baseUrl, messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
|
||||
return new WebMvcSseServerTransportProvider(
|
||||
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, baseUrl,
|
||||
messageEndpoint, sseEndpoint, keepAliveInterval, contextExtractor, securityValidator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
package io.modelcontextprotocol.server.transport;
|
||||
|
||||
import io.modelcontextprotocol.common.McpTransportContext;
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
import io.modelcontextprotocol.server.McpStatelessServerHandler;
|
||||
import io.modelcontextprotocol.server.McpTransportContextExtractor;
|
||||
|
|
@ -263,8 +264,9 @@ public class WebMvcStatelessServerTransport implements McpStatelessServerTranspo
|
|||
*/
|
||||
public WebMvcStatelessServerTransport build() {
|
||||
Assert.notNull(mcpEndpoint, "Message endpoint must be set");
|
||||
return new WebMvcStatelessServerTransport(jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper,
|
||||
mcpEndpoint, contextExtractor, securityValidator);
|
||||
return new WebMvcStatelessServerTransport(
|
||||
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
|
||||
contextExtractor, securityValidator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -112,8 +113,6 @@ public class WebMvcStreamableServerTransportProvider implements McpStreamableSer
|
|||
* Constructs a new WebMvcStreamableServerTransportProvider instance.
|
||||
* @param jsonMapper The McpJsonMapper to use for JSON serialization/deserialization
|
||||
* of messages.
|
||||
* @param baseUrl The base URL for the message endpoint, used to construct the full
|
||||
* endpoint URL for clients.
|
||||
* @param mcpEndpoint The endpoint URI where clients should send their JSON-RPC
|
||||
* messages via HTTP. This endpoint will handle GET, POST, and DELETE requests.
|
||||
* @param disallowDelete Whether to disallow DELETE requests on the endpoint.
|
||||
|
|
@ -732,8 +731,8 @@ public class WebMvcStreamableServerTransportProvider implements McpStreamableSer
|
|||
public WebMvcStreamableServerTransportProvider build() {
|
||||
Assert.notNull(this.mcpEndpoint, "MCP endpoint must be set");
|
||||
return new WebMvcStreamableServerTransportProvider(
|
||||
jsonMapper == null ? McpJsonMapper.getDefault() : jsonMapper, mcpEndpoint, disallowDelete,
|
||||
contextExtractor, keepAliveInterval, securityValidator);
|
||||
jsonMapper == null ? McpJsonDefaults.getDefaultMcpJsonMapper() : jsonMapper, mcpEndpoint,
|
||||
disallowDelete, contextExtractor, keepAliveInterval, securityValidator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package io.modelcontextprotocol.server.transport;
|
|||
import io.modelcontextprotocol.client.McpClient;
|
||||
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
|
||||
import io.modelcontextprotocol.common.McpTransportContext;
|
||||
import io.modelcontextprotocol.json.McpJsonDefaults;
|
||||
import io.modelcontextprotocol.json.McpJsonMapper;
|
||||
import io.modelcontextprotocol.server.McpServer;
|
||||
import io.modelcontextprotocol.server.TestUtil;
|
||||
|
|
@ -104,7 +105,7 @@ class WebMvcSseServerTransportProviderTests {
|
|||
.baseUrl("http://localhost:" + PORT + "/")
|
||||
.messageEndpoint(MESSAGE_ENDPOINT)
|
||||
.sseEndpoint(WebMvcSseServerTransportProvider.DEFAULT_SSE_ENDPOINT)
|
||||
.jsonMapper(McpJsonMapper.getDefault())
|
||||
.jsonMapper(McpJsonDefaults.getDefaultMcpJsonMapper())
|
||||
.contextExtractor(req -> McpTransportContext.EMPTY)
|
||||
.build();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue