-
Notifications
You must be signed in to change notification settings - Fork 7
Add tool support for document queries #17
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
Changes from all commits
2fa814b
b25ddc9
3704e12
d56c56f
2277122
cf37b1e
45d0e3c
bc2e18c
18aeb0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,56 @@ var rootCmd = &cobra.Command{ | |
| return newToolResult(resp, err) | ||
| }) | ||
|
|
||
| // Register all documents, filtered by search term | ||
| s.AddTool( | ||
| mcp.NewTool("documents", | ||
| mcp.WithDescription("Get all the documents for the opslevel account. Documents are filterable by search term. Documents could be things like runbooks, integration documentation, api documentation, readme's, or other forms of documentation."), | ||
| mcp.WithString("searchTerm", mcp.Description("To filter documents with.")), | ||
| ), | ||
| func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
| searchTerm := "" | ||
| if req.Params.Arguments["searchTerm"] != nil { | ||
| searchTerm = req.Params.Arguments["searchTerm"].(string) | ||
| } | ||
| variables := getListDocumentPayloadVariables(searchTerm) | ||
| resp, err := client.ListDocuments(&variables) | ||
| return newToolResult(resp.Nodes, err) | ||
| }) | ||
|
|
||
| // Register document by id | ||
| s.AddTool( | ||
| mcp.NewTool("document", | ||
| mcp.WithDescription("Get document contents for the opslevel account, specified by id. Documents could be things like runbooks, integration documentation, api documentation, readme's, or other forms of documentation."), | ||
| mcp.WithString("id", mcp.Required(), mcp.Description("The id of the document to fetch.")), | ||
| ), | ||
| func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
| id := req.Params.Arguments["id"].(string) | ||
| resp, err := client.GetDocument(opslevel.ID(id)) | ||
| return newToolResult(resp, err) | ||
| }) | ||
|
|
||
| // Register all documents, filtered by service id and search term | ||
| s.AddTool( | ||
| mcp.NewTool("documentsOnService", | ||
| mcp.WithDescription("Get all documents on a specified service for the opslevel account, specified by service id and filtered by search term. Documents could be things like runbooks, integration documentation, api documentation, readme's, or other forms of documentation."), | ||
| mcp.WithString("serviceId", mcp.Required(), mcp.Description("The id of the service which the documents are on.")), | ||
| mcp.WithString("searchTerm", mcp.Description("To filter documents with.")), | ||
| ), | ||
| func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
| service := opslevel.Service{ | ||
| ServiceId: opslevel.ServiceId{ | ||
| Id: opslevel.ID(req.Params.Arguments["serviceId"].(string)), | ||
| }, | ||
| } | ||
| searchTerm := "" | ||
| if req.Params.Arguments["searchTerm"] != nil { | ||
| searchTerm = req.Params.Arguments["searchTerm"].(string) | ||
| } | ||
| variables := getListDocumentPayloadVariables(searchTerm) | ||
| resp, err := service.GetDocuments(client, &variables) | ||
| return newToolResult(resp, err) | ||
| }) | ||
|
|
||
| log.Info().Msg("Starting MCP server...") | ||
| if err := server.ServeStdio(s); err != nil { | ||
| if err == context.Canceled { | ||
|
|
@@ -228,3 +278,11 @@ func setupLogging() { | |
| zerolog.SetGlobalLevel(zerolog.InfoLevel) | ||
| } | ||
| } | ||
|
|
||
| func getListDocumentPayloadVariables(searchTerm string) opslevel.PayloadVariables { | ||
| return opslevel.PayloadVariables{ | ||
| "searchTerm": searchTerm, | ||
| "after": "", | ||
| "first": 100, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to specify
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears the pattern is only if you pass https://github.com/OpsLevel/opslevel-go/blob/main/document.go#L38
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll put up an MR in opslevel-go to change this in documents (and the other spots where this pattern exists too)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is being held up by some ci issues in opslevel go. IMO we should move forwards for now without this change.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree |
||
| } | ||
| } | ||
| +3 −3 | actions.go | |
| +1 −1 | category.go | |
| +1 −1 | check.go | |
| +2 −2 | component.go | |
| +2 −2 | dependencies.go | |
| +49 −1 | document.go | |
| +3 −3 | domain.go | |
| +1 −1 | filters.go | |
| +3 −3 | infra.go | |
| +1 −1 | integration.go | |
| +1 −1 | level.go | |
| +1 −1 | maturity.go | |
| +2 −2 | property.go | |
| +4 −4 | repository.go | |
| +2 −2 | scorecards.go | |
| +1 −1 | secrets.go | |
| +17 −14 | service.go | |
| +4 −4 | service_test.go | |
| +3 −3 | system.go | |
| +4 −4 | team.go | |
| +3 −3 | user.go |
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'm curious what type this is coming in as, that it needs casting to string?
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.
Probably
anyand sincesearchTerm := ""is a string its neededThere 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.
That's correct, it's
any.