Skip to content

Commit e471c9e

Browse files
Merge pull request #17 from OpsLevel/andrew/add-docs-tools
Add tool support for document queries
2 parents d2ac4a1 + 18aeb0f commit e471c9e

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/cmd/root.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,56 @@ var rootCmd = &cobra.Command{
166166
return newToolResult(resp, err)
167167
})
168168

169+
// Register all documents, filtered by search term
170+
s.AddTool(
171+
mcp.NewTool("documents",
172+
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."),
173+
mcp.WithString("searchTerm", mcp.Description("To filter documents with.")),
174+
),
175+
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
176+
searchTerm := ""
177+
if req.Params.Arguments["searchTerm"] != nil {
178+
searchTerm = req.Params.Arguments["searchTerm"].(string)
179+
}
180+
variables := getListDocumentPayloadVariables(searchTerm)
181+
resp, err := client.ListDocuments(&variables)
182+
return newToolResult(resp.Nodes, err)
183+
})
184+
185+
// Register document by id
186+
s.AddTool(
187+
mcp.NewTool("document",
188+
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."),
189+
mcp.WithString("id", mcp.Required(), mcp.Description("The id of the document to fetch.")),
190+
),
191+
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
192+
id := req.Params.Arguments["id"].(string)
193+
resp, err := client.GetDocument(opslevel.ID(id))
194+
return newToolResult(resp, err)
195+
})
196+
197+
// Register all documents, filtered by service id and search term
198+
s.AddTool(
199+
mcp.NewTool("documentsOnService",
200+
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."),
201+
mcp.WithString("serviceId", mcp.Required(), mcp.Description("The id of the service which the documents are on.")),
202+
mcp.WithString("searchTerm", mcp.Description("To filter documents with.")),
203+
),
204+
func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
205+
service := opslevel.Service{
206+
ServiceId: opslevel.ServiceId{
207+
Id: opslevel.ID(req.Params.Arguments["serviceId"].(string)),
208+
},
209+
}
210+
searchTerm := ""
211+
if req.Params.Arguments["searchTerm"] != nil {
212+
searchTerm = req.Params.Arguments["searchTerm"].(string)
213+
}
214+
variables := getListDocumentPayloadVariables(searchTerm)
215+
resp, err := service.GetDocuments(client, &variables)
216+
return newToolResult(resp, err)
217+
})
218+
169219
log.Info().Msg("Starting MCP server...")
170220
if err := server.ServeStdio(s); err != nil {
171221
if err == context.Canceled {
@@ -229,3 +279,11 @@ func setupLogging() {
229279
zerolog.SetGlobalLevel(zerolog.InfoLevel)
230280
}
231281
}
282+
283+
func getListDocumentPayloadVariables(searchTerm string) opslevel.PayloadVariables {
284+
return opslevel.PayloadVariables{
285+
"searchTerm": searchTerm,
286+
"after": "",
287+
"first": 100,
288+
}
289+
}

0 commit comments

Comments
 (0)