You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@geaflow.apache.org by "Leomrlin (via GitHub)" <gi...@apache.org> on 2025/09/03 07:20:57 UTC

[PR] [MCP] Implement MCP local tools for demo case [geaflow]

Leomrlin opened a new pull request, #610:
URL: https://github.com/apache/geaflow/pull/610

   ### What changes were proposed in this pull request?
   <!--Please describe the major changes for this PR-->
   
   ### How was this PR tested?
   - [ ] Tests have Added for the changes
   - [ ] Production environment verified
   


-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "xincai98 (via GitHub)" <gi...@apache.org>.
xincai98 commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2324011314


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,208 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            throw new RuntimeException("Compile error: " + e.getCause().getMessage());
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+        //Store graph ddl to schema
+        try {
+            McpLocalFileUtil.createAndWriteFile(
+                    QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, ddl, graphName);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "Create graph " + graphName + " success.";
+    }
+
+    @Override
+    public String queryGraph(String graphName, String dml) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            throw new RuntimeException("Cannot get graph schema for: " + graphName);
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            throw new RuntimeException("Compile error: " + compileRunner.getErrorMsg());
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";

Review Comment:
    "USE GRAPH " + graphName + ";\n" has appeared several times, and can be written as a template to format. Same as other pattern.



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "yaozhongq (via GitHub)" <gi...@apache.org>.
yaozhongq merged PR #610:
URL: https://github.com/apache/geaflow/pull/610


-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "Leomrlin (via GitHub)" <gi...@apache.org>.
Leomrlin commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2324449567


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,208 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            throw new RuntimeException("Compile error: " + e.getCause().getMessage());
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+        //Store graph ddl to schema
+        try {
+            McpLocalFileUtil.createAndWriteFile(
+                    QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, ddl, graphName);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "Create graph " + graphName + " success.";
+    }
+
+    @Override
+    public String queryGraph(String graphName, String dml) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            throw new RuntimeException("Cannot get graph schema for: " + graphName);
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            throw new RuntimeException("Compile error: " + compileRunner.getErrorMsg());
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";

Review Comment:
   Added QueryFormatUtil::makeUseGraph



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "Leomrlin (via GitHub)" <gi...@apache.org>.
Leomrlin commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2321103547


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        if (graph == null) {

Review Comment:
   Same as above



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "Leomrlin (via GitHub)" <gi...@apache.org>.
Leomrlin commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2321102341


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+        //Store graph ddl to schema
+        try {
+            McpLocalFileUtil.createAndWriteFile(
+                    QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, ddl, graphName);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "Create graph " + graphName + " success.";
+    }
+
+    @Override
+    public String queryGraph(String graphName, String dml) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();

Review Comment:
   Changed to throw an exception with the error reason.



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "yaozhongq (via GitHub)" <gi...@apache.org>.
yaozhongq commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2332300356


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            throw new RuntimeException("Compile error: " + e.getCause().getMessage());

Review Comment:
   1. RuntimeException -> GeaflowRuntimeException
   2. print the error in the log



##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpServerTools.java:
##########
@@ -114,4 +114,98 @@ public String executeQuery(@Param(name = "query", description = "query") String
             }
         }
     }
