-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMapboxDocumentationResource.ts
More file actions
68 lines (60 loc) · 1.93 KB
/
MapboxDocumentationResource.ts
File metadata and controls
68 lines (60 loc) · 1.93 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
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
import type {
ReadResourceResult,
ServerNotification,
ServerRequest
} from '@modelcontextprotocol/sdk/types.js';
import type { HttpRequest } from '../../utils/types.js';
import { BaseResource } from '../BaseResource.js';
/**
* Resource providing the latest official Mapbox documentation
* fetched from docs.mapbox.com/llms.txt
*/
export class MapboxDocumentationResource extends BaseResource {
readonly name = 'Mapbox Documentation';
readonly uri = 'resource://mapbox-documentation';
readonly description =
'Latest official Mapbox documentation, APIs, SDKs, and developer resources. Always up-to-date comprehensive coverage of all current Mapbox services.';
readonly mimeType = 'text/markdown';
private httpRequest: HttpRequest;
constructor(params: { httpRequest: HttpRequest }) {
super();
this.httpRequest = params.httpRequest;
}
public async readCallback(
uri: URL,
_extra: RequestHandlerExtra<ServerRequest, ServerNotification>
): Promise<ReadResourceResult> {
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) {
throw new Error(
`Failed to fetch Mapbox documentation: ${response.statusText}`
);
}
const content = await response.text();
return {
contents: [
{
uri: uri.href,
mimeType: this.mimeType,
text: content
}
]
};
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : 'Unknown error occurred';
throw new Error(`Failed to fetch Mapbox documentation: ${errorMessage}`);
}
}
}