Skip to content

Instructions may be null #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
domesticmouse opened this issue Apr 30, 2025 · 1 comment
Closed

Instructions may be null #97

domesticmouse opened this issue Apr 30, 2025 · 1 comment

Comments

@domesticmouse
Copy link
Member

While attempting to run my mcp_client against @modelcontextprotocol/server-filesystem I hit an issue:

$ dart run bin/mcp_client.dart \
  npx -y @modelcontextprotocol/server-filesystem \
  ../../colorist_ui
connecting to server
server started
initializing server
[StdErr from server npx]: Secure MCP Filesystem Server running on stdio
[StdErr from server npx]: Allowed directories: [ '/Users/brett/Documents/GitHub/colorist_ui' ]
Unhandled exception:
type 'Null' is not a subtype of type 'String' in type cast
#0      InitializeResult.instructions (package:dart_mcp/src/api/initialization.dart:68:53)
#1      main (file:///Users/brett/Documents/GitHub/developer_assistant_mcp/mcp_client/bin/mcp_client.dart:38:36)
<asynchronous suspension>

The core issue is that the dart_mcp initialization code assumes that the server always supplies instructions.

Here's my code, for reference:

// Copyright (c) 2025, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:dart_mcp/client.dart';

void main(List<String> args) async {
  if (args.isEmpty) {
    print('Usage: dart mcp_client.dart <mcp server command>');
    return;
  }

  final client = MCPClient(
    ClientImplementation(name: 'example dart client', version: '0.1.0'),
  );
  print('connecting to server');
  final server = await client.connectStdioServer(
    args.first,
    args.length > 1 ? args.sublist(1) : [],
  );
  print('server started');

  print('initializing server');
  final initializeResult = await server.initialize(
    InitializeRequest(
      protocolVersion: protocolVersion,
      capabilities: client.capabilities,
      clientInfo: client.implementation,
    ),
  );
  print('''
Initialized:
  Protocol Version: ${initializeResult.protocolVersion}
  Capabilities: ${initializeResult.capabilities}
  Server Info:
    Name: ${initializeResult.serverInfo.name}
    Version: ${initializeResult.serverInfo.version}
  Instructions: ${initializeResult.instructions}
''');
  if (initializeResult.protocolVersion != protocolVersion) {
    throw StateError(
      'Protocol version mismatch, expected $protocolVersion, '
      'got ${initializeResult.protocolVersion}',
    );
  }

  if (initializeResult.capabilities.tools == null) {
    await server.shutdown();
    throw StateError('Server doesn\'t support tools!');
  }

  server.notifyInitialized(InitializedNotification());
  print('sent initialized notification');

  print('Listing tools from server: ');
  final toolsResult = await server.listTools(ListToolsRequest());
  for (final tool in toolsResult.tools) {
    print('  - Tool: ${tool.name}');
    final description = tool.description;
    if (description != null) print('    Description: $description');
  }

  await client.shutdown();
}
@jakemac53
Copy link
Contributor

closed by #98

sigurdm pushed a commit to sigurdm/ai that referenced this issue May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants