trackmcp
Back to directory

A Dart implementation of the Model Context Protocol (MCP)

2 stars DartAI & Machine Learning Updated Aug 30, 2025

Documentation

dart_mcp

A Dart implementation of the Model Context Protocol (MCP).

Features

  • Full implementation of the MCP specification
  • Support for both client and server roles
  • Built-in stdio transport layer
  • Type-safe API with JSON serialization
  • Comprehensive test coverage

Installation

Add this to your package's `pubspec.yaml` file:

yaml
dependencies:
  dart_mcp: ^1.0.0

Usage

Client Example

dart
import 'package:dart_mcp/dart_mcp.dart';

void main() async {
  // Create a transport for the client
  final transport = StdioTransport();

  // Create a client with basic capabilities
  final client = McpClient(transport);

  try {
    // Initialize the client
    final result = await client.initialize(
      capabilities: ClientCapabilities(
        sampling: SamplingCapability(),
      ),
      clientInfo: Implementation(
        name: 'example-client',
        version: '1.0.0',
      ),
    );

    print('Connected to server: ${result.serverInfo.name} ${result.serverInfo.version}');
    print('Server capabilities: ${result.capabilities}');
    
    // Send a ping request
    await client.sendRequest('ping');
    print('Ping successful');

  } catch (e) {
    print('Error: $e');
  } finally {
    await client.close();
  }
}

Server Example

dart
import 'package:dart_mcp/dart_mcp.dart';

void main() async {
  // Create a transport for the server
  final transport = StdioTransport();

  // Create a server with capabilities
  final server = McpServer(
    transport: transport,
    capabilities: ServerCapabilities(
      tools: ToolsCapability(),
      resources: ResourcesCapability(),
    ),
    serverInfo: Implementation(
      name: 'example-server',
      version: '1.0.0',
    ),
  );

  // Register request handlers
  server.onRequest('ping', (params) async {
    return EmptyResult();
  });

  // Handle client notifications
  server.onNotification('notifications/initialized', (params) {
    print('Client initialized');
  });
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

License

MIT License - see LICENSE file for details.

Frequently asked questions

What is dart_mcp?

dart_mcp is A Dart implementation of the Model Context Protocol (MCP)

How do I install dart_mcp?

Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.

Is dart_mcp open source?

Yes — it is hosted on GitHub at https://github.com/cristhro/dart_mcp and has 2 stars.

Related MCP tools

Run your own MCP server? See who uses it and what to fix.

Measure it with TrackMCP