mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-02-19 11:54:58 -05:00
fix: register all resources individually for listings
Resources are now registered individually so they appear in
resources/list responses, while also keeping the template for
dynamic access via test://static/resource/{id}.
This commit is contained in:
@@ -257,14 +257,51 @@ export const createServer = () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Register resource using modern API with a template pattern
|
||||
// Register all 100 resources individually so they appear in listings
|
||||
for (let i = 0; i < ALL_RESOURCES.length; i++) {
|
||||
const resource = ALL_RESOURCES[i];
|
||||
const resourceId = i + 1;
|
||||
|
||||
server.registerResource(
|
||||
`static-resource-${resourceId}`,
|
||||
resource.uri,
|
||||
{
|
||||
name: resource.name,
|
||||
description: `Resource ${resourceId}: ${resource.mimeType === "text/plain" ? "plaintext resource" : "binary blob resource"}`,
|
||||
mimeType: resource.mimeType,
|
||||
},
|
||||
async () => {
|
||||
// Build the resource contents based on type
|
||||
if ('text' in resource && resource.text) {
|
||||
return {
|
||||
contents: [{
|
||||
uri: resource.uri,
|
||||
mimeType: resource.mimeType,
|
||||
text: resource.text as string,
|
||||
}],
|
||||
};
|
||||
} else if ('blob' in resource && resource.blob) {
|
||||
return {
|
||||
contents: [{
|
||||
uri: resource.uri,
|
||||
mimeType: resource.mimeType,
|
||||
blob: resource.blob as string,
|
||||
}],
|
||||
};
|
||||
}
|
||||
throw new Error(`Resource ${resource.uri} has neither text nor blob`);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Also register a template for the same pattern to support dynamic access
|
||||
server.registerResource(
|
||||
'static-resources',
|
||||
'static-resources-template',
|
||||
new ResourceTemplate('test://static/resource/{id}', { list: undefined }),
|
||||
{
|
||||
description: 'A static test resource with a numeric ID',
|
||||
},
|
||||
async (uri, variables, extra) => {
|
||||
async (uri, variables) => {
|
||||
const id = Array.isArray(variables.id) ? variables.id[0] : variables.id;
|
||||
const index = parseInt(id, 10) - 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user