MCPInstall
dart_mcp logo

dart_mcp

by crbrotea 4 stars crbrotea/dart_mcp

A Dart implementation of the Model Context Protocol (MCP)

READMEmain

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.

More Developer Tools MCP servers

Similar servers from the same category.

Sourcebot

sourcebot-dev

Enables code search across multiple repository hosts including GitHub, GitLab, Gitea, Gerrit, and Bitbucket with advanced filtering options for exploring large codebases through natural language queries.

searchgit

CodeAlive

codealive-ai

Provides a bridge to CodeAlive's platform for semantic code search, repository exploration, and context-aware chat completions that leverage deep understanding of entire codebases including documentation and dependencies.

search

Provides a secure, sandboxed environment for executing Python, Node.js, and shell commands in ephemeral containers with file management capabilities for code testing, visualization, and data analysis.

filesystemdatabase

NovaCV

lightbaby

Integrates with NovaCV API to generate, analyze, and convert resumes in various formats without dealing with complex document formatting

PDFSupport+5