xintongsong commented on code in PR #421:
URL: https://github.com/apache/flink-agents/pull/421#discussion_r2671133159
##########
docs/content/docs/development/tool_use.md:
##########
@@ -185,10 +185,6 @@ ReActAgent reviewAnalysisReactAgent = new ReActAgent(
MCP (Model Context Protocol) is a standardized protocol for integrating AI
applications with external data sources and tools. MCP tools allow dynamic tool
retrieval from MCP servers.
{{< /hint >}}
-{{< hint warning >}}
-MCP Tool is only supported in python currently.
-{{< /hint >}}
Review Comment:
ditto
##########
docs/content/docs/development/tool_use.md:
##########
@@ -244,8 +243,83 @@ class ReviewAnalysisAgent(Agent):
tools=["notify_shipping_manager"], # Reference MCP tool by name
)
```
+{{< /tab >}}
+
+{{< tab "Java" >}}
+```java
+public class ReviewAnalysisAgent extends Agent {
+
+ @MCPServer
+ public static org.apache.flink.agents.integrations.mcp.MCPServer
reviewMcpServer() {
+ return org.apache.flink.agents.integrations.mcp.MCPServer
+ .builder("http://127.0.0.1:8000/mcp")
+ .timeout(Duration.ofSeconds(30))
+ .build();
+ }
+
+ @ChatModelSetup
+ public static ResourceDescriptor reviewModel() {
+ return
ResourceDescriptor.Builder.newBuilder(OllamaChatModelSetup.class.getName())
+ .addInitialArgument("connection", "ollamaChatModelConnection")
+ .addInitialArgument("model", "qwen3:8b")
+ .addInitialArgument("tools",
Collections.singletonList("notifyShippingManager")) // Reference MCP tool by
name
+ .build();
+ }
+}
+```
+{{< /tab >}}
+
+{{< /tabs >}}
**Key points:**
-- Use `@mcp_server` decorator to define MCP server connection
-- Reference MCP tools by their function name (e.g.,
`"notify_shipping_manager"`)
-- All tools from the MCP server are automatically registered
\ No newline at end of file
+- In Python, use `@mcp_server` decorator to define MCP server connection
+- In Java, use `@MCPServer` annotation to define MCP server connection
+- Use the builder pattern in Java to configure the MCP server with endpoint,
timeout, headers, and authentication
Review Comment:
Is it intended that this (builder pattern in java) is not mentioned in the
prompt pate?
##########
docs/content/docs/development/prompts.md:
##########
@@ -335,10 +335,6 @@ Prompts use `{variable_name}` syntax for template
variables. Variables are fille
MCP (Model Context Protocol) is a standardized protocol for integrating AI
applications with external data sources and tools. MCP prompts allow dynamic
prompt retrieval from MCP servers.
{{< /hint >}}
-{{< hint warning >}}
-MCP Prompt is only supported in python currently.
-{{< /hint >}}
Review Comment:
I'd suggest to mention that MCP prompt is only available in Java17+, rather
than just remove the notice.
##########
docs/content/docs/development/tool_use.md:
##########
@@ -244,8 +243,83 @@ class ReviewAnalysisAgent(Agent):
tools=["notify_shipping_manager"], # Reference MCP tool by name
)
```
+{{< /tab >}}
+
+{{< tab "Java" >}}
+```java
+public class ReviewAnalysisAgent extends Agent {
+
+ @MCPServer
+ public static org.apache.flink.agents.integrations.mcp.MCPServer
reviewMcpServer() {
+ return org.apache.flink.agents.integrations.mcp.MCPServer
+ .builder("http://127.0.0.1:8000/mcp")
+ .timeout(Duration.ofSeconds(30))
+ .build();
+ }
+
+ @ChatModelSetup
+ public static ResourceDescriptor reviewModel() {
+ return
ResourceDescriptor.Builder.newBuilder(OllamaChatModelSetup.class.getName())
+ .addInitialArgument("connection", "ollamaChatModelConnection")
+ .addInitialArgument("model", "qwen3:8b")
+ .addInitialArgument("tools",
Collections.singletonList("notifyShippingManager")) // Reference MCP tool by
name
+ .build();
+ }
+}
+```
+{{< /tab >}}
+
+{{< /tabs >}}
**Key points:**
-- Use `@mcp_server` decorator to define MCP server connection
-- Reference MCP tools by their function name (e.g.,
`"notify_shipping_manager"`)
-- All tools from the MCP server are automatically registered
\ No newline at end of file
+- In Python, use `@mcp_server` decorator to define MCP server connection
+- In Java, use `@MCPServer` annotation to define MCP server connection
+- Use the builder pattern in Java to configure the MCP server with endpoint,
timeout, headers, and authentication
+- Reference MCP tools by their function name (e.g.,
`"notify_shipping_manager"` in Python, `"notifyShippingManager"` in Java)
+- All tools from the MCP server are automatically registered
+
+### MCP Server Authentication
+
+MCP servers can be configured with authentication in both Python and Java:
+
+{{< tabs "MCP Server Authentication" >}}
+
+{{< tab "Python" >}}
+```python
+@mcp_server
+@staticmethod
+def authenticated_mcp_server() -> MCPServer:
+ """Connect to MCP server with authentication."""
+ return MCPServer(
+ endpoint="http://api.example.com/mcp",
+ headers={"Authorization": "Bearer your-token"}
+ )
Review Comment:
```suggestion
def authenticated_mcp_server() -> MCPServer:
"""Connect to MCP server with authentication."""
return MCPServer(
endpoint="http://api.example.com/mcp",
headers={"Authorization": "Bearer your-token"}
)
# Or using Basic Authentication
# credentials = base64.b64encode(b"username:password").decode("ascii")
# headers={"Authorization": f"Basic {credentials}"}
# Or using API Key Authentication
# headers={"X-API-Key": "your-api-key"}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]