Skip to content

Commit 4ca0ff1

Browse files
authored
Use shared Implementation type, add clientInfo field to MCPServer (#175)
In the [latest schema](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-03-26/schema.json) the ClientImplementation and ServerImplementation types were merged into a single Implementation type, this updates things to match. Also closes #173 which will make #174 slightly cleaner, and matches what we do for ServerConnection as well.
1 parent 885a4c5 commit 4ca0ff1

19 files changed

+56
-54
lines changed

mcp_examples/bin/file_system_server.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ final class SimpleFileSystemServer extends MCPServer
3333
with LoggingSupport, RootsTrackingSupport, ToolsSupport {
3434
SimpleFileSystemServer.fromStreamChannel(super.channel)
3535
: super.fromStreamChannel(
36-
implementation: ServerImplementation(
37-
name: 'file system',
38-
version: '0.0.1',
39-
),
36+
implementation: Implementation(name: 'file system', version: '0.0.1'),
4037
);
4138

4239
@override

mcp_examples/bin/workflow_client.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ final class WorkflowClient extends MCPClient with RootsSupport {
107107
stdinQueue = StreamQueue(
108108
stdin.transform(utf8.decoder).transform(const LineSplitter()),
109109
),
110-
super(
111-
ClientImplementation(name: 'Gemini workflow client', version: '0.1.0'),
112-
) {
110+
super(Implementation(name: 'Gemini workflow client', version: '0.1.0')) {
113111
logSink = _createLogSink(logFile);
114112
addRoot(
115113
Root(

mcp_examples/pubspec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ dependencies:
1414
google_generative_ai: ^0.4.7
1515
path: ^1.9.1
1616
stream_channel: ^2.1.4
17+
18+
dependency_overrides:
19+
dart_mcp:
20+
path: ../pkgs/dart_mcp

pkgs/dart_mcp/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
## 0.2.2-wip
1+
## 0.2.2
22

3+
- Refactor `ClientImplementation` and `ServerImplementation` to the shared
4+
`Implementation` type to match the spec. The old names are deprecated but will
5+
still work until the next breaking release.
6+
- Add `clientInfo` field to `MCPServer`, assigned during initialization.
37
- Move the `done` future from the `ServerConnection` into `MCPBase` so it is
48
available to the `MPCServer` class as well.
59

pkgs/dart_mcp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ an error, which may result in a better UX for the users of the client.
3636

3737
To implement a client, import `package:dart_mcp/client.dart` and extend the
3838
`MCPClient` class, or directly call its constructor with a
39-
`ClientImplementation` if you aren't implementing any "capabilities".
39+
`Implementation` if you aren't implementing any "capabilities".
4040

4141
For each specific MCP capability your client supports, there is a corresponding
4242
mixin that you can use (`RootsSupport`, `SamplingSupport`, etc). Each mixin has

pkgs/dart_mcp/example/simple_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:dart_mcp/client.dart';
66

77
void main() async {
88
final client = MCPClient(
9-
ClientImplementation(name: 'example dart client', version: '0.1.0'),
9+
Implementation(name: 'example dart client', version: '0.1.0'),
1010
);
1111
print('connecting to server');
1212
final server = await client.connectStdioServer('dart', [

pkgs/dart_mcp/example/simple_server.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main() {
2929
base class DartMCPServer extends MCPServer with ToolsSupport {
3030
DartMCPServer(super.channel)
3131
: super.fromStreamChannel(
32-
implementation: ServerImplementation(
32+
implementation: Implementation(
3333
name: 'example dart server',
3434
version: '0.1.0',
3535
),

pkgs/dart_mcp/lib/src/api/initialization.dart

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension type InitializeRequest._fromMap(Map<String, Object?> _value)
1313
factory InitializeRequest({
1414
required ProtocolVersion protocolVersion,
1515
required ClientCapabilities capabilities,
16-
required ClientImplementation clientInfo,
16+
required Implementation clientInfo,
1717
MetaWithProgressToken? meta,
1818
}) => InitializeRequest._fromMap({
1919
'protocolVersion': protocolVersion.versionString,
@@ -33,8 +33,7 @@ extension type InitializeRequest._fromMap(Map<String, Object?> _value)
3333
ClientCapabilities get capabilities =>
3434
_value['capabilities'] as ClientCapabilities;
3535

36-
ClientImplementation get clientInfo =>
37-
_value['clientInfo'] as ClientImplementation;
36+
Implementation get clientInfo => _value['clientInfo'] as Implementation;
3837
}
3938

4039
/// After receiving an initialize request from the client, the server sends
@@ -44,7 +43,7 @@ extension type InitializeResult.fromMap(Map<String, Object?> _value)
4443
factory InitializeResult({
4544
required ProtocolVersion protocolVersion,
4645
required ServerCapabilities serverCapabilities,
47-
required ServerImplementation serverInfo,
46+
required Implementation serverInfo,
4847
String? instructions,
4948
}) => InitializeResult.fromMap({
5049
'protocolVersion': protocolVersion.versionString,
@@ -74,8 +73,7 @@ extension type InitializeResult.fromMap(Map<String, Object?> _value)
7473
ServerCapabilities get capabilities =>
7574
_value['capabilities'] as ServerCapabilities;
7675

77-
ServerImplementation get serverInfo =>
78-
_value['serverInfo'] as ServerImplementation;
76+
Implementation get serverInfo => _value['serverInfo'] as Implementation;
7977

8078
/// Instructions describing how to use the server and its features.
8179
///
@@ -295,24 +293,17 @@ extension type Tools.fromMap(Map<String, Object?> _value) {
295293
}
296294
}
297295

298-
/// Describes the name and version of an MCP client implementation.
299-
extension type ClientImplementation.fromMap(Map<String, Object?> _value) {
300-
factory ClientImplementation({
301-
required String name,
302-
required String version,
303-
}) => ClientImplementation.fromMap({'name': name, 'version': version});
296+
/// Describes the name and version of an MCP implementation.
297+
extension type Implementation.fromMap(Map<String, Object?> _value) {
298+
factory Implementation({required String name, required String version}) =>
299+
Implementation.fromMap({'name': name, 'version': version});
304300

305301
String get name => _value['name'] as String;
306302
String get version => _value['version'] as String;
307303
}
308304

309-
/// Describes the name and version of an MCP server implementation.
310-
extension type ServerImplementation.fromMap(Map<String, Object?> _value) {
311-
factory ServerImplementation({
312-
required String name,
313-
required String version,
314-
}) => ServerImplementation.fromMap({'name': name, 'version': version});
305+
@Deprecated('Use Implementation instead.')
306+
typedef ClientImplementation = Implementation;
315307

316-
String get name => _value['name'] as String;
317-
String get version => _value['version'] as String;
318-
}
308+
@Deprecated('Use Implementation instead.')
309+
typedef ServerImplementation = Implementation;

pkgs/dart_mcp/lib/src/client/client.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ part 'sampling_support.dart';
2929
/// this will be invoked at the end of base class constructor.
3030
base class MCPClient {
3131
/// A description of the client sent to servers during initialization.
32-
final ClientImplementation implementation;
32+
final Implementation implementation;
3333

3434
MCPClient(this.implementation) {
3535
initialize();
@@ -128,10 +128,10 @@ base class ServerConnection extends MCPBase {
128128
/// protocol version.
129129
late ProtocolVersion protocolVersion;
130130

131-
/// The [ServerImplementation] returned from the [initialize] request.
131+
/// The [Implementation] returned from the [initialize] request.
132132
///
133133
/// Only non-null after [initialize] has successfully completed.
134-
ServerImplementation? serverInfo;
134+
Implementation? serverInfo;
135135

136136
/// The [ServerCapabilities] returned from the [initialize] request.
137137
///

pkgs/dart_mcp/lib/src/client/sampling_support.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ base mixin SamplingSupport on MCPClient {
2626
/// request gave when it was initialized.
2727
FutureOr<CreateMessageResult> handleCreateMessage(
2828
CreateMessageRequest request,
29-
ServerImplementation serverInfo,
29+
Implementation serverInfo,
3030
);
3131
}

0 commit comments

Comments
 (0)