MCP ExplorerExplorer

Dart Mcp

@crbroteaon 10 months ago
1 MIT
FreeCommunity
AI Systems
A Dart implementation of the Model Context Protocol (MCP)

Overview

What is Dart Mcp

dart_mcp is a Dart implementation of the Model Context Protocol (MCP), which facilitates communication between clients and servers in a structured manner.

Use cases

Use cases for dart_mcp include building client-server applications, implementing tools that require communication with a server, and developing applications that need to handle notifications and requests efficiently.

How to use

To use dart_mcp, add it to your project’s pubspec.yaml file as a dependency. You can then create a client or server using the provided examples, initializing them with the necessary capabilities and handling requests and notifications.

Key features

Key features of dart_mcp include a full implementation of the MCP specification, support for both client and server roles, a built-in stdio transport layer, a type-safe API with JSON serialization, and comprehensive test coverage.

Where to use

dart_mcp can be used in various domains where structured communication between clients and servers is required, such as in real-time applications, data synchronization, and remote procedure calls.

Content

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:

dependencies:
  dart_mcp: ^1.0.0

Usage

Client Example

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

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.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers