diff --git a/pom.xml b/pom.xml
index 36ed71b..6650ff3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,6 +66,9 @@
0.1.0-SNAPSHOT
0.12.0
+ 21
+
+
@@ -73,7 +76,9 @@
com.kingsrook.qqq
qqq-bom-pom
- 0.40.0
+
+ 4.1.0-RC.21
pom
import
@@ -97,7 +102,14 @@
com.fasterxml.jackson.core
jackson-databind
- 2.14.0
+
+
+
+
+ jakarta.servlet
+ jakarta.servlet-api
+ 6.0.0
+ provided
@@ -108,13 +120,48 @@
org.assertj
assertj-core
- 3.27.3
+ 3.27.7
+ test
+
+
+ com.kingsrook.qqq
+ qqq-middleware-javalin
+ test
+
+
+ com.kingsrook.qqq
+ qqq-backend-module-rdbms
+ test
+
+
+ com.kingsrook.qqq
+ qqq-backend-module-postgres
+ test
+
+
+ com.h2database
+ h2
+ 2.2.220
+ test
+
+
+ org.testcontainers
+ testcontainers
+ 2.0.3
test
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ @{argLine} -Duser.timezone=UTC
+
+
org.jacoco
jacoco-maven-plugin
diff --git a/src/main/java/com/kingsrook/qbits/middlewaremcp/TableAccess.java b/src/main/java/com/kingsrook/qbits/middlewaremcp/TableAccess.java
new file mode 100644
index 0000000..d2fbf35
--- /dev/null
+++ b/src/main/java/com/kingsrook/qbits/middlewaremcp/TableAccess.java
@@ -0,0 +1,91 @@
+/*
+ * QQQ - Low-code Application Framework for Engineers.
+ * Copyright (C) 2021-2024. Kingsrook, LLC
+ * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
+ * contact@kingsrook.com
+ * https://github.com/Kingsrook/
+ *
+ * Licensed 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 com.kingsrook.qbits.middlewaremcp;
+
+
+import java.util.Set;
+import com.kingsrook.qbits.middlewaremcp.model.MCPTableMetaData;
+import com.kingsrook.qqq.backend.core.actions.metadata.MetaDataAction;
+import com.kingsrook.qqq.backend.core.exceptions.QException;
+import com.kingsrook.qqq.backend.core.model.actions.metadata.MetaDataInput;
+import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
+import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
+
+
+/*******************************************************************************
+ ** Which tables the CURRENT session may even learn about through MCP. A table is
+ ** discoverable only if the server exposes it (allow list, not hidden, not
+ ** excluded) AND the session's own permissions let it see the table (the same
+ ** decision the application's metadata makes for that session), so listing and
+ ** describing never disclose a table the caller could not open. Must be called
+ ** with the caller's QContext in place.
+ *******************************************************************************/
+public final class TableAccess
+{
+ /***************************************************************************
+ ** Utility class.
+ ***************************************************************************/
+ private TableAccess()
+ {
+ }
+
+
+
+ /***************************************************************************
+ ** The table names the current session may see, from the application's own
+ ** metadata for that session.
+ ***************************************************************************/
+ public static Set visibleToSession() throws QException
+ {
+ return new MetaDataAction().execute(new MetaDataInput()).getTables().keySet();
+ }
+
+
+
+ /***************************************************************************
+ ** Whether the table is exposed by this server (independent of the caller).
+ ***************************************************************************/
+ public static boolean isExposed(QInstance qInstance, QMCPMetaData mcpMetaData, String tableName)
+ {
+ QTableMetaData table = qInstance.getTable(tableName);
+ if(table == null || Boolean.TRUE.equals(table.getIsHidden()))
+ {
+ return false;
+ }
+ Set exposed = mcpMetaData.getExposedTableNames();
+ if(exposed != null && !exposed.contains(tableName))
+ {
+ return false;
+ }
+ MCPTableMetaData supplemental = (MCPTableMetaData) table.getSupplementalMetaData(MCPTableMetaData.TYPE);
+ return supplemental == null || !supplemental.isExcluded();
+ }
+
+
+
+ /***************************************************************************
+ ** Exposed by this server and visible to the current session.
+ ***************************************************************************/
+ public static boolean isDiscoverable(QInstance qInstance, QMCPMetaData mcpMetaData, String tableName) throws QException
+ {
+ return isExposed(qInstance, mcpMetaData, tableName) && visibleToSession().contains(tableName);
+ }
+}
diff --git a/src/main/java/com/kingsrook/qbits/middlewaremcp/resources/TableListResourceHandler.java b/src/main/java/com/kingsrook/qbits/middlewaremcp/resources/TableListResourceHandler.java
index b8d2a51..f10e4c1 100644
--- a/src/main/java/com/kingsrook/qbits/middlewaremcp/resources/TableListResourceHandler.java
+++ b/src/main/java/com/kingsrook/qbits/middlewaremcp/resources/TableListResourceHandler.java
@@ -33,6 +33,7 @@ import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qbits.middlewaremcp.QMCPMetaData;
+import com.kingsrook.qbits.middlewaremcp.TableAccess;
import com.kingsrook.qbits.middlewaremcp.model.MCPTableMetaData;
import com.kingsrook.qbits.middlewaremcp.session.MCPSessionProviderInterface;
import io.modelcontextprotocol.server.McpSyncServerExchange;
@@ -77,6 +78,7 @@ public class TableListResourceHandler
try
{
Set exposedTableNames = mcpMetaData.getExposedTableNames();
+ Set visible = TableAccess.visibleToSession();
List