Initial commit: Setting up OpenRouter MCP server for multimodal capabilities
This commit is contained in:
54
src/tool-handlers/get-model-info.ts
Normal file
54
src/tool-handlers/get-model-info.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { McpError } from '@modelcontextprotocol/sdk/types.js';
|
||||
import { ModelCache } from '../model-cache.js';
|
||||
|
||||
export interface GetModelInfoToolRequest {
|
||||
model: string;
|
||||
}
|
||||
|
||||
export async function handleGetModelInfo(
|
||||
request: { params: { arguments: GetModelInfoToolRequest } },
|
||||
modelCache: ModelCache
|
||||
) {
|
||||
const args = request.params.arguments;
|
||||
|
||||
try {
|
||||
if (!modelCache.isCacheValid()) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Model cache is empty or expired. Please call search_models first to populate the cache.',
|
||||
},
|
||||
],
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
|
||||
const model = modelCache.getModel(args.model);
|
||||
if (!model) {
|
||||
throw new McpError('NotFound', `Model '${args.model}' not found`);
|
||||
}
|
||||
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: JSON.stringify(model, null, 2),
|
||||
},
|
||||
],
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Error retrieving model info: ${error.message}`,
|
||||
},
|
||||
],
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user