dbx-mcp-server
Version:
A Model Context Protocol server for Dropbox integration with AI-powered PDF analysis, multi-directory indexing, and parallel processing
64 lines • 2.32 kB
JavaScript
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
import { ResourceResolver } from './resource-resolver.js';
export class ResourceHandler {
constructor() {
this.resolver = new ResourceResolver();
}
async listResources(path, options = {}) {
try {
const uri = `dbx://${path}`;
const contents = await this.resolver.resolveCollection(uri, options);
return contents.map(content => ({
type: content.mimeType === 'application/x-directory' ? 'collection' :
options.asAttachment ? 'attachment' : 'inline',
uri: content.uri,
content: options.includeContent ? content : undefined
}));
}
catch (error) {
throw new McpError(ErrorCode.InternalError, `Failed to list resources: ${error.message}`);
}
}
async readResource(uri, options = {}) {
try {
return await this.resolver.resolveResource(uri, options);
}
catch (error) {
throw new McpError(ErrorCode.InternalError, `Failed to read resource: ${error.message}`);
}
}
async readCollection(uri) {
try {
return await this.resolver.resolveCollection(uri, {
recursive: true,
includeContent: true
});
}
catch (error) {
throw new McpError(ErrorCode.InternalError, `Failed to read collection: ${error.message}`);
}
}
// Helper method to process resources for a prompt
async processPromptResources(resources) {
try {
await this.resolver.processResources({ resources, name: 'temp' });
}
catch (error) {
throw new McpError(ErrorCode.InternalError, `Failed to process prompt resources: ${error.message}`);
}
}
// Helper method to handle binary files
async readBinaryResource(uri) {
return this.readResource(uri, {
encoding: 'base64'
});
}
// Helper method to filter resources by type
async listResourcesByType(path, extensions) {
return this.listResources(path, {
filter: extensions,
includeContent: false
});
}
}
//# sourceMappingURL=resource-handler.js.map