-
Notifications
You must be signed in to change notification settings - Fork 2
DT-3187: Java MCP Proof of Concept #2897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rushtong
wants to merge
9
commits into
develop
Choose a base branch
from
gr-mcp-java-poc
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b37909e
poc wip: first pass mcp implementation
rushtong aa27acc
poc wip: fixes
rushtong 013b797
poc wip: update to non-deprecated mcp paths
rushtong 9682623
poc wip: clean up import
rushtong ca8931b
poc wip: clean up formats
rushtong 553ca45
Merge branch 'develop' into gr-mcp-java-poc
rushtong ce16ad2
poc wip: use an annotation-based approach to registering MCP tools
rushtong 45faf51
poc wip: spotless
rushtong 8655464
poc wip: semgrep
rushtong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/org/broadinstitute/consent/http/mcp/ConsentJsonSchemaValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.broadinstitute.consent.http.mcp; | ||
|
|
||
| import io.modelcontextprotocol.json.schema.JsonSchemaValidator; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * No-op {@link JsonSchemaValidator} that accepts all tool-call inputs without validation. | ||
| * | ||
| * <p>The SDK requires a {@link JsonSchemaValidator} via ServiceLoader. The default implementation | ||
| * ({@code DefaultJsonSchemaValidator} in {@code mcp-json-jackson2}) uses {@code | ||
| * com.networknt:json-schema-validator 1.5.7}, which conflicts with the project's 3.0.2 pin. We | ||
| * register this pass-through instead. | ||
| * | ||
| * <p>MCP tool schemas in this service are simple Maps used for documentation only; runtime | ||
| * validation of tool arguments is not required. | ||
| */ | ||
| public class ConsentJsonSchemaValidator implements JsonSchemaValidator { | ||
|
|
||
| @Override | ||
| public ValidationResponse validate(Map<String, Object> schema, Object structuredContent) { | ||
| // Pass through — tool-argument validation is not required for DUOS MCP tools. | ||
| return ValidationResponse.asValid(String.valueOf(structuredContent)); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/broadinstitute/consent/http/mcp/ConsentJsonSchemaValidatorSupplier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.broadinstitute.consent.http.mcp; | ||
|
|
||
| import io.modelcontextprotocol.json.schema.JsonSchemaValidator; | ||
| import io.modelcontextprotocol.json.schema.JsonSchemaValidatorSupplier; | ||
|
|
||
| /** | ||
| * ServiceLoader registration for {@link JsonSchemaValidator}. | ||
| * | ||
| * <p>Registered in {@code | ||
| * META-INF/services/io.modelcontextprotocol.json.schema.JsonSchemaValidatorSupplier}. | ||
| */ | ||
| public class ConsentJsonSchemaValidatorSupplier implements JsonSchemaValidatorSupplier { | ||
|
|
||
| @Override | ||
| public JsonSchemaValidator get() { | ||
| return new ConsentJsonSchemaValidator(); | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
src/main/java/org/broadinstitute/consent/http/mcp/ConsentMcpJsonMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package org.broadinstitute.consent.http.mcp; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import io.modelcontextprotocol.json.McpJsonMapper; | ||
| import io.modelcontextprotocol.json.TypeRef; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Network-free {@link McpJsonMapper} implementation backed by Jackson's {@link ObjectMapper}. | ||
| * | ||
| * <p>The SDK ships {@code mcp-json-jackson2} as the default Jackson adapter, but that module | ||
| * registers a {@code JacksonJsonSchemaValidatorSupplier} via ServiceLoader which depends on {@code | ||
| * com.networknt:json-schema-validator 1.5.7}. This project pins 3.0.2, whose API is incompatible | ||
| * (the {@code SpecVersion$VersionFlag} inner class was removed), causing a {@link | ||
| * NoClassDefFoundError} at startup. | ||
| * | ||
| * <p>This implementation provides only the JSON serialisation/deserialisation that the MCP server | ||
| * transport and tool dispatching actually need — no schema validation. {@code mcp-json-jackson2} is | ||
| * excluded from the Maven dependency tree entirely. | ||
| */ | ||
| public class ConsentMcpJsonMapper implements McpJsonMapper { | ||
|
|
||
| private final ObjectMapper mapper; | ||
|
|
||
| public ConsentMcpJsonMapper(ObjectMapper mapper) { | ||
| this.mapper = mapper; | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T readValue(String content, Class<T> type) throws IOException { | ||
| return mapper.readValue(content, type); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T readValue(byte[] content, Class<T> type) throws IOException { | ||
| return mapper.readValue(content, type); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T readValue(String content, TypeRef<T> type) throws IOException { | ||
| return mapper.readValue(content, mapper.getTypeFactory().constructType(type.getType())); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T readValue(byte[] content, TypeRef<T> type) throws IOException { | ||
| return mapper.readValue(content, mapper.getTypeFactory().constructType(type.getType())); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T convertValue(Object fromValue, Class<T> type) { | ||
| return mapper.convertValue(fromValue, type); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T convertValue(Object fromValue, TypeRef<T> type) { | ||
| return mapper.convertValue(fromValue, mapper.getTypeFactory().constructType(type.getType())); | ||
| } | ||
|
|
||
| @Override | ||
| public String writeValueAsString(Object value) throws IOException { | ||
| return mapper.writeValueAsString(value); | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] writeValueAsBytes(Object value) throws IOException { | ||
| return mapper.writeValueAsBytes(value); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/broadinstitute/consent/http/mcp/ConsentMcpJsonMapperSupplier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.broadinstitute.consent.http.mcp; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import io.modelcontextprotocol.json.McpJsonMapper; | ||
| import io.modelcontextprotocol.json.McpJsonMapperSupplier; | ||
|
|
||
| /** | ||
| * ServiceLoader registration for {@link McpJsonMapper}. | ||
| * | ||
| * <p>The SDK discovers a default {@link McpJsonMapper} via {@code | ||
| * ServiceLoader<McpJsonMapperSupplier>} when {@link McpJsonMapper#getDefault()} is called | ||
| * internally. Because we excluded {@code mcp-json-jackson2} (to avoid its transitive dependency on | ||
| * {@code com.networknt:json-schema-validator 1.5.7} which conflicts with the project's 3.0.2 pin), | ||
| * we register this supplier instead so the SDK can find a mapper at runtime. | ||
| * | ||
| * <p>Registered in {@code META-INF/services/io.modelcontextprotocol.json.McpJsonMapperSupplier}. | ||
| */ | ||
| public class ConsentMcpJsonMapperSupplier implements McpJsonMapperSupplier { | ||
|
|
||
| @Override | ||
| public McpJsonMapper get() { | ||
| return new ConsentMcpJsonMapper(new ObjectMapper()); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/broadinstitute/consent/http/mcp/ConsentMcpManaged.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.broadinstitute.consent.http.mcp; | ||
|
|
||
| import io.dropwizard.lifecycle.Managed; | ||
| import io.modelcontextprotocol.server.McpStatelessSyncServer; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Dropwizard {@link Managed} wrapper for {@link McpStatelessSyncServer}. | ||
| * | ||
| * <p>Dropwizard calls {@link #start()} after all resources are registered and the HTTP server is | ||
| * running, and calls {@link #stop()} during graceful shutdown before the JVM exits. | ||
| * | ||
| * <p>{@code McpStatelessSyncServer} has no explicit {@code start()} method — it begins serving as | ||
| * soon as the transport servlet receives connections. {@code closeGracefully()} handles shutdown. | ||
| */ | ||
| public class ConsentMcpManaged implements Managed { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(ConsentMcpManaged.class); | ||
|
|
||
| private final McpStatelessSyncServer server; | ||
|
|
||
| public ConsentMcpManaged(McpStatelessSyncServer server) { | ||
| this.server = server; | ||
| } | ||
|
|
||
| @Override | ||
| public void start() { | ||
| // McpStatelessSyncServer starts automatically when the transport servlet receives connections. | ||
| LOGGER.info("Consent MCP server ready"); | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
| LOGGER.info("Stopping Consent MCP server"); | ||
| try { | ||
| server.closeGracefully(); | ||
| LOGGER.info("Consent MCP server stopped"); | ||
| } catch (Exception e) { | ||
| LOGGER.warn("MCP server did not shut down cleanly", e); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we want to return the internals to the user. A better error might be "Your browser sent something we could't understand" as the exception to the user, but maybe log that the condition was reached and decode the bearerToken that was provided so we know the user having the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, this is not intended to be production ready yet. I fully intend to throw this code away if we do go down this path and instead implement this in much smaller phases.