|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:io'; |
| 6 | + |
| 7 | +import 'package:dart_mcp/client.dart'; |
| 8 | +import 'package:test/test.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + group('dart mcp-server', () { |
| 12 | + test('can be connected with a client', () async { |
| 13 | + final client = TestMCPClient(); |
| 14 | + addTearDown(client.shutdown); |
| 15 | + final serverConnection = await client.connectStdioServer( |
| 16 | + Platform.resolvedExecutable, |
| 17 | + ['mcp-server', '--experimental-mcp-server']); |
| 18 | + final initializeResult = await serverConnection.initialize( |
| 19 | + InitializeRequest( |
| 20 | + protocolVersion: ProtocolVersion.latestSupported, |
| 21 | + capabilities: client.capabilities, |
| 22 | + clientInfo: client.implementation)); |
| 23 | + |
| 24 | + expect(initializeResult.protocolVersion, ProtocolVersion.latestSupported); |
| 25 | + serverConnection.notifyInitialized(); |
| 26 | + |
| 27 | + expect( |
| 28 | + await serverConnection.listTools(ListToolsRequest()), |
| 29 | + isNotEmpty, |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + test('requires the --experimental-mcp-server flag', () async { |
| 34 | + final processResult = |
| 35 | + await Process.run(Platform.resolvedExecutable, ['mcp-server']); |
| 36 | + expect(processResult.exitCode, isNot(0)); |
| 37 | + expect(processResult.stderr, |
| 38 | + contains('Missing required flag --experimental-mcp-server')); |
| 39 | + }); |
| 40 | + }); |
| 41 | +} |
| 42 | + |
| 43 | +base class TestMCPClient extends MCPClient { |
| 44 | + TestMCPClient() |
| 45 | + : super(Implementation(name: 'test client', version: '0.1.0')); |
| 46 | +} |
0 commit comments