import { ChangerawrClient } from '../client/changerawr-client.js';
// Resource interface
export interface MCPResource {
uri: string;
name: string;
description: string;
mimeType: string;
read: (uri: string, client: ChangerawrClient) => Promise<any>;
}
// Import individual resources
import { projectListResource } from './project-resources.js';
import { changelogResource } from './changelog-resources.js';
// Resource registry class
class ResourceRegistry {
private resources: Map<string, MCPResource> = new Map();
constructor() {
this.registerResources();
}
private registerResources() {
// Project resources
this.register(projectListResource);
// Changelog resources
this.register(changelogResource);
}
register(resource: MCPResource) {
this.resources.set(resource.uri, resource);
}
getResourceByUri(uri: string): MCPResource | undefined {
// Check for exact match first
if (this.resources.has(uri)) {
return this.resources.get(uri);
}
// Check for pattern matches
for (const [pattern, resource] of this.resources.entries()) {
if (this.matchesPattern(pattern, uri)) {
return resource;
}
}
return undefined;
}
private matchesPattern(pattern: string, uri: string): boolean {
// Convert pattern to regex (simple implementation)
// changerawr://projects/{projectId} -> ^changerawr://projects/([^/]+)$
const regexPattern = pattern
.replace(/\{[^}]+\}/g, '([^/]+)')
.replace(/\//g, '\\/')
.replace(/\./g, '\\.');
const regex = new RegExp(`^${regexPattern}$`);
return regex.test(uri);
}
getResourceDefinitions() {
return Array.from(this.resources.values()).map(resource => ({
uri: resource.uri,
name: resource.name,
description: resource.description,
mimeType: resource.mimeType,
}));
}
listResourceUris(): string[] {
return Array.from(this.resources.keys());
}
}
// Export singleton instance
export const resourceRegistry = new ResourceRegistry();