-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathBaseResource.ts
More file actions
43 lines (39 loc) · 1.04 KB
/
BaseResource.ts
File metadata and controls
43 lines (39 loc) · 1.04 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
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
import type {
ReadResourceResult,
ServerNotification,
ServerRequest
} from '@modelcontextprotocol/sdk/types.js';
/**
* Base class for MCP resources
*/
export abstract class BaseResource {
abstract readonly name: string;
abstract readonly uri: string;
abstract readonly description: string;
abstract readonly mimeType: string;
/**
* Install this resource to the MCP server
*/
installTo(server: McpServer): void {
server.registerResource(
this.name,
this.uri,
{
description: this.description,
mimeType: this.mimeType
},
this.readCallback.bind(this)
);
}
/**
* Callback to read the resource content
*/
public abstract readCallback(
uri: URL,
extra: RequestHandlerExtra<ServerRequest, ServerNotification>
): Promise<ReadResourceResult>;
}