Skip to content

Commit b29c23f

Browse files
Fix: Correct resource fallback tool detection logic
The previous logic incorrectly checked clientCapabilities.resources which doesn't exist (resources is a SERVER capability, not a CLIENT capability). Now correctly detects clients by name using getClientVersion() and only registers fallback tools for clients with known resource support issues (e.g., Claude Desktop). Result: MCP Inspector and other proper clients now see 23 tools instead of 26, with resource fallback tools only appearing for Claude clients. MCP Inspector Output After Fix: Tools (23): [ "bounding_box_tool", "check_color_contrast_tool", "compare_styles_tool", "coordinate_conversion_tool", "country_bounding_box_tool", "create_style_tool", "create_token_tool", "delete_style_tool", "geojson_preview_tool", "get_feedback_tool", "list_feedback_tool", "list_styles_tool", "list_tokens_tool", "optimize_style_tool", "preview_style_tool", "retrieve_style_tool", "style_builder_tool", "style_comparison_tool", "tilequery_tool", "update_style_tool", "validate_expression_tool", "validate_geojson_tool", "validate_style_tool" ] Resources (5): [ "resource://mapbox-documentation", "resource://mapbox-layer-type-mapping", "resource://mapbox-streets-v8-fields", "resource://mapbox-style-layers", "resource://mapbox-token-scopes" ] Fixes dynamic tool registration to work as intended.
1 parent 0b57cb9 commit b29c23f

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

src/index.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ async function main() {
226226

227227
// After connection, dynamically register capability-dependent tools
228228
const clientCapabilities = server.server.getClientCapabilities();
229+
230+
// Debug: Log what capabilities we detected
231+
server.server.sendLoggingMessage({
232+
level: 'info',
233+
data: `Client capabilities detected: ${JSON.stringify(clientCapabilities, null, 2)}`
234+
});
235+
229236
let toolsAdded = false;
230237

231238
// Register elicitation tools if client supports elicitation
@@ -246,14 +253,20 @@ async function main() {
246253
});
247254
}
248255

249-
// Register resource fallback tools if client doesn't properly support resources
250-
// Note: GetReferenceTool exists as a workaround for Claude Desktop which lists resources
251-
// but doesn't automatically fetch them. Most modern clients support resources properly.
252-
const supportsResources = clientCapabilities?.resources !== undefined;
253-
if (!supportsResources && enabledResourceFallbackTools.length > 0) {
256+
// Register resource fallback tools for clients with known resource support issues
257+
// Note: Resources are a core MCP feature, but some clients (like Claude Desktop) can list
258+
// resources but don't automatically fetch them. We detect these clients by name.
259+
// Most modern MCP clients (Inspector, VS Code, etc.) support resources properly.
260+
const clientVersion = server.server.getClientVersion();
261+
const clientName = clientVersion?.name?.toLowerCase() || '';
262+
263+
// Known clients with resource support issues
264+
const needsResourceFallback = clientName.includes('claude');
265+
266+
if (needsResourceFallback && enabledResourceFallbackTools.length > 0) {
254267
server.server.sendLoggingMessage({
255268
level: 'info',
256-
data: `Client lacks full resource support. Registering ${enabledResourceFallbackTools.length} resource fallback tools`
269+
data: `Client "${clientVersion?.name}" has known resource issues. Registering ${enabledResourceFallbackTools.length} resource fallback tools`
257270
});
258271

259272
enabledResourceFallbackTools.forEach((tool) => {
@@ -263,7 +276,7 @@ async function main() {
263276
} else if (enabledResourceFallbackTools.length > 0) {
264277
server.server.sendLoggingMessage({
265278
level: 'debug',
266-
data: `Client supports resources properly. Skipping ${enabledResourceFallbackTools.length} resource fallback tools`
279+
data: `Client "${clientVersion?.name}" supports resources properly. Skipping ${enabledResourceFallbackTools.length} resource fallback tools`
267280
});
268281
}
269282

0 commit comments

Comments
 (0)