Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions pkgs/dart_mcp_server/lib/src/mixins/pub_dev_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ import '../utils/json.dart';
/// Limit the number of concurrent requests.
final _pool = Pool(10);

/// The number of reults to return for a query.
/// The number of results to return for a query.
// If this should be set higher than 10 we need to implement paging of the
// http://pub.dev/api/search endpoint.
final _resultsLimit = 10;

/// The number of identifiers we list per packages.
final _maxIdentifiersListed = 200;

/// Mix this in to any MCPServer to add support for doing searches on pub.dev.
base mixin PubDevSupport on ToolsSupport {
final _client = Client();
Expand Down Expand Up @@ -56,7 +53,7 @@ base mixin PubDevSupport on ToolsSupport {
return CallToolResult(
content: [
TextContent(
text: 'No packages mached the query, consider simplifying it.',
text: 'No packages matched the query, consider simplifying it.',
),
],
isError: true,
Expand All @@ -80,9 +77,6 @@ base mixin PubDevSupport on ToolsSupport {
(packageName) => (
versionListing: retrieve('api/packages/$packageName'),
score: retrieve('api/packages/$packageName/score'),
docIndex: retrieve(
'documentation/$packageName/latest/index.json',
),
),
)
.toList();
Expand All @@ -94,18 +88,6 @@ base mixin PubDevSupport on ToolsSupport {
final packageName = packageNames[i];
final versionListing = await subQueryFutures[i].versionListing;
final scoreResult = await subQueryFutures[i].score;
final docIndex = await subQueryFutures[i].docIndex;

Map<String, Object?> identifiers(Object index) {
final items = dig<List>(index, []);
return {
'qualifiedNames': [
for (final item in items.take(_maxIdentifiersListed))
dig<String>(item, ['qualifiedName']),
],
};
}

results.add(
TextContent(
text: jsonEncode({
Expand Down Expand Up @@ -144,7 +126,6 @@ base mixin PubDevSupport on ToolsSupport {
.where((t) => (t as String).startsWith('publisher:'))
.firstOrNull,
},
if (docIndex != null) ...{'api': identifiers(docIndex)},
}),
),
);
Expand All @@ -164,8 +145,7 @@ base mixin PubDevSupport on ToolsSupport {
description:
'Searches pub.dev for packages relevant to a given search query. '
'The response will describe each result with its download count, '
'package description, topics, license, publisher, and a list of '
'identifiers in the public api.',
'package description, topics, license, and publisher.',
annotations: ToolAnnotations(title: 'pub.dev search', readOnlyHint: true),
inputSchema: Schema.object(
properties: {
Expand Down
5 changes: 1 addition & 4 deletions pkgs/dart_mcp_server/test/tools/pub_dev_search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ void main() {
'license:osi-approved',
],
'publisher': 'publisher:google.dev',
'api': {
'qualifiedNames': containsAll(['retry', 'retry.RetryOptions']),
},
});
});
}, _GoldenResponseClient.new);
Expand Down Expand Up @@ -161,7 +158,7 @@ void main() {
expect(result.isError, isTrue);
expect(
(result.content[0] as TextContent).text,
contains('No packages mached the query, consider simplifying it'),
contains('No packages matched the query, consider simplifying it'),
);
});
},
Expand Down