+
+
+    /**
+     * A tool that provides create graph capabilities.
+     *
+     * @param graphName graph name to create.
+     * @param ddl Create graph ddl.
+     * @return execute result or error message.
+     */
+    @ToolMapping(description = ToolDesc.createGraph)
+    public String createGraph(@Param(name = McpConstants.GRAPH_NAME, description = "create graph name") String graphName,
+                              @Param(name = McpConstants.DDL, description = "create graph ddl") String ddl) {
+        try {
+            Map<String, Object> config = YamlParser.loadConfig();
+            GeaFlowMcpActions mcpActions = new GeaFlowMcpActionsLocalImpl(config);
+            if (config.containsKey(SERVER_USER)) {
+                mcpActions.withUser(config.get(SERVER_USER).toString());
+            }
+            return mcpActions.createGraph(graphName, ddl);
+        } catch (Exception e) {
+            LOGGER.error(e.getMessage(), e);
+            return e.getMessage();
+        }
+    }
+
+    /**
+     * A tool that get graph schema.
+     *
+     * @param graphName graphName to get.
+     * @return execute result or error message.
+     */
+    @ToolMapping(description = ToolDesc.getGraphSchema)
+    public String getGraphSchema(@Param(name = McpConstants.GRAPH_NAME, description = "get graph schema name") String graphName) {
+        try {
+            Map<String, Object> config = YamlParser.loadConfig();
+            GeaFlowMcpActions mcpActions = new GeaFlowMcpActionsLocalImpl(config);
+            if (config.containsKey(SERVER_USER)) {

Review Comment:
   Allow anonymous inquiries?



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "Leomrlin (via GitHub)" <gi...@apache.org>.
Leomrlin commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2321102987


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+        //Store graph ddl to schema
+        try {
+            McpLocalFileUtil.createAndWriteFile(
+                    QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, ddl, graphName);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "Create graph " + graphName + " success.";
+    }
+
+    @Override
+    public String queryGraph(String graphName, String dml) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            return compileRunner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";
+        runner.withQuery(ddl + "\n" + usingGraph + dml);
+        try {
+            runner.execute();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "run query success: " + dml;
+    }
+
+    @Override
+    public String queryType(String graphName, String type) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            return compileRunner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";
+        String dql = null;
+        String dirName = "query_result_" + Instant.now().toEpochMilli();
+        String resultPath = QueryLocalRunner.DSL_STATE_REMOTE_PATH + "/" + dirName;
+        GeaFlowTable resultTable = null;
+        for (GeaFlowGraph.VertexTable vertexTable : graph.getVertexTables()) {
+            if (vertexTable.getTypeName().equals(type)) {
+                dql = QueryFormatUtil.makeResultTable(vertexTable, resultPath)
+                        + "\n" + QueryFormatUtil.makeEntityTableQuery(vertexTable);
+                resultTable = vertexTable;
+            }
+        }
+        for (GeaFlowGraph.EdgeTable edgeTable : graph.getEdgeTables()) {
+            if (edgeTable.getTypeName().equals(type)) {
+                dql = QueryFormatUtil.makeResultTable(edgeTable, resultPath)
+                        + "\n" + QueryFormatUtil.makeEntityTableQuery(edgeTable);
+                resultTable = edgeTable;
+            }
+        }
+        runner.withQuery(ddl + "\n" + usingGraph + dql);
+        String resultContent = "null";
+        try {
+            runner.execute();
+            resultContent = readFile(resultPath);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        String schemaContent = "type: " + type + "\nschema: " + resultTable.getFields().stream()

Review Comment:
   Added resultTable null check to return error directly.



##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+        //Store graph ddl to schema
+        try {
+            McpLocalFileUtil.createAndWriteFile(
+                    QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, ddl, graphName);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "Create graph " + graphName + " success.";
+    }
+
+    @Override
+    public String queryGraph(String graphName, String dml) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            return compileRunner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";
+        runner.withQuery(ddl + "\n" + usingGraph + dml);
+        try {
+            runner.execute();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "run query success: " + dml;
+    }
+
+    @Override
+    public String queryType(String graphName, String type) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            return compileRunner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";
+        String dql = null;
+        String dirName = "query_result_" + Instant.now().toEpochMilli();
+        String resultPath = QueryLocalRunner.DSL_STATE_REMOTE_PATH + "/" + dirName;
+        GeaFlowTable resultTable = null;
+        for (GeaFlowGraph.VertexTable vertexTable : graph.getVertexTables()) {
+            if (vertexTable.getTypeName().equals(type)) {
+                dql = QueryFormatUtil.makeResultTable(vertexTable, resultPath)
+                        + "\n" + QueryFormatUtil.makeEntityTableQuery(vertexTable);
+                resultTable = vertexTable;
+            }
+        }
+        for (GeaFlowGraph.EdgeTable edgeTable : graph.getEdgeTables()) {
+            if (edgeTable.getTypeName().equals(type)) {
+                dql = QueryFormatUtil.makeResultTable(edgeTable, resultPath)
+                        + "\n" + QueryFormatUtil.makeEntityTableQuery(edgeTable);
+                resultTable = edgeTable;
+            }
+        }
+        runner.withQuery(ddl + "\n" + usingGraph + dql);
+        String resultContent = "null";
+        try {
+            runner.execute();
+            resultContent = readFile(resultPath);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        String schemaContent = "type: " + type + "\nschema: " + resultTable.getFields().stream()
+                .map(TableField::getName).collect(Collectors.joining("|"));
+        return schemaContent + "\n" + resultContent;
+    }
+
+    @Override
+    public String getGraphSchema(String graphName) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();

Review Comment:
   Removed



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "Leomrlin (via GitHub)" <gi...@apache.org>.
Leomrlin commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2335989839


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            throw new RuntimeException("Compile error: " + e.getCause().getMessage());

Review Comment:
   Modified



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "Leomrlin (via GitHub)" <gi...@apache.org>.
Leomrlin commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2335991543


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpServerTools.java:
##########
@@ -114,4 +114,98 @@ public String executeQuery(@Param(name = "query", description = "query") String
             }
         }
     }
+
+
+    /**
+     * A tool that provides create graph capabilities.
+     *
+     * @param graphName graph name to create.
+     * @param ddl Create graph ddl.
+     * @return execute result or error message.
+     */
+    @ToolMapping(description = ToolDesc.createGraph)
+    public String createGraph(@Param(name = McpConstants.GRAPH_NAME, description = "create graph name") String graphName,
+                              @Param(name = McpConstants.DDL, description = "create graph ddl") String ddl) {
+        try {
+            Map<String, Object> config = YamlParser.loadConfig();
+            GeaFlowMcpActions mcpActions = new GeaFlowMcpActionsLocalImpl(config);
+            if (config.containsKey(SERVER_USER)) {
+                mcpActions.withUser(config.get(SERVER_USER).toString());
+            }
+            return mcpActions.createGraph(graphName, ddl);
+        } catch (Exception e) {
+            LOGGER.error(e.getMessage(), e);
+            return e.getMessage();
+        }
+    }
+
+    /**
+     * A tool that get graph schema.
+     *
+     * @param graphName graphName to get.
+     * @return execute result or error message.
+     */
+    @ToolMapping(description = ToolDesc.getGraphSchema)
+    public String getGraphSchema(@Param(name = McpConstants.GRAPH_NAME, description = "get graph schema name") String graphName) {
+        try {
+            Map<String, Object> config = YamlParser.loadConfig();
+            GeaFlowMcpActions mcpActions = new GeaFlowMcpActionsLocalImpl(config);
+            if (config.containsKey(SERVER_USER)) {

Review Comment:
   The user serves to distinguish the context and can be empty.



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "kitalkuyo-gita (via GitHub)" <gi...@apache.org>.
kitalkuyo-gita commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2320645170


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+        //Store graph ddl to schema
+        try {
+            McpLocalFileUtil.createAndWriteFile(
+                    QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, ddl, graphName);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "Create graph " + graphName + " success.";
+    }
+
+    @Override
+    public String queryGraph(String graphName, String dml) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            return compileRunner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";
+        runner.withQuery(ddl + "\n" + usingGraph + dml);
+        try {
+            runner.execute();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "run query success: " + dml;
+    }
+
+    @Override
+    public String queryType(String graphName, String type) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            return compileRunner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";
+        String dql = null;
+        String dirName = "query_result_" + Instant.now().toEpochMilli();
+        String resultPath = QueryLocalRunner.DSL_STATE_REMOTE_PATH + "/" + dirName;
+        GeaFlowTable resultTable = null;
+        for (GeaFlowGraph.VertexTable vertexTable : graph.getVertexTables()) {
+            if (vertexTable.getTypeName().equals(type)) {
+                dql = QueryFormatUtil.makeResultTable(vertexTable, resultPath)
+                        + "\n" + QueryFormatUtil.makeEntityTableQuery(vertexTable);
+                resultTable = vertexTable;
+            }
+        }
+        for (GeaFlowGraph.EdgeTable edgeTable : graph.getEdgeTables()) {
+            if (edgeTable.getTypeName().equals(type)) {
+                dql = QueryFormatUtil.makeResultTable(edgeTable, resultPath)
+                        + "\n" + QueryFormatUtil.makeEntityTableQuery(edgeTable);
+                resultTable = edgeTable;
+            }
+        }
+        runner.withQuery(ddl + "\n" + usingGraph + dql);
+        String resultContent = "null";
+        try {
+            runner.execute();
+            resultContent = readFile(resultPath);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        String schemaContent = "type: " + type + "\nschema: " + resultTable.getFields().stream()

Review Comment:
   The variables dql and resultTable may be null, but no null value processing is performed subsequently. Directly accessing resultTable.getFields() may cause NPE risk.



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "kitalkuyo-gita (via GitHub)" <gi...@apache.org>.
kitalkuyo-gita commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2320643995


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+        //Store graph ddl to schema
+        try {
+            McpLocalFileUtil.createAndWriteFile(
+                    QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, ddl, graphName);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "Create graph " + graphName + " success.";
+    }
+
+    @Override
+    public String queryGraph(String graphName, String dml) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();

Review Comment:
   When graph == null, an exception is thrown directly. For other errors, a string is returned. The error handling style is inconsistent. Even if there is a judgment below that graph == null, a string will be returned.



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "kitalkuyo-gita (via GitHub)" <gi...@apache.org>.
kitalkuyo-gita commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2320647529


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+        //Store graph ddl to schema
+        try {
+            McpLocalFileUtil.createAndWriteFile(
+                    QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, ddl, graphName);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "Create graph " + graphName + " success.";
+    }
+
+    @Override
+    public String queryGraph(String graphName, String dml) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            return compileRunner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";
+        runner.withQuery(ddl + "\n" + usingGraph + dml);
+        try {
+            runner.execute();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        return "run query success: " + dml;
+    }
+
+    @Override
+    public String queryType(String graphName, String type) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();
+        String ddl = null;
+        try {
+            ddl = McpLocalFileUtil.readFile(QueryLocalRunner.DSL_STATE_REMOTE_SCHEM_PATH, graphName);
+        } catch (Throwable e) {
+            return "Cannot get graph schema for: " + graphName;
+        }
+        compileRunner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = compileRunner.compileGraph();
+        } catch (Throwable e) {
+            return compileRunner.getErrorMsg();
+        }
+        if (graph == null) {
+            throw new RuntimeException("Cannot create graph: " + graphName);
+        }
+
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphDefine(ddl);
+        String usingGraph = "USE GRAPH " + graphName + ";\n";
+        String dql = null;
+        String dirName = "query_result_" + Instant.now().toEpochMilli();
+        String resultPath = QueryLocalRunner.DSL_STATE_REMOTE_PATH + "/" + dirName;
+        GeaFlowTable resultTable = null;
+        for (GeaFlowGraph.VertexTable vertexTable : graph.getVertexTables()) {
+            if (vertexTable.getTypeName().equals(type)) {
+                dql = QueryFormatUtil.makeResultTable(vertexTable, resultPath)
+                        + "\n" + QueryFormatUtil.makeEntityTableQuery(vertexTable);
+                resultTable = vertexTable;
+            }
+        }
+        for (GeaFlowGraph.EdgeTable edgeTable : graph.getEdgeTables()) {
+            if (edgeTable.getTypeName().equals(type)) {
+                dql = QueryFormatUtil.makeResultTable(edgeTable, resultPath)
+                        + "\n" + QueryFormatUtil.makeEntityTableQuery(edgeTable);
+                resultTable = edgeTable;
+            }
+        }
+        runner.withQuery(ddl + "\n" + usingGraph + dql);
+        String resultContent = "null";
+        try {
+            runner.execute();
+            resultContent = readFile(resultPath);
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        String schemaContent = "type: " + type + "\nschema: " + resultTable.getFields().stream()
+                .map(TableField::getName).collect(Collectors.joining("|"));
+        return schemaContent + "\n" + resultContent;
+    }
+
+    @Override
+    public String getGraphSchema(String graphName) {
+        QueryLocalRunner compileRunner = new QueryLocalRunner();

Review Comment:
   This variable is not used, is it reserved?



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org


Re: [PR] [MCP] Implement MCP local tools for demo case [geaflow]

Posted by "kitalkuyo-gita (via GitHub)" <gi...@apache.org>.
kitalkuyo-gita commented on code in PR #610:
URL: https://github.com/apache/geaflow/pull/610#discussion_r2320688362


##########
geaflow-mcp/src/main/java/org/apache/geaflow/mcp/server/GeaFlowMcpActionsLocalImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.geaflow.mcp.server;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.geaflow.cluster.local.client.LocalEnvironment;
+import org.apache.geaflow.dsl.common.types.TableField;
+import org.apache.geaflow.dsl.schema.GeaFlowGraph;
+import org.apache.geaflow.dsl.schema.GeaFlowTable;
+import org.apache.geaflow.env.IEnvironment;
+import org.apache.geaflow.mcp.server.util.McpLocalFileUtil;
+import org.apache.geaflow.mcp.server.util.QueryFormatUtil;
+import org.apache.geaflow.mcp.server.util.QueryLocalRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class GeaFlowMcpActionsLocalImpl implements GeaFlowMcpActions {
+
+    private Map<String, Object> configs;
+    private String user;
+    private IEnvironment localEnv = new LocalEnvironment();
+
+    public GeaFlowMcpActionsLocalImpl(Map<String, Object> configs) {
+        this.configs = configs;
+    }
+
+    @Override
+    public String createGraph(String graphName, String ddl) {
+        QueryLocalRunner runner = new QueryLocalRunner();
+        runner.withGraphName(graphName).withGraphDefine(ddl);
+        GeaFlowGraph graph;
+        try {
+            graph = runner.compileGraph();
+        } catch (Throwable e) {
+            return runner.getErrorMsg();
+        }
+        if (graph == null) {

Review Comment:
   When graph == null, an exception is thrown directly. For other errors, a string is returned. The error handling style is inconsistent. Even if there is a judgment below that graph == null, a string will be returned.



-- 
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: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org