-
Notifications
You must be signed in to change notification settings - Fork 49
Add MCP endpoint for audit and failed messages #5391
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
Open
WilliamBZA
wants to merge
35
commits into
master
Choose a base branch
from
add-mcp
base: master
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.
Open
Changes from 12 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
2189e04
Add failed message MCP server
WilliamBZA 1c80991
Add feature flag check for MCP
WilliamBZA 7b47a30
Update to v1.1.0 of ModelContextProtocol.AspNetCore
WilliamBZA 5c5645e
Turn MCP off by default
WilliamBZA 2c00d5e
Put packages in alphabetical order
WilliamBZA e4ab0ea
Update approvals
WilliamBZA 4c8ecda
Don't pass the full settings object in
WilliamBZA add9235
Add failed message MCP server
WilliamBZA ae22f8a
Use /mcp as the route
WilliamBZA a160b4d
Add MCP for audit
WilliamBZA 5da1181
Remove duplicate project reference
WilliamBZA 49d946b
Update approvals
WilliamBZA 312e2a7
Add test
WilliamBZA fbc8a00
Move to approvals
WilliamBZA 481de0d
Move tests to use POCOs
WilliamBZA 7e014b5
Move packages to be in alphabetical order
WilliamBZA 9bf1cbc
Add unit tests for MCP
WilliamBZA fe4d19a
Add primary acceptance tests
WilliamBZA 0efd5dc
Update MCP descriptions
WilliamBZA 97b03b6
Add approval file
WilliamBZA a12b134
Update audit approval files
WilliamBZA 92a4624
Update raven audit approval
WilliamBZA 23165d4
Order approval files
WilliamBZA 2a920c8
Add logging
WilliamBZA a788827
Improve MCP metadata guidance for AI clients (#5402)
danielmarbach 06d9e45
Align wording order
danielmarbach 5a43098
Return typed structured content for MCP tools while preserving text c…
danielmarbach 537bc13
Add MCP source-generated JSON contexts
danielmarbach 2959499
Removed unused options type
danielmarbach eb44439
Only enable destructive actions if explicitly set
WilliamBZA 7c71b5d
Don't use backing field
WilliamBZA 72996f4
Don't load tools from assembly
WilliamBZA 83fb9b5
Add MCP environment data provider
johnsimons 456b966
Forgot to register it!
johnsimons 732568a
Merge pull request #5413 from Particular/john/data
johnsimons 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
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,147 @@ | ||
| #nullable enable | ||
|
|
||
| namespace ServiceControl.Audit.Mcp; | ||
|
|
||
| using System.ComponentModel; | ||
| using System.Text.Json; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Infrastructure; | ||
| using ModelContextProtocol.Server; | ||
| using Persistence; | ||
|
|
||
| [McpServerToolType] | ||
|
danielmarbach marked this conversation as resolved.
Outdated
|
||
| public class AuditMessageTools(IAuditDataStore store) | ||
| { | ||
| [McpServerTool, Description("Get a list of successfully processed audit messages. Supports paging and sorting. Returns message metadata including endpoints, timing information, and message type.")] | ||
|
danielmarbach marked this conversation as resolved.
Outdated
|
||
| public async Task<string> GetAuditMessages( | ||
| [Description("Whether to include system messages in results. Default is false")] bool includeSystemMessages = false, | ||
| [Description("Page number (1-based). Default is 1")] int page = 1, | ||
| [Description("Number of results per page. Default is 50")] int perPage = 50, | ||
| [Description("Sort field: time_sent, processed_at, message_type, critical_time, delivery_time, processing_time. Default is time_sent")] string sort = "time_sent", | ||
| [Description("Sort direction: asc or desc. Default is desc")] string direction = "desc", | ||
| [Description("Filter by time sent start (ISO 8601 format)")] string? timeSentFrom = null, | ||
| [Description("Filter by time sent end (ISO 8601 format)")] string? timeSentTo = null, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var pagingInfo = new PagingInfo(page, perPage); | ||
| var sortInfo = new SortInfo(sort, direction); | ||
| var timeSentRange = new DateTimeRange(timeSentFrom, timeSentTo); | ||
|
|
||
| var results = await store.GetMessages(includeSystemMessages, pagingInfo, sortInfo, timeSentRange, cancellationToken); | ||
|
|
||
| return JsonSerializer.Serialize(new | ||
| { | ||
| results.QueryStats.TotalCount, | ||
| results.Results | ||
| }, McpJsonOptions.Default); | ||
| } | ||
|
|
||
| [McpServerTool, Description("Search audit messages by a keyword or phrase. Searches across message content and metadata.")] | ||
|
danielmarbach marked this conversation as resolved.
Outdated
|
||
| public async Task<string> SearchAuditMessages( | ||
| [Description("The search query string")] string query, | ||
| [Description("Page number (1-based). Default is 1")] int page = 1, | ||
| [Description("Number of results per page. Default is 50")] int perPage = 50, | ||
| [Description("Sort field: time_sent, processed_at, message_type, critical_time, delivery_time, processing_time. Default is time_sent")] string sort = "time_sent", | ||
| [Description("Sort direction: asc or desc. Default is desc")] string direction = "desc", | ||
| [Description("Filter by time sent start (ISO 8601 format)")] string? timeSentFrom = null, | ||
| [Description("Filter by time sent end (ISO 8601 format)")] string? timeSentTo = null, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var pagingInfo = new PagingInfo(page, perPage); | ||
| var sortInfo = new SortInfo(sort, direction); | ||
| var timeSentRange = new DateTimeRange(timeSentFrom, timeSentTo); | ||
|
|
||
| var results = await store.QueryMessages(query, pagingInfo, sortInfo, timeSentRange, cancellationToken); | ||
|
|
||
| return JsonSerializer.Serialize(new | ||
| { | ||
| results.QueryStats.TotalCount, | ||
| results.Results | ||
| }, McpJsonOptions.Default); | ||
| } | ||
|
|
||
| [McpServerTool, Description("Get audit messages received by a specific endpoint. Can optionally filter by keyword.")] | ||
| public async Task<string> GetAuditMessagesByEndpoint( | ||
| [Description("The name of the receiving endpoint")] string endpointName, | ||
| [Description("Optional keyword to filter messages")] string? keyword = null, | ||
| [Description("Whether to include system messages in results. Default is false")] bool includeSystemMessages = false, | ||
| [Description("Page number (1-based). Default is 1")] int page = 1, | ||
| [Description("Number of results per page. Default is 50")] int perPage = 50, | ||
| [Description("Sort field: time_sent, processed_at, message_type, critical_time, delivery_time, processing_time. Default is time_sent")] string sort = "time_sent", | ||
| [Description("Sort direction: asc or desc. Default is desc")] string direction = "desc", | ||
| [Description("Filter by time sent start (ISO 8601 format)")] string? timeSentFrom = null, | ||
| [Description("Filter by time sent end (ISO 8601 format)")] string? timeSentTo = null, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var pagingInfo = new PagingInfo(page, perPage); | ||
| var sortInfo = new SortInfo(sort, direction); | ||
| var timeSentRange = new DateTimeRange(timeSentFrom, timeSentTo); | ||
|
|
||
| var results = keyword != null | ||
| ? await store.QueryMessagesByReceivingEndpointAndKeyword(endpointName, keyword, pagingInfo, sortInfo, timeSentRange, cancellationToken) | ||
| : await store.QueryMessagesByReceivingEndpoint(includeSystemMessages, endpointName, pagingInfo, sortInfo, timeSentRange, cancellationToken); | ||
|
|
||
| return JsonSerializer.Serialize(new | ||
| { | ||
| results.QueryStats.TotalCount, | ||
| results.Results | ||
| }, McpJsonOptions.Default); | ||
| } | ||
|
|
||
| [McpServerTool, Description("Get all audit messages that belong to a specific conversation. A conversation groups related messages that were triggered by the same initial message.")] | ||
| public async Task<string> GetAuditMessagesByConversation( | ||
| [Description("The conversation ID to filter by")] string conversationId, | ||
| [Description("Page number (1-based). Default is 1")] int page = 1, | ||
| [Description("Number of results per page. Default is 50")] int perPage = 50, | ||
| [Description("Sort field: time_sent, processed_at, message_type, critical_time, delivery_time, processing_time. Default is time_sent")] string sort = "time_sent", | ||
| [Description("Sort direction: asc or desc. Default is desc")] string direction = "desc", | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var pagingInfo = new PagingInfo(page, perPage); | ||
| var sortInfo = new SortInfo(sort, direction); | ||
|
|
||
| var results = await store.QueryMessagesByConversationId(conversationId, pagingInfo, sortInfo, cancellationToken); | ||
|
|
||
| return JsonSerializer.Serialize(new | ||
| { | ||
| results.QueryStats.TotalCount, | ||
| results.Results | ||
| }, McpJsonOptions.Default); | ||
| } | ||
|
|
||
| [McpServerTool, Description("Get the body content of a specific audit message by its message ID.")] | ||
| public async Task<string> GetAuditMessageBody( | ||
| [Description("The message ID")] string messageId, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var result = await store.GetMessageBody(messageId, cancellationToken); | ||
|
|
||
| if (!result.Found) | ||
| { | ||
| return JsonSerializer.Serialize(new { Error = $"Message '{messageId}' not found." }, McpJsonOptions.Default); | ||
| } | ||
|
|
||
| if (!result.HasContent) | ||
| { | ||
| return JsonSerializer.Serialize(new { Error = $"Message '{messageId}' has no body content." }, McpJsonOptions.Default); | ||
| } | ||
|
|
||
| if (result.StringContent != null) | ||
| { | ||
| return JsonSerializer.Serialize(new | ||
| { | ||
| result.ContentType, | ||
| result.ContentLength, | ||
| Body = result.StringContent | ||
| }, McpJsonOptions.Default); | ||
| } | ||
|
|
||
| return JsonSerializer.Serialize(new | ||
| { | ||
| result.ContentType, | ||
| result.ContentLength, | ||
| Body = "(stream content - not available as text)" | ||
| }, McpJsonOptions.Default); | ||
| } | ||
| } | ||
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,40 @@ | ||
| #nullable enable | ||
|
|
||
| namespace ServiceControl.Audit.Mcp; | ||
|
|
||
| using System.ComponentModel; | ||
| using System.Text.Json; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using ModelContextProtocol.Server; | ||
| using Persistence; | ||
|
|
||
| [McpServerToolType] | ||
| public class EndpointTools(IAuditDataStore store) | ||
| { | ||
| [McpServerTool, Description("Get a list of all known endpoints that have sent or received audit messages.")] | ||
| public async Task<string> GetKnownEndpoints(CancellationToken cancellationToken = default) | ||
| { | ||
| var results = await store.QueryKnownEndpoints(cancellationToken); | ||
|
|
||
| return JsonSerializer.Serialize(new | ||
| { | ||
| results.QueryStats.TotalCount, | ||
| results.Results | ||
| }, McpJsonOptions.Default); | ||
| } | ||
|
|
||
| [McpServerTool, Description("Get audit message counts per day for a specific endpoint. Useful for understanding message throughput.")] | ||
| public async Task<string> GetEndpointAuditCounts( | ||
| [Description("The name of the endpoint")] string endpointName, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var results = await store.QueryAuditCounts(endpointName, cancellationToken); | ||
|
|
||
| return JsonSerializer.Serialize(new | ||
| { | ||
| results.QueryStats.TotalCount, | ||
| results.Results | ||
| }, McpJsonOptions.Default); | ||
| } | ||
| } |
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,16 @@ | ||
| #nullable enable | ||
|
|
||
| namespace ServiceControl.Audit.Mcp; | ||
|
|
||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| static class McpJsonOptions | ||
| { | ||
| public static JsonSerializerOptions Default { get; } = new() | ||
| { | ||
| PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, | ||
| WriteIndented = false | ||
| }; | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.