Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,24 @@ jobs:
with:
java-version: ${{ matrix.java-version }}
distribution: 'adopt'
- name: Install python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Install Python dependencies for MCP tests
run: |
cd python
uv sync --all-extras
- name: Run Java Tests
run: tools/ut.sh -j
run: |
# Add Python venv to PATH so Java tests can find MCP dependencies
export PATH="${{ github.workspace }}/python/.venv/bin:$PATH"
export PYTHONPATH="${{ github.workspace }}/python/.venv/lib/python3.11/site-packages:$PYTHONPATH"
tools/ut.sh -j
Copy link
Contributor

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-java pipeline. In theory, any test case that interacts with an external system should be considered as integration test or e2e test.

Copy link
Contributor Author

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?

Copy link
Contributor

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.


python_tests:
name: ut-python [${{ matrix.os }}] [python-${{ matrix.python-version}}]
Expand Down
22 changes: 22 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,26 @@ under the License.
</dependency>
</dependencies>

<profiles>
<profile>
<id>java-11</id>
<activation>
<jdk>[11,17)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>org/apache/flink/agents/api/annotation/MCPServer.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public ReActAgent(
"Output schema must be RowTypeInfo or Pojo class.");
}
Prompt schemaPrompt =
new Prompt(
Prompt.fromText(
String.format(
"The final response should be json format, and match the schema %s",
jsonSchema));
Expand Down
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 {}
Loading