Skip to content

Commit 6a9bcee

Browse files
committed
Finish test
1 parent c6338e1 commit 6a9bcee

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

api/src/org/labkey/api/mcp/McpService.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
import io.modelcontextprotocol.server.McpServerFeatures;
55
import jakarta.servlet.http.HttpSession;
6+
import org.apache.logging.log4j.Logger;
67
import org.jetbrains.annotations.NotNull;
78
import org.jspecify.annotations.NonNull;
89
import org.labkey.api.data.Container;
910
import org.labkey.api.security.User;
1011
import org.labkey.api.services.ServiceRegistry;
1112
import org.labkey.api.util.HtmlString;
13+
import org.labkey.api.util.logging.LogHelper;
1214
import org.labkey.api.writer.ContainerUser;
1315
import org.springframework.ai.chat.client.ChatClient;
1416
import org.springframework.ai.chat.model.ToolContext;
@@ -78,6 +80,8 @@
7880
///
7981
public interface McpService extends ToolCallbackProvider
8082
{
83+
Logger LOG = LogHelper.getLogger(McpService.class, "MCP registration exceptions");
84+
8185
// Interface for MCP classes that we will "ingest" using Spring annotations. Provides a few helper methods.
8286
interface McpImpl
8387
{
@@ -119,13 +123,21 @@ static void setInstance(McpService service)
119123

120124
default void register(McpImpl mcp)
121125
{
122-
ToolCallback[] tools = ToolCallbacks.from(mcp);
123-
if (tools.length > 0)
124-
registerTools(Arrays.asList(tools), mcp);
126+
try
127+
{
128+
ToolCallback[] tools = ToolCallbacks.from(mcp);
129+
if (tools.length > 0)
130+
registerTools(Arrays.asList(tools), mcp);
125131

126-
var resources = new SyncMcpResourceProvider(List.of(mcp)).getResourceSpecifications();
127-
if (null != resources && !resources.isEmpty())
128-
registerResources(resources);
132+
var resources = new SyncMcpResourceProvider(List.of(mcp)).getResourceSpecifications();
133+
if (null != resources && !resources.isEmpty())
134+
registerResources(resources);
135+
}
136+
catch (Exception e)
137+
{
138+
String advice = e.getMessage().contains("victools") ? " Try doing a clean build of API." : "";
139+
LOG.error("Exception while registering MCP implementations. The MCP server will not be available.{}", advice, e);
140+
}
129141
}
130142

131143
void registerTools(@NotNull List<ToolCallback> tools, McpImpl mcp);

query/src/org/labkey/query/controllers/QueryMcp.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static JSONObject _listTables(String fullQuotedName, ContainerUser cu)
162162
var defaultSchema = DefaultSchema.get(cu.getUser(), cu.getContainer());
163163
var schema = DefaultSchema.resolve(defaultSchema, fullKey);
164164
if (!(schema instanceof UserSchema userSchema))
165-
throw new NotFoundException("Could not find schema for " + fullQuotedName);
165+
throw new NotFoundException("Could not find schema " + fullQuotedName);
166166

167167
JSONArray array = new JSONArray();
168168
CaseInsensitiveHashSet names = new CaseInsensitiveHashSet(schema.getTableNames());
@@ -218,7 +218,7 @@ public JSONObject _listColumns(String fullQuotedName, ToolContext toolContext)
218218
}
219219
else if (fullKey.size() == 1)
220220
{
221-
throw new NotFoundException("You need to provide a fully qualified schema and table");
221+
throw new NotFoundException("tableName must be a fully qualified schema and table e.g. \"schema\".\"table or query\"");
222222
}
223223
else
224224
{
@@ -231,11 +231,11 @@ else if (fullKey.size() == 1)
231231

232232
var schema = DefaultSchema.resolve(defaultSchema, schemaKey);
233233
if (null == schema)
234-
throw new NotFoundException("Could not find schema for : " + fullQuotedName);
234+
throw new NotFoundException("Could not find schema " + fullQuotedName);
235235

236236
TableInfo td = schema.getTable(tableName, null);
237237
if (null == td)
238-
throw new NotFoundException("Could not find table for : " + fullQuotedName);
238+
throw new NotFoundException("Could not find table " + fullQuotedName);
239239

240240
String sourceSQL = null;
241241
if (schema instanceof UserSchema userSchema)

0 commit comments

Comments
 (0)