-
Notifications
You must be signed in to change notification settings - Fork 79
[Feature][Java] Add MCP support in Java #356
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
Open
yanand0909
wants to merge
7
commits into
apache:main
Choose a base branch
from
yanand0909:add_java_mcp_recource
base: main
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.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e1cebc7
[Feature][Java] Add MCP support in Java
yanand0909 b60f6de
[Feature][Java] update MCP Server and rebase with main
yanand0909 4372715
[Feature][Java] Remove docker dependency and use python server for test
yanand0909 ebc21d5
[Feature][Java] Add profiles to support multiple java versions
yanand0909 38f5cd1
[Feature][Java] Use reflection in agent plan to avoid import issue fo…
yanand0909 dc96dbc
[Feature][Java] Address comments and update PythonPrompt
yanand0909 4e1897b
[Feature][Java] Moved MCP implementation to intgerations module
yanand0909 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
Sxnan marked this conversation as resolved.
Show resolved
Hide resolved
|
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
68 changes: 68 additions & 0 deletions
68
api/src/main/java/org/apache/flink/agents/api/annotation/MCPServer.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 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.flink.agents.api.annotation; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Annotation to mark a method as an MCP server resource that should be managed by the agent plan. | ||
| * | ||
| * <p>Methods annotated with @MCPServer will be scanned during agent plan creation. The agent plan | ||
| * will automatically: | ||
| * | ||
| * <ul> | ||
| * <li>Discover all tools exposed by the MCP server via {@code listTools()} | ||
| * <li>Discover all prompts exposed by the MCP server via {@code listPrompts()} | ||
| * <li>Register each tool and prompt as individual resources | ||
| * <li>Close the MCP server connection after discovery | ||
| * </ul> | ||
| * | ||
| * <p>Example usage: | ||
| * | ||
| * <pre>{@code | ||
| * public class MyAgent extends Agent { | ||
| * @MCPServer | ||
| * public static MCPServer myMcpServer() { | ||
| * return MCPServer.builder("http://localhost:8000/mcp") | ||
| * .timeout(Duration.ofSeconds(30)) | ||
| * .build(); | ||
| * } | ||
| * | ||
| * @ChatModelSetup | ||
| * public static ChatModel chatModel() { | ||
| * return new ChatModel.Builder() | ||
| * .prompt("greeting") // MCP prompt from server | ||
| * .tools(List.of("calculator")) // MCP tool from server | ||
| * .build(); | ||
| * } | ||
| * } | ||
| * }</pre> | ||
| * | ||
| * <p>This is the Java equivalent of Python's {@code @mcp_server} decorator. | ||
| * | ||
| * @see org.apache.flink.agents.integrations.mcp.MCPServer | ||
| * @see org.apache.flink.agents.integrations.mcp.MCPTool | ||
| * @see org.apache.flink.agents.integrations.mcp.MCPPrompt | ||
| */ | ||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface MCPServer {} |
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.
IIUC, we need this to start an external mcp server, so that we can access from the test cases? If that is the case, I'd suggest to move the test cases that depends on external mcp server to the
it-javapipeline. In theory, any test case that interacts with an external system should be considered as integration test or e2e test.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.
This is for AgentPlanDeclareMCPServerTest to test whether MCP Tools and Prompts from MCP Server is properly discoverable, we need a running MCP server for this test. Do you think we should move this test to integration test?
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.
Yes, I think we can move that test to integration test.