-
Notifications
You must be signed in to change notification settings - Fork 18
add analytics support to the Dart MCP server #174
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
Draft
jakemac53
wants to merge
6
commits into
main
Choose a base branch
from
analytics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c575b9a
add analytics support to the Dart MCP server
jakemac53 d013e3c
Merge branch 'main' into analytics
jakemac53 a33b871
Merge branch 'main' into analytics
jakemac53 01fbfcd
use the shared clientInfo field
jakemac53 7445996
code review updates
jakemac53 f0fd70f
Merge branch 'main' into analytics
jakemac53 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// 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:unified_analytics/unified_analytics.dart'; | ||
|
||
/// An interface class that provides a access to an [Analytics] instance, if | ||
/// enabled. | ||
/// | ||
/// The `DartMCPServer` class implements this class so that [Analytics] | ||
/// methods can be easily mocked during testing. | ||
abstract interface class AnalyticsSupport { | ||
Analytics? get analytics; | ||
} | ||
|
||
enum AnalyticsEvent { callTool, readResource } | ||
|
||
/// The metrics for a resources/read MCP handler. | ||
final class ReadResourceMetrics extends CustomMetrics { | ||
jakemac53 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// The kind of resource that was read. | ||
/// | ||
/// We don't want to record the full URI. | ||
final ResourceKind kind; | ||
|
||
/// The length of the resource. | ||
final int length; | ||
|
||
/// The time it took to read the resource. | ||
final int elapsedMilliseconds; | ||
|
||
ReadResourceMetrics({ | ||
required this.kind, | ||
required this.length, | ||
required this.elapsedMilliseconds, | ||
}); | ||
|
||
@override | ||
Map<String, Object> toMap() => { | ||
_kind: kind.name, | ||
_length: length, | ||
_elapsedMilliseconds: elapsedMilliseconds, | ||
}; | ||
} | ||
|
||
/// The metrics for a tools/call MCP handler. | ||
final class CallToolMetrics extends CustomMetrics { | ||
/// The name of the tool that was invoked. | ||
final String tool; | ||
|
||
/// Whether or not the tool call succeeded. | ||
final bool success; | ||
|
||
/// The time it took to invoke the tool. | ||
final int elapsedMilliseconds; | ||
|
||
CallToolMetrics({ | ||
required this.tool, | ||
required this.success, | ||
required this.elapsedMilliseconds, | ||
}); | ||
|
||
@override | ||
Map<String, Object> toMap() => { | ||
_tool: tool, | ||
_success: success, | ||
_elapsedMilliseconds: elapsedMilliseconds, | ||
}; | ||
} | ||
|
||
enum ResourceKind { runtimeErrors } | ||
|
||
const _elapsedMilliseconds = 'elapsedMilliseconds'; | ||
const _kind = 'kind'; | ||
const _length = 'length'; | ||
const _success = 'success'; | ||
const _tool = 'tool'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we actually create the Analytics instance here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are allowed to that would simplify things, otherwise we need a custom entry point in the SDK which does create one.
I just don't know if it is kosher or not, it feels a bit weird to be putting the current tool as the
dartTool
, when this is actually a binary that can be ran in other ways (from source, or as a git dep).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @anderdobo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option would be a command line flag to enable analytics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we look up the resolved executable to see if the starting script was from the
dart mcp-server
command?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, we will just get the dart native runtime as the resolved executable afaik.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Then if we need to use the Dart CLI as the parent tool, adding a hidden flag that is set from the dart mcp-server command only could be a good workaround. We should get clarity on that first from Ander though.