-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDeleteStyleTool.ts
More file actions
57 lines (50 loc) · 1.64 KB
/
Copy pathDeleteStyleTool.ts
File metadata and controls
57 lines (50 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
import type { HttpRequest } from '../../utils/types.js';
import type { ToolExecutionContext } from '../../utils/tracing.js';
import { getUserNameFromToken } from '../../utils/jwtUtils.js';
import { MapboxApiBasedTool } from '../MapboxApiBasedTool.js';
import {
DeleteStyleSchema,
DeleteStyleInput
} from './DeleteStyleTool.input.schema.js';
export class DeleteStyleTool extends MapboxApiBasedTool<
typeof DeleteStyleSchema
> {
name = 'delete_style_tool';
description = 'Delete a Mapbox style by ID';
readonly annotations = {
readOnlyHint: false,
destructiveHint: true,
idempotentHint: true,
openWorldHint: true,
title: 'Delete Mapbox Style Tool'
};
constructor(params: { httpRequest: HttpRequest }) {
super({ inputSchema: DeleteStyleSchema, httpRequest: params.httpRequest });
}
protected async execute(
input: DeleteStyleInput,
accessToken: string,
_context: ToolExecutionContext
): Promise<CallToolResult> {
const username = getUserNameFromToken(accessToken);
const url = `${MapboxApiBasedTool.mapboxApiEndpoint}styles/v1/${encodeURIComponent(username)}/${encodeURIComponent(input.styleId)}?access_token=${accessToken}`;
const response = await this.httpRequest(url, {
method: 'DELETE'
});
if (response.status !== 204) {
return this.handleApiError(response, 'delete style');
}
return {
content: [
{
type: 'text',
text: 'Style deleted successfully'
}
],
isError: false
};
}
}