pubdev_context 0.4.0-rc.1 copy "pubdev_context: ^0.4.0-rc.1" to clipboard
pubdev_context: ^0.4.0-rc.1 copied to clipboard

Model Context Protocol (MCP) server for pub.dev. Gives AI agents structured access to search, compare, evaluate, and inspect Dart and Flutter packages.

example/pubdev_context.dart

/// Example: start pubdev_context and query it with an in-process MCP client.
///
/// Run from the package root:
/// ```bash
/// dart run example/pubdev_context.dart
/// ```
library;

import 'dart:async';
import 'dart:io';

import 'package:dart_mcp/client.dart';
import 'package:pubdev_context/src/cache/memory_cache.dart';
import 'package:pubdev_context/src/config/config.dart';
import 'package:pubdev_context/src/data/models.dart';
import 'package:pubdev_context/src/data/pub_client.dart';
import 'package:pubdev_context/src/server.dart';
import 'package:stream_channel/stream_channel.dart';

Future<void> main() async {
  // Wire an in-process channel pair so server and client share a process.
  final clientCtrl = StreamController<String>();
  final serverCtrl = StreamController<String>();
  serverCtrl.stream.listen(null, onDone: () {});

  final serverChannel = StreamChannel<String>.withCloseGuarantee(
    clientCtrl.stream,
    serverCtrl.sink,
  );
  final clientChannel = StreamChannel<String>.withCloseGuarantee(
    serverCtrl.stream,
    clientCtrl.sink,
  );

  // Start the server.
  final server = PubMcpServer(
    serverChannel,
    config: const PubMcpConfig(),
    client: PubDevClient(),
    searchCache: ResponseCache<List<PackageSummary>>(),
    packageCache: ResponseCache<PackageDetail>(),
    changelogCache: ResponseCache<List<ChangelogEntry>>(),
    changelogRawCache: ResponseCache<String>(),
    apiIndexCache: ResponseCache<List<DartdocSymbol>>(),
    readmeCache: ResponseCache<String>(),
    symbolDocCache: ResponseCache<String>(),
    sourceFilesCache: ResponseCache<Map<String, String>>(),
    metaCache: ResponseCache<String>(),
  );

  // Connect an MCP client and initialise.
  final mcpClient = _ExampleClient();
  final connection = mcpClient.connectServer(clientChannel);
  await connection.initialize(
    InitializeRequest(
      protocolVersion: ProtocolVersion.latestSupported,
      capabilities: mcpClient.capabilities,
      clientInfo: mcpClient.implementation,
    ),
  );
  connection.notifyInitialized(InitializedNotification());
  await server.initialized;

  // Call search_packages.
  final result = await connection.callTool(
    CallToolRequest(
      name: 'search_packages',
      arguments: {'query': 'http', 'limit': 3, 'sort': 'likes'},
    ),
  );

  final text = (result.content.first as TextContent).text;
  stdout.writeln(text);

  await mcpClient.shutdown();
  await server.shutdown();
}

base class _ExampleClient extends MCPClient {
  _ExampleClient() : super(Implementation(name: 'example-client', version: '0.0.1'));
}
1
likes
160
points
264
downloads

Documentation

API reference

Publisher

verified publisherphilippgerber.li

Weekly Downloads

Model Context Protocol (MCP) server for pub.dev. Gives AI agents structured access to search, compare, evaluate, and inspect Dart and Flutter packages.

Homepage
Repository (GitHub)
View/report issues

Topics

#mcp #pub-dev #dart #ai #flutter

License

MIT (license)

Dependencies

analyzer, archive, cli_config, dart_mcp, html, http

More

Packages that depend on pubdev_context