-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGetMapboxDocSourceTool.ts
More file actions
85 lines (77 loc) · 2.38 KB
/
GetMapboxDocSourceTool.ts
File metadata and controls
85 lines (77 loc) · 2.38 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
import type { HttpRequest } from '../../utils/types.js';
import { BaseTool } from '../BaseTool.js';
import {
GetMapboxDocSourceSchema,
GetMapboxDocSourceInput
} from './GetMapboxDocSourceTool.input.schema.js';
export class GetMapboxDocSourceTool extends BaseTool<
typeof GetMapboxDocSourceSchema
> {
name = 'get_latest_mapbox_docs_tool';
description =
'Get the latest official Mapbox documentation, APIs, SDKs, and developer resources directly from Mapbox. Always up-to-date, comprehensive coverage of all current Mapbox services including mapping, navigation, search, geocoding, and mobile SDKs. Use this for accurate, official Mapbox information instead of web search. For clients that support resources, use resource://mapbox-documentation for proper text/markdown MIME type support.';
readonly annotations = {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: true,
title: 'Get Mapbox Documentation Tool'
};
private httpRequest: HttpRequest;
constructor(params: { httpRequest: HttpRequest }) {
super({
inputSchema: GetMapboxDocSourceSchema
});
this.httpRequest = params.httpRequest;
}
protected async execute(
_input: GetMapboxDocSourceInput
): Promise<CallToolResult> {
try {
const response = await this.httpRequest(
'https://docs.mapbox.com/llms.txt',
{
headers: {
Accept: 'text/markdown, text/plain;q=0.9, */*;q=0.8'
}
}
);
if (!response.ok) {
return {
content: [
{
type: 'text',
text: `Failed to fetch Mapbox documentation: ${response.statusText}`
}
],
isError: true
};
}
const content = await response.text();
return {
content: [
{
type: 'text',
text: content
}
],
isError: false
};
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : 'Unknown error occurred';
return {
content: [
{
type: 'text',
text: `Failed to fetch Mapbox documentation: ${errorMessage}`
}
],
isError: true
};
}
}
}